diff --git a/build.gradle b/build.gradle index 2e13094403..d0347e6f08 100644 --- a/build.gradle +++ b/build.gradle @@ -107,7 +107,8 @@ configure([rootProject] + javaProjects) { project -> // Previously there could be a split-package issue between JSR250 and JSR305 javax.annotation packages, // but since 6.0 JSR 250 annotations such as @Resource and @PostConstruct have been replaced by their // JakartaEE equivalents in the jakarta.annotation package. - //"https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/" + //"https://www.javadoc.io/doc/com.google.code.findbugs/jsr305/3.0.2/", + "https://jspecify.dev/docs/api/" ] as String[] } diff --git a/framework-docs/src/main/kotlin/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.kt b/framework-docs/src/main/kotlin/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.kt index f91e78a548..0db14f210f 100644 --- a/framework-docs/src/main/kotlin/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.kt +++ b/framework-docs/src/main/kotlin/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.kt @@ -28,9 +28,7 @@ class CustomCacheConfiguration { // tag::snippet[] @Bean fun cacheManager(): CacheManager { - return CaffeineCacheManager().apply { - cacheNames = listOf("default", "books") - } + return CaffeineCacheManager("default", "books") } // end::snippet[] } \ No newline at end of file diff --git a/framework-platform/framework-platform.gradle b/framework-platform/framework-platform.gradle index 5ae3e67b62..73717dd4e1 100644 --- a/framework-platform/framework-platform.gradle +++ b/framework-platform/framework-platform.gradle @@ -131,6 +131,7 @@ dependencies { api("org.htmlunit:htmlunit:4.6.0") api("org.javamoney:moneta:1.4.4") api("org.jruby:jruby:9.4.9.0") + api("org.jspecify:jspecify:1.0.0") api("org.junit.support:testng-engine:1.0.5") api("org.mozilla:rhino:1.7.15") api("org.ogce:xpp3:1.1.6") diff --git a/gradle/spring-module.gradle b/gradle/spring-module.gradle index ff48a66e39..c0c9eea155 100644 --- a/gradle/spring-module.gradle +++ b/gradle/spring-module.gradle @@ -13,8 +13,8 @@ dependencies { jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.37' jmh 'org.openjdk.jmh:jmh-generator-bytecode:1.37' jmh 'net.sf.jopt-simple:jopt-simple' - errorprone 'com.uber.nullaway:nullaway:0.10.26' - errorprone 'com.google.errorprone:error_prone_core:2.9.0' + errorprone 'com.uber.nullaway:nullaway:0.12.2' + errorprone 'com.google.errorprone:error_prone_core:2.35.1' } pluginManager.withPlugin("kotlin") { diff --git a/integration-tests/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests.java b/integration-tests/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests.java index 15fbd10d78..b416fc3edf 100644 --- a/integration-tests/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests.java +++ b/integration-tests/src/test/java/org/springframework/aop/framework/autoproxy/AdvisorAutoProxyCreatorIntegrationTests.java @@ -20,6 +20,7 @@ import java.lang.reflect.Method; import java.util.List; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.support.AopUtils; @@ -31,7 +32,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.transaction.NoTransactionException; import org.springframework.transaction.interceptor.TransactionInterceptor; import org.springframework.transaction.testfixture.CallCountingTransactionManager; 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 8c2c5d6ef8..e7d89ca7bd 100644 --- a/spring-aop/src/main/java/org/springframework/aop/AfterReturningAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/AfterReturningAdvice.java @@ -18,7 +18,7 @@ package org.springframework.aop; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * After returning advice is invoked only on normal method return, not if an 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 806744d09c..1103590a57 100644 --- a/spring-aop/src/main/java/org/springframework/aop/MethodBeforeAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/MethodBeforeAdvice.java @@ -18,7 +18,7 @@ package org.springframework.aop; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Advice invoked before a method is invoked. Such advices cannot 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 2cc637621c..d6f929f8a6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java +++ b/spring-aop/src/main/java/org/springframework/aop/ProxyMethodInvocation.java @@ -17,8 +17,7 @@ package org.springframework.aop; import org.aopalliance.intercept.MethodInvocation; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Extension of the AOP Alliance {@link org.aopalliance.intercept.MethodInvocation} @@ -83,7 +82,6 @@ public interface ProxyMethodInvocation extends MethodInvocation { * @return the value of the attribute, or {@code null} if not set * @see #setUserAttribute */ - @Nullable - Object getUserAttribute(String key); + @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 d518ddb444..df550f7711 100644 --- a/spring-aop/src/main/java/org/springframework/aop/TargetClassAware.java +++ b/spring-aop/src/main/java/org/springframework/aop/TargetClassAware.java @@ -16,7 +16,7 @@ package org.springframework.aop; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Minimal interface for exposing the target class behind a proxy. @@ -36,7 +36,6 @@ public interface TargetClassAware { * (typically a proxy configuration or an actual proxy). * @return the target Class, or {@code null} if not known */ - @Nullable - Class getTargetClass(); + @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 c19982f319..9429d43bb7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/TargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/TargetSource.java @@ -16,7 +16,7 @@ package org.springframework.aop; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A {@code TargetSource} is used to obtain the current "target" of @@ -42,8 +42,7 @@ public interface TargetSource extends TargetClassAware { * @return the type of targets returned by this {@link TargetSource} */ @Override - @Nullable - Class getTargetClass(); + @Nullable Class getTargetClass(); /** * Will all calls to {@link #getTarget()} return the same object? @@ -64,8 +63,7 @@ public interface TargetSource extends TargetClassAware { * or {@code null} if there is no actual target instance * @throws Exception if the target object can't be resolved */ - @Nullable - Object getTarget() throws Exception; + @Nullable Object getTarget() throws Exception; /** * Release the given target object obtained from the 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 2e2ee857f3..7ffffab8bc 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 @@ -31,6 +31,7 @@ import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.weaver.tools.JoinPointMatch; import org.aspectj.weaver.tools.PointcutParameter; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AopInvocationException; import org.springframework.aop.MethodMatcher; @@ -42,7 +43,6 @@ 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; @@ -118,16 +118,13 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence * This will be non-null if the creator of this advice object knows the argument names * and sets them explicitly. */ - @Nullable - private String[] argumentNames; + private @Nullable String @Nullable [] argumentNames; /** Non-null if after throwing advice binds the thrown value. */ - @Nullable - private String throwingName; + private @Nullable String throwingName; /** Non-null if after returning advice binds the return value. */ - @Nullable - private String returningName; + private @Nullable String returningName; private Class discoveredReturningType = Object.class; @@ -145,13 +142,11 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence */ private int joinPointStaticPartArgumentIndex = -1; - @Nullable - private Map argumentBindings; + private @Nullable Map argumentBindings; private boolean argumentsIntrospected = false; - @Nullable - private Type discoveredReturningGenericType; + private @Nullable Type discoveredReturningGenericType; // Note: Unlike return type, no such generic information is needed for the throwing type, // since Java doesn't allow exception types to be parameterized. @@ -212,8 +207,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence /** * Return the ClassLoader for aspect instances. */ - @Nullable - public final ClassLoader getAspectClassLoader() { + public final @Nullable ClassLoader getAspectClassLoader() { return this.aspectInstanceFactory.getAspectClassLoader(); } @@ -318,8 +312,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence return this.discoveredReturningType; } - @Nullable - protected Type getDiscoveredReturningGenericType() { + protected @Nullable Type getDiscoveredReturningGenericType() { return this.discoveredReturningGenericType; } @@ -657,8 +650,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence /** * Get the current join point match at the join point we are being dispatched on. */ - @Nullable - protected JoinPointMatch getJoinPointMatch() { + protected @Nullable JoinPointMatch getJoinPointMatch() { MethodInvocation mi = ExposeInvocationInterceptor.currentInvocation(); if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); @@ -672,8 +664,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence // 'last man wins' which is not what we want at all. // Using the expression is guaranteed to be safe, since 2 identical expressions // are guaranteed to bind in exactly the same way. - @Nullable - protected JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) { + protected @Nullable JoinPointMatch getJoinPointMatch(ProxyMethodInvocation pmi) { String expression = this.pointcut.getExpression(); return (expression != null ? (JoinPointMatch) pmi.getUserAttribute(expression) : null); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java index 4ddf6303ed..b4367ad04a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectInstanceFactory.java @@ -16,8 +16,9 @@ package org.springframework.aop.aspectj; +import org.jspecify.annotations.Nullable; + import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; /** * Interface implemented to provide an instance of an AspectJ aspect. @@ -44,7 +45,6 @@ public interface AspectInstanceFactory extends Ordered { * @return the aspect class loader (or {@code null} for the bootstrap loader) * @see org.springframework.util.ClassUtils#getDefaultClassLoader() */ - @Nullable - ClassLoader getAspectClassLoader(); + @Nullable ClassLoader getAspectClassLoader(); } 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 ec9b634ff8..b783c37e57 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 @@ -28,9 +28,9 @@ import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.weaver.tools.PointcutParser; import org.aspectj.weaver.tools.PointcutPrimitive; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -157,22 +157,19 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov /** The pointcut expression associated with the advice, as a simple String. */ - @Nullable - private final String pointcutExpression; + private final @Nullable String pointcutExpression; private boolean raiseExceptions; /** If the advice is afterReturning, and binds the return value, this is the parameter name used. */ - @Nullable - private String returningName; + private @Nullable String returningName; /** If the advice is afterThrowing, and binds the thrown value, this is the parameter name used. */ - @Nullable - private String throwingName; + private @Nullable String throwingName; private Class[] argumentTypes = new Class[0]; - private String[] parameterNameBindings = new String[0]; + private @Nullable String[] parameterNameBindings = new String[0]; private int numberOfRemainingUnboundArguments; @@ -221,8 +218,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov * @return the parameter names */ @Override - @Nullable - public String[] getParameterNames(Method method) { + public @Nullable String @Nullable [] getParameterNames(Method method) { this.argumentTypes = method.getParameterTypes(); this.numberOfRemainingUnboundArguments = this.argumentTypes.length; this.parameterNameBindings = new String[this.numberOfRemainingUnboundArguments]; @@ -289,8 +285,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov * {@link #setRaiseExceptions(boolean) raiseExceptions} has been set to {@code true} */ @Override - @Nullable - public String[] getParameterNames(Constructor ctor) { + public String @Nullable [] getParameterNames(Constructor ctor) { if (this.raiseExceptions) { throw new UnsupportedOperationException("An advice method can never be a constructor"); } @@ -453,8 +448,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov /** * If the token starts meets Java identifier conventions, it's in. */ - @Nullable - private String maybeExtractVariableName(@Nullable String candidateToken) { + private @Nullable String maybeExtractVariableName(@Nullable String candidateToken) { if (AspectJProxyUtils.isVariableName(candidateToken)) { return candidateToken; } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterAdvice.java index a8081b461a..d0ed4f9f24 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterAdvice.java @@ -21,9 +21,9 @@ import java.lang.reflect.Method; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AfterAdvice; -import org.springframework.lang.Nullable; /** * Spring AOP advice wrapping an AspectJ after advice method. @@ -43,8 +43,7 @@ public class AspectJAfterAdvice extends AbstractAspectJAdvice @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } 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 48cedab1be..b0a8a99a54 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 @@ -20,9 +20,10 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + 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; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterThrowingAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterThrowingAdvice.java index 953658d66e..4444f2175e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterThrowingAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAfterThrowingAdvice.java @@ -21,9 +21,9 @@ import java.lang.reflect.Method; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AfterAdvice; -import org.springframework.lang.Nullable; /** * Spring AOP advice wrapping an AspectJ after-throwing advice method. @@ -58,8 +58,7 @@ public class AspectJAfterThrowingAdvice extends AbstractAspectJAdvice } @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } 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 4ea59280d1..b97ef421a5 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 @@ -17,11 +17,11 @@ package org.springframework.aop.aspectj; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; 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. @@ -59,8 +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) { + public static @Nullable AspectJPrecedenceInformation getAspectJPrecedenceInformationFor(Advisor anAdvisor) { if (anAdvisor instanceof AspectJPrecedenceInformation ajpi) { return ajpi; } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java index d1584c54af..bc3ca787da 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJAroundAdvice.java @@ -23,9 +23,9 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.weaver.tools.JoinPointMatch; +import org.jspecify.annotations.Nullable; import org.springframework.aop.ProxyMethodInvocation; -import org.springframework.lang.Nullable; /** * Spring AOP around advice (MethodInterceptor) that wraps @@ -61,8 +61,7 @@ public class AspectJAroundAdvice extends AbstractAspectJAdvice implements Method } @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } 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 aeb258e0a3..99b4f1ea48 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 @@ -39,6 +39,7 @@ import org.aspectj.weaver.tools.PointcutParser; import org.aspectj.weaver.tools.PointcutPrimitive; import org.aspectj.weaver.tools.ShadowMatch; import org.aspectj.weaver.tools.UnsupportedPointcutPrimitiveException; +import org.jspecify.annotations.Nullable; import org.springframework.aop.ClassFilter; import org.springframework.aop.IntroductionAwareMethodMatcher; @@ -54,7 +55,6 @@ 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -99,8 +99,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut private static final Log logger = LogFactory.getLog(AspectJExpressionPointcut.class); - @Nullable - private Class pointcutDeclarationScope; + private @Nullable Class pointcutDeclarationScope; private boolean aspectCompiledByAjc; @@ -108,14 +107,11 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut private Class[] pointcutParameterTypes = new Class[0]; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private transient ClassLoader pointcutClassLoader; + private transient @Nullable ClassLoader pointcutClassLoader; - @Nullable - private transient PointcutExpression pointcutExpression; + private transient @Nullable PointcutExpression pointcutExpression; private transient boolean pointcutParsingFailed = false; @@ -207,8 +203,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut /** * Determine the ClassLoader to use for pointcut evaluation. */ - @Nullable - private ClassLoader determinePointcutClassLoader() { + private @Nullable ClassLoader determinePointcutClassLoader() { if (this.beanFactory instanceof ConfigurableBeanFactory cbf) { return cbf.getBeanClassLoader(); } @@ -403,8 +398,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut } } - @Nullable - protected String getCurrentProxiedBeanName() { + protected @Nullable String getCurrentProxiedBeanName() { return ProxyCreationContext.getCurrentProxiedBeanName(); } @@ -412,8 +406,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) { + private @Nullable PointcutExpression getFallbackPointcutExpression(Class targetClass) { try { ClassLoader classLoader = targetClass.getClassLoader(); if (classLoader != null && classLoader != this.pointcutClassLoader) { diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java index 9f4b1e990d..918a61ee55 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJExpressionPointcutAdvisor.java @@ -16,11 +16,12 @@ package org.springframework.aop.aspectj; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Pointcut; import org.springframework.aop.support.AbstractGenericPointcutAdvisor; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; /** * Spring AOP Advisor that can be used for any AspectJ pointcut expression. @@ -38,8 +39,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv this.pointcut.setExpression(expression); } - @Nullable - public String getExpression() { + public @Nullable String getExpression() { return this.pointcut.getExpression(); } @@ -47,8 +47,7 @@ public class AspectJExpressionPointcutAdvisor extends AbstractGenericPointcutAdv this.pointcut.setLocation(location); } - @Nullable - public String getLocation() { + public @Nullable String getLocation() { return this.pointcut.getLocation(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJMethodBeforeAdvice.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJMethodBeforeAdvice.java index 207291c51d..561714af57 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJMethodBeforeAdvice.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJMethodBeforeAdvice.java @@ -19,8 +19,9 @@ package org.springframework.aop.aspectj; import java.io.Serializable; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.MethodBeforeAdvice; -import org.springframework.lang.Nullable; /** * Spring AOP advice that wraps an AspectJ before method. diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java index 543146243a..94487cae88 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJPointcutAdvisor.java @@ -17,11 +17,11 @@ package org.springframework.aop.aspectj; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Pointcut; import org.springframework.aop.PointcutAdvisor; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -38,8 +38,7 @@ public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered { private final Pointcut pointcut; - @Nullable - private Integer order; + private @Nullable Integer order; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java index be7c856940..9d28753114 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/AspectJProxyUtils.java @@ -18,10 +18,11 @@ package org.springframework.aop.aspectj; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Advisor; import org.springframework.aop.PointcutAdvisor; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** 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 68eb55c9c4..a53d71c84b 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 @@ -25,11 +25,11 @@ import org.aspectj.lang.Signature; import org.aspectj.lang.reflect.MethodSignature; import org.aspectj.lang.reflect.SourceLocation; import org.aspectj.runtime.internal.AroundClosure; +import org.jspecify.annotations.Nullable; 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; /** @@ -55,16 +55,13 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, private final ProxyMethodInvocation methodInvocation; - @Nullable - private Object[] args; + private Object @Nullable [] args; /** Lazily initialized signature object. */ - @Nullable - private Signature signature; + private @Nullable Signature signature; /** Lazily initialized source location object. */ - @Nullable - private SourceLocation sourceLocation; + private @Nullable SourceLocation sourceLocation; /** @@ -84,14 +81,12 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, } @Override - @Nullable - public Object proceed() throws Throwable { + public @Nullable Object proceed() throws Throwable { return this.methodInvocation.invocableClone().proceed(); } @Override - @Nullable - public Object proceed(Object[] arguments) throws Throwable { + public @Nullable Object proceed(Object[] arguments) throws Throwable { Assert.notNull(arguments, "Argument array passed to proceed cannot be null"); if (arguments.length != this.methodInvocation.getArguments().length) { throw new IllegalArgumentException("Expecting " + @@ -114,8 +109,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() { + public @Nullable Object getTarget() { return this.methodInvocation.getThis(); } @@ -180,8 +174,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, */ private class MethodSignatureImpl implements MethodSignature { - @Nullable - private volatile String[] parameterNames; + private volatile String @Nullable [] parameterNames; @Override public String getName() { @@ -219,8 +212,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint, } @Override - @Nullable - public String[] getParameterNames() { + public String @Nullable [] getParameterNames() { String[] parameterNames = this.parameterNames; if (parameterNames == null) { parameterNames = parameterNameDiscoverer.getParameterNames(getMethod()); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java index bf37296a6e..3c34ea0e99 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/RuntimeTestWalker.java @@ -36,8 +36,8 @@ import org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegate; import org.aspectj.weaver.reflect.ReflectionVar; import org.aspectj.weaver.reflect.ShadowMatchImpl; import org.aspectj.weaver.tools.ShadowMatch; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -79,8 +79,7 @@ class RuntimeTestWalker { } - @Nullable - private final Test runtimeTest; + private final @Nullable Test runtimeTest; public RuntimeTestWalker(ShadowMatch shadowMatch) { diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/ShadowMatchUtils.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/ShadowMatchUtils.java index beb3ac63bb..3c26b4abc5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/ShadowMatchUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/ShadowMatchUtils.java @@ -21,9 +21,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.aspectj.weaver.tools.ShadowMatch; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.ExpressionPointcut; -import org.springframework.lang.Nullable; /** * Internal {@link ShadowMatch} utilities. @@ -49,8 +49,7 @@ public abstract class ShadowMatchUtils { * @param method the method * @return the {@code ShadowMatch} to use for the specified expression and method */ - @Nullable - static ShadowMatch getShadowMatch(ExpressionPointcut expression, Method method) { + static @Nullable ShadowMatch getShadowMatch(ExpressionPointcut expression, Method method) { return shadowMatchCache.get(new Key(expression, method)); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java index f8a674ab13..1e2d45f4bf 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/SimpleAspectInstanceFactory.java @@ -18,9 +18,10 @@ package org.springframework.aop.aspectj; import java.lang.reflect.InvocationTargetException; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopConfigException; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -77,8 +78,7 @@ public class SimpleAspectInstanceFactory implements AspectInstanceFactory { } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { return this.aspectClass.getClassLoader(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java index 04edaa8076..a285945bc5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/SingletonAspectInstanceFactory.java @@ -18,8 +18,9 @@ package org.springframework.aop.aspectj; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -54,8 +55,7 @@ public class SingletonAspectInstanceFactory implements AspectInstanceFactory, Se } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { return this.aspectInstance.getClass().getClassLoader(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java index d6ddae2671..b3cff467db 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java @@ -20,9 +20,9 @@ import java.util.Objects; import org.aspectj.weaver.tools.PointcutParser; import org.aspectj.weaver.tools.TypePatternMatcher; +import org.jspecify.annotations.Nullable; import org.springframework.aop.ClassFilter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -39,8 +39,7 @@ public class TypePatternClassFilter implements ClassFilter { private String typePattern = ""; - @Nullable - private TypePatternMatcher aspectJTypePatternMatcher; + private @Nullable TypePatternMatcher aspectJTypePatternMatcher; /** 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 8400c54360..03a36ba11a 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 @@ -35,12 +35,12 @@ import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.reflect.AjType; import org.aspectj.lang.reflect.AjTypeSystem; import org.aspectj.lang.reflect.PerClauseKind; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopConfigException; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; /** * Abstract base class for factories that can create Spring AOP Advisors @@ -112,8 +112,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac * (there should only be one anyway...). */ @SuppressWarnings("unchecked") - @Nullable - protected static AspectJAnnotation findAspectJAnnotationOnMethod(Method method) { + protected static @Nullable AspectJAnnotation findAspectJAnnotationOnMethod(Method method) { for (Class annotationType : ASPECTJ_ANNOTATION_CLASSES) { AspectJAnnotation annotation = findAnnotation(method, (Class) annotationType); if (annotation != null) { @@ -123,8 +122,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac return null; } - @Nullable - private static AspectJAnnotation findAnnotation(Method method, Class annotationType) { + private static @Nullable AspectJAnnotation findAnnotation(Method method, Class annotationType) { Annotation annotation = AnnotationUtils.findAnnotation(method, annotationType); if (annotation != null) { return new AspectJAnnotation(annotation); @@ -242,8 +240,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac private static final String[] EMPTY_ARRAY = new String[0]; @Override - @Nullable - public String[] getParameterNames(Method method) { + public String @Nullable [] getParameterNames(Method method) { if (method.getParameterCount() == 0) { return EMPTY_ARRAY; } @@ -266,8 +263,7 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac } @Override - @Nullable - public String[] getParameterNames(Constructor ctor) { + public @Nullable String @Nullable [] getParameterNames(Constructor ctor) { throw new UnsupportedOperationException("Spring AOP cannot handle constructor advice"); } } diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AnnotationAwareAspectJAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AnnotationAwareAspectJAutoProxyCreator.java index 926392693e..f53b1cdba5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AnnotationAwareAspectJAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AnnotationAwareAspectJAutoProxyCreator.java @@ -20,11 +20,12 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -49,14 +50,11 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class AnnotationAwareAspectJAutoProxyCreator extends AspectJAwareAdvisorAutoProxyCreator { - @Nullable - private List includePatterns; + private @Nullable List includePatterns; - @Nullable - private AspectJAdvisorFactory aspectJAdvisorFactory; + private @Nullable AspectJAdvisorFactory aspectJAdvisorFactory; - @Nullable - private BeanFactoryAspectJAdvisorsBuilder aspectJAdvisorsBuilder; + private @Nullable BeanFactoryAspectJAdvisorsBuilder aspectJAdvisorsBuilder; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java index cfc8856477..1c237ed55f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessor.java @@ -18,13 +18,14 @@ package org.springframework.aop.aspectj.annotation; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.MemberCategory; import org.springframework.beans.factory.aot.BeanRegistrationAotContribution; import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor; import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -43,8 +44,7 @@ class AspectJAdvisorBeanRegistrationAotProcessor implements BeanRegistrationAotP @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { if (aspectjPresent) { Class beanClass = registeredBean.getBeanClass(); if (compiledByAjc(beanClass)) { 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 c3bf168529..31dcf53d68 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 @@ -20,11 +20,11 @@ import java.lang.reflect.Method; import java.util.List; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; 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 @@ -80,8 +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, + @Nullable Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName); /** @@ -100,8 +99,7 @@ public interface AspectJAdvisorFactory { * @see org.springframework.aop.aspectj.AspectJAfterReturningAdvice * @see org.springframework.aop.aspectj.AspectJAfterThrowingAdvice */ - @Nullable - Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, + @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/AspectJBeanFactoryInitializationAotProcessor.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessor.java index 71e7bea2b4..f859dc3f82 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessor.java @@ -18,6 +18,8 @@ package org.springframework.aop.aspectj.annotation; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AbstractAspectJAdvice; import org.springframework.aot.generate.GenerationContext; @@ -27,7 +29,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContrib import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor; import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -45,8 +46,7 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial @Override - @Nullable - public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { + public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { if (aspectJPresent) { return AspectDelegate.processAheadOfTime(beanFactory); } @@ -59,8 +59,7 @@ class AspectJBeanFactoryInitializationAotProcessor implements BeanFactoryInitial */ private static class AspectDelegate { - @Nullable - private static AspectContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { + private static @Nullable AspectContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { BeanFactoryAspectJAdvisorsBuilder builder = new BeanFactoryAspectJAdvisorsBuilder(beanFactory); List advisors = builder.buildAspectJAdvisors(); return (advisors.isEmpty() ? null : new AspectContribution(advisors)); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java index 28d5aa13e5..d0425b6e0e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectInstanceFactory.java @@ -18,11 +18,12 @@ package org.springframework.aop.aspectj.annotation; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.Ordered; import org.springframework.core.annotation.OrderUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -91,8 +92,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { return (this.beanFactory instanceof ConfigurableBeanFactory cbf ? cbf.getBeanClassLoader() : ClassUtils.getDefaultClassLoader()); } @@ -103,8 +103,7 @@ public class BeanFactoryAspectInstanceFactory implements MetadataAwareAspectInst } @Override - @Nullable - public Object getAspectCreationMutex() { + public @Nullable Object getAspectCreationMutex() { if (this.beanFactory.isSingleton(this.name)) { // Rely on singleton semantics provided by the factory -> no local lock. return null; diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java index 21bc248e50..4cb6dd3cb9 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/BeanFactoryAspectJAdvisorsBuilder.java @@ -25,12 +25,12 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.aspectj.lang.reflect.PerClauseKind; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.framework.AopConfigException; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -49,8 +49,7 @@ public class BeanFactoryAspectJAdvisorsBuilder { private final AspectJAdvisorFactory advisorFactory; - @Nullable - private volatile List aspectBeanNames; + private volatile @Nullable List aspectBeanNames; private final Map> advisorsCache = new ConcurrentHashMap<>(); diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java index db20f76081..12a6a47813 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/InstantiationModelAwarePointcutAdvisorImpl.java @@ -23,6 +23,7 @@ import java.lang.reflect.Method; import org.aopalliance.aop.Advice; import org.aspectj.lang.reflect.PerClauseKind; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Pointcut; import org.springframework.aop.aspectj.AspectJExpressionPointcut; @@ -31,7 +32,6 @@ import org.springframework.aop.aspectj.InstantiationModelAwarePointcutAdvisor; import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactory.AspectJAnnotation; import org.springframework.aop.support.DynamicMethodMatcherPointcut; import org.springframework.aop.support.Pointcuts; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -73,14 +73,11 @@ final class InstantiationModelAwarePointcutAdvisorImpl private final boolean lazy; - @Nullable - private Advice instantiatedAdvice; + private @Nullable Advice instantiatedAdvice; - @Nullable - private Boolean isBeforeAdvice; + private @Nullable Boolean isBeforeAdvice; - @Nullable - private Boolean isAfterAdvice; + private @Nullable Boolean isAfterAdvice; public InstantiationModelAwarePointcutAdvisorImpl(AspectJExpressionPointcut declaredPointcut, @@ -271,8 +268,7 @@ final class InstantiationModelAwarePointcutAdvisorImpl private final Pointcut preInstantiationPointcut; - @Nullable - private LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory; + private @Nullable LazySingletonAspectInstanceFactoryDecorator aspectInstanceFactory; public PerTargetInstantiationModelPointcut(AspectJExpressionPointcut declaredPointcut, Pointcut preInstantiationPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory) { diff --git a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/LazySingletonAspectInstanceFactoryDecorator.java b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/LazySingletonAspectInstanceFactoryDecorator.java index 73ba36c79d..a20fc06df8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/LazySingletonAspectInstanceFactoryDecorator.java +++ b/spring-aop/src/main/java/org/springframework/aop/aspectj/annotation/LazySingletonAspectInstanceFactoryDecorator.java @@ -18,7 +18,8 @@ package org.springframework.aop.aspectj.annotation; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -33,8 +34,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar private final MetadataAwareAspectInstanceFactory maaif; - @Nullable - private volatile Object materialized; + private volatile @Nullable Object materialized; /** @@ -74,8 +74,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { return this.maaif.getAspectClassLoader(); } @@ -85,8 +84,7 @@ public class LazySingletonAspectInstanceFactoryDecorator implements MetadataAwar } @Override - @Nullable - public Object getAspectCreationMutex() { + public @Nullable Object getAspectCreationMutex() { return this.maaif.getAspectCreationMutex(); } 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 cb3e29baf4..08c6291081 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 @@ -16,8 +16,9 @@ package org.springframework.aop.aspectj.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.aspectj.AspectInstanceFactory; -import org.springframework.lang.Nullable; /** * Subinterface of {@link org.springframework.aop.aspectj.AspectInstanceFactory} @@ -41,7 +42,6 @@ public interface MetadataAwareAspectInstanceFactory extends AspectInstanceFactor * @return the mutex object (may be {@code null} for no mutex to use) * @since 4.3 */ - @Nullable - Object getAspectCreationMutex(); + @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 e4eec7a919..1f33f9c8c0 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 @@ -32,6 +32,7 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.DeclareParents; import org.aspectj.lang.annotation.Pointcut; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.MethodBeforeAdvice; @@ -49,7 +50,6 @@ 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.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils.MethodFilter; @@ -96,8 +96,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto } - @Nullable - private final BeanFactory beanFactory; + private final @Nullable BeanFactory beanFactory; /** @@ -183,8 +182,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto * @param introductionField the field to introspect * @return the Advisor instance, or {@code null} if not an Advisor */ - @Nullable - private Advisor getDeclareParentsAdvisor(Field introductionField) { + private @Nullable Advisor getDeclareParentsAdvisor(Field introductionField) { DeclareParents declareParents = introductionField.getAnnotation(DeclareParents.class); if (declareParents == null) { // Not an introduction field @@ -201,8 +199,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto @Override - @Nullable - public Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, + public @Nullable Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrderInAspect, String aspectName) { validate(aspectInstanceFactory.getAspectMetadata().getAspectClass()); @@ -225,8 +222,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto } } - @Nullable - private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class candidateAspectClass) { + private @Nullable AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Class candidateAspectClass) { AspectJAnnotation aspectJAnnotation = AbstractAspectJAdvisorFactory.findAspectJAnnotationOnMethod(candidateAdviceMethod); if (aspectJAnnotation == null) { @@ -244,8 +240,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto @Override - @Nullable - public Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, + public @Nullable Advice getAdvice(Method candidateAdviceMethod, AspectJExpressionPointcut expressionPointcut, MetadataAwareAspectInstanceFactory aspectInstanceFactory, int declarationOrder, String aspectName) { Class candidateAspectClass = aspectInstanceFactory.getAspectMetadata().getAspectClass(); 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 b5cf524700..4f9573c2f7 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,9 +3,7 @@ * *

Normally to be used through an AspectJAutoProxyCreator rather than directly. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.aspectj.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d83cd88d54..65e6bf298d 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,9 +2,7 @@ * Base classes enabling auto-proxying based on AspectJ. * Support for AspectJ annotation aspects resides in the "aspectj.annotation" package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.aspectj.autoproxy; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2ffe8b1643..45dce8a86a 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.aop.aspectj; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java b/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java index 25c8fa2c4d..6c53d9df0d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AdvisorComponentDefinition.java @@ -16,11 +16,12 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanReference; import org.springframework.beans.factory.parsing.AbstractComponentDefinition; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -110,8 +111,7 @@ public class AdvisorComponentDefinition extends AbstractComponentDefinition { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.advisorDefinition.getSource(); } 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 1bba8f1c20..6ec5ea3460 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 @@ -19,6 +19,8 @@ package org.springframework.aop.config; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator; import org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator; import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator; @@ -26,7 +28,6 @@ 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; /** @@ -64,37 +65,31 @@ public abstract class AopConfigUtils { } - @Nullable - public static BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) { + public static @Nullable BeanDefinition registerAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) { return registerAutoProxyCreatorIfNecessary(registry, null); } - @Nullable - public static BeanDefinition registerAutoProxyCreatorIfNecessary( + public static @Nullable BeanDefinition registerAutoProxyCreatorIfNecessary( BeanDefinitionRegistry registry, @Nullable Object source) { return registerOrEscalateApcAsRequired(InfrastructureAdvisorAutoProxyCreator.class, registry, source); } - @Nullable - public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) { + public static @Nullable BeanDefinition registerAspectJAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) { return registerAspectJAutoProxyCreatorIfNecessary(registry, null); } - @Nullable - public static BeanDefinition registerAspectJAutoProxyCreatorIfNecessary( + public static @Nullable BeanDefinition registerAspectJAutoProxyCreatorIfNecessary( BeanDefinitionRegistry registry, @Nullable Object source) { return registerOrEscalateApcAsRequired(AspectJAwareAdvisorAutoProxyCreator.class, registry, source); } - @Nullable - public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) { + public static @Nullable BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(BeanDefinitionRegistry registry) { return registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry, null); } - @Nullable - public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary( + public static @Nullable BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary( BeanDefinitionRegistry registry, @Nullable Object source) { return registerOrEscalateApcAsRequired(AnnotationAwareAspectJAutoProxyCreator.class, registry, source); @@ -114,8 +109,7 @@ public abstract class AopConfigUtils { } } - @Nullable - private static BeanDefinition registerOrEscalateApcAsRequired( + private static @Nullable BeanDefinition registerOrEscalateApcAsRequired( Class cls, BeanDefinitionRegistry registry, @Nullable Object source) { Assert.notNull(registry, "BeanDefinitionRegistry must not be null"); diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java index 5acb1cc5ac..fca1bef8dd 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AopNamespaceUtils.java @@ -16,13 +16,13 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.lang.Nullable; /** * Utility class for handling registration of auto-proxy creators used internally diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java b/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java index 53d0d789a4..7b283baad8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AspectComponentDefinition.java @@ -16,10 +16,11 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanReference; import org.springframework.beans.factory.parsing.CompositeComponentDefinition; -import org.springframework.lang.Nullable; /** * {@link org.springframework.beans.factory.parsing.ComponentDefinition} @@ -38,8 +39,8 @@ public class AspectComponentDefinition extends CompositeComponentDefinition { private final BeanReference[] beanReferences; - public AspectComponentDefinition(String aspectName, @Nullable BeanDefinition[] beanDefinitions, - @Nullable BeanReference[] beanReferences, @Nullable Object source) { + public AspectComponentDefinition(String aspectName, BeanDefinition @Nullable [] beanDefinitions, + BeanReference @Nullable [] beanReferences, @Nullable Object source) { super(aspectName, source); this.beanDefinitions = (beanDefinitions != null ? beanDefinitions : new BeanDefinition[0]); diff --git a/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java b/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java index 70b9762006..27090155eb 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/AspectJAutoProxyBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -25,7 +26,6 @@ import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.support.ManagedList; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.lang.Nullable; /** * {@link BeanDefinitionParser} for the {@code aspectj-autoproxy} tag, @@ -39,8 +39,7 @@ import org.springframework.lang.Nullable; class AspectJAutoProxyBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { AopNamespaceUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(parserContext, element); extendBeanDefinition(element, parserContext); return null; 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 c13c6446a3..bcf4fc006e 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 @@ -19,6 +19,7 @@ package org.springframework.aop.config; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -45,7 +46,6 @@ 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; @@ -97,8 +97,7 @@ class ConfigBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element)); parserContext.pushContainingComponent(compositeDef); @@ -453,8 +452,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) { + private @Nullable Object parsePointcutProperty(Element element, ParserContext parserContext) { if (element.hasAttribute(POINTCUT) && element.hasAttribute(POINTCUT_REF)) { parserContext.getReaderContext().error( "Cannot define both 'pointcut' and 'pointcut-ref' on tag.", diff --git a/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java index ebff6ee73e..e48e5feb42 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/MethodLocatingFactoryBean.java @@ -18,11 +18,12 @@ package org.springframework.aop.config; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -33,14 +34,11 @@ import org.springframework.util.StringUtils; */ public class MethodLocatingFactoryBean implements FactoryBean, BeanFactoryAware { - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; - @Nullable - private String methodName; + private @Nullable String methodName; - @Nullable - private Method method; + private @Nullable Method method; /** @@ -84,8 +82,7 @@ public class MethodLocatingFactoryBean implements FactoryBean, BeanFacto @Override - @Nullable - public Method getObject() throws Exception { + public @Nullable Method getObject() throws Exception { return this.method; } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/PointcutComponentDefinition.java b/spring-aop/src/main/java/org/springframework/aop/config/PointcutComponentDefinition.java index 389a5b4216..f089a80d19 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/PointcutComponentDefinition.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/PointcutComponentDefinition.java @@ -16,9 +16,10 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.parsing.AbstractComponentDefinition; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -63,8 +64,7 @@ public class PointcutComponentDefinition extends AbstractComponentDefinition { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.pointcutDefinition.getSource(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java b/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java index 446d5f93e0..4ad0100cef 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/SimpleBeanFactoryAwareAspectInstanceFactory.java @@ -16,12 +16,13 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.aspectj.AspectInstanceFactory; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -35,11 +36,9 @@ import org.springframework.util.ClassUtils; */ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstanceFactory, BeanFactoryAware { - @Nullable - private String aspectBeanName; + private @Nullable String aspectBeanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** @@ -69,8 +68,7 @@ public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstan } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { if (this.beanFactory instanceof ConfigurableBeanFactory cbf) { return cbf.getBeanClassLoader(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/config/SpringConfiguredBeanDefinitionParser.java b/spring-aop/src/main/java/org/springframework/aop/config/SpringConfiguredBeanDefinitionParser.java index f3adcd6a67..c119ad2771 100644 --- a/spring-aop/src/main/java/org/springframework/aop/config/SpringConfiguredBeanDefinitionParser.java +++ b/spring-aop/src/main/java/org/springframework/aop/config/SpringConfiguredBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.aop.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -23,7 +24,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; 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; /** * {@link BeanDefinitionParser} responsible for parsing the @@ -52,8 +52,7 @@ class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) { RootBeanDefinition def = new RootBeanDefinition(); def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME); 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 b0d1010cb3..5fb98e99ed 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,9 +2,7 @@ * Support package for declarative AOP configuration, * with XML schema being the primary configuration format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java index 95eeda4a7a..0eb8764cc2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractAdvisingBeanPostProcessor.java @@ -19,12 +19,13 @@ package org.springframework.aop.framework; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Advisor; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; import org.springframework.core.SmartClassLoader; -import org.springframework.lang.Nullable; /** * Base class for {@link BeanPostProcessor} implementations that apply a @@ -37,8 +38,7 @@ import org.springframework.lang.Nullable; public abstract class AbstractAdvisingBeanPostProcessor extends ProxyProcessorSupport implements SmartInstantiationAwareBeanPostProcessor { - @Nullable - protected Advisor advisor; + protected @Nullable Advisor advisor; protected boolean beforeExistingAdvisors = false; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java index fa1642835c..6e6f7aad56 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AbstractSingletonProxyFactoryBean.java @@ -16,6 +16,8 @@ package org.springframework.aop.framework; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry; import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry; @@ -24,7 +26,6 @@ import org.springframework.beans.factory.BeanClassLoaderAware; 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; /** @@ -42,26 +43,20 @@ import org.springframework.util.ClassUtils; public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig implements FactoryBean, BeanClassLoaderAware, InitializingBean { - @Nullable - private Object target; + private @Nullable Object target; - @Nullable - private Class[] proxyInterfaces; + private Class @Nullable [] proxyInterfaces; - @Nullable - private Object[] preInterceptors; + private Object @Nullable [] preInterceptors; - @Nullable - private Object[] postInterceptors; + private Object @Nullable [] postInterceptors; /** Default is global AdvisorAdapterRegistry. */ private AdvisorAdapterRegistry advisorAdapterRegistry = GlobalAdvisorAdapterRegistry.getInstance(); - @Nullable - private transient ClassLoader proxyClassLoader; + private transient @Nullable ClassLoader proxyClassLoader; - @Nullable - private Object proxy; + private @Nullable Object proxy; /** @@ -221,8 +216,7 @@ public abstract class AbstractSingletonProxyFactoryBean extends ProxyConfig } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { if (this.proxy != null) { return this.proxy.getClass(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java index 707c98f267..72a9d07d41 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/AdvisedSupport.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.DynamicIntroductionAdvice; @@ -40,7 +41,6 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.aop.target.EmptyTargetSource; import org.springframework.aop.target.SingletonTargetSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -108,12 +108,10 @@ public class AdvisedSupport extends ProxyConfig implements Advised { private List advisorKey = this.advisors; /** Cache with Method as key and advisor chain List as value. */ - @Nullable - private transient Map> methodCache; + private transient @Nullable Map> methodCache; /** Cache with shared interceptors which are not method-specific. */ - @Nullable - private transient volatile List cachedInterceptors; + private transient volatile @Nullable List cachedInterceptors; /** * Optional field for {@link AopProxy} implementations to store metadata in. @@ -121,8 +119,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { * @since 6.1.3 * @see JdkDynamicAopProxy#JdkDynamicAopProxy(AdvisedSupport) */ - @Nullable - transient volatile Object proxyMetadataCache; + transient volatile @Nullable Object proxyMetadataCache; /** @@ -178,8 +175,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised { } @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { return this.targetSource.getTargetClass(); } @@ -705,11 +701,9 @@ public class AdvisedSupport extends ProxyConfig implements Advised { private final Class adviceType; - @Nullable - private final String classFilterKey; + private final @Nullable String classFilterKey; - @Nullable - private final String methodMatcherKey; + private final @Nullable String methodMatcherKey; public AdvisorKeyEntry(Advisor advisor) { this.adviceType = advisor.getAdvice().getClass(); 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 3d31b8c7d4..947b059054 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,7 +19,7 @@ package org.springframework.aop.framework; import java.lang.reflect.Method; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Factory interface for advisor chains. 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 9653ced6bc..cac3ea7785 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 @@ -16,8 +16,9 @@ package org.springframework.aop.framework; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; /** * Class containing static methods used to obtain information about the current AOP invocation. @@ -80,8 +81,7 @@ public final class AopContext { * @return the old proxy, which may be {@code null} if none was bound * @see #currentProxy() */ - @Nullable - static Object setCurrentProxy(@Nullable Object proxy) { + static @Nullable 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 f103477504..b278e64f53 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,7 +16,7 @@ package org.springframework.aop.framework; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Delegate interface for a configured AOP proxy, allowing for the creation 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 26651f6200..7967fef25e 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 @@ -23,13 +23,14 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.SpringProxy; import org.springframework.aop.TargetClassAware; 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.ClassUtils; import org.springframework.util.ObjectUtils; @@ -58,8 +59,7 @@ public abstract class AopProxyUtils { * @see Advised#getTargetSource() * @see SingletonTargetSource#getTarget() */ - @Nullable - public static Object getSingletonTarget(Object candidate) { + public static @Nullable Object getSingletonTarget(Object candidate) { if (candidate instanceof Advised advised) { TargetSource targetSource = advised.getTargetSource(); if (targetSource instanceof SingletonTargetSource singleTargetSource) { @@ -253,7 +253,7 @@ public abstract class AopProxyUtils { * @return a cloned argument array, or the original if no adaptation is needed * @since 4.2.3 */ - static Object[] adaptArgumentsIfNecessary(Method method, @Nullable Object[] arguments) { + static Object[] adaptArgumentsIfNecessary(Method method, Object @Nullable [] arguments) { if (ObjectUtils.isEmpty(arguments)) { return new Object[0]; } 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 aad0b4e9e0..bf03bc79b2 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 @@ -30,6 +30,7 @@ import java.util.WeakHashMap; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AopInvocationException; import org.springframework.aop.RawTargetAccess; @@ -51,7 +52,6 @@ import org.springframework.cglib.transform.impl.UndeclaredThrowableStrategy; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.SmartClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -113,11 +113,9 @@ class CglibAopProxy implements AopProxy, Serializable { /** The configuration used to configure this proxy. */ protected final AdvisedSupport advised; - @Nullable - protected Object[] constructorArgs; + protected Object @Nullable [] constructorArgs; - @Nullable - protected Class[] constructorArgTypes; + protected Class @Nullable [] constructorArgTypes; /** Dispatcher used for methods on Advised. */ private final transient AdvisedDispatcher advisedDispatcher; @@ -144,7 +142,7 @@ class CglibAopProxy implements AopProxy, Serializable { * @param constructorArgs the constructor argument values * @param constructorArgTypes the constructor argument types */ - public void setConstructorArguments(@Nullable Object[] constructorArgs, @Nullable Class[] constructorArgTypes) { + public void setConstructorArguments(Object @Nullable [] constructorArgs, Class @Nullable [] constructorArgTypes) { if (constructorArgs == null || constructorArgTypes == null) { throw new IllegalArgumentException("Both 'constructorArgs' and 'constructorArgTypes' need to be specified"); } @@ -415,8 +413,7 @@ class CglibAopProxy implements AopProxy, Serializable { * {@code proxy} and also verifies that {@code null} is not returned as a primitive. * Also takes care of the conversion from {@code Mono} to Kotlin Coroutines if needed. */ - @Nullable - private static Object processReturnType( + private static @Nullable Object processReturnType( Object proxy, @Nullable Object target, Method method, Object[] arguments, @Nullable Object returnValue) { // Massage return value if necessary @@ -455,16 +452,14 @@ class CglibAopProxy implements AopProxy, Serializable { */ private static class StaticUnadvisedInterceptor implements MethodInterceptor, Serializable { - @Nullable - private final Object target; + private final @Nullable Object target; public StaticUnadvisedInterceptor(@Nullable Object target) { this.target = target; } @Override - @Nullable - public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + public @Nullable Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object retVal = AopUtils.invokeJoinpointUsingReflection(this.target, method, args); return processReturnType(proxy, this.target, method, args, retVal); } @@ -477,16 +472,14 @@ class CglibAopProxy implements AopProxy, Serializable { */ private static class StaticUnadvisedExposedInterceptor implements MethodInterceptor, Serializable { - @Nullable - private final Object target; + private final @Nullable Object target; public StaticUnadvisedExposedInterceptor(@Nullable Object target) { this.target = target; } @Override - @Nullable - public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + public @Nullable Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; try { oldProxy = AopContext.setCurrentProxy(proxy); @@ -514,8 +507,7 @@ class CglibAopProxy implements AopProxy, Serializable { } @Override - @Nullable - public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + public @Nullable Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object target = this.targetSource.getTarget(); try { Object retVal = AopUtils.invokeJoinpointUsingReflection(target, method, args); @@ -542,8 +534,7 @@ class CglibAopProxy implements AopProxy, Serializable { } @Override - @Nullable - public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + public @Nullable Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; Object target = this.targetSource.getTarget(); try { @@ -568,16 +559,14 @@ class CglibAopProxy implements AopProxy, Serializable { */ private static class StaticDispatcher implements Dispatcher, Serializable { - @Nullable - private final Object target; + private final @Nullable Object target; public StaticDispatcher(@Nullable Object target) { this.target = target; } @Override - @Nullable - public Object loadObject() { + public @Nullable Object loadObject() { return this.target; } } @@ -655,11 +644,9 @@ class CglibAopProxy implements AopProxy, Serializable { private final List adviceChain; - @Nullable - private final Object target; + private final @Nullable Object target; - @Nullable - private final Class targetClass; + private final @Nullable Class targetClass; public FixedChainStaticTargetInterceptor( List adviceChain, @Nullable Object target, @Nullable Class targetClass) { @@ -670,8 +657,7 @@ class CglibAopProxy implements AopProxy, Serializable { } @Override - @Nullable - public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + public @Nullable Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { MethodInvocation invocation = new ReflectiveMethodInvocation( proxy, this.target, method, args, this.targetClass, this.adviceChain); // If we get here, we need to create a MethodInvocation. @@ -695,8 +681,7 @@ class CglibAopProxy implements AopProxy, Serializable { } @Override - @Nullable - public Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { + public @Nullable Object intercept(Object proxy, Method method, Object[] args, MethodProxy methodProxy) throws Throwable { Object oldProxy = null; boolean setProxyContext = false; Object target = null; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/CoroutinesUtils.java b/spring-aop/src/main/java/org/springframework/aop/framework/CoroutinesUtils.java index f1e0609616..80c2fe245d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/CoroutinesUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/CoroutinesUtils.java @@ -19,10 +19,10 @@ package org.springframework.aop.framework; import kotlin.coroutines.Continuation; import kotlinx.coroutines.reactive.ReactiveFlowKt; import kotlinx.coroutines.reactor.MonoKt; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; /** * Package-visible class designed to avoid a hard dependency on Kotlin and Coroutines dependency at runtime. @@ -41,9 +41,8 @@ abstract class CoroutinesUtils { } } - @Nullable @SuppressWarnings({"unchecked", "rawtypes"}) - static Object awaitSingleOrNull(@Nullable Object value, Object continuation) { + static @Nullable Object awaitSingleOrNull(@Nullable Object value, Object continuation) { return MonoKt.awaitSingleOrNull(value instanceof Mono mono ? mono : Mono.justOrEmpty(value), (Continuation) continuation); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java index 73c2fb4308..686a8df551 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/DefaultAdvisorChainFactory.java @@ -24,6 +24,7 @@ import java.util.List; import org.aopalliance.intercept.Interceptor; import org.aopalliance.intercept.MethodInterceptor; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.IntroductionAdvisor; @@ -32,7 +33,6 @@ import org.springframework.aop.MethodMatcher; import org.springframework.aop.PointcutAdvisor; import org.springframework.aop.framework.adapter.AdvisorAdapterRegistry; import org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry; -import org.springframework.lang.Nullable; /** * A simple but definitive way of working out an advice chain for a Method, diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java index 3ab70ee9e8..ac4c8c0270 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/JdkDynamicAopProxy.java @@ -27,6 +27,7 @@ import java.util.List; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AopInvocationException; import org.springframework.aop.RawTargetAccess; @@ -35,7 +36,6 @@ import org.springframework.aop.support.AopUtils; import org.springframework.core.DecoratingProxy; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -163,8 +163,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa * unless a hook method throws an exception. */ @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object oldProxy = null; boolean setProxyContext = false; 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 56330a6395..da05db588d 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 @@ -17,9 +17,9 @@ package org.springframework.aop.framework; import org.aopalliance.intercept.Interceptor; +import org.jspecify.annotations.Nullable; import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java index f40ff95ca5..fdec5887de 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java @@ -27,6 +27,7 @@ import org.aopalliance.aop.Advice; import org.aopalliance.intercept.Interceptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.TargetSource; @@ -43,7 +44,6 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -101,11 +101,9 @@ public class ProxyFactoryBean extends ProxyCreatorSupport private static final Log logger = LogFactory.getLog(ProxyFactoryBean.class); - @Nullable - private String[] interceptorNames; + private String @Nullable [] interceptorNames; - @Nullable - private String targetName; + private @Nullable String targetName; private boolean autodetectInterfaces = true; @@ -115,20 +113,17 @@ public class ProxyFactoryBean extends ProxyCreatorSupport private boolean freezeProxy = false; - @Nullable - private transient ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader(); + private transient @Nullable ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader(); private transient boolean classLoaderConfigured = false; - @Nullable - private transient BeanFactory beanFactory; + private transient @Nullable BeanFactory beanFactory; /** Whether the advisor chain has already been initialized. */ private boolean advisorChainInitialized = false; /** If this is a singleton, the cached singleton proxy instance. */ - @Nullable - private Object singletonInstance; + private @Nullable Object singletonInstance; /** @@ -246,8 +241,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport * @return a fresh AOP proxy reflecting the current state of this factory */ @Override - @Nullable - public Object getObject() throws BeansException { + public @Nullable Object getObject() throws BeansException { initializeAdvisorChain(); if (isSingleton()) { return getSingletonInstance(); @@ -268,8 +262,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport * @see org.springframework.aop.framework.AopProxy#getProxyClass */ @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { synchronized (this) { if (this.singletonInstance != null) { return this.singletonInstance.getClass(); diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java index f58e0be379..96f224c2c8 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ProxyProcessorSupport.java @@ -18,12 +18,13 @@ package org.springframework.aop.framework; import java.io.Closeable; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -45,8 +46,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC */ private int order = Ordered.LOWEST_PRECEDENCE; - @Nullable - private ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader proxyClassLoader = ClassUtils.getDefaultClassLoader(); private boolean classLoaderConfigured = false; @@ -80,8 +80,7 @@ public class ProxyProcessorSupport extends ProxyConfig implements Ordered, BeanC /** * Return the configured proxy ClassLoader for this processor. */ - @Nullable - protected ClassLoader getProxyClassLoader() { + protected @Nullable ClassLoader getProxyClassLoader() { return this.proxyClassLoader; } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java index b5ad8c36f1..e4158ee852 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/ReflectiveMethodInvocation.java @@ -24,11 +24,11 @@ import java.util.Map; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.ProxyMethodInvocation; import org.springframework.aop.support.AopUtils; import org.springframework.core.BridgeMethodResolver; -import org.springframework.lang.Nullable; /** * Spring's implementation of the AOP Alliance @@ -63,21 +63,18 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea protected final Object proxy; - @Nullable - protected final Object target; + protected final @Nullable Object target; protected final Method method; protected Object[] arguments; - @Nullable - private final Class targetClass; + private final @Nullable Class targetClass; /** * Lazily initialized map of user-specific attributes for this invocation. */ - @Nullable - private Map userAttributes; + private @Nullable Map userAttributes; /** * List of MethodInterceptor and InterceptorAndDynamicMethodMatcher @@ -106,7 +103,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea * but would complicate the code. And it would work only for static pointcuts. */ protected ReflectiveMethodInvocation( - Object proxy, @Nullable Object target, Method method, @Nullable Object[] arguments, + Object proxy, @Nullable Object target, Method method, Object @Nullable [] arguments, @Nullable Class targetClass, List interceptorsAndDynamicMethodMatchers) { this.proxy = proxy; @@ -124,8 +121,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea } @Override - @Nullable - public final Object getThis() { + public final @Nullable Object getThis() { return this.target; } @@ -156,8 +152,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea @Override - @Nullable - public Object proceed() throws Throwable { + public @Nullable Object proceed() throws Throwable { // We start with an index of -1 and increment early. if (this.currentInterceptorIndex == this.interceptorsAndDynamicMethodMatchers.size() - 1) { return invokeJoinpoint(); @@ -191,8 +186,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea * @return the return value of the joinpoint * @throws Throwable if invoking the joinpoint resulted in an exception */ - @Nullable - protected Object invokeJoinpoint() throws Throwable { + protected @Nullable Object invokeJoinpoint() throws Throwable { return AopUtils.invokeJoinpointUsingReflection(this.target, this.method, this.arguments); } @@ -260,8 +254,7 @@ public class ReflectiveMethodInvocation implements ProxyMethodInvocation, Clonea } @Override - @Nullable - public Object getUserAttribute(String key) { + public @Nullable Object getUserAttribute(String key) { return (this.userAttributes != null ? this.userAttributes.get(key) : null); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AfterReturningAdviceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AfterReturningAdviceInterceptor.java index 4ce1c45c87..1080230451 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AfterReturningAdviceInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/AfterReturningAdviceInterceptor.java @@ -20,10 +20,10 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AfterAdvice; import org.springframework.aop.AfterReturningAdvice; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,8 +52,7 @@ public class AfterReturningAdviceInterceptor implements MethodInterceptor, After @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { Object retVal = mi.proceed(); this.advice.afterReturning(retVal, mi.getMethod(), mi.getArguments(), mi.getThis()); return retVal; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/MethodBeforeAdviceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/MethodBeforeAdviceInterceptor.java index 09683e0257..a7a26a4288 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/MethodBeforeAdviceInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/MethodBeforeAdviceInterceptor.java @@ -20,10 +20,10 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.BeforeAdvice; import org.springframework.aop.MethodBeforeAdvice; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,8 +52,7 @@ public class MethodBeforeAdviceInterceptor implements MethodInterceptor, BeforeA @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { this.advice.before(mi.getMethod(), mi.getArguments(), mi.getThis()); return mi.proceed(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java index 2baf3e93b1..b9d03e7b23 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/adapter/ThrowsAdviceInterceptor.java @@ -25,10 +25,10 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.AfterAdvice; import org.springframework.aop.framework.AopConfigException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -131,8 +131,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice { @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } @@ -150,8 +149,7 @@ public class ThrowsAdviceInterceptor implements MethodInterceptor, AfterAdvice { * @param exception the exception thrown * @return a handler for the given exception type, or {@code null} if none found */ - @Nullable - private Method getExceptionHandler(Throwable exception) { + private @Nullable Method getExceptionHandler(Throwable exception) { Class exceptionClass = exception.getClass(); if (logger.isTraceEnabled()) { logger.trace("Trying to find handler for exception of type [" + exceptionClass.getName() + "]"); 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 1925e47bfb..331af93b4e 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,9 +9,7 @@ * *

These adapters do not depend on any other Spring framework classes to allow such usage. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.framework.adapter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java index 7a71cb5756..91364f1856 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractAdvisorAutoProxyCreator.java @@ -18,6 +18,8 @@ package org.springframework.aop.framework.autoproxy; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Advisor; import org.springframework.aop.TargetSource; import org.springframework.aop.framework.AopConfigException; @@ -26,7 +28,6 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -53,8 +54,7 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyCreator { - @Nullable - private BeanFactoryAdvisorRetrievalHelper advisorRetrievalHelper; + private @Nullable BeanFactoryAdvisorRetrievalHelper advisorRetrievalHelper; @Override @@ -73,8 +73,7 @@ public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyC @Override - @Nullable - protected Object[] getAdvicesAndAdvisorsForBean( + protected Object @Nullable [] getAdvicesAndAdvisorsForBean( Class beanClass, String beanName, @Nullable TargetSource targetSource) { List advisors = findEligibleAdvisors(beanClass, beanName); 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 ffdf6173f1..cb60fccd72 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 @@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.aopalliance.aop.Advice; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.Pointcut; @@ -48,7 +49,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor; import org.springframework.core.SmartClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -101,8 +101,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * Convenience constant for subclasses: Return value for "do not proxy". * @see #getAdvicesAndAdvisorsForBean */ - @Nullable - protected static final Object[] DO_NOT_PROXY = null; + protected static final Object @Nullable [] DO_NOT_PROXY = null; /** * Convenience constant for subclasses: Return value for @@ -129,11 +128,9 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport private boolean applyCommonInterceptorsFirst = true; - @Nullable - private TargetSourceCreator[] customTargetSourceCreators; + private TargetSourceCreator @Nullable [] customTargetSourceCreators; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; private final Set targetSourcedBeans = ConcurrentHashMap.newKeySet(16); @@ -215,15 +212,13 @@ 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() { + protected @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @Override - @Nullable - public Class predictBeanType(Class beanClass, String beanName) { + public @Nullable Class predictBeanType(Class beanClass, String beanName) { if (this.proxyTypes.isEmpty()) { return null; } @@ -256,8 +251,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport } @Override - @Nullable - public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) { + public Constructor @Nullable [] determineCandidateConstructors(Class beanClass, String beanName) { return null; } @@ -269,8 +263,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport } @Override - @Nullable - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) { + public @Nullable Object postProcessBeforeInstantiation(Class beanClass, String beanName) { Object cacheKey = getCacheKey(beanClass, beanName); if (!StringUtils.hasLength(beanName) || !this.targetSourcedBeans.contains(beanName)) { @@ -311,8 +304,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * @see #getAdvicesAndAdvisorsForBean */ @Override - @Nullable - public Object postProcessAfterInitialization(@Nullable Object bean, String beanName) { + public @Nullable Object postProcessAfterInitialization(@Nullable Object bean, String beanName) { if (bean != null) { Object cacheKey = getCacheKey(bean.getClass(), beanName); if (this.earlyBeanReferences.remove(cacheKey) != bean) { @@ -426,8 +418,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * @return a TargetSource for this bean * @see #setCustomTargetSourceCreators */ - @Nullable - protected TargetSource getCustomTargetSource(Class beanClass, String beanName) { + protected @Nullable TargetSource getCustomTargetSource(Class beanClass, String beanName) { // We can't create fancy target sources for directly registered singletons. if (this.customTargetSourceCreators != null && this.beanFactory != null && this.beanFactory.containsBean(beanName)) { @@ -460,19 +451,19 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * @see #buildAdvisors */ protected Object createProxy(Class beanClass, @Nullable String beanName, - @Nullable Object[] specificInterceptors, TargetSource targetSource) { + Object @Nullable [] specificInterceptors, TargetSource targetSource) { return buildProxy(beanClass, beanName, specificInterceptors, targetSource, false); } private Class createProxyClass(Class beanClass, @Nullable String beanName, - @Nullable Object[] specificInterceptors, TargetSource targetSource) { + Object @Nullable [] specificInterceptors, TargetSource targetSource) { return (Class) buildProxy(beanClass, beanName, specificInterceptors, targetSource, true); } private Object buildProxy(Class beanClass, @Nullable String beanName, - @Nullable Object[] specificInterceptors, TargetSource targetSource, boolean classOnly) { + Object @Nullable [] specificInterceptors, TargetSource targetSource, boolean classOnly) { if (this.beanFactory instanceof ConfigurableListableBeanFactory clbf) { AutoProxyUtils.exposeTargetClass(clbf, beanName, beanClass); @@ -554,7 +545,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * specific to this bean (may be empty, but not null) * @return the list of Advisors for the given bean */ - protected Advisor[] buildAdvisors(@Nullable String beanName, @Nullable Object[] specificInterceptors) { + protected Advisor[] buildAdvisors(@Nullable String beanName, Object @Nullable [] specificInterceptors) { // Handle prototypes correctly... Advisor[] commonInterceptors = resolveInterceptorNames(); @@ -633,8 +624,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport * @see #DO_NOT_PROXY * @see #PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS */ - @Nullable - protected abstract Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, + protected abstract Object @Nullable [] getAdvicesAndAdvisorsForBean(Class beanClass, String beanName, @Nullable TargetSource customTargetSource) throws BeansException; } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java index 0dbea8a467..3cba6a7fd5 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/AbstractBeanFactoryAwareAdvisingPostProcessor.java @@ -16,12 +16,13 @@ package org.springframework.aop.framework.autoproxy; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AbstractAdvisingBeanPostProcessor; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; /** * Extension of {@link AbstractAutoProxyCreator} which implements {@link BeanFactoryAware}, @@ -40,8 +41,7 @@ import org.springframework.lang.Nullable; public abstract class AbstractBeanFactoryAwareAdvisingPostProcessor extends AbstractAdvisingBeanPostProcessor implements BeanFactoryAware { - @Nullable - private ConfigurableListableBeanFactory beanFactory; + private @Nullable ConfigurableListableBeanFactory beanFactory; @Override 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 92c25b432d..0208b14e51 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 @@ -16,11 +16,12 @@ package org.springframework.aop.framework.autoproxy; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.Conventions; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -84,8 +85,7 @@ public abstract class AutoProxyUtils { * @since 4.2.3 * @see org.springframework.beans.factory.BeanFactory#getType(String) */ - @Nullable - public static Class determineTargetClass( + public static @Nullable Class determineTargetClass( ConfigurableListableBeanFactory beanFactory, @Nullable String beanName) { if (beanName == null) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java index a82a8bce56..4ff290ec34 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanFactoryAdvisorRetrievalHelper.java @@ -21,13 +21,13 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCurrentlyInCreationException; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -44,8 +44,7 @@ public class BeanFactoryAdvisorRetrievalHelper { private final ConfigurableListableBeanFactory beanFactory; - @Nullable - private volatile String[] cachedAdvisorBeanNames; + private volatile String @Nullable [] cachedAdvisorBeanNames; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreator.java index 27aa054736..8ab713d01e 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreator.java @@ -19,10 +19,11 @@ package org.springframework.aop.framework.autoproxy; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.PatternMatchUtils; @@ -48,8 +49,7 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator { private static final String[] NO_ALIASES = new String[0]; - @Nullable - private List beanNames; + private @Nullable List beanNames; /** @@ -81,8 +81,7 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator { * @see #setBeanNames(String...) */ @Override - @Nullable - protected TargetSource getCustomTargetSource(Class beanClass, String beanName) { + protected @Nullable TargetSource getCustomTargetSource(Class beanClass, String beanName) { return (isSupportedBeanName(beanClass, beanName) ? super.getCustomTargetSource(beanClass, beanName) : null); } @@ -93,8 +92,7 @@ public class BeanNameAutoProxyCreator extends AbstractAutoProxyCreator { * @see #setBeanNames(String...) */ @Override - @Nullable - protected Object[] getAdvicesAndAdvisorsForBean( + protected Object @Nullable [] getAdvicesAndAdvisorsForBean( Class beanClass, String beanName, @Nullable TargetSource targetSource) { return (isSupportedBeanName(beanClass, beanName) ? diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/DefaultAdvisorAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/DefaultAdvisorAutoProxyCreator.java index 07aff4a3f9..98122847d2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/DefaultAdvisorAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/DefaultAdvisorAutoProxyCreator.java @@ -16,8 +16,9 @@ package org.springframework.aop.framework.autoproxy; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanNameAware; -import org.springframework.lang.Nullable; /** * {@code BeanPostProcessor} implementation that creates AOP proxies based on all @@ -44,8 +45,7 @@ public class DefaultAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCrea private boolean usePrefix = false; - @Nullable - private String advisorBeanNamePrefix; + private @Nullable String advisorBeanNamePrefix; /** @@ -78,8 +78,7 @@ public class DefaultAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCrea * Return the prefix for bean names that will cause them to be included * for auto-proxying by this object. */ - @Nullable - public String getAdvisorBeanNamePrefix() { + public @Nullable String getAdvisorBeanNamePrefix() { return this.advisorBeanNamePrefix; } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/InfrastructureAdvisorAutoProxyCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/InfrastructureAdvisorAutoProxyCreator.java index f283920fca..0c11bc8c22 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/InfrastructureAdvisorAutoProxyCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/InfrastructureAdvisorAutoProxyCreator.java @@ -16,9 +16,10 @@ package org.springframework.aop.framework.autoproxy; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; /** * Auto-proxy creator that considers infrastructure Advisor beans only, @@ -30,8 +31,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class InfrastructureAdvisorAutoProxyCreator extends AbstractAdvisorAutoProxyCreator { - @Nullable - private ConfigurableListableBeanFactory beanFactory; + private @Nullable ConfigurableListableBeanFactory beanFactory; @Override 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 314fcc98f2..19a30ad6c7 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 @@ -16,8 +16,9 @@ package org.springframework.aop.framework.autoproxy; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; /** * Holder for the current proxy creation context, as exposed by auto-proxy creators @@ -42,8 +43,7 @@ public final 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() { + public static @Nullable String getCurrentProxiedBeanName() { return currentProxiedBeanName.get(); } 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 012c060e98..e8a88d2d5b 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 @@ -16,8 +16,9 @@ package org.springframework.aop.framework.autoproxy; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; /** * Implementations can create special target sources, such as pooling target @@ -40,7 +41,6 @@ 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); + @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 328312146a..15acaaff35 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,9 +9,7 @@ * as post-processors beans are only automatically detected in application contexts. * Post-processors can be explicitly registered on a ConfigurableBeanFactory instead. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.framework.autoproxy; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 b9a5e4e4c4..4fd9054084 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 @@ -21,6 +21,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.TargetSource; import org.springframework.aop.framework.AopInfrastructureBean; @@ -33,7 +34,6 @@ import org.springframework.beans.factory.config.BeanDefinition; 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; import org.springframework.util.Assert; /** @@ -59,8 +59,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ConfigurableBeanFactory beanFactory; + private @Nullable ConfigurableBeanFactory beanFactory; /** Internally used DefaultListableBeanFactory instances, keyed by bean name. */ private final Map internalBeanFactories = new HashMap<>(); @@ -78,8 +77,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator /** * Return the BeanFactory that this TargetSourceCreators runs in. */ - @Nullable - protected final BeanFactory getBeanFactory() { + protected final @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @@ -94,8 +92,7 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator //--------------------------------------------------------------------- @Override - @Nullable - public final TargetSource getTargetSource(Class beanClass, String beanName) { + public final @Nullable TargetSource getTargetSource(Class beanClass, String beanName) { AbstractBeanFactoryBasedTargetSource targetSource = createBeanFactoryBasedTargetSource(beanClass, beanName); if (targetSource == null) { @@ -195,8 +192,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( + protected abstract @Nullable AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( Class beanClass, String beanName); } diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java index 68ca052447..bca5d66424 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/LazyInitTargetSourceCreator.java @@ -16,11 +16,12 @@ package org.springframework.aop.framework.autoproxy.target; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource; import org.springframework.aop.target.LazyInitTargetSource; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; /** * {@code TargetSourceCreator} that enforces a {@link LazyInitTargetSource} for @@ -62,8 +63,7 @@ public class LazyInitTargetSourceCreator extends AbstractBeanFactoryBasedTargetS } @Override - @Nullable - protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( + protected @Nullable AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( Class beanClass, String beanName) { if (getBeanFactory() instanceof ConfigurableListableBeanFactory clbf) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java index f7df6c3024..18836564c6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/QuickTargetSourceCreator.java @@ -16,11 +16,12 @@ package org.springframework.aop.framework.autoproxy.target; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.target.AbstractBeanFactoryBasedTargetSource; import org.springframework.aop.target.CommonsPool2TargetSource; import org.springframework.aop.target.PrototypeTargetSource; import org.springframework.aop.target.ThreadLocalTargetSource; -import org.springframework.lang.Nullable; /** * Convenient TargetSourceCreator using bean name prefixes to create one of three @@ -55,8 +56,7 @@ public class QuickTargetSourceCreator extends AbstractBeanFactoryBasedTargetSour public static final String PREFIX_PROTOTYPE = "!"; @Override - @Nullable - protected final AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( + protected final @Nullable AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource( Class beanClass, String beanName) { if (beanName.startsWith(PREFIX_COMMONS_POOL)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package-info.java b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package-info.java index 2e0608db9d..928aa745b3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/framework/autoproxy/target/package-info.java @@ -2,9 +2,7 @@ * Various {@link org.springframework.aop.framework.autoproxy.TargetSourceCreator} * implementations for use with Spring's AOP auto-proxying support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.framework.autoproxy.target; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c05af5dea9..db79833a47 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,9 +12,7 @@ * or ApplicationContext. However, proxies can be created programmatically using the * ProxyFactory class. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.framework; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java index 536e6e3ade..a9e7d6ca11 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractMonitoringInterceptor.java @@ -19,8 +19,7 @@ package org.springframework.aop.interceptor; import java.lang.reflect.Method; import org.aopalliance.intercept.MethodInvocation; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Base class for monitoring interceptors, such as performance monitors. diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractTraceInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractTraceInterceptor.java index 2d67708c35..8ff8cbd619 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractTraceInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AbstractTraceInterceptor.java @@ -22,9 +22,9 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,8 +52,7 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser * The default {@code Log} instance used to write trace messages. * This instance is mapped to the implementing {@code Class}. */ - @Nullable - protected transient Log defaultLogger = LogFactory.getLog(getClass()); + protected transient @Nullable Log defaultLogger = LogFactory.getLog(getClass()); /** * Indicates whether proxy class names should be hidden when using dynamic loggers. @@ -125,8 +124,7 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser * @see #invokeUnderTrace(org.aopalliance.intercept.MethodInvocation, org.apache.commons.logging.Log) */ @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { Log logger = getLoggerForInvocation(invocation); if (isInterceptorEnabled(invocation, logger)) { return invokeUnderTrace(invocation, logger); @@ -245,7 +243,6 @@ public abstract class AbstractTraceInterceptor implements MethodInterceptor, Ser * @see #writeToLog(Log, String) * @see #writeToLog(Log, String, Throwable) */ - @Nullable - protected abstract Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable; + protected abstract @Nullable Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable; } 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 d9276cef97..d5588f8867 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 @@ -27,6 +27,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -38,7 +39,6 @@ import org.springframework.beans.factory.config.EmbeddedValueResolver; 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.StringValueResolver; @@ -78,11 +78,9 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { private SingletonSupplier exceptionHandler; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private final Map executors = new ConcurrentHashMap<>(16); @@ -167,8 +165,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * Determine the specific executor to use when executing the given method. * @return the executor to use (or {@code null}, but just if no default executor is available) */ - @Nullable - protected AsyncTaskExecutor determineAsyncExecutor(Method method) { + protected @Nullable AsyncTaskExecutor determineAsyncExecutor(Method method) { AsyncTaskExecutor executor = this.executors.get(method); if (executor == null) { Executor targetExecutor; @@ -203,8 +200,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @see #determineAsyncExecutor(Method) * @see #findQualifiedExecutor(BeanFactory, String) */ - @Nullable - protected abstract String getExecutorQualifier(Method method); + protected abstract @Nullable String getExecutorQualifier(Method method); /** * Retrieve a target executor for the given qualifier. @@ -213,8 +209,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @since 4.2.6 * @see #getExecutorQualifier(Method) */ - @Nullable - protected Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, String qualifier) { + protected @Nullable Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, String qualifier) { if (beanFactory == null) { throw new IllegalStateException("BeanFactory must be set on " + getClass().getSimpleName() + " to access qualified executor '" + qualifier + "'"); @@ -234,8 +229,7 @@ public abstract class AsyncExecutionAspectSupport implements BeanFactoryAware { * @see #findQualifiedExecutor(BeanFactory, String) * @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME */ - @Nullable - protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) { + protected @Nullable Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) { if (beanFactory != null) { try { // Search for TaskExecutor bean... not plain Executor since that would @@ -281,8 +275,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) { + protected @Nullable Object doSubmit(Callable task, AsyncTaskExecutor executor, Class returnType) { if (CompletableFuture.class.isAssignableFrom(returnType)) { return executor.submitCompletable(task); } diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java index 9333759224..edc54e3d26 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/AsyncExecutionInterceptor.java @@ -24,6 +24,7 @@ import java.util.concurrent.Future; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.BeanFactory; @@ -31,7 +32,6 @@ import org.springframework.core.BridgeMethodResolver; import org.springframework.core.Ordered; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.SimpleAsyncTaskExecutor; -import org.springframework.lang.Nullable; /** * AOP Alliance {@code MethodInterceptor} that processes method invocations @@ -97,9 +97,8 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple * otherwise. */ @Override - @Nullable @SuppressWarnings("NullAway") - public Object invoke(final MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(final MethodInvocation invocation) throws Throwable { Class targetClass = (invocation.getThis() != null ? AopUtils.getTargetClass(invocation.getThis()) : null); final Method userMethod = BridgeMethodResolver.getMostSpecificMethod(invocation.getMethod(), targetClass); @@ -140,8 +139,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple * @see #determineAsyncExecutor(Method) */ @Override - @Nullable - protected String getExecutorQualifier(Method method) { + protected @Nullable String getExecutorQualifier(Method method) { return null; } @@ -154,8 +152,7 @@ public class AsyncExecutionInterceptor extends AsyncExecutionAspectSupport imple * @see #DEFAULT_TASK_EXECUTOR_BEAN_NAME */ @Override - @Nullable - protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) { + protected @Nullable Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) { Executor defaultExecutor = super.getDefaultExecutor(beanFactory); return (defaultExecutor != null ? defaultExecutor : new SimpleAsyncTaskExecutor()); } diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptor.java index 3e6e6e9b7c..65d540f939 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/ConcurrencyThrottleInterceptor.java @@ -20,8 +20,8 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ConcurrencyThrottleSupport; /** @@ -49,8 +49,7 @@ public class ConcurrencyThrottleInterceptor extends ConcurrencyThrottleSupport } @Override - @Nullable - public Object invoke(MethodInvocation methodInvocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation methodInvocation) throws Throwable { beforeAccess(); try { return methodInvocation.proceed(); 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 46c879ff1d..157b5ef1a1 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 @@ -22,8 +22,8 @@ import java.util.regex.Pattern; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StopWatch; diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/DebugInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/DebugInterceptor.java index 06ea610290..288771bb9a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/DebugInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/DebugInterceptor.java @@ -17,8 +17,7 @@ package org.springframework.aop.interceptor; import org.aopalliance.intercept.MethodInvocation; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * AOP Alliance {@code MethodInterceptor} that can be introduced in a chain @@ -58,8 +57,7 @@ public class DebugInterceptor extends SimpleTraceInterceptor { @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { synchronized (this) { this.count++; } diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java index 1f095ed89e..f43a9ee8d2 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeBeanNameAdvisors.java @@ -18,6 +18,7 @@ package org.springframework.aop.interceptor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.ProxyMethodInvocation; @@ -25,7 +26,6 @@ import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.aop.support.DelegatingIntroductionInterceptor; import org.springframework.beans.factory.NamedBean; -import org.springframework.lang.Nullable; /** * Convenient methods for creating advisors that may be used when autoproxying beans @@ -110,8 +110,7 @@ public abstract class ExposeBeanNameAdvisors { } @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } @@ -134,8 +133,7 @@ public abstract class ExposeBeanNameAdvisors { } @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { if (!(mi instanceof ProxyMethodInvocation pmi)) { throw new IllegalStateException("MethodInvocation is not a Spring ProxyMethodInvocation: " + mi); } diff --git a/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeInvocationInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeInvocationInterceptor.java index 18c9caf1ea..a3a7bca9ac 100644 --- a/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeInvocationInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/interceptor/ExposeInvocationInterceptor.java @@ -20,12 +20,12 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.core.NamedThreadLocal; import org.springframework.core.PriorityOrdered; -import org.springframework.lang.Nullable; /** * Interceptor that exposes the current {@link org.aopalliance.intercept.MethodInvocation} @@ -89,8 +89,7 @@ public final class ExposeInvocationInterceptor implements MethodInterceptor, Pri } @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { MethodInvocation oldInvocation = invocation.get(); invocation.set(mi); try { 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 eb2a05f4be..186d58aa07 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,9 +3,7 @@ * More specific interceptors can be found in corresponding * functionality packages, like "transaction" and "orm". */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.interceptor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2b87bce534..f2d5c60508 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,9 +17,7 @@ *

Spring AOP can be used programmatically or (preferably) * integrated with the Spring IoC container. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java index af2c7af67a..d2081dfc61 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyBeanRegistrationAotProcessor.java @@ -22,6 +22,7 @@ import javax.lang.model.element.Modifier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GenerationContext; @@ -38,7 +39,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.ResolvableType; import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; -import org.springframework.lang.Nullable; /** * {@link BeanRegistrationAotProcessor} for {@link ScopedProxyFactoryBean}. @@ -53,9 +53,8 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc @Override - @Nullable @SuppressWarnings("NullAway") - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); if (beanClass.equals(ScopedProxyFactoryBean.class)) { String targetBeanName = getTargetBeanName(registeredBean.getMergedBeanDefinition()); @@ -73,14 +72,12 @@ class ScopedProxyBeanRegistrationAotProcessor implements BeanRegistrationAotProc return null; } - @Nullable - private String getTargetBeanName(BeanDefinition beanDefinition) { + private @Nullable String getTargetBeanName(BeanDefinition beanDefinition) { Object value = beanDefinition.getPropertyValues().get("targetBeanName"); return (value instanceof String targetBeanName ? targetBeanName : null); } - @Nullable - private BeanDefinition getTargetBeanDefinition( + private @Nullable BeanDefinition getTargetBeanDefinition( ConfigurableBeanFactory beanFactory, @Nullable String targetBeanName) { if (targetBeanName != null && beanFactory.containsBean(targetBeanName)) { diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java index a787a1ee80..8beeff41ff 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyFactoryBean.java @@ -18,6 +18,8 @@ package org.springframework.aop.scope; import java.lang.reflect.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopInfrastructureBean; import org.springframework.aop.framework.ProxyConfig; import org.springframework.aop.framework.ProxyFactory; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -59,12 +60,10 @@ public class ScopedProxyFactoryBean extends ProxyConfig private final SimpleBeanTargetSource scopedTargetSource = new SimpleBeanTargetSource(); /** The name of the target bean. */ - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; /** The cached singleton proxy. */ - @Nullable - private Object proxy; + private @Nullable Object proxy; /** @@ -117,8 +116,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig @Override - @Nullable - public Object getObject() { + public @Nullable Object getObject() { if (this.proxy == null) { throw new FactoryBeanNotInitializedException(); } @@ -126,8 +124,7 @@ public class ScopedProxyFactoryBean extends ProxyConfig } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { if (this.proxy != null) { return this.proxy.getClass(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java index 2eee3a4258..f2f073613b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java +++ b/spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java @@ -16,6 +16,8 @@ package org.springframework.aop.scope; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.autoproxy.AutoProxyUtils; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; @@ -23,7 +25,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 443f903968..2736df6ebf 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,9 +1,7 @@ /** * Support for AOP-based scoping of target objects, with configurable backend. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.scope; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 e6a10c621b..6afa797771 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 @@ -20,10 +20,10 @@ import java.io.IOException; import java.io.ObjectInputStream; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,14 +42,11 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcutAdvisor implements BeanFactoryAware { - @Nullable - private String adviceBeanName; + private @Nullable String adviceBeanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private transient volatile Advice advice; + private transient volatile @Nullable Advice advice; private transient Object adviceMonitor = new Object(); @@ -69,8 +66,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() { + public @Nullable 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 5330f2c00d..080751196a 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,7 +18,7 @@ package org.springframework.aop.support; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract superclass for expression pointcuts, @@ -33,11 +33,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public abstract class AbstractExpressionPointcut implements ExpressionPointcut, Serializable { - @Nullable - private String location; + private @Nullable String location; - @Nullable - private String expression; + private @Nullable String expression; /** @@ -53,8 +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() { + public @Nullable String getLocation() { return this.location; } @@ -89,8 +86,7 @@ public abstract class AbstractExpressionPointcut implements ExpressionPointcut, * Return this pointcut's expression. */ @Override - @Nullable - public String getExpression() { + public @Nullable String getExpression() { return this.expression; } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java index fc5527270e..72cd6011d1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java @@ -19,10 +19,10 @@ package org.springframework.aop.support; import java.io.Serializable; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.PointcutAdvisor; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -38,8 +38,7 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") public abstract class AbstractPointcutAdvisor implements PointcutAdvisor, Ordered, Serializable { - @Nullable - private Integer order; + private @Nullable Integer order; public void setOrder(int order) { diff --git a/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java index acb56fd468..885f70a79c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/AbstractRegexpMethodPointcut.java @@ -20,7 +20,8 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.Arrays; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; 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 38eba72e6d..f6fa342415 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 @@ -28,6 +28,7 @@ import java.util.Set; import kotlin.coroutines.Continuation; import kotlin.coroutines.CoroutineContext; import kotlinx.coroutines.Job; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Advisor; import org.springframework.aop.AopInvocationException; @@ -43,7 +44,6 @@ import org.springframework.core.CoroutinesUtils; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodIntrospector; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -347,8 +347,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(@Nullable Object target, Method method, Object[] args) + public static @Nullable Object invokeJoinpointUsingReflection(@Nullable Object target, Method method, Object[] args) throws Throwable { // Use reflection to invoke the method. diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java index 929196e66b..be84eeb584 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ClassFilters.java @@ -20,8 +20,9 @@ import java.io.Serializable; import java.util.Arrays; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java index 432635510c..40ba09555d 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ComposablePointcut.java @@ -18,10 +18,11 @@ package org.springframework.aop.support; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + 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; /** 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 43707df5c2..fc7e7af34a 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 @@ -23,10 +23,11 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; +import org.jspecify.annotations.Nullable; + 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.PatternMatchUtils; diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java index ce68704856..80ac2ea261 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultBeanFactoryPointcutAdvisor.java @@ -16,8 +16,9 @@ package org.springframework.aop.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Pointcut; -import org.springframework.lang.Nullable; /** * Concrete BeanFactory-based PointcutAdvisor that allows for any Advice 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 930255c62c..f95cf95a0b 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 @@ -21,13 +21,13 @@ import java.util.LinkedHashSet; import java.util.Set; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.ClassFilter; 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; diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java b/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java index 45c2e17254..b6e5a5dd80 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DefaultPointcutAdvisor.java @@ -19,9 +19,9 @@ package org.springframework.aop.support; import java.io.Serializable; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Pointcut; -import org.springframework.lang.Nullable; /** * Convenient Pointcut-driven Advisor implementation. diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java index 0f3d511c0d..6a4ebc23cc 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DelegatePerTargetObjectIntroductionInterceptor.java @@ -20,11 +20,11 @@ import java.util.Map; import java.util.WeakHashMap; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.DynamicIntroductionAdvice; import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.ProxyMethodInvocation; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -86,8 +86,7 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction * method, which handles introduced interfaces and forwarding to the target. */ @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { if (isMethodOnIntroducedInterface(mi)) { Object delegate = getIntroductionDelegateFor(mi.getThis()); @@ -114,8 +113,7 @@ public class DelegatePerTargetObjectIntroductionInterceptor extends Introduction * that it is introduced into. This method is never called for * {@link MethodInvocation MethodInvocations} on the introduced interfaces. */ - @Nullable - protected Object doProceed(MethodInvocation mi) throws Throwable { + protected @Nullable Object doProceed(MethodInvocation mi) throws Throwable { // If we get here, just pass the invocation on. return mi.proceed(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java b/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java index bd9647a0f4..1948ef5647 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/DelegatingIntroductionInterceptor.java @@ -17,11 +17,11 @@ package org.springframework.aop.support; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.DynamicIntroductionAdvice; import org.springframework.aop.IntroductionInterceptor; import org.springframework.aop.ProxyMethodInvocation; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -57,8 +57,7 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport * Object that actually implements the interfaces. * May be "this" if a subclass implements the introduced interfaces. */ - @Nullable - private Object delegate; + private @Nullable Object delegate; /** @@ -102,8 +101,7 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport * method, which handles introduced interfaces and forwarding to the target. */ @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { if (isMethodOnIntroducedInterface(mi)) { // Using the following method rather than direct reflection, we // get correct handling of InvocationTargetException @@ -131,8 +129,7 @@ public class DelegatingIntroductionInterceptor extends IntroductionInfoSupport * that it is introduced into. This method is never called for * {@link MethodInvocation MethodInvocations} on the introduced interfaces. */ - @Nullable - protected Object doProceed(MethodInvocation mi) throws Throwable { + protected @Nullable Object doProceed(MethodInvocation mi) throws Throwable { // If we get here, just pass the invocation on. return mi.proceed(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java index 99b76e135d..a4ba549c6b 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/ExpressionPointcut.java @@ -16,8 +16,9 @@ package org.springframework.aop.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Pointcut; -import org.springframework.lang.Nullable; /** * Interface to be implemented by pointcuts that use String expressions. @@ -30,7 +31,6 @@ public interface ExpressionPointcut extends Pointcut { /** * Return the String expression for this pointcut. */ - @Nullable - String getExpression(); + @Nullable String getExpression(); } 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 f2d226adfb..53c558a498 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 @@ -20,10 +20,11 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.Objects; +import org.jspecify.annotations.Nullable; + 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; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java index 9a11e60b87..b3967854d3 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/NameMatchMethodPointcut.java @@ -22,7 +22,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.PatternMatchUtils; /** 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 bc41a9fbdd..79dca14707 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 @@ -19,9 +19,9 @@ package org.springframework.aop.support; import java.io.Serializable; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Pointcut; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -45,11 +45,9 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") public class RegexpMethodPointcutAdvisor extends AbstractGenericPointcutAdvisor { - @Nullable - private String[] patterns; + private String @Nullable [] patterns; - @Nullable - private AbstractRegexpMethodPointcut pointcut; + private @Nullable AbstractRegexpMethodPointcut pointcut; private final Object pointcutMonitor = new SerializableMonitor(); diff --git a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java index c4bf82a186..d0cf1eb21a 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java @@ -18,8 +18,9 @@ package org.springframework.aop.support; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java index 9b234633ad..6385d108f7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationClassFilter.java @@ -18,9 +18,10 @@ package org.springframework.aop.support.annotation; import java.lang.annotation.Annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 c6e11ecf77..864ecd9fdc 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 @@ -18,11 +18,12 @@ package org.springframework.aop.support.annotation; import java.lang.annotation.Annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java index 520519ff72..3e637663f0 100644 --- a/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java +++ b/spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMethodMatcher.java @@ -20,10 +20,11 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Proxy; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.support.AopUtils; import org.springframework.aop.support.StaticMethodMatcher; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 a5ec1d421a..367eb88543 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,9 +1,7 @@ /** * Annotation support for AOP pointcuts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.support.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a39f2d4c30..af967794b4 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,9 +1,7 @@ /** * Convenience classes for using Spring's AOP API. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java index 6ab195c0a7..55930b639f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractBeanFactoryBasedTargetSource.java @@ -21,11 +21,11 @@ import java.util.Objects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.TargetSource; 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.ObjectUtils; @@ -60,19 +60,16 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour protected final transient Log logger = LogFactory.getLog(getClass()); /** Name of the target bean we will create on each invocation. */ - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; /** Class of the target. */ - @Nullable - private volatile Class targetClass; + private volatile @Nullable Class targetClass; /** * BeanFactory that owns this TargetSource. We need to hold onto this * reference so that we can create new prototype instances as necessary. */ - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** @@ -128,8 +125,7 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { Class targetClass = this.targetClass; if (targetClass != null) { return targetClass; diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java index 5783875701..7c8af147ad 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractLazyCreationTargetSource.java @@ -18,9 +18,9 @@ package org.springframework.aop.target; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; /** * {@link org.springframework.aop.TargetSource} implementation that will @@ -46,8 +46,7 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource { protected final Log logger = LogFactory.getLog(getClass()); /** The lazily initialized target object. */ - @Nullable - private Object lazyTarget; + private @Nullable Object lazyTarget; /** @@ -67,8 +66,7 @@ public abstract class AbstractLazyCreationTargetSource implements TargetSource { * @see #isInitialized() */ @Override - @Nullable - public synchronized Class getTargetClass() { + public synchronized @Nullable Class getTargetClass() { return (this.lazyTarget != null ? this.lazyTarget.getClass() : null); } diff --git a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java index 30e9c1e2ef..e6cf192e8f 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/AbstractPoolingTargetSource.java @@ -16,13 +16,14 @@ package org.springframework.aop.target; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.support.DefaultIntroductionAdvisor; import org.springframework.aop.support.DelegatingIntroductionInterceptor; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.DisposableBean; -import org.springframework.lang.Nullable; /** * Abstract base class for pooling {@link org.springframework.aop.TargetSource} @@ -101,8 +102,7 @@ public abstract class AbstractPoolingTargetSource extends AbstractPrototypeBased * APIs, so we're forgiving with our exception signature */ @Override - @Nullable - public abstract Object getTarget() throws Exception; + public abstract @Nullable Object getTarget() throws Exception; /** * Return the given object to the pool. diff --git a/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java index 4c0e5b48da..8160f62a48 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/CommonsPool2TargetSource.java @@ -22,8 +22,8 @@ import org.apache.commons.pool2.PooledObjectFactory; import org.apache.commons.pool2.impl.DefaultPooledObject; import org.apache.commons.pool2.impl.GenericObjectPool; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -81,8 +81,7 @@ public class CommonsPool2TargetSource extends AbstractPoolingTargetSource implem /** * The Apache Commons {@code ObjectPool} used to pool target objects. */ - @Nullable - private ObjectPool pool; + private @Nullable ObjectPool pool; /** 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 cfcb3b119f..75575446f3 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,8 +19,9 @@ package org.springframework.aop.target; import java.io.Serializable; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -71,8 +72,7 @@ public final class EmptyTargetSource implements TargetSource, Serializable { // Instance implementation //--------------------------------------------------------------------- - @Nullable - private final Class targetClass; + private final @Nullable Class targetClass; private final boolean isStatic; @@ -94,8 +94,7 @@ public final class EmptyTargetSource implements TargetSource, Serializable { * Always returns the specified target Class, or {@code null} if none. */ @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { return this.targetClass; } @@ -111,8 +110,7 @@ public final class EmptyTargetSource implements TargetSource, Serializable { * Always returns {@code null}. */ @Override - @Nullable - public Object getTarget() { + public @Nullable Object getTarget() { return null; } diff --git a/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java index fb5aceefca..dd4babd56c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/HotSwappableTargetSource.java @@ -18,8 +18,9 @@ package org.springframework.aop.target; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-aop/src/main/java/org/springframework/aop/target/LazyInitTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/LazyInitTargetSource.java index e69a01842e..3b766190a7 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/LazyInitTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/LazyInitTargetSource.java @@ -16,8 +16,9 @@ package org.springframework.aop.target; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; /** * {@link org.springframework.aop.TargetSource} that lazily accesses a @@ -60,8 +61,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class LazyInitTargetSource extends AbstractBeanFactoryBasedTargetSource { - @Nullable - private Object target; + private @Nullable Object target; @Override diff --git a/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java index 11e3a9e8fe..f947f29804 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/SingletonTargetSource.java @@ -18,8 +18,9 @@ package org.springframework.aop.target; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; diff --git a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java index 5871ac8b95..645a5602d6 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/AbstractRefreshableTargetSource.java @@ -18,9 +18,9 @@ package org.springframework.aop.target.dynamic; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; /** * Abstract {@link org.springframework.aop.TargetSource} implementation that @@ -42,8 +42,7 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - protected Object targetObject; + protected @Nullable Object targetObject; private long refreshCheckDelay = -1; @@ -75,8 +74,7 @@ public abstract class AbstractRefreshableTargetSource implements TargetSource, R } @Override - @Nullable - public final synchronized Object getTarget() { + public final synchronized @Nullable Object getTarget() { if ((refreshCheckDelayElapsed() && requiresRefresh()) || this.targetObject == null) { refresh(); } diff --git a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package-info.java b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package-info.java index 5ac4c66c18..27d8af4ff1 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/dynamic/package-info.java @@ -2,9 +2,7 @@ * Support for dynamic, refreshable {@link org.springframework.aop.TargetSource} * implementations for use with Spring AOP. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.target.dynamic; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/main/java/org/springframework/aop/target/package-info.java b/spring-aop/src/main/java/org/springframework/aop/target/package-info.java index 292cdcce5d..88fb11976c 100644 --- a/spring-aop/src/main/java/org/springframework/aop/target/package-info.java +++ b/spring-aop/src/main/java/org/springframework/aop/target/package-info.java @@ -2,9 +2,7 @@ * Various {@link org.springframework.aop.TargetSource} implementations for use * with Spring AOP. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aop.target; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/TrickyAspectJPointcutExpressionTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/TrickyAspectJPointcutExpressionTests.java index d7dec7bf33..74484dcf70 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/TrickyAspectJPointcutExpressionTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/TrickyAspectJPointcutExpressionTests.java @@ -24,6 +24,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.Advisor; @@ -32,7 +33,6 @@ import org.springframework.aop.ThrowsAdvice; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java index e6b8fe34cc..c84bfd4dd7 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJAdvisorBeanRegistrationAotProcessorTests.java @@ -16,6 +16,7 @@ package org.springframework.aop.aspectj.annotation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GenerationContext; @@ -26,7 +27,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotContribution; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -65,8 +65,7 @@ class AspectJAdvisorBeanRegistrationAotProcessorTests { } } - @Nullable - private static BeanRegistrationAotContribution createContribution(Class beanClass) { + private static @Nullable BeanRegistrationAotContribution createContribution(Class beanClass) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass)); return new AspectJAdvisorBeanRegistrationAotProcessor() diff --git a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessorTests.java b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessorTests.java index 810409ee0f..a9bc36d97d 100644 --- a/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessorTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectJBeanFactoryInitializationAotProcessorTests.java @@ -20,6 +20,7 @@ import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GenerationContext; @@ -28,7 +29,6 @@ import org.springframework.aot.test.generate.TestGenerationContext; import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -61,8 +61,7 @@ class AspectJBeanFactoryInitializationAotProcessorTests { } } - @Nullable - private static BeanFactoryInitializationAotContribution createContribution(Class beanClass) { + private static @Nullable BeanFactoryInitializationAotContribution createContribution(Class beanClass) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass)); return new AspectJBeanFactoryInitializationAotProcessor().processAheadOfTime(beanFactory); diff --git a/spring-aop/src/test/java/org/springframework/aop/framework/AbstractProxyExceptionHandlingTests.java b/spring-aop/src/test/java/org/springframework/aop/framework/AbstractProxyExceptionHandlingTests.java index 6b3e34cba8..d187204d9d 100644 --- a/spring-aop/src/test/java/org/springframework/aop/framework/AbstractProxyExceptionHandlingTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/framework/AbstractProxyExceptionHandlingTests.java @@ -20,14 +20,13 @@ import java.lang.reflect.UndeclaredThrowableException; import java.util.Objects; import org.aopalliance.intercept.MethodInterceptor; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockito.stubbing.Answer; -import org.springframework.lang.Nullable; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.BDDMockito.willAnswer; @@ -82,8 +81,7 @@ abstract class AbstractProxyExceptionHandlingTests { @Nested class WhenThereIsOneInterceptorTests { - @Nullable - private Throwable throwableSeenByInterceptor; + private @Nullable Throwable throwableSeenByInterceptor; @BeforeEach void beforeEach() { diff --git a/spring-aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java b/spring-aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java index fb4d1ed6f7..5da2f556be 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/AopUtilsTests.java @@ -19,6 +19,7 @@ package org.springframework.aop.support; import java.lang.reflect.Method; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.ClassFilter; @@ -31,7 +32,6 @@ import org.springframework.aop.testfixture.interceptor.NopInterceptor; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.ResolvableType; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java b/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java index 54b3657703..0e59d7530c 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/ComposablePointcutTests.java @@ -18,6 +18,7 @@ package org.springframework.aop.support; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.ClassFilter; @@ -25,7 +26,6 @@ import org.springframework.aop.MethodMatcher; import org.springframework.aop.Pointcut; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java b/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java index 6fae987c9e..e1bae0239b 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/MethodMatchersTests.java @@ -18,6 +18,7 @@ package org.springframework.aop.support; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.MethodMatcher; @@ -25,7 +26,6 @@ import org.springframework.beans.testfixture.beans.IOther; import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; diff --git a/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java b/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java index 6f50a9aecc..cec4198aee 100644 --- a/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java +++ b/spring-aop/src/test/java/org/springframework/aop/support/PointcutsTests.java @@ -18,12 +18,12 @@ package org.springframework.aop.support; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.ClassFilter; import org.springframework.aop.Pointcut; import org.springframework.beans.testfixture.beans.TestBean; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/advice/MethodCounter.java b/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/advice/MethodCounter.java index ed5ba5ffc9..4551a8f3f1 100644 --- a/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/advice/MethodCounter.java +++ b/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/advice/MethodCounter.java @@ -21,7 +21,7 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract superclass for counting advices etc. diff --git a/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java b/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java index df7bb2bd98..4eaef005af 100644 --- a/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java +++ b/spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java @@ -18,8 +18,7 @@ package org.springframework.aop.testfixture.interceptor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Trivial interceptor that can be introduced in a chain to display it. diff --git a/spring-aspects/src/main/java/org/springframework/beans/factory/aspectj/package-info.java b/spring-aspects/src/main/java/org/springframework/beans/factory/aspectj/package-info.java index 675ca10d68..0497dbf9db 100644 --- a/spring-aspects/src/main/java/org/springframework/beans/factory/aspectj/package-info.java +++ b/spring-aspects/src/main/java/org/springframework/beans/factory/aspectj/package-info.java @@ -1,9 +1,7 @@ /** * AspectJ-based dependency injection support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.aspectj; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aspects/src/main/java/org/springframework/cache/aspectj/package-info.java b/spring-aspects/src/main/java/org/springframework/cache/aspectj/package-info.java index 36080e068d..b70a6b3346 100644 --- a/spring-aspects/src/main/java/org/springframework/cache/aspectj/package-info.java +++ b/spring-aspects/src/main/java/org/springframework/cache/aspectj/package-info.java @@ -1,9 +1,7 @@ /** * AspectJ-based caching support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.aspectj; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aspects/src/main/java/org/springframework/context/annotation/aspectj/package-info.java b/spring-aspects/src/main/java/org/springframework/context/annotation/aspectj/package-info.java index 4554b676e4..aebcc1a57b 100644 --- a/spring-aspects/src/main/java/org/springframework/context/annotation/aspectj/package-info.java +++ b/spring-aspects/src/main/java/org/springframework/context/annotation/aspectj/package-info.java @@ -3,9 +3,7 @@ * {@link org.springframework.beans.factory.annotation.Configurable @Configurable} * annotation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.annotation.aspectj; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/package-info.java b/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/package-info.java index 5543ab52fa..2b1d21941d 100644 --- a/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/package-info.java +++ b/spring-aspects/src/main/java/org/springframework/scheduling/aspectj/package-info.java @@ -1,9 +1,7 @@ /** * AspectJ-based scheduling support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling.aspectj; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aspects/src/main/java/org/springframework/transaction/aspectj/package-info.java b/spring-aspects/src/main/java/org/springframework/transaction/aspectj/package-info.java index 8b4c08397d..3b9f9f2da0 100644 --- a/spring-aspects/src/main/java/org/springframework/transaction/aspectj/package-info.java +++ b/spring-aspects/src/main/java/org/springframework/transaction/aspectj/package-info.java @@ -1,9 +1,7 @@ /** * AspectJ-based transaction management support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.aspectj; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-aspects/src/test/java/org/springframework/cache/config/TestEntity.java b/spring-aspects/src/test/java/org/springframework/cache/config/TestEntity.java index 0219086ed4..c069cf4a36 100644 --- a/spring-aspects/src/test/java/org/springframework/cache/config/TestEntity.java +++ b/spring-aspects/src/test/java/org/springframework/cache/config/TestEntity.java @@ -18,7 +18,8 @@ package org.springframework.cache.config; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** 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 6f2e5eff33..17bcbf39b2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java @@ -33,13 +33,13 @@ import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.CollectionFactory; 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; @@ -78,17 +78,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA private int autoGrowCollectionLimit = Integer.MAX_VALUE; - @Nullable - Object wrappedObject; + @Nullable Object wrappedObject; private String nestedPath = ""; - @Nullable - Object rootObject; + @Nullable Object rootObject; /** Map with cached nested Accessors: nested path -> Accessor instance. */ - @Nullable - private Map nestedPropertyAccessors; + private @Nullable Map nestedPropertyAccessors; /** @@ -488,8 +485,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA } @Override - @Nullable - public Class getPropertyType(String propertyName) throws BeansException { + public @Nullable Class getPropertyType(String propertyName) throws BeansException { try { PropertyHandler ph = getPropertyHandler(propertyName); if (ph != null) { @@ -516,8 +512,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA } @Override - @Nullable - public TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException { + public @Nullable TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException { try { AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName); String finalPath = getFinalPath(nestedPa, propertyName); @@ -580,8 +575,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA return false; } - @Nullable - private Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, + private @Nullable Object convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue, @Nullable Class requiredType, @Nullable TypeDescriptor td) throws TypeMismatchException { @@ -601,8 +595,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA } } - @Nullable - protected Object convertForProperty( + protected @Nullable Object convertForProperty( String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td) throws TypeMismatchException { @@ -610,16 +603,14 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA } @Override - @Nullable - public Object getPropertyValue(String propertyName) throws BeansException { + public @Nullable Object getPropertyValue(String propertyName) throws BeansException { AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName); PropertyTokenHolder tokens = getPropertyNameTokens(getFinalPath(nestedPa, propertyName)); return nestedPa.getPropertyValue(tokens); } @SuppressWarnings({"rawtypes", "unchecked"}) - @Nullable - protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException { + protected @Nullable Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException { String propertyName = tokens.canonicalName; String actualName = tokens.actualName; PropertyHandler ph = getLocalPropertyHandler(actualName); @@ -734,8 +725,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 { + protected @Nullable PropertyHandler getPropertyHandler(String propertyName) throws BeansException { Assert.notNull(propertyName, "Property name must not be null"); AbstractNestablePropertyAccessor nestedPa = getPropertyAccessorForPropertyPath(propertyName); return nestedPa.getLocalPropertyHandler(getFinalPath(nestedPa, propertyName)); @@ -747,8 +737,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); + protected abstract @Nullable PropertyHandler getLocalPropertyHandler(String propertyName); /** * Create a new nested property accessor instance. @@ -1016,8 +1005,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA */ protected abstract static class PropertyHandler { - @Nullable - private final Class propertyType; + private final @Nullable Class propertyType; private final boolean readable; @@ -1029,8 +1017,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA this.writable = writable; } - @Nullable - public Class getPropertyType() { + public @Nullable Class getPropertyType() { return this.propertyType; } @@ -1058,11 +1045,9 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA return TypeDescriptor.valueOf(getResolvableType().getNested(nestingLevel).asCollection().resolveGeneric()); } - @Nullable - public abstract TypeDescriptor nested(int level); + public abstract @Nullable TypeDescriptor nested(int level); - @Nullable - public abstract Object getValue() throws Exception; + public abstract @Nullable Object getValue() throws Exception; public abstract void setValue(@Nullable Object value) throws Exception; @@ -1086,8 +1071,7 @@ public abstract class AbstractNestablePropertyAccessor extends AbstractPropertyA public String canonicalName; - @Nullable - public String[] keys; + public String @Nullable [] keys; } } diff --git a/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java b/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java index 01e67dbdf1..e25bd96e0b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/AbstractPropertyAccessor.java @@ -21,7 +21,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract implementation of the {@link PropertyAccessor} interface. @@ -139,8 +139,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl // Redefined with public visibility. @Override - @Nullable - public Class getPropertyType(String propertyPath) { + public @Nullable Class getPropertyType(String propertyPath) { return null; } @@ -154,8 +153,7 @@ public abstract class AbstractPropertyAccessor extends TypeConverterSupport impl * accessor method failed */ @Override - @Nullable - public abstract Object getPropertyValue(String propertyName) throws BeansException; + public abstract @Nullable Object getPropertyValue(String propertyName) throws BeansException; /** * Actually set a property value. 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 3950354671..26958d37ee 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanInfoFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanInfoFactory.java @@ -19,7 +19,7 @@ package org.springframework.beans; import java.beans.BeanInfo; import java.beans.IntrospectionException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for creating {@link BeanInfo} instances for Spring beans. @@ -54,7 +54,6 @@ 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; + @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 a07cae6d3b..c7bd4d9872 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanInstantiationException.java @@ -19,7 +19,7 @@ package org.springframework.beans; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when instantiation of a bean failed. @@ -33,11 +33,9 @@ public class BeanInstantiationException extends FatalBeanException { private final Class beanClass; - @Nullable - private final Constructor constructor; + private final @Nullable Constructor constructor; - @Nullable - private final Method constructingMethod; + private final @Nullable Method constructingMethod; /** @@ -106,8 +104,7 @@ public class BeanInstantiationException extends FatalBeanException { * factory method or in case of default instantiation * @since 4.3 */ - @Nullable - public Constructor getConstructor() { + public @Nullable Constructor getConstructor() { return this.constructor; } @@ -117,8 +114,7 @@ public class BeanInstantiationException extends FatalBeanException { * or {@code null} in case of constructor-based instantiation * @since 4.3 */ - @Nullable - public Method getConstructingMethod() { + public @Nullable Method getConstructingMethod() { return this.constructingMethod; } diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java index b8d316db91..8c4ad37bc6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttribute.java @@ -16,7 +16,8 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -32,11 +33,9 @@ public class BeanMetadataAttribute implements BeanMetadataElement { private final String name; - @Nullable - private final Object value; + private final @Nullable Object value; - @Nullable - private Object source; + private @Nullable Object source; /** @@ -61,8 +60,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement { /** * Return the value of the attribute. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } @@ -75,8 +73,7 @@ public class BeanMetadataAttribute implements BeanMetadataElement { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } 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 58409cb852..9aacda4501 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataAttributeAccessor.java @@ -16,8 +16,9 @@ package org.springframework.beans; +import org.jspecify.annotations.Nullable; + import org.springframework.core.AttributeAccessorSupport; -import org.springframework.lang.Nullable; /** * Extension of {@link org.springframework.core.AttributeAccessorSupport}, @@ -30,8 +31,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement { - @Nullable - private Object source; + private @Nullable Object source; /** @@ -43,8 +43,7 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -63,8 +62,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) { + public @Nullable BeanMetadataAttribute getMetadataAttribute(String name) { return (BeanMetadataAttribute) super.getAttribute(name); } @@ -74,15 +72,13 @@ public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport impl } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.getAttribute(name); return (attribute != null ? attribute.getValue() : null); } @Override - @Nullable - public Object removeAttribute(String name) { + public @Nullable Object removeAttribute(String name) { BeanMetadataAttribute attribute = (BeanMetadataAttribute) super.removeAttribute(name); return (attribute != null ? attribute.getValue() : null); } 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 7126c64ef2..02fe45a4f1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanMetadataElement.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanMetadataElement.java @@ -16,7 +16,7 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by bean metadata elements @@ -31,8 +31,7 @@ public interface BeanMetadataElement { * Return the configuration source {@code Object} for this metadata element * (may be {@code null}). */ - @Nullable - default Object getSource() { + default @Nullable Object getSource() { return null; } 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 f4ca77b3e1..9d7af79ac7 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtils.java @@ -39,13 +39,13 @@ import kotlin.reflect.KParameter; import kotlin.reflect.full.KClasses; import kotlin.reflect.jvm.KCallablesJvm; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -182,7 +182,7 @@ public abstract class BeanUtils { * @throws BeanInstantiationException if the bean cannot be instantiated * @see Constructor#newInstance */ - public static T instantiateClass(Constructor ctor, Object... args) throws BeanInstantiationException { + public static T instantiateClass(Constructor ctor, @Nullable Object... args) throws BeanInstantiationException { Assert.notNull(ctor, "Constructor must not be null"); try { ReflectionUtils.makeAccessible(ctor); @@ -277,8 +277,7 @@ public abstract class BeanUtils { * @see Kotlin constructors * @see Record constructor declarations */ - @Nullable - public static Constructor findPrimaryConstructor(Class clazz) { + public static @Nullable Constructor findPrimaryConstructor(Class clazz) { Assert.notNull(clazz, "Class must not be null"); if (KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(clazz)) { return KotlinDelegate.findPrimaryConstructor(clazz); @@ -313,8 +312,7 @@ public abstract class BeanUtils { * @see Class#getMethod * @see #findDeclaredMethod */ - @Nullable - public static Method findMethod(Class clazz, String methodName, Class... paramTypes) { + public static @Nullable Method findMethod(Class clazz, String methodName, Class... paramTypes) { try { return clazz.getMethod(methodName, paramTypes); } @@ -334,8 +332,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) { + public static @Nullable Method findDeclaredMethod(Class clazz, String methodName, Class... paramTypes) { try { return clazz.getDeclaredMethod(methodName, paramTypes); } @@ -362,8 +359,7 @@ public abstract class BeanUtils { * @see Class#getMethods * @see #findDeclaredMethodWithMinimalParameters */ - @Nullable - public static Method findMethodWithMinimalParameters(Class clazz, String methodName) + public static @Nullable Method findMethodWithMinimalParameters(Class clazz, String methodName) throws IllegalArgumentException { Method targetMethod = findMethodWithMinimalParameters(clazz.getMethods(), methodName); @@ -385,8 +381,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) + public static @Nullable Method findDeclaredMethodWithMinimalParameters(Class clazz, String methodName) throws IllegalArgumentException { Method targetMethod = findMethodWithMinimalParameters(clazz.getDeclaredMethods(), methodName); @@ -405,8 +400,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) + public static @Nullable Method findMethodWithMinimalParameters(Method[] methods, String methodName) throws IllegalArgumentException { Method targetMethod = null; @@ -457,8 +451,7 @@ public abstract class BeanUtils { * @see #findMethod * @see #findMethodWithMinimalParameters */ - @Nullable - public static Method resolveSignature(String signature, Class clazz) { + public static @Nullable Method resolveSignature(String signature, Class clazz) { Assert.hasText(signature, "'signature' must not be empty"); Assert.notNull(clazz, "Class must not be null"); int startParen = signature.indexOf('('); @@ -511,8 +504,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 { + public static @Nullable PropertyDescriptor getPropertyDescriptor(Class clazz, String propertyName) throws BeansException { return CachedIntrospectionResults.forClass(clazz).getPropertyDescriptor(propertyName); } @@ -525,8 +517,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 { + public static @Nullable PropertyDescriptor findPropertyForMethod(Method method) throws BeansException { return findPropertyForMethod(method, method.getDeclaringClass()); } @@ -540,8 +531,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 { + public static @Nullable PropertyDescriptor findPropertyForMethod(Method method, Class clazz) throws BeansException { Assert.notNull(method, "Method must not be null"); PropertyDescriptor[] pds = getPropertyDescriptors(clazz); for (PropertyDescriptor pd : pds) { @@ -561,8 +551,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(@Nullable Class targetType) { + public static @Nullable PropertyEditor findEditorByConvention(@Nullable Class targetType) { if (targetType == null || targetType.isArray() || unknownEditorTypes.contains(targetType)) { return null; } @@ -609,7 +598,7 @@ public abstract class BeanUtils { * @param beanClasses the classes to check against * @return the property type, or {@code Object.class} as fallback */ - public static Class findPropertyType(String propertyName, @Nullable Class... beanClasses) { + public static Class findPropertyType(String propertyName, Class @Nullable ... beanClasses) { if (beanClasses != null) { for (Class beanClass : beanClasses) { PropertyDescriptor pd = getPropertyDescriptor(beanClass, propertyName); @@ -803,7 +792,7 @@ public abstract class BeanUtils { * @see BeanWrapper */ private static void copyProperties(Object source, Object target, @Nullable Class editable, - @Nullable String... ignoreProperties) throws BeansException { + String @Nullable ... ignoreProperties) throws BeansException { Assert.notNull(source, "Source must not be null"); Assert.notNull(target, "Target must not be null"); @@ -880,8 +869,7 @@ public abstract class BeanUtils { * https://kotlinlang.org/docs/reference/classes.html#constructors */ @SuppressWarnings("unchecked") - @Nullable - public static Constructor findPrimaryConstructor(Class clazz) { + public static @Nullable Constructor findPrimaryConstructor(Class clazz) { try { KClass kClass = JvmClassMappingKt.getKotlinClass(clazz); KFunction primaryCtor = KClasses.getPrimaryConstructor(kClass); @@ -912,7 +900,7 @@ public abstract class BeanUtils { * @param args the constructor arguments to apply * (use {@code null} for unspecified parameter if needed) */ - public static T instantiateClass(Constructor ctor, Object... args) + public static T instantiateClass(Constructor ctor, @Nullable Object... args) throws IllegalAccessException, InvocationTargetException, InstantiationException { KFunction kotlinConstructor = ReflectJvmMapping.getKotlinFunction(ctor); diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanUtilsRuntimeHints.java b/spring-beans/src/main/java/org/springframework/beans/BeanUtilsRuntimeHints.java index 3fc2e30673..721d92216d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanUtilsRuntimeHints.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanUtilsRuntimeHints.java @@ -16,12 +16,13 @@ package org.springframework.beans; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.core.io.ResourceEditor; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for popular conventions in diff --git a/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java b/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java index 93a9724d44..7171d78521 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java @@ -20,11 +20,11 @@ import java.beans.PropertyDescriptor; import java.lang.reflect.Method; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -64,8 +64,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements * Cached introspections results for this object, to prevent encountering * the cost of JavaBeans introspection every time. */ - @Nullable - private CachedIntrospectionResults cachedIntrospectionResults; + private @Nullable CachedIntrospectionResults cachedIntrospectionResults; /** @@ -178,8 +177,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements * @return the new value, possibly the result of type conversion * @throws TypeMismatchException if type conversion failed */ - @Nullable - public Object convertForProperty(@Nullable Object value, String propertyName) throws TypeMismatchException { + public @Nullable Object convertForProperty(@Nullable Object value, String propertyName) throws TypeMismatchException { CachedIntrospectionResults cachedIntrospectionResults = getCachedIntrospectionResults(); PropertyDescriptor pd = cachedIntrospectionResults.getPropertyDescriptor(propertyName); if (pd == null) { @@ -191,8 +189,7 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements } @Override - @Nullable - protected BeanPropertyHandler getLocalPropertyHandler(String propertyName) { + protected @Nullable BeanPropertyHandler getLocalPropertyHandler(String propertyName) { PropertyDescriptor pd = getCachedIntrospectionResults().getPropertyDescriptor(propertyName); return (pd != null ? new BeanPropertyHandler((GenericTypeAwarePropertyDescriptor) pd) : null); } @@ -261,14 +258,12 @@ public class BeanWrapperImpl extends AbstractNestablePropertyAccessor implements } @Override - @Nullable - public TypeDescriptor nested(int level) { + public @Nullable TypeDescriptor nested(int level) { return this.pd.getTypeDescriptor().nested(level); } @Override - @Nullable - public Object getValue() throws Exception { + public @Nullable Object getValue() throws Exception { Method readMethod = this.pd.getReadMethod(); Assert.state(readMethod != null, "No read method available"); ReflectionUtils.makeAccessible(readMethod); diff --git a/spring-beans/src/main/java/org/springframework/beans/BeansException.java b/spring-beans/src/main/java/org/springframework/beans/BeansException.java index f3816a16db..fcb8ab9a25 100644 --- a/spring-beans/src/main/java/org/springframework/beans/BeansException.java +++ b/spring-beans/src/main/java/org/springframework/beans/BeansException.java @@ -16,8 +16,9 @@ package org.springframework.beans; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Abstract superclass for all exceptions thrown in the beans package diff --git a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java index f29a9d3040..6c9014af84 100644 --- a/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java +++ b/spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java @@ -33,9 +33,9 @@ import java.util.concurrent.ConcurrentMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.support.SpringFactoriesLoader; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.StringUtils; @@ -375,8 +375,7 @@ public final class CachedIntrospectionResults { return this.beanInfo.getBeanDescriptor().getBeanClass(); } - @Nullable - PropertyDescriptor getPropertyDescriptor(String name) { + @Nullable PropertyDescriptor getPropertyDescriptor(String name) { PropertyDescriptor pd = this.propertyDescriptors.get(name); if (pd == null && StringUtils.hasLength(name)) { // Same lenient fallback checking as in Property... 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 38c5d26a45..9bff02f0d3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/ConfigurablePropertyAccessor.java @@ -16,8 +16,9 @@ package org.springframework.beans; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; -import org.springframework.lang.Nullable; /** * Interface that encapsulates configuration methods for a PropertyAccessor. @@ -42,8 +43,7 @@ public interface ConfigurablePropertyAccessor extends PropertyAccessor, Property /** * Return the associated ConversionService, if any. */ - @Nullable - ConversionService getConversionService(); + @Nullable ConversionService getConversionService(); /** * Set whether to extract the old property value when applying a 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 41c7f95a96..aeb0b4744c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java +++ b/spring-beans/src/main/java/org/springframework/beans/ConversionNotSupportedException.java @@ -18,7 +18,7 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when no suitable editor or converter can be found for a bean property. diff --git a/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java b/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java index 145a5cff99..9c26ee15ab 100644 --- a/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/DirectFieldAccessor.java @@ -20,9 +20,10 @@ import java.lang.reflect.Field; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -71,8 +72,7 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor { @Override - @Nullable - protected FieldPropertyHandler getLocalPropertyHandler(String propertyName) { + protected @Nullable FieldPropertyHandler getLocalPropertyHandler(String propertyName) { FieldPropertyHandler propertyHandler = this.fieldMap.get(propertyName); if (propertyHandler == null) { Field field = ReflectionUtils.findField(getWrappedClass(), propertyName); @@ -132,14 +132,12 @@ public class DirectFieldAccessor extends AbstractNestablePropertyAccessor { } @Override - @Nullable - public TypeDescriptor nested(int level) { + public @Nullable TypeDescriptor nested(int level) { return TypeDescriptor.nested(this.field, level); } @Override - @Nullable - public Object getValue() throws Exception { + public @Nullable Object getValue() throws Exception { try { ReflectionUtils.makeAccessible(this.field); return this.field.get(getWrappedInstance()); 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 5cd244f80f..d886815352 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfo.java @@ -36,8 +36,8 @@ import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -185,8 +185,7 @@ class ExtendedBeanInfo implements BeanInfo { } } - @Nullable - private PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class propertyType) { + private @Nullable PropertyDescriptor findExistingPropertyDescriptor(String propertyName, Class propertyType) { for (PropertyDescriptor pd : this.propertyDescriptors) { final Class candidateType; final String candidateName = pd.getName(); @@ -265,17 +264,13 @@ class ExtendedBeanInfo implements BeanInfo { */ static class SimplePropertyDescriptor extends PropertyDescriptor { - @Nullable - private Method readMethod; + private @Nullable Method readMethod; - @Nullable - private Method writeMethod; + private @Nullable Method writeMethod; - @Nullable - private Class propertyType; + private @Nullable Class propertyType; - @Nullable - private Class propertyEditorClass; + private @Nullable Class propertyEditorClass; public SimplePropertyDescriptor(PropertyDescriptor original) throws IntrospectionException { this(original.getName(), original.getReadMethod(), original.getWriteMethod()); @@ -292,8 +287,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @@ -303,8 +297,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { return this.writeMethod; } @@ -314,8 +307,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Class getPropertyType() { + public @Nullable Class getPropertyType() { if (this.propertyType == null) { try { this.propertyType = PropertyDescriptorUtils.findPropertyType(this.readMethod, this.writeMethod); @@ -328,8 +320,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Class getPropertyEditorClass() { + public @Nullable Class getPropertyEditorClass() { return this.propertyEditorClass; } @@ -362,26 +353,19 @@ class ExtendedBeanInfo implements BeanInfo { */ static class SimpleIndexedPropertyDescriptor extends IndexedPropertyDescriptor { - @Nullable - private Method readMethod; + private @Nullable Method readMethod; - @Nullable - private Method writeMethod; + private @Nullable Method writeMethod; - @Nullable - private Class propertyType; + private @Nullable Class propertyType; - @Nullable - private Method indexedReadMethod; + private @Nullable Method indexedReadMethod; - @Nullable - private Method indexedWriteMethod; + private @Nullable Method indexedWriteMethod; - @Nullable - private Class indexedPropertyType; + private @Nullable Class indexedPropertyType; - @Nullable - private Class propertyEditorClass; + private @Nullable Class propertyEditorClass; public SimpleIndexedPropertyDescriptor(IndexedPropertyDescriptor original) throws IntrospectionException { this(original.getName(), original.getReadMethod(), original.getWriteMethod(), @@ -404,8 +388,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @@ -415,8 +398,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { return this.writeMethod; } @@ -426,8 +408,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Class getPropertyType() { + public @Nullable Class getPropertyType() { if (this.propertyType == null) { try { this.propertyType = PropertyDescriptorUtils.findPropertyType(this.readMethod, this.writeMethod); @@ -440,8 +421,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Method getIndexedReadMethod() { + public @Nullable Method getIndexedReadMethod() { return this.indexedReadMethod; } @@ -451,8 +431,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Method getIndexedWriteMethod() { + public @Nullable Method getIndexedWriteMethod() { return this.indexedWriteMethod; } @@ -462,8 +441,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Class getIndexedPropertyType() { + public @Nullable Class getIndexedPropertyType() { if (this.indexedPropertyType == null) { try { this.indexedPropertyType = PropertyDescriptorUtils.findIndexedPropertyType( @@ -477,8 +455,7 @@ class ExtendedBeanInfo implements BeanInfo { } @Override - @Nullable - public Class getPropertyEditorClass() { + public @Nullable Class getPropertyEditorClass() { return this.propertyEditorClass; } diff --git a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfoFactory.java b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfoFactory.java index 5f41742632..49b22dcbd9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfoFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/ExtendedBeanInfoFactory.java @@ -20,8 +20,9 @@ import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.lang.reflect.Method; +import org.jspecify.annotations.NonNull; + import org.springframework.core.Ordered; -import org.springframework.lang.NonNull; /** * Extension of {@link StandardBeanInfoFactory} that supports "non-standard" @@ -43,8 +44,7 @@ import org.springframework.lang.NonNull; public class ExtendedBeanInfoFactory extends StandardBeanInfoFactory { @Override - @NonNull - public BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { + public @NonNull BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { BeanInfo beanInfo = super.getBeanInfo(beanClass); return (supports(beanClass) ? new ExtendedBeanInfo(beanInfo) : beanInfo); } diff --git a/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java b/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java index 78d9e5c62f..f5ffb24476 100644 --- a/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java +++ b/spring-beans/src/main/java/org/springframework/beans/FatalBeanException.java @@ -16,7 +16,7 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Thrown on an unrecoverable problem encountered in the diff --git a/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java b/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java index a8247f6e42..b1f4d72c7b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java +++ b/spring-beans/src/main/java/org/springframework/beans/GenericTypeAwarePropertyDescriptor.java @@ -24,13 +24,13 @@ import java.util.Objects; import java.util.Set; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.convert.Property; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -47,34 +47,25 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { private final Class beanClass; - @Nullable - private final Method readMethod; + private final @Nullable Method readMethod; - @Nullable - private final Method writeMethod; + private final @Nullable Method writeMethod; - @Nullable - private Set ambiguousWriteMethods; + private @Nullable Set ambiguousWriteMethods; private volatile boolean ambiguousWriteMethodsLogged; - @Nullable - private MethodParameter writeMethodParameter; + private @Nullable MethodParameter writeMethodParameter; - @Nullable - private volatile ResolvableType writeMethodType; + private volatile @Nullable ResolvableType writeMethodType; - @Nullable - private ResolvableType readMethodType; + private @Nullable ResolvableType readMethodType; - @Nullable - private volatile TypeDescriptor typeDescriptor; + private volatile @Nullable TypeDescriptor typeDescriptor; - @Nullable - private Class propertyType; + private @Nullable Class propertyType; - @Nullable - private final Class propertyEditorClass; + private final @Nullable Class propertyEditorClass; public GenericTypeAwarePropertyDescriptor(Class beanClass, String propertyName, @@ -136,14 +127,12 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @Override - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { return this.writeMethod; } @@ -158,8 +147,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { return this.writeMethod; } - @Nullable - public Method getWriteMethodFallback(@Nullable Class valueType) { + public @Nullable Method getWriteMethodFallback(@Nullable Class valueType) { if (this.ambiguousWriteMethods != null) { for (Method method : this.ambiguousWriteMethods) { Class paramType = method.getParameterTypes()[0]; @@ -171,8 +159,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { return null; } - @Nullable - public Method getUniqueWriteMethodFallback() { + public @Nullable Method getUniqueWriteMethodFallback() { if (this.ambiguousWriteMethods != null && this.ambiguousWriteMethods.size() == 1) { return this.ambiguousWriteMethods.iterator().next(); } @@ -213,14 +200,12 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor { } @Override - @Nullable - public Class getPropertyType() { + public @Nullable Class getPropertyType() { return this.propertyType; } @Override - @Nullable - public Class getPropertyEditorClass() { + public @Nullable Class getPropertyEditorClass() { return this.propertyEditorClass; } diff --git a/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java b/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java index c0d0f50adb..8484bdb613 100644 --- a/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/InvalidPropertyException.java @@ -16,7 +16,7 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when referring to an invalid bean property. 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 41d50521f4..e55ba9c598 100644 --- a/spring-beans/src/main/java/org/springframework/beans/Mergeable.java +++ b/spring-beans/src/main/java/org/springframework/beans/Mergeable.java @@ -16,7 +16,7 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface representing an object whose value set can be merged with diff --git a/spring-beans/src/main/java/org/springframework/beans/MethodInvocationException.java b/spring-beans/src/main/java/org/springframework/beans/MethodInvocationException.java index 327643cbbf..c7b0cdc7cc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/MethodInvocationException.java +++ b/spring-beans/src/main/java/org/springframework/beans/MethodInvocationException.java @@ -18,7 +18,7 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Thrown when a bean property getter or setter method throws an exception, 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 f52780e0ec..b2fe8dfb9b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/MutablePropertyValues.java @@ -27,7 +27,8 @@ import java.util.Set; import java.util.Spliterator; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -45,8 +46,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable { private final List propertyValueList; - @Nullable - private Set processedProperties; + private @Nullable Set processedProperties; private volatile boolean converted; @@ -268,8 +268,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable { } @Override - @Nullable - public PropertyValue getPropertyValue(String propertyName) { + public @Nullable PropertyValue getPropertyValue(String propertyName) { for (PropertyValue pv : this.propertyValueList) { if (pv.getName().equals(propertyName)) { return pv; @@ -286,8 +285,7 @@ public class MutablePropertyValues implements PropertyValues, Serializable { * @see #getPropertyValue(String) * @see PropertyValue#getValue() */ - @Nullable - public Object get(String propertyName) { + public @Nullable 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 79e017e89a..8f7c63c950 100644 --- a/spring-beans/src/main/java/org/springframework/beans/NotWritablePropertyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/NotWritablePropertyException.java @@ -16,7 +16,7 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on an attempt to set the value of a property that @@ -29,8 +29,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class NotWritablePropertyException extends InvalidPropertyException { - @Nullable - private final String[] possibleMatches; + private final String @Nullable [] possibleMatches; /** @@ -86,8 +85,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() { + public String @Nullable [] 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 7789437b55..8e148adc40 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessException.java @@ -18,7 +18,7 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Superclass for exceptions related to a property access, @@ -30,8 +30,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public abstract class PropertyAccessException extends BeansException { - @Nullable - private final PropertyChangeEvent propertyChangeEvent; + private final @Nullable PropertyChangeEvent propertyChangeEvent; /** @@ -61,24 +60,21 @@ public abstract class PropertyAccessException extends BeansException { *

May be {@code null}; only available if an actual bean property * was affected. */ - @Nullable - public PropertyChangeEvent getPropertyChangeEvent() { + public @Nullable PropertyChangeEvent getPropertyChangeEvent() { return this.propertyChangeEvent; } /** * Return the name of the affected property, if available. */ - @Nullable - public String getPropertyName() { + public @Nullable String getPropertyName() { return (this.propertyChangeEvent != null ? this.propertyChangeEvent.getPropertyName() : null); } /** * Return the affected value that was about to be set, if any. */ - @Nullable - public Object getValue() { + public @Nullable 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 03201a89d0..885dee2ffa 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessor.java @@ -18,8 +18,9 @@ package org.springframework.beans; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * Common interface for classes that can access named properties @@ -101,8 +102,7 @@ public interface PropertyAccessor { * @throws PropertyAccessException if the property was valid but the * accessor method failed */ - @Nullable - Class getPropertyType(String propertyName) throws BeansException; + @Nullable Class getPropertyType(String propertyName) throws BeansException; /** * Return a type descriptor for the specified property: @@ -114,8 +114,7 @@ public interface PropertyAccessor { * @throws PropertyAccessException if the property was valid but the * accessor method failed */ - @Nullable - TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException; + @Nullable TypeDescriptor getPropertyTypeDescriptor(String propertyName) throws BeansException; /** * Get the current value of the specified property. @@ -127,8 +126,7 @@ public interface PropertyAccessor { * @throws PropertyAccessException if the property was valid but the * accessor method failed */ - @Nullable - Object getPropertyValue(String propertyName) throws BeansException; + @Nullable Object getPropertyValue(String propertyName) throws BeansException; /** * Set the specified value as current property value. diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java index 465b3ff8b1..73b39e1ca8 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyAccessorUtils.java @@ -16,7 +16,7 @@ package org.springframework.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Utility methods for classes that perform bean property access @@ -173,8 +173,7 @@ public abstract class PropertyAccessorUtils { * (as array of the same size) * @see #canonicalPropertyName(String) */ - @Nullable - public static String[] canonicalPropertyNames(@Nullable String[] propertyNames) { + public static String @Nullable [] canonicalPropertyNames(String @Nullable [] propertyNames) { if (propertyNames == null) { return null; } 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 46491e0d2b..f4cb0db73d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyBatchUpdateException.java @@ -20,7 +20,8 @@ import java.io.PrintStream; import java.io.PrintWriter; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -73,8 +74,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) { + public @Nullable PropertyAccessException getPropertyAccessException(String propertyName) { for (PropertyAccessException pae : this.propertyAccessExceptions) { if (ObjectUtils.nullSafeEquals(propertyName, pae.getPropertyName())) { return pae; diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java index 90c2aef902..0feea72086 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyDescriptorUtils.java @@ -26,7 +26,8 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -141,8 +142,7 @@ abstract class PropertyDescriptorUtils { /** * See {@link java.beans.PropertyDescriptor#findPropertyType}. */ - @Nullable - public static Class findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod) + public static @Nullable Class findPropertyType(@Nullable Method readMethod, @Nullable Method writeMethod) throws IntrospectionException { Class propertyType = null; @@ -186,8 +186,7 @@ abstract class PropertyDescriptorUtils { /** * See {@link java.beans.IndexedPropertyDescriptor#findIndexedPropertyType}. */ - @Nullable - public static Class findIndexedPropertyType(String name, @Nullable Class propertyType, + public static @Nullable Class findIndexedPropertyType(String name, @Nullable Class propertyType, @Nullable Method indexedReadMethod, @Nullable Method indexedWriteMethod) throws IntrospectionException { Class indexedPropertyType = null; @@ -264,11 +263,9 @@ abstract class PropertyDescriptorUtils { */ private static class BasicPropertyDescriptor extends PropertyDescriptor { - @Nullable - private Method readMethod; + private @Nullable Method readMethod; - @Nullable - private Method writeMethod; + private @Nullable Method writeMethod; private final List alternativeWriteMethods = new ArrayList<>(); @@ -284,8 +281,7 @@ abstract class PropertyDescriptorUtils { } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @@ -303,8 +299,7 @@ abstract class PropertyDescriptorUtils { } @Override - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { if (this.writeMethod == null && !this.alternativeWriteMethods.isEmpty()) { if (this.readMethod == null) { return this.alternativeWriteMethods.get(0); 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 9cbbc55ca5..8d66df82cc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistry.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistry.java @@ -18,7 +18,7 @@ package org.springframework.beans; import java.beans.PropertyEditor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Encapsulates methods for registering JavaBeans {@link PropertyEditor PropertyEditors}. @@ -76,7 +76,6 @@ 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 */ - @Nullable - PropertyEditor findCustomEditor(@Nullable Class requiredType, @Nullable 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 af3e0cc00c..23cb769cc3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyEditorRegistrySupport.java @@ -44,6 +44,7 @@ import java.util.TimeZone; import java.util.UUID; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; import org.xml.sax.InputSource; import org.springframework.beans.propertyeditors.ByteArrayPropertyEditor; @@ -74,7 +75,6 @@ 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; /** @@ -92,27 +92,21 @@ import org.springframework.util.ClassUtils; */ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { - @Nullable - private ConversionService conversionService; + private @Nullable ConversionService conversionService; private boolean defaultEditorsActive = false; private boolean configValueEditorsActive = false; - @Nullable - private Map, PropertyEditor> defaultEditors; + private @Nullable Map, PropertyEditor> defaultEditors; - @Nullable - private Map, PropertyEditor> overriddenDefaultEditors; + private @Nullable Map, PropertyEditor> overriddenDefaultEditors; - @Nullable - private Map, PropertyEditor> customEditors; + private @Nullable Map, PropertyEditor> customEditors; - @Nullable - private Map customEditorsForPath; + private @Nullable Map customEditorsForPath; - @Nullable - private Map, PropertyEditor> customEditorCache; + private @Nullable Map, PropertyEditor> customEditorCache; /** @@ -126,8 +120,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { /** * Return the associated ConversionService, if any. */ - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -178,9 +171,8 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { * @return the default editor, or {@code null} if none found * @see #registerDefaultEditors */ - @Nullable @SuppressWarnings("NullAway") - public PropertyEditor getDefaultEditor(Class requiredType) { + public @Nullable PropertyEditor getDefaultEditor(Class requiredType) { if (!this.defaultEditorsActive) { return null; } @@ -312,8 +304,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { } @Override - @Nullable - public PropertyEditor findCustomEditor(@Nullable Class requiredType, @Nullable String propertyPath) { + public @Nullable PropertyEditor findCustomEditor(@Nullable Class requiredType, @Nullable String propertyPath) { Class requiredTypeToUse = requiredType; if (propertyPath != null) { if (this.customEditorsForPath != null) { @@ -372,8 +363,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) { + protected @Nullable Class getPropertyType(String propertyPath) { return null; } @@ -383,8 +373,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, @Nullable Class requiredType) { + private @Nullable PropertyEditor getCustomEditor(String propertyName, @Nullable Class requiredType) { CustomEditorHolder holder = (this.customEditorsForPath != null ? this.customEditorsForPath.get(propertyName) : null); return (holder != null ? holder.getPropertyEditor(requiredType) : null); @@ -398,8 +387,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(@Nullable Class requiredType) { + private @Nullable PropertyEditor getCustomEditor(@Nullable Class requiredType) { if (requiredType == null || this.customEditors == null) { return null; } @@ -438,8 +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) { + protected @Nullable Class guessPropertyTypeFromEditors(String propertyName) { if (this.customEditorsForPath != null) { CustomEditorHolder editorHolder = this.customEditorsForPath.get(propertyName); if (editorHolder == null) { @@ -526,8 +513,7 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { private final PropertyEditor propertyEditor; - @Nullable - private final Class registeredType; + private final @Nullable Class registeredType; private CustomEditorHolder(PropertyEditor propertyEditor, @Nullable Class registeredType) { this.propertyEditor = propertyEditor; @@ -538,13 +524,11 @@ public class PropertyEditorRegistrySupport implements PropertyEditorRegistry { return this.propertyEditor; } - @Nullable - private Class getRegisteredType() { + private @Nullable Class getRegisteredType() { return this.registeredType; } - @Nullable - private PropertyEditor getPropertyEditor(@Nullable Class requiredType) { + private @Nullable PropertyEditor getPropertyEditor(@Nullable Class requiredType) { // Special case: If no required type specified, which usually only happens for // Collection elements, or required type is not assignable to registered type, // which usually only happens for generic properties of type Object - diff --git a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java index 00f567b0f6..1a867fc5b5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValue.java @@ -18,7 +18,8 @@ package org.springframework.beans; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -44,23 +45,19 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri private final String name; - @Nullable - private final Object value; + private final @Nullable Object value; private boolean optional = false; private boolean converted = false; - @Nullable - private Object convertedValue; + private @Nullable Object convertedValue; /** Package-visible field that indicates whether conversion is necessary. */ - @Nullable - volatile Boolean conversionNecessary; + volatile @Nullable Boolean conversionNecessary; /** Package-visible field for caching the resolved property path tokens. */ - @Nullable - transient volatile Object resolvedTokens; + transient volatile @Nullable Object resolvedTokens; /** @@ -122,8 +119,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri * It is the responsibility of the BeanWrapper implementation to * perform type conversion. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } @@ -181,8 +177,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri * Return the converted value of this property value, * after processed type conversion. */ - @Nullable - public synchronized Object getConvertedValue() { + public synchronized @Nullable Object getConvertedValue() { return this.convertedValue; } 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 b754a32a0f..4134bc7072 100644 --- a/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java +++ b/spring-beans/src/main/java/org/springframework/beans/PropertyValues.java @@ -23,7 +23,7 @@ import java.util.Spliterators; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Holder containing one or more {@link PropertyValue} objects, @@ -72,8 +72,7 @@ public interface PropertyValues extends Iterable { * @param propertyName the name to search for * @return the property value, or {@code null} if none */ - @Nullable - PropertyValue getPropertyValue(String propertyName); + @Nullable PropertyValue getPropertyValue(String propertyName); /** * Return the changes since the previous PropertyValues. diff --git a/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java b/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java index 75c9a699bb..554298e03a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/SimpleBeanInfoFactory.java @@ -23,8 +23,9 @@ import java.beans.PropertyDescriptor; import java.beans.SimpleBeanInfo; import java.util.Collection; +import org.jspecify.annotations.NonNull; + import org.springframework.core.Ordered; -import org.springframework.lang.NonNull; /** * {@link BeanInfoFactory} implementation that bypasses the standard {@link java.beans.Introspector} @@ -47,8 +48,7 @@ import org.springframework.lang.NonNull; class SimpleBeanInfoFactory implements BeanInfoFactory, Ordered { @Override - @NonNull - public BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { + public @NonNull BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { Collection pds = PropertyDescriptorUtils.determineBasicProperties(beanClass); diff --git a/spring-beans/src/main/java/org/springframework/beans/StandardBeanInfoFactory.java b/spring-beans/src/main/java/org/springframework/beans/StandardBeanInfoFactory.java index d93d8d6a69..8690547429 100644 --- a/spring-beans/src/main/java/org/springframework/beans/StandardBeanInfoFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/StandardBeanInfoFactory.java @@ -20,9 +20,10 @@ import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; +import org.jspecify.annotations.NonNull; + import org.springframework.core.Ordered; import org.springframework.core.SpringProperties; -import org.springframework.lang.NonNull; /** * {@link BeanInfoFactory} implementation that performs standard @@ -66,8 +67,7 @@ public class StandardBeanInfoFactory implements BeanInfoFactory, Ordered { @Override - @NonNull - public BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { + public @NonNull BeanInfo getBeanInfo(Class beanClass) throws IntrospectionException { BeanInfo beanInfo = (shouldIntrospectorIgnoreBeaninfoClasses ? Introspector.getBeanInfo(beanClass, Introspector.IGNORE_ALL_BEANINFO) : Introspector.getBeanInfo(beanClass)); 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 200a350727..a4ac581a2d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverter.java @@ -18,9 +18,10 @@ package org.springframework.beans; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * Interface that defines type conversion methods. Typically (but not necessarily) @@ -51,8 +52,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - @Nullable - T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException; + @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException; /** * Convert the value to the required type (if necessary from a String). @@ -70,8 +70,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - @Nullable - T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, + @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam) throws TypeMismatchException; /** @@ -90,8 +89,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - @Nullable - T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field) + @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field) throws TypeMismatchException; /** @@ -110,8 +108,7 @@ public interface TypeConverter { * @see org.springframework.core.convert.ConversionService * @see org.springframework.core.convert.converter.Converter */ - @Nullable - default T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, + default @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException { throw new UnsupportedOperationException("TypeDescriptor resolution not supported"); 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 f417242754..54aaa607f0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterDelegate.java @@ -28,12 +28,12 @@ import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.CollectionFactory; 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.CollectionUtils; import org.springframework.util.NumberUtils; @@ -60,8 +60,7 @@ class TypeConverterDelegate { private final PropertyEditorRegistrySupport propertyEditorRegistry; - @Nullable - private final Object targetObject; + private final @Nullable Object targetObject; /** @@ -93,8 +92,7 @@ class TypeConverterDelegate { * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ - @Nullable - public T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, + public @Nullable T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, Object newValue, @Nullable Class requiredType) throws IllegalArgumentException { return convertIfNecessary(propertyName, oldValue, newValue, requiredType, TypeDescriptor.valueOf(requiredType)); @@ -113,8 +111,7 @@ class TypeConverterDelegate { * @throws IllegalArgumentException if type conversion failed */ @SuppressWarnings("unchecked") - @Nullable - public T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue, + public @Nullable T convertIfNecessary(@Nullable String propertyName, @Nullable Object oldValue, @Nullable Object newValue, @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws IllegalArgumentException { // Custom editor for this type? @@ -337,8 +334,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(@Nullable Class requiredType) { + private @Nullable PropertyEditor findDefaultEditor(@Nullable Class requiredType) { PropertyEditor editor = null; if (requiredType != null) { // No custom editor -> check BeanWrapperImpl's default editors. @@ -362,8 +358,7 @@ class TypeConverterDelegate { * @return the new value, possibly the result of type conversion * @throws IllegalArgumentException if type conversion failed */ - @Nullable - private Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue, + private @Nullable Object doConvertValue(@Nullable Object oldValue, @Nullable Object newValue, @Nullable Class requiredType, @Nullable PropertyEditor editor) { Object convertedValue = newValue; @@ -628,15 +623,13 @@ class TypeConverterDelegate { return (originalAllowed ? original : convertedCopy); } - @Nullable - private String buildIndexedPropertyName(@Nullable String propertyName, int index) { + private @Nullable String buildIndexedPropertyName(@Nullable String propertyName, int index) { return (propertyName != null ? propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + index + PropertyAccessor.PROPERTY_KEY_SUFFIX : null); } - @Nullable - private String buildKeyedPropertyName(@Nullable String propertyName, Object key) { + private @Nullable String buildKeyedPropertyName(@Nullable String propertyName, Object key) { return (propertyName != null ? propertyName + PropertyAccessor.PROPERTY_KEY_PREFIX + key + PropertyAccessor.PROPERTY_KEY_SUFFIX : null); diff --git a/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java b/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java index 2351382512..5bbe75ac35 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeConverterSupport.java @@ -18,11 +18,12 @@ package org.springframework.beans; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; 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; /** @@ -35,19 +36,16 @@ import org.springframework.util.Assert; */ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport implements TypeConverter { - @Nullable - TypeConverterDelegate typeConverterDelegate; + @Nullable TypeConverterDelegate typeConverterDelegate; @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException { + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException { return convertIfNecessary(null, value, requiredType, TypeDescriptor.valueOf(requiredType)); } @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam) throws TypeMismatchException { return convertIfNecessary((methodParam != null ? methodParam.getParameterName() : null), value, requiredType, @@ -55,8 +53,7 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport } @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field) + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field) throws TypeMismatchException { return convertIfNecessary((field != null ? field.getName() : null), value, requiredType, @@ -64,15 +61,13 @@ public abstract class TypeConverterSupport extends PropertyEditorRegistrySupport } @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException { return convertIfNecessary(null, value, requiredType, typeDescriptor); } - @Nullable - private T convertIfNecessary(@Nullable String propertyName, @Nullable Object value, + private @Nullable T convertIfNecessary(@Nullable String propertyName, @Nullable Object value, @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException { Assert.state(this.typeConverterDelegate != null, "No TypeConverterDelegate"); 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 ccfa6a0030..88e31532bb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java +++ b/spring-beans/src/main/java/org/springframework/beans/TypeMismatchException.java @@ -18,7 +18,8 @@ package org.springframework.beans; import java.beans.PropertyChangeEvent; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -37,14 +38,11 @@ public class TypeMismatchException extends PropertyAccessException { public static final String ERROR_CODE = "typeMismatch"; - @Nullable - private String propertyName; + private @Nullable String propertyName; - @Nullable - private final transient Object value; + private final transient @Nullable Object value; - @Nullable - private final Class requiredType; + private final @Nullable Class requiredType; /** @@ -123,8 +121,7 @@ public class TypeMismatchException extends PropertyAccessException { * Return the name of the affected property, if available. */ @Override - @Nullable - public String getPropertyName() { + public @Nullable String getPropertyName() { return this.propertyName; } @@ -132,16 +129,14 @@ public class TypeMismatchException extends PropertyAccessException { * Return the offending value (may be {@code null}). */ @Override - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } /** * Return the required target type, if any. */ - @Nullable - public Class getRequiredType() { + public @Nullable Class getRequiredType() { return this.requiredType; } 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 9290a71537..ba00f28020 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 @@ -21,9 +21,10 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.FatalBeanException; import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Exception thrown when a BeanFactory encounters an error when @@ -34,14 +35,11 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class BeanCreationException extends FatalBeanException { - @Nullable - private final String beanName; + private final @Nullable String beanName; - @Nullable - private final String resourceDescription; + private final @Nullable String resourceDescription; - @Nullable - private List relatedCauses; + private @Nullable List relatedCauses; /** @@ -120,16 +118,14 @@ public class BeanCreationException extends FatalBeanException { * Return the description of the resource that the bean * definition came from, if any. */ - @Nullable - public String getResourceDescription() { + public @Nullable String getResourceDescription() { return this.resourceDescription; } /** * Return the name of the bean requested, if any. */ - @Nullable - public String getBeanName() { + public @Nullable String getBeanName() { return this.beanName; } @@ -150,8 +146,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() { + public Throwable @Nullable [] 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 f97c34b086..780f10bbb1 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.FatalBeanException; -import org.springframework.lang.Nullable; /** * Exception thrown when a BeanFactory encounters an invalid bean definition: @@ -30,11 +31,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class BeanDefinitionStoreException extends FatalBeanException { - @Nullable - private final String resourceDescription; + private final @Nullable String resourceDescription; - @Nullable - private final String beanName; + private final @Nullable String beanName; /** @@ -113,16 +112,14 @@ public class BeanDefinitionStoreException extends FatalBeanException { /** * Return the description of the resource that the bean definition came from, if available. */ - @Nullable - public String getResourceDescription() { + public @Nullable String getResourceDescription() { return this.resourceDescription; } /** * Return the name of the bean, if available. */ - @Nullable - public String getBeanName() { + public @Nullable 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 fb1f3ffd9d..8e113a729f 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 @@ -16,9 +16,10 @@ package org.springframework.beans.factory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; /** * The root interface for accessing a Spring bean container. @@ -182,7 +183,7 @@ public interface BeanFactory { * @throws BeansException if the bean could not be created * @since 2.5 */ - Object getBean(String name, Object... args) throws BeansException; + Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException; /** * Return the bean instance that uniquely matches the given object type, if any. @@ -220,7 +221,7 @@ public interface BeanFactory { * @throws BeansException if the bean could not be created * @since 4.1 */ - T getBean(Class requiredType, Object... args) throws BeansException; + T getBean(Class requiredType, @Nullable Object @Nullable ... args) throws BeansException; /** * Return a provider for the specified bean, allowing for lazy on-demand retrieval @@ -357,8 +358,7 @@ public interface BeanFactory { * @see #getBean * @see #isTypeMatch */ - @Nullable - Class getType(String name) throws NoSuchBeanDefinitionException; + @Nullable Class getType(String name) throws NoSuchBeanDefinitionException; /** * Determine the type of the bean with the given name. More specifically, @@ -378,8 +378,7 @@ public interface BeanFactory { * @see #getBean * @see #isTypeMatch */ - @Nullable - Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException; + @Nullable Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException; /** * Return the aliases for the given bean name, if any. diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java index 0797601770..81b083cadf 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java @@ -24,9 +24,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java index fc26cc0ad5..5cc7f2420e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/CannotLoadBeanClassException.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.FatalBeanException; -import org.springframework.lang.Nullable; /** * Exception thrown when the BeanFactory cannot load the specified class @@ -29,13 +30,11 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class CannotLoadBeanClassException extends FatalBeanException { - @Nullable - private final String resourceDescription; + private final @Nullable String resourceDescription; private final String beanName; - @Nullable - private final String beanClassName; + private final @Nullable String beanClassName; /** @@ -80,8 +79,7 @@ public class CannotLoadBeanClassException extends FatalBeanException { * Return the description of the resource that the bean * definition came from. */ - @Nullable - public String getResourceDescription() { + public @Nullable String getResourceDescription() { return this.resourceDescription; } @@ -95,8 +93,7 @@ public class CannotLoadBeanClassException extends FatalBeanException { /** * Return the name of the class we were trying to load. */ - @Nullable - public String getBeanClassName() { + public @Nullable String getBeanClassName() { return this.beanClassName; } 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 c8d06fe3b0..17138b0d70 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,7 +16,7 @@ package org.springframework.beans.factory; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects used within a {@link BeanFactory} which @@ -92,8 +92,7 @@ public interface FactoryBean { * @throws Exception in case of creation errors * @see FactoryBeanNotInitializedException */ - @Nullable - T getObject() throws Exception; + @Nullable T getObject() throws Exception; /** * Return the type of object that this FactoryBean creates, @@ -114,8 +113,7 @@ public interface FactoryBean { * or {@code null} if not known at the time of the call * @see ListableBeanFactory#getBeansOfType */ - @Nullable - Class getObjectType(); + @Nullable Class getObjectType(); /** * Is the object managed by this factory a singleton? That is, 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 d7504438be..3ed796bd1a 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,7 +16,7 @@ package org.springframework.beans.factory; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Sub-interface implemented by bean factories that can be part @@ -36,8 +36,7 @@ public interface HierarchicalBeanFactory extends BeanFactory { /** * Return the parent bean factory, or {@code null} if there is none. */ - @Nullable - BeanFactory getParentBeanFactory(); + @Nullable BeanFactory getParentBeanFactory(); /** * Return whether the local bean factory contains a bean of the given name, 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 f83a5da492..981a710911 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,8 +22,9 @@ import java.lang.reflect.Field; import java.lang.reflect.Member; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -42,14 +43,11 @@ import org.springframework.util.ObjectUtils; */ public class InjectionPoint { - @Nullable - protected MethodParameter methodParameter; + protected @Nullable MethodParameter methodParameter; - @Nullable - protected Field field; + protected @Nullable Field field; - @Nullable - private volatile Annotation[] fieldAnnotations; + private volatile Annotation @Nullable [] fieldAnnotations; /** @@ -93,8 +91,7 @@ public class InjectionPoint { *

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

Note: Either MethodParameter or Field is available. * @return the Field, or {@code null} if none */ - @Nullable - public Field getField() { + public @Nullable Field getField() { return this.field; } @@ -142,8 +138,7 @@ public class InjectionPoint { * @return the annotation instance, or {@code null} if none found * @since 4.3.9 */ - @Nullable - public A getAnnotation(Class annotationType) { + public @Nullable A getAnnotation(Class annotationType) { return (this.field != null ? this.field.getAnnotation(annotationType) : obtainMethodParameter().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 4ce86eceef..5015197a89 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 @@ -20,9 +20,10 @@ import java.lang.annotation.Annotation; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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 @@ -375,8 +376,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see #getBeansWithAnnotation(Class) * @see #getType(String) */ - @Nullable - A findAnnotationOnBean(String beanName, Class annotationType) + @Nullable A findAnnotationOnBean(String beanName, Class annotationType) throws NoSuchBeanDefinitionException; /** @@ -397,8 +397,7 @@ public interface ListableBeanFactory extends BeanFactory { * @see #getBeansWithAnnotation(Class) * @see #getType(String, boolean) */ - @Nullable - A findAnnotationOnBean( + @Nullable A findAnnotationOnBean( String beanName, Class annotationType, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java b/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java index 595b40ae98..99f8a287e6 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; /** * Exception thrown when a {@code BeanFactory} is asked for a bean instance for which it @@ -35,11 +36,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class NoSuchBeanDefinitionException extends BeansException { - @Nullable - private final String beanName; + private final @Nullable String beanName; - @Nullable - private final ResolvableType resolvableType; + private final @Nullable ResolvableType resolvableType; /** @@ -107,8 +106,7 @@ public class NoSuchBeanDefinitionException extends BeansException { /** * Return the name of the missing bean, if it was a lookup by name that failed. */ - @Nullable - public String getBeanName() { + public @Nullable String getBeanName() { return this.beanName; } @@ -116,8 +114,7 @@ public class NoSuchBeanDefinitionException extends BeansException { * Return the required type of the missing bean, if it was a lookup by type * that failed. */ - @Nullable - public Class getBeanType() { + public @Nullable Class getBeanType() { return (this.resolvableType != null ? this.resolvableType.resolve() : null); } @@ -126,8 +123,7 @@ public class NoSuchBeanDefinitionException extends BeansException { * by type that failed. * @since 4.3.4 */ - @Nullable - public ResolvableType getResolvableType() { + public @Nullable ResolvableType getResolvableType() { return this.resolvableType; } 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 c2a6070c9d..88e62c0ffc 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 @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -38,8 +39,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti private final int numberOfBeansFound; - @Nullable - private final Collection beanNamesFound; + private final @Nullable Collection beanNamesFound; /** @@ -126,8 +126,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti * @since 4.3 * @see #getBeanType() */ - @Nullable - public Collection getBeanNamesFound() { + public @Nullable 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 c008e6537c..ffbffc9154 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 @@ -21,9 +21,10 @@ import java.util.function.Consumer; import java.util.function.Supplier; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.core.OrderComparator; -import org.springframework.lang.Nullable; /** * A variant of {@link ObjectFactory} designed specifically for injection points, @@ -88,8 +89,7 @@ public interface ObjectProvider extends ObjectFactory, Iterable { * @throws BeansException in case of creation errors * @see #getObject() */ - @Nullable - default T getIfAvailable() throws BeansException { + default @Nullable T getIfAvailable() throws BeansException { try { return getObject(); } @@ -141,8 +141,7 @@ public interface ObjectProvider extends ObjectFactory, Iterable { * @throws BeansException in case of creation errors * @see #getObject() */ - @Nullable - default T getIfUnique() throws BeansException { + default @Nullable T getIfUnique() throws BeansException { try { return getObject(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java index d11a5a16f8..c59a48ce0f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/UnsatisfiedDependencyException.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -32,8 +33,7 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public class UnsatisfiedDependencyException extends BeanCreationException { - @Nullable - private final InjectionPoint injectionPoint; + private final @Nullable InjectionPoint injectionPoint; /** @@ -103,8 +103,7 @@ public class UnsatisfiedDependencyException extends BeanCreationException { * Return the injection point (field or method/constructor parameter), if known. * @since 4.3 */ - @Nullable - public InjectionPoint getInjectionPoint() { + public @Nullable InjectionPoint getInjectionPoint() { return this.injectionPoint; } 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 7d3fc7628a..b788b638eb 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 @@ -16,10 +16,11 @@ package org.springframework.beans.factory.annotation; +import org.jspecify.annotations.Nullable; + 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} @@ -45,7 +46,6 @@ public interface AnnotatedBeanDefinition extends BeanDefinition { * @return the factory method metadata, or {@code null} if none * @since 4.1.1 */ - @Nullable - MethodMetadata getFactoryMethodMetadata(); + @Nullable MethodMetadata getFactoryMethodMetadata(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedGenericBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedGenericBeanDefinition.java index b8cb907063..4975b70612 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedGenericBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotatedGenericBeanDefinition.java @@ -16,11 +16,12 @@ package org.springframework.beans.factory.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; import org.springframework.core.type.StandardAnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -45,8 +46,7 @@ public class AnnotatedGenericBeanDefinition extends GenericBeanDefinition implem private final AnnotationMetadata metadata; - @Nullable - private MethodMetadata factoryMethodMetadata; + private @Nullable MethodMetadata factoryMethodMetadata; /** @@ -100,8 +100,7 @@ public class AnnotatedGenericBeanDefinition extends GenericBeanDefinition implem } @Override - @Nullable - public final MethodMetadata getFactoryMethodMetadata() { + public final @Nullable MethodMetadata getFactoryMethodMetadata() { return this.factoryMethodMetadata; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java index b3550404c5..d344ca565f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/AnnotationBeanWiringInfoResolver.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.wiring.BeanWiringInfo; import org.springframework.beans.factory.wiring.BeanWiringInfoResolver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -38,8 +39,7 @@ import org.springframework.util.ClassUtils; public class AnnotationBeanWiringInfoResolver implements BeanWiringInfoResolver { @Override - @Nullable - public BeanWiringInfo resolveWiringInfo(Object beanInstance) { + public @Nullable BeanWiringInfo resolveWiringInfo(Object beanInstance) { Assert.notNull(beanInstance, "Bean instance must not be null"); Configurable annotation = beanInstance.getClass().getAnnotation(Configurable.class); return (annotation != null ? buildWiringInfo(beanInstance, annotation) : null); 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 c187dccf97..db86247f36 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 @@ -38,6 +38,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.AccessControl; import org.springframework.aot.generate.GeneratedClass; @@ -86,7 +87,6 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -171,11 +171,9 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA private int order = Ordered.LOWEST_PRECEDENCE - 2; - @Nullable - private ConfigurableListableBeanFactory beanFactory; + private @Nullable ConfigurableListableBeanFactory beanFactory; - @Nullable - private MetadataReaderFactory metadataReaderFactory; + private @Nullable MetadataReaderFactory metadataReaderFactory; private final Set lookupMethodsChecked = ConcurrentHashMap.newKeySet(256); @@ -301,8 +299,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA } @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); String beanName = registeredBean.getBeanName(); RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition(); @@ -321,8 +318,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA return (Collection) metadata.getInjectedElements(propertyValues); } - @Nullable - private AutowireCandidateResolver getAutowireCandidateResolver() { + private @Nullable AutowireCandidateResolver getAutowireCandidateResolver() { if (this.beanFactory instanceof DefaultListableBeanFactory lbf) { return lbf.getAutowireCandidateResolver(); } @@ -350,8 +346,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA } @Override - @Nullable - public Constructor[] determineCandidateConstructors(Class beanClass, final String beanName) + public Constructor @Nullable [] determineCandidateConstructors(Class beanClass, final String beanName) throws BeanCreationException { checkLookupMethods(beanClass, beanName); @@ -612,8 +607,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA return InjectionMetadata.forElements(elements, clazz); } - @Nullable - private MergedAnnotation findAutowiredAnnotation(AccessibleObject ao) { + private @Nullable MergedAnnotation findAutowiredAnnotation(AccessibleObject ao) { MergedAnnotations annotations = MergedAnnotations.from(ao); for (Class type : this.autowiredAnnotationTypes) { MergedAnnotation annotation = annotations.get(type); @@ -698,8 +692,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA /** * Resolve the specified cached method argument or field value. */ - @Nullable - private Object resolveCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) { + private @Nullable Object resolveCachedArgument(@Nullable String beanName, @Nullable Object cachedArgument) { if (cachedArgument instanceof DependencyDescriptor descriptor) { Assert.state(this.beanFactory != null, "No BeanFactory available"); return this.beanFactory.resolveDependency(descriptor, beanName, null, null); @@ -731,8 +724,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA private volatile boolean cached; - @Nullable - private volatile Object cachedFieldValue; + private volatile @Nullable Object cachedFieldValue; public AutowiredFieldElement(Field field, boolean required) { super(field, null, required); @@ -762,8 +754,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA } } - @Nullable - private Object resolveFieldValue(Field field, Object bean, @Nullable String beanName) { + private @Nullable Object resolveFieldValue(Field field, Object bean, @Nullable String beanName) { DependencyDescriptor desc = new DependencyDescriptor(field, this.required); desc.setContainingClass(bean.getClass()); Set autowiredBeanNames = new LinkedHashSet<>(2); @@ -809,8 +800,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA private volatile boolean cached; - @Nullable - private volatile Object[] cachedMethodArguments; + private volatile Object @Nullable [] cachedMethodArguments; public AutowiredMethodElement(Method method, boolean required, @Nullable PropertyDescriptor pd) { super(method, pd, required); @@ -848,8 +838,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA } } - @Nullable - private Object[] resolveCachedArguments(@Nullable String beanName, @Nullable Object[] cachedMethodArguments) { + private Object @Nullable [] resolveCachedArguments(@Nullable String beanName, Object @Nullable [] cachedMethodArguments) { if (cachedMethodArguments == null) { return null; } @@ -860,8 +849,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA return arguments; } - @Nullable - private Object[] resolveMethodArguments(Method method, Object bean, @Nullable String beanName) { + private Object @Nullable [] resolveMethodArguments(Method method, Object bean, @Nullable String beanName) { int argumentCount = method.getParameterCount(); Object[] arguments = new Object[argumentCount]; DependencyDescriptor[] descriptors = new DependencyDescriptor[argumentCount]; @@ -949,8 +937,7 @@ public class AutowiredAnnotationBeanPostProcessor implements SmartInstantiationA private final Collection autowiredElements; - @Nullable - private final AutowireCandidateResolver candidateResolver; + private final @Nullable AutowireCandidateResolver candidateResolver; AotContribution(Class target, Collection autowiredElements, @Nullable AutowireCandidateResolver candidateResolver) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java index 7df476fe54..042df2951b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/BeanFactoryAnnotationUtils.java @@ -22,6 +22,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryUtils; @@ -34,7 +36,6 @@ import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.AutowireCandidateQualifier; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -146,8 +147,7 @@ public abstract class BeanFactoryAnnotationUtils { * @return the associated qualifier value, or {@code null} if none * @since 6.2 */ - @Nullable - public static String getQualifierValue(AnnotatedElement annotatedElement) { + public static @Nullable String getQualifierValue(AnnotatedElement annotatedElement) { Qualifier qualifier = AnnotationUtils.getAnnotation(annotatedElement, Qualifier.class); return (qualifier != null ? qualifier.value() : null); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java index 86fe4482b2..32a7b997b1 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.java @@ -19,13 +19,14 @@ package org.springframework.beans.factory.annotation; import java.lang.annotation.Annotation; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -51,11 +52,9 @@ public class CustomAutowireConfigurer implements BeanFactoryPostProcessor, BeanC private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered - @Nullable - private Set customQualifierTypes; + private @Nullable Set customQualifierTypes; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); public void setOrder(int order) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java index 085fe95b01..79a5b13fcd 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/InitDestroyAnnotationBeanPostProcessor.java @@ -35,6 +35,7 @@ import java.util.stream.Stream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanCreationException; @@ -47,7 +48,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; @@ -113,8 +113,7 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB private int order = Ordered.LOWEST_PRECEDENCE; - @Nullable - private final transient Map, LifecycleMetadata> lifecycleMetadataCache = new ConcurrentHashMap<>(256); + private final transient @Nullable Map, LifecycleMetadata> lifecycleMetadataCache = new ConcurrentHashMap<>(256); /** @@ -183,8 +182,7 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB } @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition(); beanDefinition.resolveDestroyMethodIfNecessary(); LifecycleMetadata metadata = findLifecycleMetadata(beanDefinition, registeredBean.getBeanClass()); @@ -205,7 +203,7 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB return metadata; } - private static String[] safeMerge(@Nullable String[] existingNames, Collection detectedMethods) { + private static String[] safeMerge(String @Nullable [] existingNames, Collection detectedMethods) { Stream detectedNames = detectedMethods.stream().map(LifecycleMethod::getIdentifier); Stream mergedNames = (existingNames != null ? Stream.concat(detectedNames, Stream.of(existingNames)) : detectedNames); @@ -348,11 +346,9 @@ public class InitDestroyAnnotationBeanPostProcessor implements DestructionAwareB private final Collection destroyMethods; - @Nullable - private volatile Set checkedInitMethods; + private volatile @Nullable Set checkedInitMethods; - @Nullable - private volatile Set checkedDestroyMethods; + private volatile @Nullable Set checkedDestroyMethods; public LifecycleMetadata(Class beanClass, Collection initMethods, Collection destroyMethods) { 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 bdd4e4d6a9..1abb513653 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 @@ -25,11 +25,12 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; @@ -72,8 +73,7 @@ public class InjectionMetadata { private final Collection injectedElements; - @Nullable - private volatile Set checkedElements; + private volatile @Nullable Set checkedElements; /** @@ -198,11 +198,9 @@ public class InjectionMetadata { protected final boolean isField; - @Nullable - protected final PropertyDescriptor pd; + protected final @Nullable PropertyDescriptor pd; - @Nullable - protected volatile Boolean skip; + protected volatile @Nullable Boolean skip; protected InjectedElement(Member member, @Nullable PropertyDescriptor pd) { this.member = member; @@ -335,8 +333,7 @@ public class InjectionMetadata { /** * Either this or {@link #inject} needs to be overridden. */ - @Nullable - protected Object getResourceToInject(Object target, @Nullable String requestingBeanName) { + protected @Nullable Object getResourceToInject(Object target, @Nullable String requestingBeanName) { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/JakartaAnnotationsRuntimeHints.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/JakartaAnnotationsRuntimeHints.java index c4ad0a257d..d11c0eab28 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/JakartaAnnotationsRuntimeHints.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/JakartaAnnotationsRuntimeHints.java @@ -18,10 +18,11 @@ package org.springframework.beans.factory.annotation; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} for Jakarta annotations and their pre-Jakarta equivalents. diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java index a9dee0daa7..03e253cbd8 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/annotation/ParameterResolutionDelegate.java @@ -22,13 +22,14 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Executable; import java.lang.reflect.Parameter; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -46,8 +47,7 @@ public final class ParameterResolutionDelegate { private static final AnnotatedElement EMPTY_ANNOTATED_ELEMENT = new AnnotatedElement() { @Override - @Nullable - public T getAnnotation(Class annotationClass) { + public @Nullable T getAnnotation(Class annotationClass) { return null; } @Override @@ -116,8 +116,7 @@ public final class ParameterResolutionDelegate { * @see SynthesizingMethodParameter#forExecutable(Executable, int) * @see AutowireCapableBeanFactory#resolveDependency(DependencyDescriptor, String) */ - @Nullable - public static Object resolveDependency( + public static @Nullable Object resolveDependency( Parameter parameter, int parameterIndex, Class containingClass, AutowireCapableBeanFactory beanFactory) throws BeansException { 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 1e08623006..fd29c8e102 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 @@ -22,6 +22,8 @@ import java.lang.reflect.Method; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.SimpleTypeConverter; import org.springframework.beans.TypeConverter; import org.springframework.beans.factory.BeanFactory; @@ -36,7 +38,6 @@ 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.CollectionUtils; @@ -172,8 +173,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa * {@code null} if no qualifier has been found at all */ - @Nullable - protected Boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) { + protected @Nullable Boolean checkQualifiers(BeanDefinitionHolder bdHolder, Annotation[] annotationsToSearch) { boolean qualifierFound = false; if (!ObjectUtils.isEmpty(annotationsToSearch)) { SimpleTypeConverter typeConverter = new SimpleTypeConverter(); @@ -327,14 +327,12 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa return true; } - @Nullable - protected Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class type) { + protected @Nullable Annotation getQualifiedElementAnnotation(RootBeanDefinition bd, Class type) { AnnotatedElement qualifiedElement = bd.getQualifiedElement(); return (qualifiedElement != null ? AnnotationUtils.getAnnotation(qualifiedElement, type) : null); } - @Nullable - protected Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class type) { + protected @Nullable Annotation getFactoryMethodAnnotation(RootBeanDefinition bd, Class type) { Method resolvedFactoryMethod = bd.getResolvedFactoryMethod(); return (resolvedFactoryMethod != null ? AnnotationUtils.getAnnotation(resolvedFactoryMethod, type) : null); } @@ -370,8 +368,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa } @Override - @Nullable - public String getSuggestedName(DependencyDescriptor descriptor) { + public @Nullable String getSuggestedName(DependencyDescriptor descriptor) { for (Annotation annotation : descriptor.getAnnotations()) { if (isQualifier(annotation.annotationType())) { Object value = AnnotationUtils.getValue(annotation); @@ -388,8 +385,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa * @see Value */ @Override - @Nullable - public Object getSuggestedValue(DependencyDescriptor descriptor) { + public @Nullable Object getSuggestedValue(DependencyDescriptor descriptor) { Object value = findValue(descriptor.getAnnotations()); if (value == null) { MethodParameter methodParam = descriptor.getMethodParameter(); @@ -403,8 +399,7 @@ public class QualifierAnnotationAutowireCandidateResolver extends GenericTypeAwa /** * Determine a suggested value from any of the given candidate annotations. */ - @Nullable - protected Object findValue(Annotation[] annotationsToSearch) { + protected @Nullable Object findValue(Annotation[] annotationsToSearch) { if (annotationsToSearch.length > 0) { // qualifier annotations have to be local 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 5a277e0126..5c96e85a6a 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,9 +1,7 @@ /** * Support package for annotation-driven bean configuration. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotBeanProcessingException.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotBeanProcessingException.java index 03173bf9a9..69d4f79325 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotBeanProcessingException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotBeanProcessingException.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.lang.Nullable; /** * Thrown when AOT fails to process a bean. diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotException.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotException.java index 0b1f810726..2bbf63c60b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotException.java @@ -16,7 +16,7 @@ package org.springframework.beans.factory.aot; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract superclass for all exceptions thrown by ahead-of-time processing. diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotProcessingException.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotProcessingException.java index 87613d63da..63762b0268 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotProcessingException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotProcessingException.java @@ -16,7 +16,7 @@ package org.springframework.beans.factory.aot; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Throw when an AOT processor failed. diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java index c26a9c1ac8..8b7ba09a52 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AotServices.java @@ -25,13 +25,14 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.support.SpringFactoriesLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -166,8 +167,7 @@ public final class AotServices implements Iterable { * @param beanName the bean name * @return the AOT service or {@code null} */ - @Nullable - public T findByBeanName(String beanName) { + public @Nullable T findByBeanName(String beanName) { return this.beans.get(beanName); } @@ -191,8 +191,7 @@ public final class AotServices implements Iterable { private final SpringFactoriesLoader springFactoriesLoader; - @Nullable - private final ListableBeanFactory beanFactory; + private final @Nullable ListableBeanFactory beanFactory; Loader(SpringFactoriesLoader springFactoriesLoader, @Nullable ListableBeanFactory beanFactory) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java index f4c0906479..0f32a8a2ac 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredArguments.java @@ -16,7 +16,8 @@ package org.springframework.beans.factory.aot; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -40,8 +41,7 @@ public interface AutowiredArguments { * @return the argument */ @SuppressWarnings("unchecked") - @Nullable - default T get(int index, Class requiredType) { + default @Nullable T get(int index, Class requiredType) { Object value = getObject(index); if (!ClassUtils.isAssignableValue(requiredType, value)) { throw new IllegalArgumentException("Argument type mismatch: expected '" + @@ -57,8 +57,7 @@ public interface AutowiredArguments { * @return the argument */ @SuppressWarnings("unchecked") - @Nullable - default T get(int index) { + default @Nullable T get(int index) { return (T) getObject(index); } @@ -67,8 +66,7 @@ public interface AutowiredArguments { * @param index the argument index * @return the argument */ - @Nullable - default Object getObject(int index) { + default @Nullable Object getObject(int index) { return toArray()[index]; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredFieldValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredFieldValueResolver.java index ca3a30e071..80ac8fb6df 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredFieldValueResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredFieldValueResolver.java @@ -20,6 +20,8 @@ import java.lang.reflect.Field; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableMode; import org.springframework.beans.BeansException; import org.springframework.beans.TypeConverter; @@ -29,7 +31,6 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.RegisteredBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.function.ThrowingConsumer; @@ -57,8 +58,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver private final boolean required; - @Nullable - private final String shortcutBeanName; + private final @Nullable String shortcutBeanName; private AutowiredFieldValueResolver(String fieldName, boolean required, @Nullable String shortcut) { @@ -122,9 +122,8 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver * @param requiredType the required type * @return the resolved field value */ - @Nullable @SuppressWarnings("unchecked") - public T resolve(RegisteredBean registeredBean, Class requiredType) { + public @Nullable T resolve(RegisteredBean registeredBean, Class requiredType) { Object value = resolveObject(registeredBean); Assert.isInstanceOf(requiredType, value); return (T) value; @@ -135,9 +134,8 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver * @param registeredBean the registered bean * @return the resolved field value */ - @Nullable @SuppressWarnings("unchecked") - public T resolve(RegisteredBean registeredBean) { + public @Nullable T resolve(RegisteredBean registeredBean) { return (T) resolveObject(registeredBean); } @@ -146,8 +144,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver * @param registeredBean the registered bean * @return the resolved field value */ - @Nullable - public Object resolveObject(RegisteredBean registeredBean) { + public @Nullable Object resolveObject(RegisteredBean registeredBean) { Assert.notNull(registeredBean, "'registeredBean' must not be null"); return resolveValue(registeredBean, getField(registeredBean)); } @@ -169,8 +166,7 @@ public final class AutowiredFieldValueResolver extends AutowiredElementResolver } } - @Nullable - private Object resolveValue(RegisteredBean registeredBean, Field field) { + private @Nullable Object resolveValue(RegisteredBean registeredBean, Field field) { String beanName = registeredBean.getBeanName(); Class beanClass = registeredBean.getBeanClass(); ConfigurableBeanFactory beanFactory = registeredBean.getBeanFactory(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolver.java index e52930dc3d..8775f4466f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/AutowiredMethodArgumentsResolver.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.Set; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableMode; import org.springframework.beans.BeansException; import org.springframework.beans.TypeConverter; @@ -31,7 +33,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; @@ -62,12 +63,11 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso private final boolean required; - @Nullable - private final String[] shortcutBeanNames; + private final String @Nullable [] shortcutBeanNames; private AutowiredMethodArgumentsResolver(String methodName, Class[] parameterTypes, - boolean required, @Nullable String[] shortcutBeanNames) { + boolean required, String @Nullable [] shortcutBeanNames) { Assert.hasText(methodName, "'methodName' must not be empty"); this.methodName = methodName; @@ -131,8 +131,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso * @param registeredBean the registered bean * @return the resolved method arguments */ - @Nullable - public AutowiredArguments resolve(RegisteredBean registeredBean) { + public @Nullable AutowiredArguments resolve(RegisteredBean registeredBean) { Assert.notNull(registeredBean, "'registeredBean' must not be null"); return resolveArguments(registeredBean, getMethod(registeredBean)); } @@ -154,8 +153,7 @@ public final class AutowiredMethodArgumentsResolver extends AutowiredElementReso } } - @Nullable - private AutowiredArguments resolveArguments(RegisteredBean registeredBean, + private @Nullable AutowiredArguments resolveArguments(RegisteredBean registeredBean, Method method) { String beanName = registeredBean.getBeanName(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java index 074e87df87..2108261acb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGenerator.java @@ -20,6 +20,8 @@ import java.util.List; import javax.lang.model.element.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GeneratedClass; import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GeneratedMethods; @@ -28,7 +30,6 @@ import org.springframework.aot.generate.MethodReference; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.javapoet.ClassName; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -46,8 +47,7 @@ class BeanDefinitionMethodGenerator { private final RegisteredBean registeredBean; - @Nullable - private final String currentPropertyName; + private final @Nullable String currentPropertyName; private final List aotContributions; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactory.java index 6938f0c9ef..3baa915619 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactory.java @@ -21,12 +21,12 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.aot.AotServices.Source; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.log.LogMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -89,8 +89,7 @@ class BeanDefinitionMethodGeneratorFactory { * @param currentPropertyName the property name that this bean belongs to * @return a new {@link BeanDefinitionMethodGenerator} instance or {@code null} */ - @Nullable - BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator( + @Nullable BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator( RegisteredBean registeredBean, @Nullable String currentPropertyName) { if (isExcluded(registeredBean)) { @@ -110,8 +109,7 @@ class BeanDefinitionMethodGeneratorFactory { * @param registeredBean the registered bean * @return a new {@link BeanDefinitionMethodGenerator} instance or {@code null} */ - @Nullable - BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator(RegisteredBean registeredBean) { + @Nullable BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator(RegisteredBean registeredBean) { return getBeanDefinitionMethodGenerator(registeredBean, null); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java index 29240a2c57..e412331454 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGenerator.java @@ -33,6 +33,8 @@ import java.util.function.BiPredicate; import java.util.function.Function; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GeneratedMethods; import org.springframework.aot.generate.ValueCodeGenerator; import org.springframework.aot.generate.ValueCodeGenerator.Delegate; @@ -55,7 +57,6 @@ import org.springframework.beans.factory.support.InstanceSupplier; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.CodeBlock.Builder; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -149,7 +150,7 @@ class BeanDefinitionPropertiesCodeGenerator { } private void addInitDestroyMethods(Builder code, AbstractBeanDefinition beanDefinition, - @Nullable String[] methodNames, String format) { + String @Nullable [] methodNames, String format) { // For Publisher-based destroy methods this.hints.reflection().registerType(TypeReference.of("org.reactivestreams.Publisher")); @@ -395,8 +396,7 @@ class BeanDefinitionPropertiesCodeGenerator { threadLocal.get().pop(); } - @Nullable - static String peek() { + static @Nullable String peek() { String value = threadLocal.get().peek(); return ("".equals(value) ? null : value); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorDelegates.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorDelegates.java index 1b9f1fcc8a..e07558a810 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorDelegates.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanDefinitionPropertyValueCodeGeneratorDelegates.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GeneratedMethods; import org.springframework.aot.generate.ValueCodeGenerator; @@ -37,7 +39,6 @@ import org.springframework.beans.factory.support.ManagedMap; import org.springframework.beans.factory.support.ManagedSet; import org.springframework.javapoet.AnnotationSpec; import org.springframework.javapoet.CodeBlock; -import org.springframework.lang.Nullable; /** * Code generator {@link Delegate} for common bean definition property values. @@ -102,8 +103,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates { private static final CodeBlock EMPTY_RESULT = CodeBlock.of("$T.ofEntries()", ManagedMap.class); @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { if (value instanceof ManagedMap managedMap) { return generateManagedMapCode(valueCodeGenerator, managedMap); } @@ -139,8 +139,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates { private static class LinkedHashMapDelegate extends MapDelegate { @Override - @Nullable - protected CodeBlock generateMapCode(ValueCodeGenerator valueCodeGenerator, Map map) { + protected @Nullable CodeBlock generateMapCode(ValueCodeGenerator valueCodeGenerator, Map map) { GeneratedMethods generatedMethods = valueCodeGenerator.getGeneratedMethods(); if (map instanceof LinkedHashMap && generatedMethods != null) { return generateLinkedHashMapCode(valueCodeGenerator, generatedMethods, map); @@ -175,8 +174,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates { private static class BeanReferenceDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { if (value instanceof RuntimeBeanReference runtimeBeanReference && runtimeBeanReference.getBeanType() != null) { return CodeBlock.of("new $T($T.class)", RuntimeBeanReference.class, @@ -197,8 +195,7 @@ abstract class BeanDefinitionPropertyValueCodeGeneratorDelegates { private static class TypedStringValueDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { if (value instanceof TypedStringValue typedStringValue) { return generateTypeStringValueCode(valueCodeGenerator, typedStringValue); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java index cfa48d8fc5..efb7e4cf51 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanFactoryInitializationAotProcessor.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; /** * AOT processor that makes bean factory initialization contributions by @@ -58,7 +59,6 @@ public interface BeanFactoryInitializationAotProcessor { * @param beanFactory the bean factory to process * @return a {@link BeanFactoryInitializationAotContribution} or {@code null} */ - @Nullable - BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory); + @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java index 89cbce1602..733a76c912 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanInstanceSupplier.java @@ -27,6 +27,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableMode; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; @@ -43,7 +45,6 @@ import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.SimpleInstantiationStrategy; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -85,20 +86,17 @@ public final class BeanInstanceSupplier extends AutowiredElementResolver impl private final ExecutableLookup lookup; - @Nullable - private final ThrowingFunction generatorWithoutArguments; + private final @Nullable ThrowingFunction generatorWithoutArguments; - @Nullable - private final ThrowingBiFunction generatorWithArguments; + private final @Nullable ThrowingBiFunction generatorWithArguments; - @Nullable - private final String[] shortcutBeanNames; + private final String @Nullable [] shortcutBeanNames; private BeanInstanceSupplier(ExecutableLookup lookup, @Nullable ThrowingFunction generatorWithoutArguments, @Nullable ThrowingBiFunction generatorWithArguments, - @Nullable String[] shortcutBeanNames) { + String @Nullable [] shortcutBeanNames) { this.lookup = lookup; this.generatorWithoutArguments = generatorWithoutArguments; @@ -208,8 +206,7 @@ public final class BeanInstanceSupplier extends AutowiredElementResolver impl } @Override - @Nullable - public Method getFactoryMethod() { + public @Nullable Method getFactoryMethod() { // Cached factory method retrieval for qualifier introspection etc. if (this.lookup instanceof FactoryMethodLookup factoryMethodLookup) { return factoryMethodLookup.get(); @@ -217,8 +214,7 @@ public final class BeanInstanceSupplier extends AutowiredElementResolver impl return null; } - @Nullable - private Method getFactoryMethodForGenerator() { + private @Nullable Method getFactoryMethodForGenerator() { // Avoid unnecessary currentlyInvokedFactoryMethod exposure outside of full configuration classes. if (this.lookup instanceof FactoryMethodLookup factoryMethodLookup && factoryMethodLookup.declaringClass.getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)) { @@ -328,8 +324,7 @@ public final class BeanInstanceSupplier extends AutowiredElementResolver impl return resolvedHolder; } - @Nullable - private Object resolveAutowiredArgument(RegisteredBean registeredBean, DependencyDescriptor descriptor, + private @Nullable Object resolveAutowiredArgument(RegisteredBean registeredBean, DependencyDescriptor descriptor, @Nullable ValueHolder argumentValue, Set autowiredBeanNames) { TypeConverter typeConverter = registeredBean.getBeanFactory().getTypeConverter(); @@ -426,8 +421,7 @@ public final class BeanInstanceSupplier extends AutowiredElementResolver impl private final Class[] parameterTypes; - @Nullable - private volatile Method resolvedMethod; + private volatile @Nullable Method resolvedMethod; FactoryMethodLookup(Class declaringClass, String methodName, Class[] parameterTypes) { this.declaringClass = declaringClass; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotContribution.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotContribution.java index 42a16c1523..da4c5b7a6a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotContribution.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotContribution.java @@ -18,8 +18,9 @@ package org.springframework.beans.factory.aot; import java.util.function.UnaryOperator; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GenerationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -94,8 +95,7 @@ public interface BeanRegistrationAotContribution { * they are both {@code null}. * @since 6.1 */ - @Nullable - static BeanRegistrationAotContribution concat(@Nullable BeanRegistrationAotContribution a, + static @Nullable BeanRegistrationAotContribution concat(@Nullable BeanRegistrationAotContribution a, @Nullable BeanRegistrationAotContribution b) { if (a == null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotProcessor.java index 30a57779a2..b1e65c238d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationAotProcessor.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.support.RegisteredBean; -import org.springframework.lang.Nullable; /** * AOT processor that makes bean registration contributions by processing @@ -72,8 +73,7 @@ public interface BeanRegistrationAotProcessor { * @param registeredBean the registered bean to process * @return a {@link BeanRegistrationAotContribution} or {@code null} */ - @Nullable - BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean); + @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean); /** * Return if the bean instance associated with this processor should be diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotProcessor.java index 183ad41af1..9f4491c25d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/BeanRegistrationsAotProcessor.java @@ -19,10 +19,11 @@ package org.springframework.beans.factory.aot; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.aot.BeanRegistrationsAotContribution.Registration; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; -import org.springframework.lang.Nullable; /** * {@link BeanFactoryInitializationAotProcessor} that contributes code to @@ -37,8 +38,7 @@ import org.springframework.lang.Nullable; class BeanRegistrationsAotProcessor implements BeanFactoryInitializationAotProcessor { @Override - @Nullable - public BeanRegistrationsAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { + public @Nullable BeanRegistrationsAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { BeanDefinitionMethodGeneratorFactory beanDefinitionMethodGeneratorFactory = new BeanDefinitionMethodGeneratorFactory(beanFactory); List registrations = new ArrayList<>(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/CodeWarnings.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/CodeWarnings.java index 06e5eb0d33..db504c6b8b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/CodeWarnings.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/CodeWarnings.java @@ -23,6 +23,8 @@ import java.util.Set; import java.util.function.Consumer; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.javapoet.AnnotationSpec; import org.springframework.javapoet.AnnotationSpec.Builder; @@ -30,7 +32,6 @@ import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.FieldSpec; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java index 498b04633b..48ec28face 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.function.Predicate; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.AccessControl; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.generate.MethodReference; @@ -40,7 +42,6 @@ import org.springframework.core.ResolvableType; import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.ParameterizedTypeName; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.function.SingletonSupplier; @@ -176,8 +177,7 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme .generateCode(beanDefinition); } - @Nullable - protected CodeBlock generateValueCode(GenerationContext generationContext, String name, Object value) { + protected @Nullable CodeBlock generateValueCode(GenerationContext generationContext, String name, Object value) { RegisteredBean innerRegisteredBean = getInnerRegisteredBean(value); if (innerRegisteredBean != null) { BeanDefinitionMethodGenerator methodGenerator = this.beanDefinitionMethodGeneratorFactory @@ -190,8 +190,7 @@ class DefaultBeanRegistrationCodeFragments implements BeanRegistrationCodeFragme return null; } - @Nullable - private RegisteredBean getInnerRegisteredBean(Object value) { + private @Nullable RegisteredBean getInnerRegisteredBean(Object value) { if (value instanceof BeanDefinitionHolder beanDefinitionHolder) { return RegisteredBean.ofInnerBean(this.registeredBean, beanDefinitionHolder); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java index c4a8d46f61..c331ce4049 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/InstanceSupplierCodeGenerator.java @@ -29,6 +29,7 @@ import kotlin.jvm.JvmClassMappingKt; import kotlin.reflect.KClass; import kotlin.reflect.KFunction; import kotlin.reflect.KParameter; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.AccessControl; import org.springframework.aot.generate.AccessControl.Visibility; @@ -54,7 +55,6 @@ import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.CodeBlock.Builder; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.function.ThrowingSupplier; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/package-info.java index bf7c97a915..41631ad6a3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/package-info.java @@ -1,9 +1,7 @@ /** * AOT support for bean factories. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.aot; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ea7958d4d5..d3b6364e2d 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 @@ -23,6 +23,7 @@ import java.lang.reflect.Proxy; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.SimpleTypeConverter; import org.springframework.beans.TypeConverter; @@ -33,7 +34,6 @@ 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -68,19 +68,15 @@ public abstract class AbstractFactoryBean private boolean singleton = true; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; private boolean initialized = false; - @Nullable - private T singletonInstance; + private @Nullable T singletonInstance; - @Nullable - private T earlySingletonInstance; + private @Nullable T earlySingletonInstance; /** @@ -109,8 +105,7 @@ public abstract class AbstractFactoryBean /** * Return the BeanFactory that this bean runs in. */ - @Nullable - protected BeanFactory getBeanFactory() { + protected @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @@ -184,8 +179,7 @@ public abstract class AbstractFactoryBean * @return the singleton instance that this FactoryBean holds * @throws IllegalStateException if the singleton instance is not initialized */ - @Nullable - private T getSingletonInstance() throws IllegalStateException { + private @Nullable T getSingletonInstance() throws IllegalStateException { Assert.state(this.initialized, "Singleton instance not initialized yet"); return this.singletonInstance; } @@ -208,8 +202,7 @@ public abstract class AbstractFactoryBean * @see org.springframework.beans.factory.FactoryBean#getObjectType() */ @Override - @Nullable - public abstract Class getObjectType(); + public abstract @Nullable Class getObjectType(); /** * Template method that subclasses must override to construct @@ -234,8 +227,7 @@ public abstract class AbstractFactoryBean * or {@code null} to indicate a FactoryBeanNotInitializedException * @see org.springframework.beans.factory.FactoryBeanNotInitializedException */ - @Nullable - protected Class[] getEarlySingletonInterfaces() { + protected Class @Nullable [] 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 cd7044c89f..46dff4eab4 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 @@ -18,12 +18,13 @@ package org.springframework.beans.factory.config; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; 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} @@ -381,8 +382,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory { * @since 2.5 * @see #resolveDependency(DependencyDescriptor, String, Set, TypeConverter) */ - @Nullable - Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException; + @Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException; /** * Resolve the specified dependency against the beans defined in this factory. @@ -398,8 +398,7 @@ public interface AutowireCapableBeanFactory extends BeanFactory { * @since 2.5 * @see DependencyDescriptor */ - @Nullable - Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, + @Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java index 7457494436..27771db8eb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/AutowiredPropertyMarker.java @@ -18,7 +18,7 @@ package org.springframework.beans.factory.config; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple marker class for an individually autowired property value, to be added 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 0f6f6ab5cb..f581179a8c 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 @@ -16,11 +16,12 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.MutablePropertyValues; import org.springframework.core.AttributeAccessor; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; /** * A BeanDefinition describes a bean instance, which has property values, @@ -93,8 +94,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { /** * Return the name of the parent definition of this bean definition, if any. */ - @Nullable - String getParentName(); + @Nullable String getParentName(); /** * Specify the bean class name of this bean definition. @@ -118,8 +118,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * @see #getFactoryBeanName() * @see #getFactoryMethodName() */ - @Nullable - String getBeanClassName(); + @Nullable String getBeanClassName(); /** * Override the target scope of this bean, specifying a new scope name. @@ -132,8 +131,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(); + @Nullable String getScope(); /** * Set whether this bean should be lazily initialized. @@ -155,13 +153,12 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * constructor arguments. This property should just be necessary for other kinds * of dependencies like statics (*ugh*) or database preparation on startup. */ - void setDependsOn(@Nullable String... dependsOn); + void setDependsOn(String @Nullable ... dependsOn); /** * Return the bean names that this bean depends on. */ - @Nullable - String[] getDependsOn(); + String @Nullable [] getDependsOn(); /** * Set whether this bean is a candidate for getting autowired into some other bean. @@ -222,8 +219,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * @see #getFactoryMethodName() * @see #getBeanClassName() */ - @Nullable - String getFactoryBeanName(); + @Nullable String getFactoryBeanName(); /** * Specify a factory method, if any. This method will be invoked with @@ -240,8 +236,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * @see #getFactoryBeanName() * @see #getBeanClassName() */ - @Nullable - String getFactoryMethodName(); + @Nullable String getFactoryMethodName(); /** * Return the constructor argument values for this bean. @@ -285,8 +280,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * Return the name of the initializer method. * @since 5.1 */ - @Nullable - String getInitMethodName(); + @Nullable String getInitMethodName(); /** * Set the name of the destroy method. @@ -298,8 +292,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { * Return the name of the destroy method. * @since 5.1 */ - @Nullable - String getDestroyMethodName(); + @Nullable String getDestroyMethodName(); /** * Set the role hint for this {@code BeanDefinition}. The role hint @@ -331,8 +324,7 @@ public interface BeanDefinition extends AttributeAccessor, BeanMetadataElement { /** * Return a human-readable description of this bean definition. */ - @Nullable - String getDescription(); + @Nullable String getDescription(); // Read-only attributes @@ -373,8 +365,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(); + @Nullable String getResourceDescription(); /** * Return the originating BeanDefinition, or {@code null} if none. @@ -382,7 +373,6 @@ 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(); + @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 9b76f819fc..eded121a8c 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 @@ -16,9 +16,10 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + 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; @@ -43,8 +44,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement { private final String beanName; - @Nullable - private final String[] aliases; + private final String @Nullable [] aliases; /** @@ -62,7 +62,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, @Nullable String[] aliases) { + public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, String @Nullable [] aliases) { Assert.notNull(beanDefinition, "BeanDefinition must not be null"); Assert.notNull(beanName, "Bean name must not be null"); this.beanDefinition = beanDefinition; @@ -103,8 +103,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() { + public String @Nullable [] getAliases() { return this.aliases; } @@ -113,8 +112,7 @@ public class BeanDefinitionHolder implements BeanMetadataElement { * @see BeanDefinition#getSource() */ @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.beanDefinition.getSource(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java index 878735ec1a..f91bf12c3b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanDefinitionVisitor.java @@ -22,9 +22,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringValueResolver; @@ -47,8 +48,7 @@ import org.springframework.util.StringValueResolver; */ public class BeanDefinitionVisitor { - @Nullable - private StringValueResolver valueResolver; + private @Nullable StringValueResolver valueResolver; /** @@ -170,8 +170,7 @@ public class BeanDefinitionVisitor { } @SuppressWarnings("rawtypes") - @Nullable - protected Object resolveValue(@Nullable Object value) { + protected @Nullable Object resolveValue(@Nullable Object value) { if (value instanceof BeanDefinition beanDef) { visitBeanDefinition(beanDef); } @@ -284,8 +283,7 @@ public class BeanDefinitionVisitor { * @param strVal the original String value * @return the resolved String value */ - @Nullable - protected String resolveStringValue(String strVal) { + protected @Nullable String resolveStringValue(String strVal) { if (this.valueResolver == null) { throw new IllegalStateException("No StringValueResolver specified - pass a resolver " + "object into the constructor or override the 'resolveStringValue' method"); 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 7fa5b36b07..0b5eb79a64 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,7 +16,8 @@ package org.springframework.beans.factory.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -29,8 +30,7 @@ public class BeanExpressionContext { private final ConfigurableBeanFactory beanFactory; - @Nullable - private final Scope scope; + private final @Nullable Scope scope; public BeanExpressionContext(ConfigurableBeanFactory beanFactory, @Nullable Scope scope) { @@ -43,8 +43,7 @@ public class BeanExpressionContext { return this.beanFactory; } - @Nullable - public final Scope getScope() { + public final @Nullable Scope getScope() { return this.scope; } @@ -54,8 +53,7 @@ public class BeanExpressionContext { (this.scope != null && this.scope.resolveContextualObject(key) != null)); } - @Nullable - public Object getObject(String key) { + public @Nullable 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/BeanExpressionResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java index 2975de790c..30159c400a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/BeanExpressionResolver.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; /** * Strategy interface for resolving a value by evaluating it as an expression, @@ -42,7 +43,6 @@ public interface BeanExpressionResolver { * @return the resolved value (potentially the given value as-is) * @throws BeansException if evaluation failed */ - @Nullable - Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException; + @Nullable Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException; } 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 7288aa476c..5aa701f193 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; /** * Factory hook that allows for custom modification of new bean instances — @@ -70,8 +71,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 { + default @Nullable Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { return bean; } @@ -96,8 +96,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 { + default @Nullable 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 af9616b44a..cfb1128153 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 @@ -19,6 +19,8 @@ package org.springframework.beans.factory.config; import java.beans.PropertyEditor; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.beans.PropertyEditorRegistry; import org.springframework.beans.TypeConverter; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.HierarchicalBeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.core.convert.ConversionService; import org.springframework.core.metrics.ApplicationStartup; -import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; /** @@ -94,8 +95,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * (only {@code null} if even the system ClassLoader isn't accessible). * @see org.springframework.util.ClassUtils#forName(String, ClassLoader) */ - @Nullable - ClassLoader getBeanClassLoader(); + @Nullable ClassLoader getBeanClassLoader(); /** * Specify a temporary ClassLoader to use for type matching purposes. @@ -113,8 +113,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * if any. * @since 2.5 */ - @Nullable - ClassLoader getTempClassLoader(); + @Nullable ClassLoader getTempClassLoader(); /** * Set whether to cache bean metadata such as given bean definitions @@ -144,8 +143,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * Return the resolution strategy for expressions in bean definition values. * @since 3.0 */ - @Nullable - BeanExpressionResolver getBeanExpressionResolver(); + @Nullable BeanExpressionResolver getBeanExpressionResolver(); /** * Set the {@link Executor} (possibly a {@link org.springframework.core.task.TaskExecutor}) @@ -160,8 +158,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * for background bootstrapping, if any. * @since 6.2 */ - @Nullable - Executor getBootstrapExecutor(); + @Nullable Executor getBootstrapExecutor(); /** * Specify a {@link ConversionService} to use for converting @@ -174,8 +171,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * Return the associated ConversionService, if any. * @since 3.0 */ - @Nullable - ConversionService getConversionService(); + @Nullable ConversionService getConversionService(); /** * Add a PropertyEditorRegistrar to be applied to all bean creation processes. @@ -246,8 +242,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); + @Nullable String resolveEmbeddedValue(String value); /** * Add a new BeanPostProcessor that will get applied to beans created @@ -290,8 +285,7 @@ public interface ConfigurableBeanFactory extends HierarchicalBeanFactory, Single * @return the registered Scope implementation, or {@code null} if none * @see #registerScope */ - @Nullable - Scope getRegisteredScope(String scopeName); + @Nullable Scope getRegisteredScope(String scopeName); /** * Set the {@code ApplicationStartup} for this bean factory. diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java index fe451841ab..c17bb52e99 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ConfigurableListableBeanFactory.java @@ -18,10 +18,11 @@ package org.springframework.beans.factory.config; import java.util.Iterator; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.lang.Nullable; /** * Configuration interface to be implemented by most listable bean factories. 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 175f5a4c0b..09579f00fb 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 @@ -24,9 +24,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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; @@ -144,8 +145,7 @@ public class ConstructorArgumentValues { * untyped values only) * @return the ValueHolder for the argument, or {@code null} if none set */ - @Nullable - public ValueHolder getIndexedArgumentValue(int index, @Nullable Class requiredType) { + public @Nullable ValueHolder getIndexedArgumentValue(int index, @Nullable Class requiredType) { return getIndexedArgumentValue(index, requiredType, null); } @@ -158,8 +158,7 @@ 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 */ - @Nullable - public ValueHolder getIndexedArgumentValue(int index, @Nullable Class requiredType, @Nullable String requiredName) { + public @Nullable 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 && @@ -246,8 +245,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) { + public @Nullable ValueHolder getGenericArgumentValue(Class requiredType) { return getGenericArgumentValue(requiredType, null, null); } @@ -257,8 +255,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) { + public @Nullable ValueHolder getGenericArgumentValue(Class requiredType, String requiredName) { return getGenericArgumentValue(requiredType, requiredName, null); } @@ -274,8 +271,7 @@ 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 */ - @Nullable - public ValueHolder getGenericArgumentValue(@Nullable Class requiredType, @Nullable String requiredName, + public @Nullable ValueHolder getGenericArgumentValue(@Nullable Class requiredType, @Nullable String requiredName, @Nullable Set usedValueHolders) { for (ValueHolder valueHolder : this.genericArgumentValues) { @@ -316,8 +312,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) { + public @Nullable ValueHolder getArgumentValue(int index, Class requiredType) { return getArgumentValue(index, requiredType, null, null); } @@ -329,8 +324,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) { + public @Nullable ValueHolder getArgumentValue(int index, Class requiredType, String requiredName) { return getArgumentValue(index, requiredType, requiredName, null); } @@ -348,8 +342,7 @@ 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 */ - @Nullable - public ValueHolder getArgumentValue(int index, @Nullable Class requiredType, + public @Nullable ValueHolder getArgumentValue(int index, @Nullable Class requiredType, @Nullable String requiredName, @Nullable Set usedValueHolders) { Assert.isTrue(index >= 0, "Index must not be negative"); @@ -455,22 +448,17 @@ public class ConstructorArgumentValues { */ public static class ValueHolder implements BeanMetadataElement { - @Nullable - private Object value; + private @Nullable Object value; - @Nullable - private String type; + private @Nullable String type; - @Nullable - private String name; + private @Nullable String name; - @Nullable - private Object source; + private @Nullable Object source; private boolean converted = false; - @Nullable - private Object convertedValue; + private @Nullable Object convertedValue; /** * Create a new ValueHolder for the given value. @@ -512,8 +500,7 @@ public class ConstructorArgumentValues { /** * Return the value for the constructor argument. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } @@ -527,8 +514,7 @@ public class ConstructorArgumentValues { /** * Return the type of the constructor argument. */ - @Nullable - public String getType() { + public @Nullable String getType() { return this.type; } @@ -542,8 +528,7 @@ public class ConstructorArgumentValues { /** * Return the name of the constructor argument. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -556,8 +541,7 @@ public class ConstructorArgumentValues { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -582,8 +566,7 @@ public class ConstructorArgumentValues { * Return the converted value of the constructor argument, * after processed type conversion. */ - @Nullable - public synchronized Object getConvertedValue() { + public synchronized @Nullable Object getConvertedValue() { return this.convertedValue; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java index 64963ead54..2d3dd8a5bb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomEditorConfigurer.java @@ -21,11 +21,11 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.PropertyEditorRegistrar; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -99,11 +99,9 @@ public class CustomEditorConfigurer implements BeanFactoryPostProcessor, Ordered private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered - @Nullable - private PropertyEditorRegistrar[] propertyEditorRegistrars; + private PropertyEditorRegistrar @Nullable [] propertyEditorRegistrars; - @Nullable - private Map, Class> customEditors; + private @Nullable Map, Class> customEditors; public void setOrder(int order) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java index 8bf43ae269..901ad062c2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/CustomScopeConfigurer.java @@ -19,11 +19,12 @@ package org.springframework.beans.factory.config; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -46,13 +47,11 @@ import org.springframework.util.ClassUtils; */ public class CustomScopeConfigurer implements BeanFactoryPostProcessor, BeanClassLoaderAware, Ordered { - @Nullable - private Map scopes; + private @Nullable Map scopes; private int order = Ordered.LOWEST_PRECEDENCE; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); /** 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 e7dc1a602a..5084f049e8 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 @@ -26,6 +26,7 @@ import java.util.Optional; import kotlin.reflect.KProperty; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; @@ -36,7 +37,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.ResolvableType; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -52,16 +52,13 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable private final Class declaringClass; - @Nullable - private String methodName; + private @Nullable String methodName; - @Nullable - private Class[] parameterTypes; + private Class @Nullable [] parameterTypes; private int parameterIndex; - @Nullable - private String fieldName; + private @Nullable String fieldName; private final boolean required; @@ -69,14 +66,11 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable private int nestingLevel = 1; - @Nullable - private Class containingClass; + private @Nullable Class containingClass; - @Nullable - private transient volatile ResolvableType resolvableType; + private transient volatile @Nullable ResolvableType resolvableType; - @Nullable - private transient volatile TypeDescriptor typeDescriptor; + private transient volatile @Nullable TypeDescriptor typeDescriptor; /** @@ -213,8 +207,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable * @throws BeansException in case of the not-unique scenario being fatal * @since 5.1 */ - @Nullable - public Object resolveNotUnique(ResolvableType type, Map matchingBeans) throws BeansException { + public @Nullable Object resolveNotUnique(ResolvableType type, Map matchingBeans) throws BeansException { throw new NoUniqueBeanDefinitionException(type, matchingBeans.keySet()); } @@ -230,8 +223,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 { + public @Nullable Object resolveShortcut(BeanFactory beanFactory) throws BeansException { return null; } @@ -355,8 +347,7 @@ public class DependencyDescriptor extends InjectionPoint implements Serializable * Determine the name of the wrapped parameter/field. * @return the declared name (may be {@code null} if unresolvable) */ - @Nullable - public String getDependencyName() { + public @Nullable String getDependencyName() { return (this.field != null ? this.field.getName() : obtainMethodParameter().getParameterName()); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java index f38156bcb9..ea2bf5b8ab 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/EmbeddedValueResolver.java @@ -16,7 +16,8 @@ package org.springframework.beans.factory.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringValueResolver; /** @@ -38,8 +39,7 @@ public class EmbeddedValueResolver implements StringValueResolver { private final BeanExpressionContext exprContext; - @Nullable - private final BeanExpressionResolver exprResolver; + private final @Nullable BeanExpressionResolver exprResolver; public EmbeddedValueResolver(ConfigurableBeanFactory beanFactory) { @@ -49,8 +49,7 @@ public class EmbeddedValueResolver implements StringValueResolver { @Override - @Nullable - public String resolveStringValue(String strVal) { + public @Nullable String resolveStringValue(String strVal) { String value = this.exprContext.getBeanFactory().resolveEmbeddedValue(strVal); if (this.exprResolver != null && value != null) { Object evaluated = this.exprResolver.evaluate(value, this.exprContext); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java index 6c132145b3..37f21f36c7 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/FieldRetrievingFactoryBean.java @@ -18,13 +18,14 @@ package org.springframework.beans.factory.config; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanNameAware; 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -58,27 +59,20 @@ import org.springframework.util.StringUtils; public class FieldRetrievingFactoryBean implements FactoryBean, BeanNameAware, BeanClassLoaderAware, InitializingBean { - @Nullable - private Class targetClass; + private @Nullable Class targetClass; - @Nullable - private Object targetObject; + private @Nullable Object targetObject; - @Nullable - private String targetField; + private @Nullable String targetField; - @Nullable - private String staticField; + private @Nullable String staticField; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); // the field we will retrieve - @Nullable - private Field fieldObject; + private @Nullable Field fieldObject; /** @@ -95,8 +89,7 @@ public class FieldRetrievingFactoryBean /** * Return the target class on which the field is defined. */ - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { return this.targetClass; } @@ -114,8 +107,7 @@ public class FieldRetrievingFactoryBean /** * Return the target object on which the field is defined. */ - @Nullable - public Object getTargetObject() { + public @Nullable Object getTargetObject() { return this.targetObject; } @@ -133,8 +125,7 @@ public class FieldRetrievingFactoryBean /** * Return the name of the field to be retrieved. */ - @Nullable - public String getTargetField() { + public @Nullable String getTargetField() { return this.targetField; } @@ -210,8 +201,7 @@ public class FieldRetrievingFactoryBean @Override - @Nullable - public Object getObject() throws IllegalAccessException { + public @Nullable Object getObject() throws IllegalAccessException { if (this.fieldObject == null) { throw new FactoryBeanNotInitializedException(); } @@ -227,8 +217,7 @@ public class FieldRetrievingFactoryBean } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return (this.fieldObject != null ? this.fieldObject.getType() : null); } 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 e842353cb5..c00cb529b2 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 @@ -16,9 +16,10 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + 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, @@ -66,8 +67,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor { * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getBeanClass() * @see org.springframework.beans.factory.support.AbstractBeanDefinition#getFactoryMethodName() */ - @Nullable - default Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { + default @Nullable Object postProcessBeforeInstantiation(Class beanClass, String beanName) throws BeansException { return null; } @@ -102,8 +102,7 @@ public interface InstantiationAwareBeanPostProcessor extends BeanPostProcessor { * @throws org.springframework.beans.BeansException in case of errors * @since 5.1 */ - @Nullable - default PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) + default @Nullable PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) throws BeansException { return pvs; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java index d9b89210f0..b73a9f9a8e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ListFactoryBean.java @@ -19,10 +19,11 @@ package org.springframework.beans.factory.config; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.TypeConverter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; /** * Simple factory for shared List instances. Allows for central setup @@ -35,12 +36,10 @@ import org.springframework.lang.Nullable; */ public class ListFactoryBean extends AbstractFactoryBean> { - @Nullable - private List sourceList; + private @Nullable List sourceList; @SuppressWarnings("rawtypes") - @Nullable - private Class targetListClass; + private @Nullable Class targetListClass; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java index b02673c8b7..307fe53ba0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/MapFactoryBean.java @@ -18,10 +18,11 @@ package org.springframework.beans.factory.config; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.TypeConverter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -35,12 +36,10 @@ import org.springframework.util.CollectionUtils; */ public class MapFactoryBean extends AbstractFactoryBean> { - @Nullable - private Map sourceMap; + private @Nullable Map sourceMap; @SuppressWarnings("rawtypes") - @Nullable - private Class targetMapClass; + private @Nullable Class targetMapClass; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java index eb5ae4c0b7..be10715dd2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingBean.java @@ -18,13 +18,14 @@ package org.springframework.beans.factory.config; import java.lang.reflect.InvocationTargetException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.TypeConverter; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.support.ArgumentConvertingMethodInvoker; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -67,11 +68,9 @@ import org.springframework.util.ClassUtils; public class MethodInvokingBean extends ArgumentConvertingMethodInvoker implements BeanClassLoaderAware, BeanFactoryAware, InitializingBean { - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private ConfigurableBeanFactory beanFactory; + private @Nullable ConfigurableBeanFactory beanFactory; @Override @@ -117,8 +116,7 @@ public class MethodInvokingBean extends ArgumentConvertingMethodInvoker * Perform the invocation and convert InvocationTargetException * into the underlying target exception. */ - @Nullable - protected Object invokeWithTargetException() throws Exception { + protected @Nullable Object invokeWithTargetException() throws Exception { try { return invoke(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingFactoryBean.java index ec89f904e4..6e6a4a8a62 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/MethodInvokingFactoryBean.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; -import org.springframework.lang.Nullable; /** * {@link FactoryBean} which returns a value which is the result of a static or instance @@ -88,8 +89,7 @@ public class MethodInvokingFactoryBean extends MethodInvokingBean implements Fac private boolean initialized = false; /** Method call result in the singleton case. */ - @Nullable - private Object singletonObject; + private @Nullable Object singletonObject; /** @@ -116,8 +116,7 @@ public class MethodInvokingFactoryBean extends MethodInvokingBean implements Fac * specified method on the fly. */ @Override - @Nullable - public Object getObject() throws Exception { + public @Nullable Object getObject() throws Exception { if (this.singleton) { if (!this.initialized) { throw new FactoryBeanNotInitializedException(); @@ -136,8 +135,7 @@ public class MethodInvokingFactoryBean extends MethodInvokingBean implements Fac * or {@code null} if not known in advance. */ @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { if (!isPrepared()) { // Not fully initialized yet -> return null to indicate "not known yet". return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBean.java index e1f9208ad8..1474a3879e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ObjectFactoryCreatingFactoryBean.java @@ -18,10 +18,11 @@ package org.springframework.beans.factory.config; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.ObjectFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -97,8 +98,7 @@ import org.springframework.util.Assert; */ public class ObjectFactoryCreatingFactoryBean extends AbstractFactoryBean> { - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; /** 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 6e37fc17fb..4c6035d3c9 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 @@ -16,11 +16,12 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + 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; /** @@ -110,25 +111,20 @@ public abstract class PlaceholderConfigurerSupport extends PropertyResourceConfi protected String placeholderSuffix = DEFAULT_PLACEHOLDER_SUFFIX; /** Defaults to {@value #DEFAULT_VALUE_SEPARATOR}. */ - @Nullable - protected String valueSeparator = DEFAULT_VALUE_SEPARATOR; + protected @Nullable String valueSeparator = DEFAULT_VALUE_SEPARATOR; /** Defaults to {@link #DEFAULT_ESCAPE_CHARACTER}. */ - @Nullable - protected Character escapeCharacter = DEFAULT_ESCAPE_CHARACTER; + protected @Nullable Character escapeCharacter = DEFAULT_ESCAPE_CHARACTER; protected boolean trimValues = false; - @Nullable - protected String nullValue; + protected @Nullable String nullValue; protected boolean ignoreUnresolvablePlaceholders = false; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** 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 fc616b895e..e100e9e314 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 @@ -20,9 +20,10 @@ import java.util.Properties; import java.util.prefs.BackingStoreException; import java.util.prefs.Preferences; +import org.jspecify.annotations.Nullable; + 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 @@ -47,11 +48,9 @@ import org.springframework.lang.Nullable; @Deprecated public class PreferencesPlaceholderConfigurer extends PropertyPlaceholderConfigurer implements InitializingBean { - @Nullable - private String systemTreePath; + private @Nullable String systemTreePath; - @Nullable - private String userTreePath; + private @Nullable String userTreePath; private Preferences systemPrefs = Preferences.systemRoot(); @@ -120,8 +119,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(@Nullable String path, String key, Preferences preferences) { + protected @Nullable String resolvePlaceholder(@Nullable String path, String key, Preferences preferences) { if (path != null) { // Do not create the node if it does not exist... try { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertiesFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertiesFactoryBean.java index 47a857eb1f..803d593241 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertiesFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertiesFactoryBean.java @@ -19,10 +19,11 @@ package org.springframework.beans.factory.config; import java.io.IOException; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.support.PropertiesLoaderSupport; -import org.springframework.lang.Nullable; /** * Allows for making a properties file from a classpath location available @@ -48,8 +49,7 @@ public class PropertiesFactoryBean extends PropertiesLoaderSupport private boolean singleton = true; - @Nullable - private Properties singletonInstance; + private @Nullable Properties singletonInstance; /** @@ -75,8 +75,7 @@ public class PropertiesFactoryBean extends PropertiesLoaderSupport } @Override - @Nullable - public final Properties getObject() throws IOException { + public final @Nullable Properties getObject() throws IOException { if (this.singleton) { return this.singletonInstance; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java index b22e52be3d..6ef0b5f81c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyPathFactoryBean.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory.config; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeansException; @@ -27,7 +28,6 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -87,23 +87,17 @@ public class PropertyPathFactoryBean implements FactoryBean, BeanNameAwa private static final Log logger = LogFactory.getLog(PropertyPathFactoryBean.class); - @Nullable - private BeanWrapper targetBeanWrapper; + private @Nullable BeanWrapper targetBeanWrapper; - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; - @Nullable - private String propertyPath; + private @Nullable String propertyPath; - @Nullable - private Class resultType; + private @Nullable Class resultType; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** @@ -202,8 +196,7 @@ public class PropertyPathFactoryBean implements FactoryBean, BeanNameAwa @Override - @Nullable - public Object getObject() throws BeansException { + public @Nullable Object getObject() throws BeansException { BeanWrapper target = this.targetBeanWrapper; if (target != null) { if (logger.isWarnEnabled() && this.targetBeanName != null && @@ -225,8 +218,7 @@ public class PropertyPathFactoryBean implements FactoryBean, BeanNameAwa } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return this.resultType; } 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 51d9124850..77d430073e 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 @@ -19,10 +19,11 @@ package org.springframework.beans.factory.config; import java.util.Map; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.core.SpringProperties; import org.springframework.core.env.AbstractEnvironment; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; @@ -153,8 +154,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport * @see System#getProperty * @see #resolvePlaceholder(String, java.util.Properties) */ - @Nullable - protected String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) { + protected @Nullable String resolvePlaceholder(String placeholder, Properties props, int systemPropertiesMode) { String propVal = null; if (systemPropertiesMode == SYSTEM_PROPERTIES_MODE_OVERRIDE) { propVal = resolveSystemProperty(placeholder); @@ -181,8 +181,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) { + protected @Nullable String resolvePlaceholder(String placeholder, Properties props) { return props.getProperty(placeholder); } @@ -195,8 +194,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport * @see System#getProperty(String) * @see System#getenv(String) */ - @Nullable - protected String resolveSystemProperty(String key) { + protected @Nullable String resolveSystemProperty(String key) { try { String value = System.getProperty(key); if (value == null && this.searchSystemEnvironment) { @@ -240,8 +238,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport } @Override - @Nullable - public String resolveStringValue(String strVal) throws BeansException { + public @Nullable String resolveStringValue(String strVal) throws BeansException { String resolved = this.helper.replacePlaceholders(strVal, this.resolver); if (trimValues) { resolved = resolved.trim(); @@ -260,8 +257,7 @@ public class PropertyPlaceholderConfigurer extends PlaceholderConfigurerSupport } @Override - @Nullable - public String resolvePlaceholder(String placeholderName) { + public @Nullable String resolvePlaceholder(String placeholderName) { return PropertyPlaceholderConfigurer.this.resolvePlaceholder(placeholderName, this.props, systemPropertiesMode); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ProviderCreatingFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ProviderCreatingFactoryBean.java index 96d7bf3a60..9fcb489660 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ProviderCreatingFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ProviderCreatingFactoryBean.java @@ -19,10 +19,10 @@ package org.springframework.beans.factory.config; import java.io.Serializable; import jakarta.inject.Provider; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -43,8 +43,7 @@ import org.springframework.util.Assert; */ public class ProviderCreatingFactoryBean extends AbstractFactoryBean> { - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java index f04a8d103e..ad8be03a38 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanNameReference.java @@ -16,7 +16,8 @@ package org.springframework.beans.factory.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -33,8 +34,7 @@ public class RuntimeBeanNameReference implements BeanReference { private final String beanName; - @Nullable - private Object source; + private @Nullable Object source; /** @@ -60,8 +60,7 @@ public class RuntimeBeanNameReference implements BeanReference { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java index 361b786dd3..f96518c7c3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/RuntimeBeanReference.java @@ -16,7 +16,8 @@ package org.springframework.beans.factory.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -33,13 +34,11 @@ public class RuntimeBeanReference implements BeanReference { private final String beanName; - @Nullable - private final Class beanType; + private final @Nullable Class beanType; private final boolean toParent; - @Nullable - private Object source; + private @Nullable Object source; /** @@ -103,8 +102,7 @@ public class RuntimeBeanReference implements BeanReference { * Return the requested bean type if resolution by type is demanded. * @since 5.2 */ - @Nullable - public Class getBeanType() { + public @Nullable Class getBeanType() { return this.beanType; } @@ -124,8 +122,7 @@ public class RuntimeBeanReference implements BeanReference { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } 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 8073dda0d9..cb4cb0de1d 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.ObjectFactory; -import org.springframework.lang.Nullable; /** * Strategy interface used by a {@link ConfigurableBeanFactory}, @@ -89,8 +90,7 @@ public interface Scope { * @throws IllegalStateException if the underlying scope is not currently active * @see #registerDestructionCallback */ - @Nullable - Object remove(String name); + @Nullable Object remove(String name); /** * Register a callback to be executed on destruction of the specified @@ -130,8 +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); + @Nullable Object resolveContextualObject(String key); /** * Return the conversation ID for the current underlying scope, if any. @@ -148,7 +147,6 @@ public interface Scope { * conversation ID for the current scope * @throws IllegalStateException if the underlying scope is not currently active */ - @Nullable - String getConversationId(); + @Nullable String getConversationId(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java index 590280998d..78b5b78160 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/ServiceLocatorFactoryBean.java @@ -22,6 +22,8 @@ import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; import org.springframework.beans.FatalBeanException; @@ -30,7 +32,6 @@ import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -190,20 +191,15 @@ import org.springframework.util.StringUtils; */ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFactoryAware, InitializingBean { - @Nullable - private Class serviceLocatorInterface; + private @Nullable Class serviceLocatorInterface; - @Nullable - private Constructor serviceLocatorExceptionConstructor; + private @Nullable Constructor serviceLocatorExceptionConstructor; - @Nullable - private Properties serviceMappings; + private @Nullable Properties serviceMappings; - @Nullable - private ListableBeanFactory beanFactory; + private @Nullable ListableBeanFactory beanFactory; - @Nullable - private Object proxy; + private @Nullable Object proxy; /** @@ -329,14 +325,12 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFacto @Override - @Nullable - public Object getObject() { + public @Nullable Object getObject() { return this.proxy; } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return this.serviceLocatorInterface; } @@ -394,7 +388,7 @@ public class ServiceLocatorFactoryBean implements FactoryBean, BeanFacto /** * Check whether a service id was passed in. */ - private String tryGetBeanName(@Nullable Object[] args) { + private String tryGetBeanName(Object @Nullable [] args) { String beanName = ""; if (args != null && args.length == 1 && args[0] != null) { beanName = args[0].toString(); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java index 8b30f8eb8f..6b579da353 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/SetFactoryBean.java @@ -18,10 +18,11 @@ package org.springframework.beans.factory.config; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.TypeConverter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -35,12 +36,10 @@ import org.springframework.util.CollectionUtils; */ public class SetFactoryBean extends AbstractFactoryBean> { - @Nullable - private Set sourceSet; + private @Nullable Set sourceSet; @SuppressWarnings("rawtypes") - @Nullable - private Class targetSetClass; + private @Nullable Class targetSetClass; /** 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 b1f9f876b4..0da3086b9e 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 @@ -18,7 +18,7 @@ package org.springframework.beans.factory.config; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that defines a registry for shared bean instances. @@ -83,8 +83,7 @@ public interface SingletonBeanRegistry { * @return the registered singleton object, or {@code null} if none found * @see ConfigurableListableBeanFactory#getBeanDefinition */ - @Nullable - Object getSingleton(String beanName); + @Nullable Object getSingleton(String beanName); /** * Check if this registry contains a singleton instance with the given name. 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 86455b173c..79aae284a2 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 @@ -18,8 +18,9 @@ package org.springframework.beans.factory.config; import java.lang.reflect.Constructor; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; /** * Extension of the {@link InstantiationAwareBeanPostProcessor} interface, @@ -46,8 +47,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 { + default @Nullable Class predictBeanType(Class beanClass, String beanName) throws BeansException { return null; } @@ -75,8 +75,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) + default Constructor @Nullable [] determineCandidateConstructors(Class beanClass, String beanName) throws BeansException { return null; 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 c4d9c5c8e5..b807dd4cb0 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 @@ -18,8 +18,9 @@ package org.springframework.beans.factory.config; import java.util.Comparator; +import org.jspecify.annotations.Nullable; + 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; @@ -39,17 +40,13 @@ import org.springframework.util.ObjectUtils; */ public class TypedStringValue implements BeanMetadataElement, Comparable { - @Nullable - private String value; + private @Nullable String value; - @Nullable - private volatile Object targetType; + private volatile @Nullable Object targetType; - @Nullable - private Object source; + private @Nullable Object source; - @Nullable - private String specifiedTypeName; + private @Nullable String specifiedTypeName; private volatile boolean dynamic; @@ -97,8 +94,7 @@ public class TypedStringValue implements BeanMetadataElement, Comparable clazz) { return clazz.getName(); @@ -159,8 +154,7 @@ public class TypedStringValue implements BeanMetadataElement, Comparable resolveTargetType(@Nullable ClassLoader classLoader) throws ClassNotFoundException { + public @Nullable Class resolveTargetType(@Nullable ClassLoader classLoader) throws ClassNotFoundException { String typeName = getTargetTypeName(); if (typeName == null) { return null; @@ -180,8 +174,7 @@ public class TypedStringValue implements BeanMetadataElement, Comparable map; + private @Nullable Map map; /** @@ -99,8 +99,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean getObject() { + public @Nullable Map getObject() { return (this.map != null ? this.map : createMap()); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java index 472188fd38..e0d332027f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java @@ -30,6 +30,7 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.LoaderOptions; import org.yaml.snakeyaml.Yaml; @@ -42,7 +43,6 @@ import org.yaml.snakeyaml.representer.Representer; import org.springframework.core.CollectionFactory; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java index 5c09abda68..670294147a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlPropertiesFactoryBean.java @@ -18,10 +18,11 @@ package org.springframework.beans.factory.config; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.CollectionFactory; -import org.springframework.lang.Nullable; /** * Factory for {@link java.util.Properties} that reads from a YAML source, @@ -85,8 +86,7 @@ public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryB private boolean singleton = true; - @Nullable - private Properties properties; + private @Nullable Properties properties; /** @@ -110,8 +110,7 @@ public class YamlPropertiesFactoryBean extends YamlProcessor implements FactoryB } @Override - @Nullable - public Properties getObject() { + public @Nullable Properties getObject() { return (this.properties != null ? this.properties : createProperties()); } 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 280e916ab1..5ba69e3876 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,9 +1,7 @@ /** * SPI interfaces and configuration-related convenience classes for bean factories. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java index 0d9a67cd04..cbc2ed07e3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionReader.java @@ -33,6 +33,7 @@ import groovy.lang.GroovySystem; import groovy.lang.MetaClass; import org.codehaus.groovy.runtime.DefaultGroovyMethods; import org.codehaus.groovy.runtime.InvokerHelper; +import org.jspecify.annotations.Nullable; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -53,7 +54,6 @@ import org.springframework.beans.factory.xml.XmlReaderContext; import org.springframework.core.io.DescriptiveResource; 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.ObjectUtils; import org.springframework.util.StringUtils; @@ -151,11 +151,9 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp private MetaClass metaClass = GroovySystem.getMetaClassRegistry().getMetaClass(getClass()); - @Nullable - private Binding binding; + private @Nullable Binding binding; - @Nullable - private GroovyBeanDefinitionWrapper currentBeanDefinition; + private @Nullable GroovyBeanDefinitionWrapper currentBeanDefinition; /** @@ -207,8 +205,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp /** * Return a specified binding for Groovy variables, if any. */ - @Nullable - public Binding getBinding() { + public @Nullable Binding getBinding() { return this.binding; } @@ -251,8 +248,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp @SuppressWarnings("serial") Closure beans = new Closure<>(this) { @Override - @Nullable - public Object call(Object... args) { + public @Nullable Object call(Object... args) { invokeBeanDefiningClosure((Closure) args[0]); return null; } @@ -658,8 +654,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp * */ @Override - @Nullable - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { Binding binding = getBinding(); if (binding != null && binding.hasVariable(name)) { return binding.getVariable(name); @@ -733,8 +728,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp private final String name; - @Nullable - public Object value; + public @Nullable Object value; public DeferredProperty(GroovyBeanDefinitionWrapper beanDefinition, String name, @Nullable Object value) { this.beanDefinition = beanDefinition; @@ -769,8 +763,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp } @Override - @Nullable - public Object getProperty(String property) { + public @Nullable Object getProperty(String property) { if (property.equals("beanName")) { return getBeanName(); } @@ -809,8 +802,7 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp private final String propertyName; - @Nullable - private final Object propertyValue; + private final @Nullable Object propertyValue; public GroovyPropertyValue(String propertyName, @Nullable Object propertyValue) { this.propertyName = propertyName; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java index 895646d9da..b0f71df9bb 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyBeanDefinitionWrapper.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Set; import groovy.lang.GroovyObjectSupport; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; @@ -30,7 +31,6 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.GenericBeanDefinition; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -57,23 +57,17 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport { FACTORY_BEAN, FACTORY_METHOD, INIT_METHOD, DESTROY_METHOD, SINGLETON); - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private final Class clazz; + private final @Nullable Class clazz; - @Nullable - private final Collection constructorArgs; + private final @Nullable Collection constructorArgs; - @Nullable - private AbstractBeanDefinition definition; + private @Nullable AbstractBeanDefinition definition; - @Nullable - private BeanWrapper definitionWrapper; + private @Nullable BeanWrapper definitionWrapper; - @Nullable - private String parentName; + private @Nullable String parentName; GroovyBeanDefinitionWrapper(String beanName) { @@ -91,8 +85,7 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport { } - @Nullable - public String getBeanName() { + public @Nullable String getBeanName() { return this.beanName; } @@ -159,8 +152,7 @@ class GroovyBeanDefinitionWrapper extends GroovyObjectSupport { @Override - @Nullable - public Object getProperty(String property) { + public @Nullable Object getProperty(String property) { Assert.state(this.definitionWrapper != null, "BeanDefinition wrapper not initialized"); if (this.definitionWrapper.isReadableProperty(property)) { return this.definitionWrapper.getPropertyValue(property); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyDynamicElementReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyDynamicElementReader.java index b8b9efd520..31e9d9de5e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyDynamicElementReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/GroovyDynamicElementReader.java @@ -25,13 +25,13 @@ import groovy.lang.GroovyObject; import groovy.lang.GroovyObjectSupport; import groovy.lang.Writable; import groovy.xml.StreamingMarkupBuilder; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate; -import org.springframework.lang.Nullable; /** * Used by GroovyBeanDefinitionReader to read a Spring XML namespace expression @@ -69,8 +69,7 @@ class GroovyDynamicElementReader extends GroovyObjectSupport { @Override - @Nullable - public Object invokeMethod(String name, Object obj) { + public @Nullable Object invokeMethod(String name, Object obj) { Object[] args = (Object[]) obj; if (name.equals("doCall")) { @SuppressWarnings("unchecked") diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/package-info.java b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/package-info.java index 9201a52782..a48700cf46 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/groovy/package-info.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/groovy/package-info.java @@ -1,9 +1,7 @@ /** * Support package for Groovy-based bean definitions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.groovy; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a29b453f3e..48c6b5c60b 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,9 +9,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 27bed9e3c9..875b6a81d8 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -33,8 +34,7 @@ public class AliasDefinition implements BeanMetadataElement { private final String alias; - @Nullable - private final Object source; + private final @Nullable Object source; /** @@ -76,8 +76,7 @@ public class AliasDefinition implements BeanMetadataElement { } @Override - @Nullable - public final Object getSource() { + public final @Nullable Object getSource() { return this.source; } 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 ad8e72ed48..4dd2c97ba4 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 @@ -19,12 +19,13 @@ package org.springframework.beans.factory.parsing; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyValue; 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, @Nullable String[] aliases) { + public BeanComponentDefinition(BeanDefinition beanDefinition, String beanName, String @Nullable [] aliases) { this(new BeanDefinitionHolder(beanDefinition, beanName, aliases)); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java index efd846ceda..e7658cd819 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/CompositeComponentDefinition.java @@ -19,7 +19,8 @@ package org.springframework.beans.factory.parsing; import java.util.ArrayList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -35,8 +36,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition { private final String name; - @Nullable - private final Object source; + private final @Nullable Object source; private final List nestedComponents = new ArrayList<>(); @@ -59,8 +59,7 @@ public class CompositeComponentDefinition extends AbstractComponentDefinition { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } 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 3dc71bb4b3..1de71d5c92 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 @@ -18,8 +18,7 @@ package org.springframework.beans.factory.parsing; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple {@link ProblemReporter} implementation that exhibits fail-fast 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 3740250221..861fc64379 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 @@ -16,9 +16,10 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -32,11 +33,9 @@ public class ImportDefinition implements BeanMetadataElement { private final String importedResource; - @Nullable - private final Resource[] actualResources; + private final Resource @Nullable [] actualResources; - @Nullable - private final Object source; + private final @Nullable Object source; /** @@ -61,7 +60,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, @Nullable Resource[] actualResources, @Nullable Object source) { + public ImportDefinition(String importedResource, Resource @Nullable [] actualResources, @Nullable Object source) { Assert.notNull(importedResource, "Imported resource must not be null"); this.importedResource = importedResource; this.actualResources = actualResources; @@ -76,14 +75,12 @@ public class ImportDefinition implements BeanMetadataElement { return this.importedResource; } - @Nullable - public final Resource[] getActualResources() { + public final Resource @Nullable [] getActualResources() { return this.actualResources; } @Override - @Nullable - public final Object getSource() { + public final @Nullable Object getSource() { return this.source; } 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 b06c524ce0..50b77dc534 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +38,7 @@ public class Location { private final Resource resource; - @Nullable - private final Object source; + private final @Nullable Object source; /** @@ -75,8 +75,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() { + public @Nullable Object getSource() { return this.source; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/NullSourceExtractor.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/NullSourceExtractor.java index 1205b3fa8e..165667d9e9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/NullSourceExtractor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/NullSourceExtractor.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Simple implementation of {@link SourceExtractor} that returns {@code null} @@ -35,8 +36,7 @@ public class NullSourceExtractor implements SourceExtractor { * This implementation simply returns {@code null} for any input. */ @Override - @Nullable - public Object extractSource(Object sourceCandidate, @Nullable Resource definitionResource) { + public @Nullable Object extractSource(Object sourceCandidate, @Nullable Resource definitionResource) { return null; } 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 afbb139571..c1b1afb0fe 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,7 +18,7 @@ package org.springframework.beans.factory.parsing; import java.util.ArrayDeque; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple {@link ArrayDeque}-based structure for tracking the logical position during @@ -74,8 +74,7 @@ public final class ParseState { * Return the {@link Entry} currently at the top of the {@link ArrayDeque} or * {@code null} if the {@link ArrayDeque} is empty. */ - @Nullable - public Entry peek() { + public @Nullable Entry peek() { return this.state.peek(); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractor.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractor.java index 1365c9932b..1d45254592 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractor.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/PassThroughSourceExtractor.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Simple {@link SourceExtractor} implementation that just passes 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 86d58000d1..e724c5e85e 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,7 +16,8 @@ package org.springframework.beans.factory.parsing; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -36,11 +37,9 @@ public class Problem { private final Location location; - @Nullable - private final ParseState parseState; + private final @Nullable ParseState parseState; - @Nullable - private final Throwable rootCause; + private final @Nullable Throwable rootCause; /** @@ -105,16 +104,14 @@ public class Problem { /** * Get the {@link ParseState} at the time of the error (may be {@code null}). */ - @Nullable - public ParseState getParseState() { + public @Nullable ParseState getParseState() { return this.parseState; } /** * Get the underlying exception that caused the error (may be {@code null}). */ - @Nullable - public Throwable getRootCause() { + public @Nullable Throwable getRootCause() { return this.rootCause; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java index 2b95aa8f6c..7879ba648e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ReaderContext.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Context that gets passed along a bean definition reading process, @@ -203,8 +204,7 @@ public class ReaderContext { * @see #getSourceExtractor() * @see SourceExtractor#extractSource */ - @Nullable - public Object extractSource(Object sourceCandidate) { + public @Nullable Object extractSource(Object sourceCandidate) { return this.sourceExtractor.extractSource(sourceCandidate, this.resource); } 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 8809cd2473..960b0b3ae7 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory.parsing; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Simple strategy allowing tools to control how source metadata is attached @@ -45,7 +46,6 @@ public interface SourceExtractor { * (may be {@code null}) * @return the source metadata object to store (may be {@code null}) */ - @Nullable - Object extractSource(Object sourceCandidate, @Nullable 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 0f57ef1351..dcb31b3e73 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,9 +1,7 @@ /** * Support infrastructure for bean definition parsing. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.parsing; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/AbstractServiceLoaderBasedFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/AbstractServiceLoaderBasedFactoryBean.java index 3ee514663c..27f3342d7e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/AbstractServiceLoaderBasedFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/AbstractServiceLoaderBasedFactoryBean.java @@ -18,9 +18,10 @@ package org.springframework.beans.factory.serviceloader; import java.util.ServiceLoader; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -35,11 +36,9 @@ import org.springframework.util.ClassUtils; public abstract class AbstractServiceLoaderBasedFactoryBean extends AbstractFactoryBean implements BeanClassLoaderAware { - @Nullable - private Class serviceType; + private @Nullable Class serviceType; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); /** @@ -52,8 +51,7 @@ public abstract class AbstractServiceLoaderBasedFactoryBean extends AbstractFact /** * Return the desired service type. */ - @Nullable - public Class getServiceType() { + public @Nullable Class getServiceType() { return this.serviceType; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceFactoryBean.java index 535a53716e..1698abcdc2 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/serviceloader/ServiceFactoryBean.java @@ -19,8 +19,9 @@ package org.springframework.beans.factory.serviceloader; import java.util.Iterator; import java.util.ServiceLoader; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.lang.Nullable; /** * {@link org.springframework.beans.factory.FactoryBean} that exposes the @@ -44,8 +45,7 @@ public class ServiceFactoryBean extends AbstractServiceLoaderBasedFactoryBean im } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return getServiceType(); } 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 b6a97c2c7e..5c6a933563 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,9 +1,7 @@ /** * Support package for the Java {@link java.util.ServiceLoader} facility. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.serviceloader; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 1ddddbe82d..dd35a4f867 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 @@ -34,6 +34,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; @@ -73,7 +74,6 @@ 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.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -125,8 +125,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac private InstantiationStrategy instantiationStrategy; /** Resolver strategy for method parameter names. */ - @Nullable - private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); + private @Nullable ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); /** Whether to automatically try to resolve circular references between beans. */ private boolean allowCircularReferences = true; @@ -216,8 +215,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * Return the ParameterNameDiscoverer to use for resolving method parameter * names if needed. */ - @Nullable - public ParameterNameDiscoverer getParameterNameDiscoverer() { + public @Nullable ParameterNameDiscoverer getParameterNameDiscoverer() { return this.parameterNameDiscoverer; } @@ -467,8 +465,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac } @Override - @Nullable - public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException { + public @Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) throws BeansException { return resolveDependency(descriptor, requestingBeanName, null, null); } @@ -483,7 +480,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #doCreateBean */ @Override - protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) + protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] args) throws BeanCreationException { if (logger.isTraceEnabled()) { @@ -551,7 +548,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #instantiateUsingFactoryMethod * @see #autowireConstructor */ - protected Object doCreateBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) + protected Object doCreateBean(String beanName, RootBeanDefinition mbd, Object @Nullable [] args) throws BeanCreationException { // Instantiate the bean. @@ -649,8 +646,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac } @Override - @Nullable - protected Class predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { + protected @Nullable Class predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { Class targetType = determineTargetType(beanName, mbd, typesToMatch); // Apply SmartInstantiationAwareBeanPostProcessors to predict the // eventual type after a before-instantiation shortcut. @@ -675,8 +671,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) { + protected @Nullable Class determineTargetType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { Class targetType = mbd.getTargetType(); if (targetType == null) { if (mbd.getFactoryMethodName() != null) { @@ -709,8 +704,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) { + protected @Nullable Class getTypeForFactoryMethod(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { ResolvableType cachedReturnType = mbd.factoryMethodReturnType; if (cachedReturnType != null) { return cachedReturnType.resolve(); @@ -989,8 +983,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) { + private @Nullable FactoryBean getSingletonFactoryBeanForTypeCheck(String beanName, RootBeanDefinition mbd) { this.singletonLock.lock(); try { BeanWrapper bw = this.factoryBeanInstanceCache.get(beanName); @@ -1055,8 +1048,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) { + private @Nullable FactoryBean getNonSingletonFactoryBeanForTypeCheck(String beanName, RootBeanDefinition mbd) { if (isPrototypeCurrentlyInCreation(beanName)) { return null; } @@ -1114,8 +1106,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return the shortcut-determined bean instance, or {@code null} if none */ @SuppressWarnings("deprecation") - @Nullable - protected Object resolveBeforeInstantiation(String beanName, RootBeanDefinition mbd) { + protected @Nullable Object resolveBeforeInstantiation(String beanName, RootBeanDefinition mbd) { Object bean = null; if (!Boolean.FALSE.equals(mbd.beforeInstantiationResolved)) { // Make sure bean class is actually resolved at this point. @@ -1144,8 +1135,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) { + protected @Nullable Object applyBeanPostProcessorsBeforeInstantiation(Class beanClass, String beanName) { for (InstantiationAwareBeanPostProcessor bp : getBeanPostProcessorCache().instantiationAware) { Object result = bp.postProcessBeforeInstantiation(beanClass, beanName); if (result != null) { @@ -1167,7 +1157,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #autowireConstructor * @see #instantiateBean */ - protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) { + protected BeanWrapper createBeanInstance(String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] args) { // Make sure bean class is actually resolved at this point. Class beanClass = resolveBeanClass(mbd, beanName); @@ -1269,8 +1259,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return the bean instance (possibly {@code null}) * @since 6.0.7 */ - @Nullable - protected Object obtainInstanceFromSupplier(Supplier supplier, String beanName, RootBeanDefinition mbd) + protected @Nullable Object obtainInstanceFromSupplier(Supplier supplier, String beanName, RootBeanDefinition mbd) throws Exception { if (supplier instanceof ThrowingSupplier throwingSupplier) { @@ -1307,8 +1296,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(@Nullable Class beanClass, String beanName) + protected Constructor @Nullable [] determineConstructorsFromBeanPostProcessors(@Nullable Class beanClass, String beanName) throws BeansException { if (beanClass != null && hasInstantiationAwareBeanPostProcessors()) { @@ -1352,7 +1340,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @see #getBean(String, Object[]) */ protected BeanWrapper instantiateUsingFactoryMethod( - String beanName, RootBeanDefinition mbd, @Nullable Object[] explicitArgs) { + String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] explicitArgs) { return new ConstructorResolver(this).instantiateUsingFactoryMethod(beanName, mbd, explicitArgs); } @@ -1372,7 +1360,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac * @return a BeanWrapper for the new instance */ protected BeanWrapper autowireConstructor( - String beanName, RootBeanDefinition mbd, @Nullable Constructor[] ctors, @Nullable Object[] explicitArgs) { + String beanName, RootBeanDefinition mbd, Constructor @Nullable [] ctors, @Nullable Object @Nullable [] explicitArgs) { return new ConstructorResolver(this).autowireConstructor(beanName, mbd, ctors, explicitArgs); } @@ -1759,8 +1747,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac /** * Convert the given value for the specified target property. */ - @Nullable - private Object convertForProperty( + private @Nullable Object convertForProperty( @Nullable Object value, String propertyName, BeanWrapper bw, TypeConverter converter) { if (converter instanceof BeanWrapperImpl beanWrapper) { @@ -1974,8 +1961,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac } @Override - @Nullable - public Constructor[] getPreferredConstructors() { + public Constructor @Nullable [] getPreferredConstructors() { Constructor[] fromAttribute = super.getPreferredConstructors(); if (fromAttribute != null) { return fromAttribute; @@ -2002,8 +1988,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac } @Override - @Nullable - public String getDependencyName() { + public @Nullable String getDependencyName() { return null; } } 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 ab66ca7c8f..2a8a44e326 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 @@ -24,6 +24,8 @@ import java.util.Map; import java.util.Set; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataAttributeAccessor; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -32,7 +34,6 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.core.ResolvableType; 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; @@ -165,25 +166,21 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess public static final String INFER_METHOD = "(inferred)"; - @Nullable - private volatile Object beanClass; + private volatile @Nullable Object beanClass; - @Nullable - private String scope = SCOPE_DEFAULT; + private @Nullable String scope = SCOPE_DEFAULT; private boolean abstractFlag = false; private boolean backgroundInit = false; - @Nullable - private Boolean lazyInit; + private @Nullable Boolean lazyInit; private int autowireMode = AUTOWIRE_NO; private int dependencyCheck = DEPENDENCY_CHECK_NONE; - @Nullable - private String[] dependsOn; + private String @Nullable [] dependsOn; private boolean autowireCandidate = true; @@ -195,32 +192,25 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess private final Map qualifiers = new LinkedHashMap<>(); - @Nullable - private Supplier instanceSupplier; + private @Nullable Supplier instanceSupplier; private boolean nonPublicAccessAllowed = true; private boolean lenientConstructorResolution = true; - @Nullable - private String factoryBeanName; + private @Nullable String factoryBeanName; - @Nullable - private String factoryMethodName; + private @Nullable String factoryMethodName; - @Nullable - private ConstructorArgumentValues constructorArgumentValues; + private @Nullable ConstructorArgumentValues constructorArgumentValues; - @Nullable - private MutablePropertyValues propertyValues; + private @Nullable MutablePropertyValues propertyValues; private MethodOverrides methodOverrides = new MethodOverrides(); - @Nullable - private String[] initMethodNames; + private String @Nullable [] initMethodNames; - @Nullable - private String[] destroyMethodNames; + private String @Nullable [] destroyMethodNames; private boolean enforceInitMethod = true; @@ -230,11 +220,9 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess private int role = BeanDefinition.ROLE_APPLICATION; - @Nullable - private String description; + private @Nullable String description; - @Nullable - private Resource resource; + private @Nullable Resource resource; /** @@ -429,8 +417,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @see #getBeanClass() */ @Override - @Nullable - public String getBeanClassName() { + public @Nullable String getBeanClassName() { Object beanClassObject = this.beanClass; // defensive access to volatile beanClass field return (beanClassObject instanceof Class clazz ? clazz.getName() : (String) beanClassObject); } @@ -494,8 +481,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @return the resolved bean class * @throws ClassNotFoundException if the class name could be resolved */ - @Nullable - public Class resolveBeanClass(@Nullable ClassLoader classLoader) throws ClassNotFoundException { + public @Nullable Class resolveBeanClass(@Nullable ClassLoader classLoader) throws ClassNotFoundException { String className = getBeanClassName(); if (className == null) { return null; @@ -534,8 +520,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess *

The default is {@link #SCOPE_DEFAULT}. */ @Override - @Nullable - public String getScope() { + public @Nullable String getScope() { return this.scope; } @@ -631,8 +616,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @return the lazy-init flag if explicitly set, or {@code null} otherwise * @since 5.2 */ - @Nullable - public Boolean getLazyInit() { + public @Nullable Boolean getLazyInit() { return this.lazyInit; } @@ -710,7 +694,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess *

The default is no beans to explicitly depend on. */ @Override - public void setDependsOn(@Nullable String... dependsOn) { + public void setDependsOn(String @Nullable ... dependsOn) { this.dependsOn = dependsOn; } @@ -719,8 +703,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess *

The default is no beans to explicitly depend on. */ @Override - @Nullable - public String[] getDependsOn() { + public String @Nullable [] getDependsOn() { return this.dependsOn; } @@ -824,8 +807,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess /** * Return the qualifier mapped to the provided type name. */ - @Nullable - public AutowireCandidateQualifier getQualifier(String typeName) { + public @Nullable AutowireCandidateQualifier getQualifier(String typeName) { return this.qualifiers.get(typeName); } @@ -864,8 +846,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() { + public @Nullable Supplier getInstanceSupplier() { return this.instanceSupplier; } @@ -922,8 +903,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @see #getBeanClass() */ @Override - @Nullable - public String getFactoryBeanName() { + public @Nullable String getFactoryBeanName() { return this.factoryBeanName; } @@ -943,8 +923,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @see RootBeanDefinition#getResolvedFactoryMethod() */ @Override - @Nullable - public String getFactoryMethodName() { + public @Nullable String getFactoryMethodName() { return this.factoryMethodName; } @@ -1038,7 +1017,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @since 6.0 * @see #setInitMethodName */ - public void setInitMethodNames(@Nullable String... initMethodNames) { + public void setInitMethodNames(String @Nullable ... initMethodNames) { this.initMethodNames = initMethodNames; } @@ -1046,8 +1025,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * Return the names of the initializer methods. * @since 6.0 */ - @Nullable - public String[] getInitMethodNames() { + public String @Nullable [] getInitMethodNames() { return this.initMethodNames; } @@ -1066,8 +1044,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess *

Use the first one in case of multiple methods. */ @Override - @Nullable - public String getInitMethodName() { + public @Nullable String getInitMethodName() { return (!ObjectUtils.isEmpty(this.initMethodNames) ? this.initMethodNames[0] : null); } @@ -1098,7 +1075,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @since 6.0 * @see #setDestroyMethodName */ - public void setDestroyMethodNames(@Nullable String... destroyMethodNames) { + public void setDestroyMethodNames(String @Nullable ... destroyMethodNames) { this.destroyMethodNames = destroyMethodNames; } @@ -1106,8 +1083,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * Return the names of the destroy methods. * @since 6.0 */ - @Nullable - public String[] getDestroyMethodNames() { + public String @Nullable [] getDestroyMethodNames() { return this.destroyMethodNames; } @@ -1126,8 +1102,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess *

Use the first one in case of multiple methods. */ @Override - @Nullable - public String getDestroyMethodName() { + public @Nullable String getDestroyMethodName() { return (!ObjectUtils.isEmpty(this.destroyMethodNames) ? this.destroyMethodNames[0] : null); } @@ -1201,8 +1176,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess *

The default is no description. */ @Override - @Nullable - public String getDescription() { + public @Nullable String getDescription() { return this.description; } @@ -1217,8 +1191,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess /** * Return the resource that this bean definition came from. */ - @Nullable - public Resource getResource() { + public @Nullable Resource getResource() { return this.resource; } @@ -1235,8 +1208,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @see #setResourceDescription */ @Override - @Nullable - public String getResourceDescription() { + public @Nullable String getResourceDescription() { return (this.resource != null ? this.resource.getDescription() : null); } @@ -1252,8 +1224,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess * @see #setOriginatingBeanDefinition */ @Override - @Nullable - public BeanDefinition getOriginatingBeanDefinition() { + public @Nullable BeanDefinition getOriginatingBeanDefinition() { return (this.resource instanceof BeanDefinitionResource bdr ? bdr.getBeanDefinition() : null); } 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 40a4503551..97635a0958 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 @@ -22,6 +22,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.core.env.Environment; @@ -31,7 +32,6 @@ 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; /** @@ -53,11 +53,9 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead private final BeanDefinitionRegistry registry; - @Nullable - private ResourceLoader resourceLoader; + private @Nullable ResourceLoader resourceLoader; - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; private Environment environment; @@ -124,8 +122,7 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead } @Override - @Nullable - public ResourceLoader getResourceLoader() { + public @Nullable ResourceLoader getResourceLoader() { return this.resourceLoader; } @@ -141,8 +138,7 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead } @Override - @Nullable - public ClassLoader getBeanClassLoader() { + public @Nullable ClassLoader getBeanClassLoader() { return this.beanClassLoader; } 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 60029e60a9..64d89ab6f7 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 @@ -31,6 +31,8 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Predicate; import java.util.function.UnaryOperator; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeansException; @@ -69,7 +71,6 @@ import org.springframework.core.convert.ConversionService; import org.springframework.core.log.LogMessage; import org.springframework.core.metrics.ApplicationStartup; import org.springframework.core.metrics.StartupStep; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -115,27 +116,22 @@ import org.springframework.util.StringValueResolver; public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport implements ConfigurableBeanFactory { /** Parent bean factory, for bean inheritance support. */ - @Nullable - private BeanFactory parentBeanFactory; + private @Nullable BeanFactory parentBeanFactory; /** ClassLoader to resolve bean class names with, if necessary. */ - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); /** ClassLoader to temporarily resolve bean class names with, if necessary. */ - @Nullable - private ClassLoader tempClassLoader; + private @Nullable ClassLoader tempClassLoader; /** Whether to cache bean metadata or rather reobtain it for every access. */ private boolean cacheBeanMetadata = true; /** Resolution strategy for expressions in bean definition values. */ - @Nullable - private BeanExpressionResolver beanExpressionResolver; + private @Nullable BeanExpressionResolver beanExpressionResolver; /** Spring ConversionService to use instead of PropertyEditors. */ - @Nullable - private ConversionService conversionService; + private @Nullable ConversionService conversionService; /** Custom PropertyEditorRegistrars to apply to the beans of this factory. */ private final Set propertyEditorRegistrars = new LinkedHashSet<>(4); @@ -144,8 +140,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp private final Map, Class> customEditors = new HashMap<>(4); /** A custom TypeConverter to use, overriding the default PropertyEditor mechanism. */ - @Nullable - private TypeConverter typeConverter; + private @Nullable TypeConverter typeConverter; /** String resolvers to apply, for example, to annotation attribute values. */ private final List embeddedValueResolvers = new CopyOnWriteArrayList<>(); @@ -154,8 +149,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp private final List beanPostProcessors = new BeanPostProcessorCacheAwareList(); /** Cache of pre-filtered post-processors. */ - @Nullable - private BeanPostProcessorCache beanPostProcessorCache; + private @Nullable BeanPostProcessorCache beanPostProcessorCache; /** Map from scope identifier String to corresponding Scope. */ private final Map scopes = new LinkedHashMap<>(8); @@ -205,7 +199,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - public Object getBean(String name, Object... args) throws BeansException { + public Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException { return doGetBean(name, null, args, false); } @@ -218,7 +212,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @return an instance of the bean * @throws BeansException if the bean could not be created */ - public T getBean(String name, @Nullable Class requiredType, @Nullable Object... args) + public T getBean(String name, @Nullable Class requiredType, @Nullable Object @Nullable ... args) throws BeansException { return doGetBean(name, requiredType, args, false); @@ -237,7 +231,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp */ @SuppressWarnings("unchecked") protected T doGetBean( - String name, @Nullable Class requiredType, @Nullable Object[] args, boolean typeCheckOnly) + String name, @Nullable Class requiredType, @Nullable Object @Nullable [] args, boolean typeCheckOnly) throws BeansException { String beanName = transformedBeanName(name); @@ -703,14 +697,12 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public Class getType(String name) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name) throws NoSuchBeanDefinitionException { return getType(name, true); } @Override - @Nullable - public Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { String beanName = transformedBeanName(name); // Check manually registered singletons. @@ -798,8 +790,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp //--------------------------------------------------------------------- @Override - @Nullable - public BeanFactory getParentBeanFactory() { + public @Nullable BeanFactory getParentBeanFactory() { return this.parentBeanFactory; } @@ -832,8 +823,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public ClassLoader getBeanClassLoader() { + public @Nullable ClassLoader getBeanClassLoader() { return this.beanClassLoader; } @@ -843,8 +833,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public ClassLoader getTempClassLoader() { + public @Nullable ClassLoader getTempClassLoader() { return this.tempClassLoader; } @@ -864,8 +853,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public BeanExpressionResolver getBeanExpressionResolver() { + public @Nullable BeanExpressionResolver getBeanExpressionResolver() { return this.beanExpressionResolver; } @@ -875,8 +863,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -921,8 +908,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() { + protected @Nullable TypeConverter getCustomTypeConverter() { return this.typeConverter; } @@ -953,8 +939,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public String resolveEmbeddedValue(@Nullable String value) { + public @Nullable String resolveEmbeddedValue(@Nullable String value) { if (value == null) { return null; } @@ -1089,8 +1074,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } @Override - @Nullable - public Scope getRegisteredScope(String scopeName) { + public @Nullable Scope getRegisteredScope(String scopeName) { Assert.notNull(scopeName, "Scope identifier must not be null"); return this.scopes.get(scopeName); } @@ -1489,7 +1473,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @param beanName the name of the bean * @param args the arguments for bean creation, if any */ - protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object[] args) { + protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object @Nullable [] args) { if (mbd.isAbstract()) { throw new BeanIsAbstractException(beanName); } @@ -1534,8 +1518,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(RootBeanDefinition mbd, String beanName, Class... typesToMatch) + protected @Nullable Class resolveBeanClass(RootBeanDefinition mbd, String beanName, Class... typesToMatch) throws CannotLoadBeanClassException { try { @@ -1560,8 +1543,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp } } - @Nullable - private Class doResolveBeanClass(RootBeanDefinition mbd, Class... typesToMatch) + private @Nullable Class doResolveBeanClass(RootBeanDefinition mbd, Class... typesToMatch) throws ClassNotFoundException { ClassLoader beanClassLoader = getBeanClassLoader(); @@ -1628,8 +1610,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @return the resolved value * @see #setBeanExpressionResolver */ - @Nullable - protected Object evaluateBeanDefinitionString(@Nullable String value, @Nullable BeanDefinition beanDefinition) { + protected @Nullable Object evaluateBeanDefinitionString(@Nullable String value, @Nullable BeanDefinition beanDefinition) { if (this.beanExpressionResolver == null) { return value; } @@ -1660,8 +1641,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) { + protected @Nullable Class predictBeanType(String beanName, RootBeanDefinition mbd, Class... typesToMatch) { Class targetType = mbd.getTargetType(); if (targetType != null) { return targetType; @@ -1978,7 +1958,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp * @return a new instance of the bean * @throws BeanCreationException if the bean could not be created */ - protected abstract Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args) + protected abstract Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] args) throws BeanCreationException; 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 c078572af5..a33573cb36 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 @@ -16,10 +16,11 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; 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 @@ -79,8 +80,7 @@ public interface AutowireCandidateResolver { * @return the qualifier value, if any * @since 6.2 */ - @Nullable - default String getSuggestedName(DependencyDescriptor descriptor) { + default @Nullable String getSuggestedName(DependencyDescriptor descriptor) { return null; } @@ -92,8 +92,7 @@ public interface AutowireCandidateResolver { * or {@code null} if none found * @since 3.0 */ - @Nullable - default Object getSuggestedValue(DependencyDescriptor descriptor) { + default @Nullable Object getSuggestedValue(DependencyDescriptor descriptor) { return null; } @@ -107,8 +106,7 @@ public interface AutowireCandidateResolver { * or {@code null} if straight resolution is to be performed * @since 4.0 */ - @Nullable - default Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { + default @Nullable Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { return null; } @@ -121,8 +119,7 @@ public interface AutowireCandidateResolver { * @return the lazy resolution proxy class for the dependency target, if any * @since 6.0 */ - @Nullable - default Class getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) { + default @Nullable Class getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java index 1a6f0c8753..9e79e6e224 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/AutowireUtils.java @@ -32,10 +32,11 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.TypedStringValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java index d82d66bd75..627059921c 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java @@ -18,11 +18,12 @@ package org.springframework.beans.factory.support; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.AutowiredPropertyMarker; import org.springframework.beans.factory.config.BeanDefinitionCustomizer; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java index eb76dd9d13..ef70bb65fa 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionDefaults.java @@ -16,7 +16,8 @@ package org.springframework.beans.factory.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -29,18 +30,15 @@ import org.springframework.util.StringUtils; */ public class BeanDefinitionDefaults { - @Nullable - private Boolean lazyInit; + private @Nullable Boolean lazyInit; private int autowireMode = AbstractBeanDefinition.AUTOWIRE_NO; private int dependencyCheck = AbstractBeanDefinition.DEPENDENCY_CHECK_NONE; - @Nullable - private String initMethodName; + private @Nullable String initMethodName; - @Nullable - private String destroyMethodName; + private @Nullable String destroyMethodName; /** @@ -68,8 +66,7 @@ public class BeanDefinitionDefaults { * @return the lazy-init flag if explicitly set, or {@code null} otherwise * @since 5.2 */ - @Nullable - public Boolean getLazyInit() { + public @Nullable Boolean getLazyInit() { return this.lazyInit; } @@ -124,8 +121,7 @@ public class BeanDefinitionDefaults { /** * Return the name of the default initializer method. */ - @Nullable - public String getInitMethodName() { + public @Nullable String getInitMethodName() { return this.initMethodName; } @@ -143,8 +139,7 @@ public class BeanDefinitionDefaults { /** * Return the name of the default destroy method. */ - @Nullable - public String getDestroyMethodName() { + public @Nullable String getDestroyMethodName() { return this.destroyMethodName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionOverrideException.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionOverrideException.java index a815db479f..0a5ac2cec4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionOverrideException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionOverrideException.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.NonNull; + import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.lang.NonNull; /** * Subclass of {@link BeanDefinitionStoreException} indicating an invalid override @@ -75,8 +76,7 @@ public class BeanDefinitionOverrideException extends BeanDefinitionStoreExceptio * Return the description of the resource that the bean definition came from. */ @Override - @NonNull - public String getResourceDescription() { + public @NonNull String getResourceDescription() { return String.valueOf(super.getResourceDescription()); } @@ -84,8 +84,7 @@ public class BeanDefinitionOverrideException extends BeanDefinitionStoreExceptio * Return the name of the bean. */ @Override - @NonNull - public String getBeanName() { + public @NonNull String getBeanName() { return String.valueOf(super.getBeanName()); } 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 8441abbc76..b6eeb3ae23 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 @@ -16,10 +16,11 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + 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 that specifies load methods with @@ -63,8 +64,7 @@ public interface BeanDefinitionReader { * @see #loadBeanDefinitions(String) * @see org.springframework.core.io.support.ResourcePatternResolver */ - @Nullable - ResourceLoader getResourceLoader(); + @Nullable ResourceLoader getResourceLoader(); /** * Return the class loader to use for bean classes. @@ -72,8 +72,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(); + @Nullable ClassLoader getBeanClassLoader(); /** * Return the {@link BeanNameGenerator} to use for anonymous beans 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 b02687792e..678e37d948 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 @@ -16,11 +16,12 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + 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; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java index f59222a962..54f61ada5f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionResource.java @@ -20,9 +20,10 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.io.AbstractResource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 c3efcdcc0b..08af87df25 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 @@ -25,6 +25,8 @@ import java.util.Properties; import java.util.Set; import java.util.function.BiFunction; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeansException; @@ -41,7 +43,6 @@ import org.springframework.beans.factory.config.NamedBeanHolder; 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.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -127,8 +128,7 @@ public class BeanDefinitionValueResolver { * @param value the value object to resolve * @return the resolved object */ - @Nullable - public Object resolveValueIfNecessary(Object argName, @Nullable Object value) { + public @Nullable 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 ref) { @@ -268,8 +268,7 @@ public class BeanDefinitionValueResolver { * @param value the candidate value (may be an expression) * @return the resolved value */ - @Nullable - protected Object evaluate(TypedStringValue value) { + protected @Nullable Object evaluate(TypedStringValue value) { Object result = doEvaluate(value.getValue()); if (!ObjectUtils.nullSafeEquals(result, value.getValue())) { value.setDynamic(); @@ -282,8 +281,7 @@ public class BeanDefinitionValueResolver { * @param value the original value (may be an expression) * @return the resolved value if necessary, or the original value */ - @Nullable - protected Object evaluate(@Nullable Object value) { + protected @Nullable Object evaluate(@Nullable Object value) { if (value instanceof String str) { return doEvaluate(str); } @@ -310,8 +308,7 @@ public class BeanDefinitionValueResolver { * @param value the original value (may be an expression) * @return the resolved value if necessary, or the original String value */ - @Nullable - private Object doEvaluate(@Nullable String value) { + private @Nullable Object doEvaluate(@Nullable String value) { return this.beanFactory.evaluateBeanDefinitionString(value, this.beanDefinition); } @@ -322,8 +319,7 @@ public class BeanDefinitionValueResolver { * @throws ClassNotFoundException if the specified type cannot be resolved * @see TypedStringValue#resolveTargetType */ - @Nullable - protected Class resolveTargetType(TypedStringValue value) throws ClassNotFoundException { + protected @Nullable Class resolveTargetType(TypedStringValue value) throws ClassNotFoundException { if (value.hasTargetType()) { return value.getTargetType(); } @@ -333,8 +329,7 @@ public class BeanDefinitionValueResolver { /** * Resolve a reference to another bean in the factory. */ - @Nullable - private Object resolveReference(Object argName, RuntimeBeanReference ref) { + private @Nullable Object resolveReference(Object argName, RuntimeBeanReference ref) { try { Object bean; Class beanType = ref.getBeanType(); @@ -385,8 +380,7 @@ public class BeanDefinitionValueResolver { * @param mbd the merged bean definition for the inner bean * @return the resolved inner bean instance */ - @Nullable - private Object resolveInnerBeanValue(Object argName, String innerBeanName, RootBeanDefinition mbd) { + private @Nullable Object resolveInnerBeanValue(Object argName, String innerBeanName, RootBeanDefinition mbd) { try { // Check given bean name whether it is unique. If not already unique, // add counter - increasing the counter until the name is unique. 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 4c1f826f56..416e7b29f9 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 @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; @@ -36,7 +37,6 @@ import org.springframework.cglib.proxy.MethodInterceptor; import org.springframework.cglib.proxy.MethodProxy; import org.springframework.cglib.proxy.NoOp; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -241,8 +241,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt } @Override - @Nullable - public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { + public @Nullable Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { // Cast is safe, as CallbackFilter filters are used selectively. LookupOverride lo = (LookupOverride) getBeanDefinition().getMethodOverrides().getOverride(method); Assert.state(lo != null, "LookupOverride not found"); @@ -276,9 +275,8 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt this.owner = owner; } - @Nullable @Override - public Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { + public @Nullable Object intercept(Object obj, Method method, Object[] args, MethodProxy mp) throws Throwable { ReplaceOverride ro = (ReplaceOverride) getBeanDefinition().getMethodOverrides().getOverride(method); Assert.state(ro != null, "ReplaceOverride not found"); // TODO could cache if a singleton for minor performance optimization @@ -286,8 +284,7 @@ public class CglibSubclassingInstantiationStrategy extends SimpleInstantiationSt return processReturnType(method, mr.reimplement(obj, method, args)); } - @Nullable - private T processReturnType(Method method, @Nullable T returnValue) { + private @Nullable T processReturnType(Method method, @Nullable T returnValue) { Class returnType = method.getReturnType(); if (returnValue == null && returnType != void.class && returnType.isPrimitive()) { throw new IllegalStateException( diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java index 5f15616d95..6cb7c13f0d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ChildBeanDefinition.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.ConstructorArgumentValues; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -46,8 +47,7 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") public class ChildBeanDefinition extends AbstractBeanDefinition { - @Nullable - private String parentName; + private @Nullable String parentName; /** @@ -136,8 +136,7 @@ public class ChildBeanDefinition extends AbstractBeanDefinition { } @Override - @Nullable - public String getParentName() { + public @Nullable String getParentName() { return this.parentName; } 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 39d0323db4..d3c2bee08b 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 @@ -38,6 +38,7 @@ import java.util.function.Predicate; import java.util.function.Supplier; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.BeanUtils; @@ -68,7 +69,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.NamedThreadLocal; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -133,7 +133,7 @@ class ConstructorResolver { */ @SuppressWarnings("NullAway") public BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mbd, - @Nullable Constructor[] chosenCtors, @Nullable Object[] explicitArgs) { + Constructor @Nullable [] chosenCtors, @Nullable Object @Nullable [] explicitArgs) { BeanWrapperImpl bw = new BeanWrapperImpl(); this.beanFactory.initBeanWrapper(bw); @@ -395,7 +395,7 @@ class ConstructorResolver { */ @SuppressWarnings("NullAway") public BeanWrapper instantiateUsingFactoryMethod( - String beanName, RootBeanDefinition mbd, @Nullable Object[] explicitArgs) { + String beanName, RootBeanDefinition mbd, @Nullable Object @Nullable [] explicitArgs) { BeanWrapperImpl bw = new BeanWrapperImpl(); this.beanFactory.initBeanWrapper(bw); @@ -431,7 +431,7 @@ class ConstructorResolver { Method factoryMethodToUse = null; ArgumentsHolder argsHolderToUse = null; - Object[] argsToUse = null; + @Nullable Object[] argsToUse = null; if (explicitArgs != null) { argsToUse = explicitArgs; @@ -647,7 +647,7 @@ class ConstructorResolver { } private Object instantiate(String beanName, RootBeanDefinition mbd, - @Nullable Object factoryBean, Method factoryMethod, Object[] args) { + @Nullable Object factoryBean, Method factoryMethod, @Nullable Object[] args) { try { return this.beanFactory.getInstantiationStrategy().instantiate( @@ -719,7 +719,7 @@ class ConstructorResolver { */ private ArgumentsHolder createArgumentArray( String beanName, RootBeanDefinition mbd, @Nullable ConstructorArgumentValues resolvedValues, - BeanWrapper bw, Class[] paramTypes, @Nullable String[] paramNames, Executable executable, + BeanWrapper bw, Class[] paramTypes, String @Nullable [] paramNames, Executable executable, boolean autowiring, boolean fallback) throws UnsatisfiedDependencyException { TypeConverter customConverter = this.beanFactory.getCustomTypeConverter(); @@ -897,8 +897,7 @@ class ConstructorResolver { /** * Resolve the specified argument which is supposed to be autowired. */ - @Nullable - Object resolveAutowiredArgument(DependencyDescriptor descriptor, Class paramType, String beanName, + @Nullable Object resolveAutowiredArgument(DependencyDescriptor descriptor, Class paramType, String beanName, @Nullable Set autowiredBeanNames, TypeConverter typeConverter, boolean fallback) { if (InjectionPoint.class.isAssignableFrom(paramType)) { @@ -1041,8 +1040,7 @@ class ConstructorResolver { return ResolvableType.forInstance(value); } - @Nullable - private Constructor resolveConstructor(String beanName, RootBeanDefinition mbd, + private @Nullable Constructor resolveConstructor(String beanName, RootBeanDefinition mbd, Supplier beanType, List valueTypes) { Class type = ClassUtils.getUserClass(beanType.get().toClass()); @@ -1089,8 +1087,7 @@ class ConstructorResolver { return (typeConversionFallbackMatches.size() == 1 ? typeConversionFallbackMatches.get(0) : null); } - @Nullable - private Method resolveFactoryMethod(String beanName, RootBeanDefinition mbd, List valueTypes) { + private @Nullable Method resolveFactoryMethod(String beanName, RootBeanDefinition mbd, List valueTypes) { if (mbd.isFactoryMethodUnique) { Method resolvedFactoryMethod = mbd.getResolvedFactoryMethod(); if (resolvedFactoryMethod != null) { @@ -1149,8 +1146,7 @@ class ConstructorResolver { return null; } - @Nullable - private Method resolveFactoryMethod(List executables, + private @Nullable Method resolveFactoryMethod(List executables, Function> parameterTypesFactory, List valueTypes) { @@ -1257,8 +1253,7 @@ class ConstructorResolver { BeanUtils.isSimpleValueType(valueType.toClass())); } - @Nullable - private Class getFactoryBeanClass(String beanName, RootBeanDefinition mbd) { + private @Nullable Class getFactoryBeanClass(String beanName, RootBeanDefinition mbd) { Class beanClass = this.beanFactory.resolveBeanClass(mbd, beanName); return (beanClass != null && FactoryBean.class.isAssignableFrom(beanClass) ? beanClass : null); } @@ -1288,8 +1283,7 @@ class ConstructorResolver { * This variant adds a lenient fallback to the default constructor if available, similar to * {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor#determineCandidateConstructors}. */ - @Nullable - static Constructor[] determinePreferredConstructors(Class clazz) { + static Constructor @Nullable [] determinePreferredConstructors(Class clazz) { Constructor primaryCtor = BeanUtils.findPrimaryConstructor(clazz); Constructor defaultCtor; @@ -1337,11 +1331,11 @@ class ConstructorResolver { */ private static class ArgumentsHolder { - public final Object[] rawArguments; + public final @Nullable Object[] rawArguments; - public final Object[] arguments; + public final @Nullable Object[] arguments; - public final Object[] preparedArguments; + public final @Nullable Object[] preparedArguments; public boolean resolveNecessary = false; @@ -1351,7 +1345,7 @@ class ConstructorResolver { this.preparedArguments = new Object[size]; } - public ArgumentsHolder(Object[] args) { + public ArgumentsHolder(@Nullable Object[] args) { this.rawArguments = args; this.arguments = args; this.preparedArguments = args; @@ -1401,8 +1395,7 @@ class ConstructorResolver { */ private static class ConstructorPropertiesChecker { - @Nullable - public static String[] evaluate(Constructor candidate, int paramCount) { + public static String @Nullable [] evaluate(Constructor candidate, int paramCount) { ConstructorProperties cp = candidate.getAnnotation(ConstructorProperties.class); if (cp != null) { String[] names = cp.value(); @@ -1427,8 +1420,7 @@ class ConstructorResolver { @SuppressWarnings("serial") private static class ConstructorDependencyDescriptor extends DependencyDescriptor { - @Nullable - private volatile String shortcut; + private volatile @Nullable String shortcut; public ConstructorDependencyDescriptor(MethodParameter methodParameter, boolean required) { super(methodParameter, required); @@ -1443,8 +1435,7 @@ class ConstructorResolver { } @Override - @Nullable - public Object resolveShortcut(BeanFactory beanFactory) { + public @Nullable Object resolveShortcut(BeanFactory beanFactory) { String shortcut = this.shortcut; return (shortcut != null ? beanFactory.getBean(shortcut, getDependencyType()) : 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 48bbeec50f..692ffcb2d5 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 @@ -47,6 +47,7 @@ import java.util.function.Supplier; import java.util.stream.Stream; import jakarta.inject.Provider; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.TypeConverter; @@ -82,7 +83,6 @@ import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.log.LogMessage; import org.springframework.core.metrics.StartupStep; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -128,8 +128,7 @@ import org.springframework.util.StringUtils; public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable { - @Nullable - private static Class jakartaInjectProviderClass; + private static @Nullable Class jakartaInjectProviderClass; static { try { @@ -148,22 +147,18 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto new ConcurrentHashMap<>(8); /** Optional id for this factory, for serialization purposes. */ - @Nullable - private String serializationId; + private @Nullable String serializationId; /** Whether to allow re-registration of a different definition with the same name. */ - @Nullable - private Boolean allowBeanDefinitionOverriding; + private @Nullable Boolean allowBeanDefinitionOverriding; /** Whether to allow eager class loading even for lazy-init beans. */ private boolean allowEagerClassLoading = true; - @Nullable - private Executor bootstrapExecutor; + private @Nullable Executor bootstrapExecutor; /** Optional OrderComparator for dependency Lists and arrays. */ - @Nullable - private Comparator dependencyComparator; + private @Nullable Comparator dependencyComparator; /** Resolver to use for checking if a bean definition is an autowire candidate. */ private AutowireCandidateResolver autowireCandidateResolver = SimpleAutowireCandidateResolver.INSTANCE; @@ -193,8 +188,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto private volatile Set manualSingletonNames = new LinkedHashSet<>(16); /** Cached array of bean definition names in case of frozen configuration. */ - @Nullable - private volatile String[] frozenBeanDefinitionNames; + private volatile String @Nullable [] frozenBeanDefinitionNames; /** Whether bean definition metadata may be cached for all beans. */ private volatile boolean configurationFrozen; @@ -240,8 +234,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * to be deserialized from this id back into the BeanFactory object, if needed. * @since 4.1.2 */ - @Nullable - public String getSerializationId() { + public @Nullable String getSerializationId() { return this.serializationId; } @@ -294,8 +287,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public Executor getBootstrapExecutor() { + public @Nullable Executor getBootstrapExecutor() { return this.bootstrapExecutor; } @@ -313,8 +305,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * Return the dependency comparator for this BeanFactory (may be {@code null}). * @since 4.0 */ - @Nullable - public Comparator getDependencyComparator() { + public @Nullable Comparator getDependencyComparator() { return this.dependencyComparator; } @@ -366,7 +357,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto @SuppressWarnings("unchecked") @Override - public T getBean(Class requiredType, @Nullable Object... args) throws BeansException { + public T getBean(Class requiredType, Object @Nullable ... args) throws BeansException { Assert.notNull(requiredType, "Required type must not be null"); Object resolved = resolveBean(ResolvableType.forRawClass(requiredType), args, false); if (resolved == null) { @@ -439,8 +430,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return resolved; } @Override - @Nullable - public T getIfAvailable() throws BeansException { + public @Nullable T getIfAvailable() throws BeansException { try { return resolveBean(requiredType, null, false); } @@ -462,8 +452,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } @Override - @Nullable - public T getIfUnique() throws BeansException { + public @Nullable T getIfUnique() throws BeansException { try { return resolveBean(requiredType, null, true); } @@ -511,8 +500,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto }; } - @Nullable - private T resolveBean(ResolvableType requiredType, @Nullable Object[] args, boolean nonUniqueAsNull) { + private @Nullable T resolveBean(ResolvableType requiredType, Object @Nullable [] args, boolean nonUniqueAsNull) { NamedBeanHolder namedBean = resolveNamedBean(requiredType, args, nonUniqueAsNull); if (namedBean != null) { return namedBean.getBeanInstance(); @@ -749,16 +737,14 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public A findAnnotationOnBean(String beanName, Class annotationType) + public @Nullable A findAnnotationOnBean(String beanName, Class annotationType) throws NoSuchBeanDefinitionException { return findAnnotationOnBean(beanName, annotationType, true); } @Override - @Nullable - public A findAnnotationOnBean( + public @Nullable A findAnnotationOnBean( String beanName, Class annotationType, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { @@ -971,8 +957,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - protected Object obtainInstanceFromSupplier(Supplier supplier, String beanName, RootBeanDefinition mbd) + protected @Nullable Object obtainInstanceFromSupplier(Supplier supplier, String beanName, RootBeanDefinition mbd) throws Exception { if (supplier instanceof InstanceSupplier instanceSupplier) { @@ -982,7 +967,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object[] args) { + protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName, @Nullable Object @Nullable [] args) { super.checkMergedBeanDefinition(mbd, beanName, args); if (mbd.isBackgroundInit()) { @@ -1003,8 +988,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - protected Boolean isCurrentThreadAllowedToHoldSingletonLock() { + protected @Nullable Boolean isCurrentThreadAllowedToHoldSingletonLock() { return (this.preInstantiationPhase ? this.preInstantiationThread.get() != PreInstantiation.BACKGROUND : null); } @@ -1060,8 +1044,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } - @Nullable - private CompletableFuture preInstantiateSingleton(String beanName, RootBeanDefinition mbd) { + private @Nullable CompletableFuture preInstantiateSingleton(String beanName, RootBeanDefinition mbd) { if (mbd.isBackgroundInit()) { Executor executor = getBootstrapExecutor(); if (executor != null) { @@ -1427,9 +1410,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @SuppressWarnings("unchecked") - @Nullable - private NamedBeanHolder resolveNamedBean( - ResolvableType requiredType, @Nullable Object[] args, boolean nonUniqueAsNull) throws BeansException { + private @Nullable NamedBeanHolder resolveNamedBean( + ResolvableType requiredType, Object @Nullable [] args, boolean nonUniqueAsNull) throws BeansException { Assert.notNull(requiredType, "Required type must not be null"); String[] candidateNames = getBeanNamesForType(requiredType); @@ -1482,9 +1464,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return null; } - @Nullable - private NamedBeanHolder resolveNamedBean( - String beanName, ResolvableType requiredType, @Nullable Object[] args) throws BeansException { + private @Nullable NamedBeanHolder resolveNamedBean( + String beanName, ResolvableType requiredType, Object @Nullable [] args) throws BeansException { Object bean = getBean(beanName, null, args); if (bean instanceof NullBean) { @@ -1494,8 +1475,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, + public @Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException { descriptor.initParameterNameDiscovery(getParameterNameDiscoverer()); @@ -1519,9 +1499,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter); } - @Nullable @SuppressWarnings("NullAway") - public Object doResolveDependency(DependencyDescriptor descriptor, @Nullable String beanName, + public @Nullable Object doResolveDependency(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException { InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor); @@ -1637,8 +1616,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } - @Nullable - private Object resolveInstance(Object candidate, DependencyDescriptor descriptor, Class type, String name) { + private @Nullable Object resolveInstance(Object candidate, DependencyDescriptor descriptor, Class type, String name) { Object result = candidate; if (result instanceof NullBean) { // Raise exception if null encountered for required injection point @@ -1654,8 +1632,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } - @Nullable - private Object resolveMultipleBeans(DependencyDescriptor descriptor, @Nullable String beanName, + private @Nullable Object resolveMultipleBeans(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) { Class type = descriptor.getDependencyType(); @@ -1711,8 +1688,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } - @Nullable - private Object resolveMultipleBeansFallback(DependencyDescriptor descriptor, @Nullable String beanName, + private @Nullable Object resolveMultipleBeansFallback(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) { Class type = descriptor.getDependencyType(); @@ -1726,8 +1702,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return null; } - @Nullable - private Object resolveMultipleBeanCollection(DependencyDescriptor descriptor, @Nullable String beanName, + private @Nullable Object resolveMultipleBeanCollection(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) { Class elementType = descriptor.getResolvableType().asCollection().resolveGeneric(); @@ -1753,8 +1728,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return result; } - @Nullable - private Object resolveMultipleBeanMap(DependencyDescriptor descriptor, @Nullable String beanName, + private @Nullable Object resolveMultipleBeanMap(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) { ResolvableType mapType = descriptor.getResolvableType().asMap(); @@ -1787,8 +1761,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return getAutowireCandidateResolver().isRequired(descriptor); } - @Nullable - private Comparator adaptDependencyComparator(Map matchingBeans) { + private @Nullable Comparator adaptDependencyComparator(Map matchingBeans) { Comparator comparator = getDependencyComparator(); if (comparator instanceof OrderComparator orderComparator) { return orderComparator.withSourceProvider( @@ -1903,8 +1876,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) { + protected @Nullable String determineAutowireCandidate(Map candidates, DependencyDescriptor descriptor) { Class requiredType = descriptor.getDependencyType(); // Step 1: check primary candidate String primaryCandidate = determinePrimaryCandidate(candidates, requiredType); @@ -1953,8 +1925,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) { + protected @Nullable String determinePrimaryCandidate(Map candidates, Class requiredType) { String primaryBeanName = null; // First pass: identify unique primary candidate for (Map.Entry entry : candidates.entrySet()) { @@ -2005,8 +1976,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto * the same highest priority value * @see #getPriority(Object) */ - @Nullable - protected String determineHighestPriorityCandidate(Map candidates, Class requiredType) { + protected @Nullable String determineHighestPriorityCandidate(Map candidates, Class requiredType) { String highestPriorityBeanName = null; Integer highestPriority = null; boolean highestPriorityConflictDetected = false; @@ -2086,8 +2056,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) { + protected @Nullable Integer getPriority(Object beanInstance) { Comparator comparator = getDependencyComparator(); if (comparator instanceof OrderComparator orderComparator) { return orderComparator.getPriority(beanInstance); @@ -2325,8 +2294,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto private final boolean optional; - @Nullable - private final String beanName; + private final @Nullable String beanName; public DependencyObjectProvider(DependencyDescriptor descriptor, @Nullable String beanName) { this.descriptor = new NestedDependencyDescriptor(descriptor); @@ -2369,8 +2337,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public Object getIfAvailable() throws BeansException { + public @Nullable Object getIfAvailable() throws BeansException { try { if (this.optional) { return createOptionalDependency(this.descriptor, this.beanName); @@ -2409,8 +2376,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public Object getIfUnique() throws BeansException { + public @Nullable Object getIfUnique() throws BeansException { DependencyDescriptor descriptorToUse = new DependencyDescriptor(this.descriptor) { @Override public boolean isRequired() { @@ -2421,8 +2387,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto return true; } @Override - @Nullable - public Object resolveNotUnique(ResolvableType type, Map matchingBeans) { + public @Nullable Object resolveNotUnique(ResolvableType type, Map matchingBeans) { return null; } }; @@ -2453,8 +2418,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } } - @Nullable - protected Object getValue() throws BeansException { + protected @Nullable Object getValue() throws BeansException { if (this.optional) { return createOptionalDependency(this.descriptor, this.beanName); } @@ -2500,8 +2464,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public Object get() throws BeansException { + public @Nullable Object get() throws BeansException { return getValue(); } } @@ -2526,8 +2489,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto } @Override - @Nullable - public Object getOrderSource(Object obj) { + public @Nullable Object getOrderSource(Object obj) { String beanName = this.instancesToBeanNames.get(obj); if (beanName == null) { return null; 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 bebcc11540..da7e299ef2 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 @@ -28,6 +28,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCreationNotAllowedException; import org.springframework.beans.factory.BeanCurrentlyInCreationException; @@ -35,7 +37,6 @@ 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; @@ -104,8 +105,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements private volatile boolean singletonsCurrentlyInDestruction = false; /** Collection of suppressed Exceptions, available for associating related causes. */ - @Nullable - private Set suppressedExceptions; + private @Nullable Set suppressedExceptions; /** Disposable bean instances: bean name to disposable instance. */ private final Map disposableBeans = new LinkedHashMap<>(); @@ -176,8 +176,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements } @Override - @Nullable - public Object getSingleton(String beanName) { + public @Nullable Object getSingleton(String beanName) { return getSingleton(beanName, true); } @@ -189,8 +188,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) { + protected @Nullable Object getSingleton(String beanName, boolean allowEarlyReference) { // Quick check for existing instance without full singleton lock. Object singletonObject = this.singletonObjects.get(beanName); if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) { @@ -334,8 +332,7 @@ public class DefaultSingletonBeanRegistry extends SimpleAliasRegistry implements * indication (traditional behavior: always holding a full lock) * @since 6.2 */ - @Nullable - protected Boolean isCurrentThreadAllowedToHoldSingletonLock() { + protected @Nullable Boolean isCurrentThreadAllowedToHoldSingletonLock() { return null; } 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 f95fd951e3..1b0149e9fe 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 @@ -27,6 +27,7 @@ import java.util.concurrent.Future; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -35,7 +36,6 @@ import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -89,14 +89,11 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { private boolean invokeAutoCloseable; - @Nullable - private String[] destroyMethodNames; + private String @Nullable [] destroyMethodNames; - @Nullable - private transient Method[] destroyMethods; + private transient Method @Nullable [] destroyMethods; - @Nullable - private final List beanPostProcessors; + private final @Nullable List beanPostProcessors; /** @@ -177,7 +174,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { * Create a new DisposableBeanAdapter for the given bean. */ private DisposableBeanAdapter(Object bean, String beanName, boolean nonPublicAccessAllowed, - boolean invokeDisposableBean, boolean invokeAutoCloseable, @Nullable String[] destroyMethodNames, + boolean invokeDisposableBean, boolean invokeAutoCloseable, String @Nullable [] destroyMethodNames, @Nullable List postProcessors) { this.bean = bean; @@ -261,8 +258,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } - @Nullable - private Method determineDestroyMethod(String destroyMethodName) { + private @Nullable Method determineDestroyMethod(String destroyMethodName) { try { Class beanClass = this.bean.getClass(); MethodDescriptor descriptor = MethodDescriptor.create(this.beanName, beanClass, destroyMethodName); @@ -286,8 +282,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { } } - @Nullable - private Method findDestroyMethod(Class clazz, String name) { + private @Nullable Method findDestroyMethod(Class clazz, String name) { return (this.nonPublicAccessAllowed ? BeanUtils.findMethodWithMinimalParameters(clazz, name) : BeanUtils.findMethodWithMinimalParameters(clazz.getMethods(), name)); @@ -408,8 +403,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 - static String[] inferDestroyMethodsIfNecessary(Class target, RootBeanDefinition beanDefinition) { + static String @Nullable [] inferDestroyMethodsIfNecessary(Class target, RootBeanDefinition beanDefinition) { String[] destroyMethodNames = beanDefinition.getDestroyMethodNames(); if (destroyMethodNames != null && destroyMethodNames.length > 1) { return destroyMethodNames; @@ -469,8 +463,7 @@ class DisposableBeanAdapter implements DisposableBean, Runnable, Serializable { * @param processors the List to search * @return the filtered List of DestructionAwareBeanPostProcessors */ - @Nullable - private static List filterPostProcessors( + private static @Nullable List filterPostProcessors( List processors, Object bean) { List filteredPostProcessors = null; 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 ffcd87bbfb..da0199f0d1 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 @@ -19,6 +19,8 @@ package org.springframework.beans.factory.support; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCurrentlyInCreationException; @@ -26,7 +28,6 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.FactoryBeanNotInitializedException; import org.springframework.core.AttributeAccessor; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; /** * Support base class for singleton registries which need to handle @@ -50,8 +51,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(FactoryBean factoryBean) { + protected @Nullable Class getTypeForFactoryBean(FactoryBean factoryBean) { try { return factoryBean.getObjectType(); } @@ -102,8 +102,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) { + protected @Nullable Object getCachedObjectForFactoryBean(String beanName) { return this.factoryBeanObjectCache.get(beanName); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java index 570957cf99..fdfb87480b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/GenericBeanDefinition.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -40,10 +41,10 @@ import org.springframework.util.ObjectUtils; * @see ChildBeanDefinition */ @SuppressWarnings("serial") -public class GenericBeanDefinition extends AbstractBeanDefinition { +public class +GenericBeanDefinition extends AbstractBeanDefinition { - @Nullable - private String parentName; + private @Nullable String parentName; /** @@ -74,8 +75,7 @@ public class GenericBeanDefinition extends AbstractBeanDefinition { } @Override - @Nullable - public String getParentName() { + public @Nullable String getParentName() { return this.parentName; } 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 f422594f70..81d4b201cb 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 @@ -19,6 +19,8 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; @@ -27,7 +29,6 @@ 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; /** @@ -45,8 +46,7 @@ import org.springframework.util.ClassUtils; public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCandidateResolver implements BeanFactoryAware, Cloneable { - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; @Override @@ -54,8 +54,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan this.beanFactory = beanFactory; } - @Nullable - protected final BeanFactory getBeanFactory() { + protected final @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @@ -161,8 +160,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan return dependencyType.isAssignableFrom(targetType); } - @Nullable - protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) { + protected @Nullable RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition rbd) { BeanDefinitionHolder decDef = rbd.getDecoratedDefinition(); if (decDef != null && this.beanFactory instanceof ConfigurableListableBeanFactory clbf) { if (clbf.containsBeanDefinition(decDef.getBeanName())) { @@ -175,8 +173,7 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCan return null; } - @Nullable - protected ResolvableType getReturnTypeForFactoryMethod(RootBeanDefinition rbd, DependencyDescriptor descriptor) { + protected @Nullable 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... ResolvableType returnType = rbd.factoryMethodReturnType; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstanceSupplier.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstanceSupplier.java index 22e65bc12b..76c68376fe 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/InstanceSupplier.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/InstanceSupplier.java @@ -19,7 +19,8 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.function.ThrowingBiFunction; import org.springframework.util.function.ThrowingSupplier; @@ -59,8 +60,7 @@ public interface InstanceSupplier extends ThrowingSupplier { * another means. * @return the factory method used to create the instance, or {@code null} */ - @Nullable - default Method getFactoryMethod() { + default @Nullable Method getFactoryMethod() { return null; } @@ -83,8 +83,7 @@ public interface InstanceSupplier extends ThrowingSupplier { return after.applyWithException(registeredBean, InstanceSupplier.this.get(registeredBean)); } @Override - @Nullable - public Method getFactoryMethod() { + public @Nullable Method getFactoryMethod() { return InstanceSupplier.this.getFactoryMethod(); } }; @@ -127,8 +126,7 @@ public interface InstanceSupplier extends ThrowingSupplier { return supplier.getWithException(); } @Override - @Nullable - public Method getFactoryMethod() { + public @Nullable Method getFactoryMethod() { return factoryMethod; } }; 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 450d85aa9e..0824a2038b 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 @@ -19,9 +19,10 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + 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. @@ -80,7 +81,7 @@ public interface InstantiationStrategy { * @throws BeansException if the instantiation attempt failed */ Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner, - @Nullable Object factoryBean, Method factoryMethod, Object... args) + @Nullable Object factoryBean, Method factoryMethod, @Nullable 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 9cbcbebe94..f0be69767c 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,8 +19,9 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -41,11 +42,9 @@ import org.springframework.util.ObjectUtils; */ public class LookupOverride extends MethodOverride { - @Nullable - private final String beanName; + private final @Nullable String beanName; - @Nullable - private Method method; + private @Nullable Method method; /** @@ -75,8 +74,7 @@ public class LookupOverride extends MethodOverride { /** * Return the name of the bean that should be returned by this {@code LookupOverride}. */ - @Nullable - public String getBeanName() { + public @Nullable String getBeanName() { return this.beanName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedArray.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedArray.java index 89e346b2d9..f0dead8758 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedArray.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedArray.java @@ -16,7 +16,8 @@ package org.springframework.beans.factory.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -30,8 +31,7 @@ import org.springframework.util.Assert; public class ManagedArray extends ManagedList { /** Resolved element type for runtime creation of the target array. */ - @Nullable - volatile Class resolvedElementType; + volatile @Nullable Class resolvedElementType; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java index 2b0a25a913..43ad078b24 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedList.java @@ -20,9 +20,10 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.Mergeable; -import org.springframework.lang.Nullable; /** * Tag collection class used to hold managed List elements, which may @@ -39,11 +40,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ManagedList extends ArrayList implements Mergeable, BeanMetadataElement { - @Nullable - private Object source; + private @Nullable Object source; - @Nullable - private String elementTypeName; + private @Nullable String elementTypeName; private boolean mergeEnabled; @@ -80,8 +79,7 @@ public class ManagedList extends ArrayList implements Mergeable, BeanMetad } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -95,8 +93,7 @@ public class ManagedList extends ArrayList implements Mergeable, BeanMetad /** * Return the default element type name (class name) to be used for this list. */ - @Nullable - public String getElementTypeName() { + public @Nullable String getElementTypeName() { return this.elementTypeName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java index b0eef75e3e..f5af789f8a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedMap.java @@ -20,9 +20,10 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.Mergeable; -import org.springframework.lang.Nullable; /** * Tag collection class used to hold managed Map values, which may @@ -37,14 +38,11 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ManagedMap extends LinkedHashMap implements Mergeable, BeanMetadataElement { - @Nullable - private Object source; + private @Nullable Object source; - @Nullable - private String keyTypeName; + private @Nullable String keyTypeName; - @Nullable - private String valueTypeName; + private @Nullable String valueTypeName; private boolean mergeEnabled; @@ -86,8 +84,7 @@ public class ManagedMap extends LinkedHashMap implements Mergeable, } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -101,8 +98,7 @@ public class ManagedMap extends LinkedHashMap implements Mergeable, /** * Return the default key type name (class name) to be used for this map. */ - @Nullable - public String getKeyTypeName() { + public @Nullable String getKeyTypeName() { return this.keyTypeName; } @@ -116,8 +112,7 @@ public class ManagedMap extends LinkedHashMap implements Mergeable, /** * Return the default value type name (class name) to be used for this map. */ - @Nullable - public String getValueTypeName() { + public @Nullable String getValueTypeName() { return this.valueTypeName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java index ef00476dad..951987f446 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedProperties.java @@ -18,9 +18,10 @@ package org.springframework.beans.factory.support; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.Mergeable; -import org.springframework.lang.Nullable; /** * Tag class which represents a Spring-managed {@link Properties} instance @@ -33,8 +34,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ManagedProperties extends Properties implements Mergeable, BeanMetadataElement { - @Nullable - private Object source; + private @Nullable Object source; private boolean mergeEnabled; @@ -48,8 +48,7 @@ public class ManagedProperties extends Properties implements Mergeable, BeanMeta } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java index 1381dde651..dc25faf93d 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ManagedSet.java @@ -20,9 +20,10 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; import org.springframework.beans.Mergeable; -import org.springframework.lang.Nullable; /** * Tag collection class used to hold managed Set values, which may @@ -38,11 +39,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ManagedSet extends LinkedHashSet implements Mergeable, BeanMetadataElement { - @Nullable - private Object source; + private @Nullable Object source; - @Nullable - private String elementTypeName; + private @Nullable String elementTypeName; private boolean mergeEnabled; @@ -79,8 +78,7 @@ public class ManagedSet extends LinkedHashSet implements Mergeable, BeanMe } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -94,8 +92,7 @@ public class ManagedSet extends LinkedHashSet implements Mergeable, BeanMe /** * Return the default element type name (class name) to be used for this set. */ - @Nullable - public String getElementTypeName() { + public @Nullable String getElementTypeName() { return this.elementTypeName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java index 49ca03408e..69d983e570 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/MethodOverride.java @@ -19,8 +19,9 @@ package org.springframework.beans.factory.support; import java.lang.reflect.Method; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanMetadataElement; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -42,8 +43,7 @@ public abstract class MethodOverride implements BeanMetadataElement { private boolean overloaded = true; - @Nullable - private Object source; + private @Nullable Object source; /** @@ -90,8 +90,7 @@ public abstract class MethodOverride implements BeanMetadataElement { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } 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 d9d9e6c121..5f1efdc2d0 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 @@ -20,7 +20,7 @@ import java.lang.reflect.Method; import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Set of method overrides, determining which, if any, methods on a @@ -90,8 +90,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) { + public @Nullable MethodOverride getOverride(Method method) { MethodOverride match = null; for (MethodOverride candidate : this.overrides) { if (candidate.matches(method)) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java index ab847865b5..51de5237ff 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/NullBean.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; /** * Internal representation of a null bean instance, for example, for a {@code null} value 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 37f9094639..40a65d4e70 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 @@ -25,6 +25,8 @@ import java.util.Map; import java.util.Properties; import java.util.ResourceBundle; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyAccessor; @@ -35,7 +37,6 @@ 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; @@ -145,8 +146,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader public static final String CONSTRUCTOR_ARG_PREFIX = "$"; - @Nullable - private String defaultParentBean; + private @Nullable String defaultParentBean; private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE; @@ -180,8 +180,7 @@ public class PropertiesBeanDefinitionReader extends AbstractBeanDefinitionReader /** * Return the default parent bean for this bean factory. */ - @Nullable - public String getDefaultParentBean() { + public @Nullable String getDefaultParentBean() { return this.defaultParentBean; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java index 3f3b25cc5a..5bddb9b388 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java @@ -23,6 +23,8 @@ import java.util.Set; import java.util.function.BiFunction; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.TypeConverter; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanDefinition; @@ -31,7 +33,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.core.ResolvableType; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -57,8 +58,7 @@ public final class RegisteredBean { private final Supplier mergedBeanDefinition; - @Nullable - private final RegisteredBean parent; + private final @Nullable RegisteredBean parent; private RegisteredBean(ConfigurableListableBeanFactory beanFactory, Supplier beanName, @@ -202,8 +202,7 @@ public final class RegisteredBean { * Return the parent of this instance or {@code null} if not an inner-bean. * @return the parent */ - @Nullable - public RegisteredBean getParent() { + public @Nullable RegisteredBean getParent() { return this.parent; } @@ -245,8 +244,7 @@ public final class RegisteredBean { * @return the resolved object, or {@code null} if none found * @since 6.0.9 */ - @Nullable - public Object resolveAutowiredArgument( + public @Nullable Object resolveAutowiredArgument( DependencyDescriptor descriptor, TypeConverter typeConverter, Set autowiredBeanNames) { return new ConstructorResolver((AbstractAutowireCapableBeanFactory) getBeanFactory()) @@ -287,13 +285,11 @@ public final class RegisteredBean { private final RegisteredBean parent; - @Nullable - private final String innerBeanName; + private final @Nullable String innerBeanName; private final BeanDefinition innerBeanDefinition; - @Nullable - private volatile String resolvedBeanName; + private volatile @Nullable String resolvedBeanName; InnerBeanResolver(RegisteredBean parent, @Nullable String innerBeanName, BeanDefinition innerBeanDefinition) { Assert.isInstanceOf(AbstractAutowireCapableBeanFactory.class, parent.getBeanFactory()); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java index 4fe5ad8462..ffc3de60c0 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/ReplaceOverride.java @@ -21,7 +21,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 5f91f6bdce..f0483f1c8e 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 @@ -26,12 +26,13 @@ import java.util.LinkedHashSet; import java.util.Set; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.MutablePropertyValues; 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; /** @@ -62,11 +63,9 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class RootBeanDefinition extends AbstractBeanDefinition { - @Nullable - private BeanDefinitionHolder decoratedDefinition; + private @Nullable BeanDefinitionHolder decoratedDefinition; - @Nullable - private AnnotatedElement qualifiedElement; + private @Nullable AnnotatedElement qualifiedElement; /** Determines if the definition needs to be re-merged. */ volatile boolean stale; @@ -75,46 +74,37 @@ public class RootBeanDefinition extends AbstractBeanDefinition { boolean isFactoryMethodUnique; - @Nullable - volatile ResolvableType targetType; + volatile @Nullable ResolvableType targetType; /** Package-visible field for caching the determined Class of a given bean definition. */ - @Nullable - volatile Class resolvedTargetType; + volatile @Nullable Class resolvedTargetType; /** Package-visible field for caching if the bean is a factory bean. */ - @Nullable - volatile Boolean isFactoryBean; + volatile @Nullable Boolean isFactoryBean; /** Package-visible field for caching the return type of a generically typed factory method. */ - @Nullable - volatile ResolvableType factoryMethodReturnType; + volatile @Nullable ResolvableType factoryMethodReturnType; /** Package-visible field for caching a unique factory method candidate for introspection. */ - @Nullable - volatile Method factoryMethodToIntrospect; + volatile @Nullable Method factoryMethodToIntrospect; /** Package-visible field for caching a resolved destroy method name (also for inferred). */ - @Nullable - volatile String resolvedDestroyMethodName; + volatile @Nullable String resolvedDestroyMethodName; /** Common lock for the four constructor fields below. */ final Object constructorArgumentLock = new Object(); /** Package-visible field for caching the resolved constructor or factory method. */ - @Nullable - Executable resolvedConstructorOrFactoryMethod; + @Nullable Executable resolvedConstructorOrFactoryMethod; /** Package-visible field that marks the constructor arguments as resolved. */ boolean constructorArgumentsResolved = false; /** Package-visible field for caching fully resolved constructor arguments. */ - @Nullable - Object[] resolvedConstructorArguments; + @Nullable Object @Nullable [] resolvedConstructorArguments; /** Package-visible field for caching partly prepared constructor arguments. */ - @Nullable - Object[] preparedConstructorArguments; + @Nullable Object @Nullable [] preparedConstructorArguments; /** Common lock for the two post-processing fields below. */ final Object postProcessingLock = new Object(); @@ -123,17 +113,13 @@ public class RootBeanDefinition extends AbstractBeanDefinition { boolean postProcessed = false; /** Package-visible field that indicates a before-instantiation post-processor having kicked in. */ - @Nullable - volatile Boolean beforeInstantiationResolved; + volatile @Nullable Boolean beforeInstantiationResolved; - @Nullable - private Set externallyManagedConfigMembers; + private @Nullable Set externallyManagedConfigMembers; - @Nullable - private Set externallyManagedInitMethods; + private @Nullable Set externallyManagedInitMethods; - @Nullable - private Set externallyManagedDestroyMethods; + private @Nullable Set externallyManagedDestroyMethods; /** @@ -277,8 +263,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { @Override - @Nullable - public String getParentName() { + public @Nullable String getParentName() { return null; } @@ -299,8 +284,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { /** * Return the target definition that is being decorated by this bean definition, if any. */ - @Nullable - public BeanDefinitionHolder getDecoratedDefinition() { + public @Nullable BeanDefinitionHolder getDecoratedDefinition() { return this.decoratedDefinition; } @@ -320,8 +304,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { * Otherwise, the factory method and target class will be checked. * @since 4.3.3 */ - @Nullable - public AnnotatedElement getQualifiedElement() { + public @Nullable AnnotatedElement getQualifiedElement() { return this.qualifiedElement; } @@ -346,8 +329,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { * (either specified in advance or resolved on first instantiation). * @since 3.2.2 */ - @Nullable - public Class getTargetType() { + public @Nullable Class getTargetType() { if (this.resolvedTargetType != null) { return this.resolvedTargetType; } @@ -393,8 +375,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition { * (in which case the regular no-arg default constructor will be called) * @since 5.1 */ - @Nullable - public Constructor[] getPreferredConstructors() { + public Constructor @Nullable [] getPreferredConstructors() { Object attribute = getAttribute(PREFERRED_CONSTRUCTORS_ATTRIBUTE); if (attribute == null) { return null; @@ -451,8 +432,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() { + public @Nullable Method getResolvedFactoryMethod() { Method factoryMethod = this.factoryMethodToIntrospect; if (factoryMethod == null && getInstanceSupplier() instanceof InstanceSupplier instanceSupplier) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java index 1c7e3cb808..6e2a25d81f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/SimpleAutowireCandidateResolver.java @@ -16,9 +16,10 @@ package org.springframework.beans.factory.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.DependencyDescriptor; -import org.springframework.lang.Nullable; /** * {@link AutowireCandidateResolver} implementation to use when no annotation @@ -53,26 +54,22 @@ public class SimpleAutowireCandidateResolver implements AutowireCandidateResolve } @Override - @Nullable - public String getSuggestedName(DependencyDescriptor descriptor) { + public @Nullable String getSuggestedName(DependencyDescriptor descriptor) { return null; } @Override - @Nullable - public Object getSuggestedValue(DependencyDescriptor descriptor) { + public @Nullable Object getSuggestedValue(DependencyDescriptor descriptor) { return null; } @Override - @Nullable - public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { + public @Nullable Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { return null; } @Override - @Nullable - public Class getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) { + public @Nullable Class getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) { return null; } 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 1b54829f90..a70a17d719 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 @@ -21,11 +21,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + 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,8 +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() { + public static @Nullable Method getCurrentlyInvokedFactoryMethod() { return currentlyInvokedFactoryMethod.get(); } @@ -145,8 +145,9 @@ public class SimpleInstantiationStrategy implements InstantiationStrategy { } @Override + @SuppressWarnings("NullAway") public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory owner, - @Nullable Object factoryBean, Method factoryMethod, Object... args) { + @Nullable Object factoryBean, Method factoryMethod, @Nullable Object... args) { return instantiateWithFactoryMethod(factoryMethod, () -> { try { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java index c9bfc61de5..1ae2dd2250 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/support/StaticListableBeanFactory.java @@ -26,6 +26,8 @@ import java.util.Map; import java.util.Set; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanFactoryUtils; @@ -39,7 +41,6 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.SmartFactoryBean; 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.ObjectUtils; import org.springframework.util.StringUtils; @@ -154,7 +155,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory { } @Override - public Object getBean(String name, Object... args) throws BeansException { + public Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException { if (!ObjectUtils.isEmpty(args)) { throw new UnsupportedOperationException( "StaticListableBeanFactory does not support explicit bean creation arguments"); @@ -177,7 +178,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory { } @Override - public T getBean(Class requiredType, Object... args) throws BeansException { + public T getBean(Class requiredType, @Nullable Object @Nullable ... args) throws BeansException { if (!ObjectUtils.isEmpty(args)) { throw new UnsupportedOperationException( "StaticListableBeanFactory does not support explicit bean creation arguments"); @@ -231,14 +232,12 @@ public class StaticListableBeanFactory implements ListableBeanFactory { } @Override - @Nullable - public Class getType(String name) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name) throws NoSuchBeanDefinitionException { return getType(name, true); } @Override - @Nullable - public Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { String beanName = BeanFactoryUtils.transformedBeanName(name); Object bean = this.beans.get(beanName); @@ -315,8 +314,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory { } } @Override - @Nullable - public T getIfAvailable() throws BeansException { + public @Nullable T getIfAvailable() throws BeansException { String[] beanNames = getBeanNamesForType(requiredType); if (beanNames.length == 1) { return (T) getBean(beanNames[0]); @@ -329,8 +327,7 @@ public class StaticListableBeanFactory implements ListableBeanFactory { } } @Override - @Nullable - public T getIfUnique() throws BeansException { + public @Nullable T getIfUnique() throws BeansException { String[] beanNames = getBeanNamesForType(requiredType); if (beanNames.length == 1) { return (T) getBean(beanNames[0]); @@ -452,16 +449,14 @@ public class StaticListableBeanFactory implements ListableBeanFactory { } @Override - @Nullable - public A findAnnotationOnBean(String beanName, Class annotationType) + public @Nullable A findAnnotationOnBean(String beanName, Class annotationType) throws NoSuchBeanDefinitionException { return findAnnotationOnBean(beanName, annotationType, true); } @Override - @Nullable - public A findAnnotationOnBean( + public @Nullable A findAnnotationOnBean( String beanName, Class annotationType, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { 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 0a5599d3f0..f8bfd78b84 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,9 +2,7 @@ * Classes supporting the {@code org.springframework.beans.factory} package. * Contains abstract base classes for {@code BeanFactory} implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 6584e16bb9..8d3b0261bc 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 @@ -18,6 +18,7 @@ package org.springframework.beans.factory.wiring; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.BeanCurrentlyInCreationException; @@ -26,7 +27,6 @@ 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; @@ -52,11 +52,9 @@ public class BeanConfigurerSupport implements BeanFactoryAware, InitializingBean /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private volatile BeanWiringInfoResolver beanWiringInfoResolver; + private volatile @Nullable BeanWiringInfoResolver beanWiringInfoResolver; - @Nullable - private volatile ConfigurableListableBeanFactory beanFactory; + private volatile @Nullable ConfigurableListableBeanFactory beanFactory; /** @@ -92,8 +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() { + protected @Nullable BeanWiringInfoResolver createDefaultBeanWiringInfoResolver() { return new ClassNameBeanWiringInfoResolver(); } 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 ac8e634ced..b7844ade02 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 @@ -16,8 +16,9 @@ package org.springframework.beans.factory.wiring; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.AutowireCapableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -49,8 +50,7 @@ public class BeanWiringInfo { public static final int AUTOWIRE_BY_TYPE = AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE; - @Nullable - private String beanName; + private @Nullable String beanName; private boolean isDefaultBeanName = false; @@ -120,8 +120,7 @@ public class BeanWiringInfo { /** * Return the specific bean name that this BeanWiringInfo points to, if any. */ - @Nullable - public String getBeanName() { + public @Nullable 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 f6dc9bfcef..74c3791b27 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,7 +16,7 @@ package org.springframework.beans.factory.wiring; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface to be implemented by objects than can resolve bean name @@ -41,7 +41,6 @@ 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); + @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 c069d7d1af..c251111e92 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,9 +2,7 @@ * Mechanism to determine bean wiring metadata from a bean instance. * Foundation for aspect-driven bean configuration. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.wiring; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java index 018c85123f..8fb760bcd9 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/AbstractBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.BeanDefinitionStoreException; @@ -25,7 +26,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.AbstractBeanDefinition; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -58,8 +58,7 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars @Override - @Nullable - public final BeanDefinition parse(Element element, ParserContext parserContext) { + public final @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { AbstractBeanDefinition definition = parseInternal(element, parserContext); if (definition != null && !parserContext.isNested()) { try { @@ -150,8 +149,7 @@ public abstract class AbstractBeanDefinitionParser implements BeanDefinitionPars * @see #parse(org.w3c.dom.Element, ParserContext) * @see #postProcessComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) */ - @Nullable - protected abstract AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext); + protected abstract @Nullable AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext); /** * Should an ID be generated instead of read from the passed in {@link Element}? 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 75b70796e1..2bcba9af8e 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 @@ -16,12 +16,12 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; 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 @@ -98,8 +98,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) { + protected @Nullable String getParentName(Element element) { return null; } @@ -115,8 +114,7 @@ public abstract class AbstractSingleBeanDefinitionParser extends AbstractBeanDef * the supplied {@code Element}, or {@code null} if none * @see #getBeanClassName */ - @Nullable - protected Class getBeanClass(Element element) { + protected @Nullable Class getBeanClass(Element element) { return null; } @@ -127,8 +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) { + protected @Nullable 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 a92f282667..53da31cdc2 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 @@ -16,10 +16,10 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; 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, @@ -52,7 +52,6 @@ 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); + @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 84bf8629d5..d97c69d762 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 @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.w3c.dom.NamedNodeMap; import org.w3c.dom.Node; @@ -58,7 +59,6 @@ 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; @@ -262,8 +262,7 @@ public class BeanDefinitionParserDelegate { * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} * to pull the source metadata from the supplied {@link Element}. */ - @Nullable - protected Object extractSource(Element ele) { + protected @Nullable Object extractSource(Element ele) { return this.readerContext.extractSource(ele); } @@ -388,8 +387,7 @@ public class BeanDefinitionParserDelegate { * Return any patterns provided in the 'default-autowire-candidates' * attribute of the top-level {@code } element. */ - @Nullable - public String[] getAutowireCandidatePatterns() { + public String @Nullable [] getAutowireCandidatePatterns() { String candidatePattern = this.defaults.getAutowireCandidates(); return (candidatePattern != null ? StringUtils.commaDelimitedListToStringArray(candidatePattern) : null); } @@ -400,8 +398,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) { + public @Nullable BeanDefinitionHolder parseBeanDefinitionElement(Element ele) { return parseBeanDefinitionElement(ele, null); } @@ -410,9 +407,8 @@ public class BeanDefinitionParserDelegate { * if there were errors during parse. Errors are reported to the * {@link org.springframework.beans.factory.parsing.ProblemReporter}. */ - @Nullable @SuppressWarnings("NullAway") - public BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable BeanDefinition containingBean) { + public @Nullable BeanDefinitionHolder parseBeanDefinitionElement(Element ele, @Nullable BeanDefinition containingBean) { String id = ele.getAttribute(ID_ATTRIBUTE); String nameAttr = ele.getAttribute(NAME_ATTRIBUTE); @@ -497,8 +493,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( + public @Nullable AbstractBeanDefinition parseBeanDefinitionElement( Element ele, String beanName, @Nullable BeanDefinition containingBean) { this.parseState.push(new BeanEntry(beanName)); @@ -906,8 +901,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, @Nullable String propertyName) { + public @Nullable Object parsePropertyValue(Element ele, BeanDefinition bd, @Nullable String propertyName) { String elementName = (propertyName != null ? " element for property '" + propertyName + "'" : " element"); @@ -967,8 +961,7 @@ public class BeanDefinitionParserDelegate { * @param ele subelement of property element; we don't know which yet * @param bd the current bean definition (if any) */ - @Nullable - public Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd) { + public @Nullable Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd) { return parsePropertySubElement(ele, bd, null); } @@ -980,8 +973,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, @Nullable BeanDefinition bd, @Nullable String defaultValueType) { + public @Nullable Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd, @Nullable String defaultValueType) { if (!isDefaultNamespace(ele)) { return parseNestedCustomElement(ele, bd); } @@ -1050,8 +1042,7 @@ public class BeanDefinitionParserDelegate { /** * Return a typed String value Object for the given 'idref' element. */ - @Nullable - public Object parseIdRefElement(Element ele) { + public @Nullable Object parseIdRefElement(Element ele) { // A generic reference to any name of any bean. String refName = ele.getAttribute(BEAN_REF_ATTRIBUTE); if (!StringUtils.hasLength(refName)) { @@ -1304,8 +1295,7 @@ public class BeanDefinitionParserDelegate { /** * Parse a key sub-element of a map element. */ - @Nullable - protected Object parseKeyElement(Element keyEle, @Nullable BeanDefinition bd, String defaultKeyTypeName) { + protected @Nullable Object parseKeyElement(Element keyEle, @Nullable BeanDefinition bd, String defaultKeyTypeName) { NodeList nl = keyEle.getChildNodes(); Element subElement = null; for (int i = 0; i < nl.getLength(); i++) { @@ -1366,8 +1356,7 @@ public class BeanDefinitionParserDelegate { * @param ele the element to parse * @return the resulting bean definition */ - @Nullable - public BeanDefinition parseCustomElement(Element ele) { + public @Nullable BeanDefinition parseCustomElement(Element ele) { return parseCustomElement(ele, null); } @@ -1377,8 +1366,7 @@ public class BeanDefinitionParserDelegate { * @param containingBd the containing bean definition (if any) * @return the resulting bean definition */ - @Nullable - public BeanDefinition parseCustomElement(Element ele, @Nullable BeanDefinition containingBd) { + public @Nullable BeanDefinition parseCustomElement(Element ele, @Nullable BeanDefinition containingBd) { String namespaceUri = getNamespaceURI(ele); if (namespaceUri == null) { return null; @@ -1465,8 +1453,7 @@ public class BeanDefinitionParserDelegate { return originalDef; } - @Nullable - private BeanDefinitionHolder parseNestedCustomElement(Element ele, @Nullable BeanDefinition containingBd) { + private @Nullable BeanDefinitionHolder parseNestedCustomElement(Element ele, @Nullable BeanDefinition containingBd) { BeanDefinition innerDefinition = parseCustomElement(ele, containingBd); if (innerDefinition == null) { error("Incorrect usage of element '" + ele.getNodeName() + "' in a nested manner. " + @@ -1490,8 +1477,7 @@ public class BeanDefinitionParserDelegate { * different namespace identification mechanism. * @param node the node */ - @Nullable - public String getNamespaceURI(Node node) { + public @Nullable String getNamespaceURI(Node node) { return node.getNamespaceURI(); } 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 16496d31b9..053b165fed 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 @@ -21,12 +21,12 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * {@link EntityResolver} implementation for the Spring beans DTD, @@ -52,8 +52,7 @@ public class BeansDtdResolver implements EntityResolver { @Override - @Nullable - public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException { + public @Nullable InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public ID [" + publicId + "] and system ID [" + systemId + "]"); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java index b75e54893a..4c2a6e6c2b 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultBeanDefinitionDocumentReader.java @@ -23,6 +23,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -34,7 +35,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -77,11 +77,9 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private XmlReaderContext readerContext; + private @Nullable XmlReaderContext readerContext; - @Nullable - private BeanDefinitionParserDelegate delegate; + private @Nullable BeanDefinitionParserDelegate delegate; /** @@ -108,8 +106,7 @@ public class DefaultBeanDefinitionDocumentReader implements BeanDefinitionDocume * Invoke the {@link org.springframework.beans.factory.parsing.SourceExtractor} * to pull the source metadata from the supplied {@link Element}. */ - @Nullable - protected Object extractSource(Element ele) { + protected @Nullable Object extractSource(Element ele) { return getReaderContext().extractSource(ele); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java index 77ec6469f1..2a359b7401 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DefaultDocumentLoader.java @@ -22,12 +22,12 @@ import javax.xml.parsers.ParserConfigurationException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; -import org.springframework.lang.Nullable; import org.springframework.util.xml.XmlValidationModeDetector; /** 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 68a96ee9d2..cfa04a15e6 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 @@ -23,11 +23,11 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -59,15 +59,13 @@ public class DefaultNamespaceHandlerResolver implements NamespaceHandlerResolver protected final Log logger = LogFactory.getLog(getClass()); /** ClassLoader to use for NamespaceHandler classes. */ - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; /** Resource location to search for. */ private final String handlerMappingsLocation; /** Stores the mappings from namespace URI to NamespaceHandler class name / instance. */ - @Nullable - private volatile Map handlerMappings; + private volatile @Nullable Map handlerMappings; /** @@ -113,8 +111,7 @@ public class DefaultNamespaceHandlerResolver implements NamespaceHandlerResolver * @return the located {@link NamespaceHandler}, or {@code null} if none found */ @Override - @Nullable - public NamespaceHandler resolve(String namespaceUri) { + public @Nullable NamespaceHandler resolve(String namespaceUri) { Map handlerMappings = getHandlerMappings(); Object handlerOrClassName = handlerMappings.get(namespaceUri); if (handlerOrClassName == null) { 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 fe8f6f61a3..1edf6ea018 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 @@ -18,11 +18,11 @@ package org.springframework.beans.factory.xml; import java.io.IOException; +import org.jspecify.annotations.Nullable; 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; /** @@ -78,8 +78,7 @@ public class DelegatingEntityResolver implements EntityResolver { @Override - @Nullable - public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) + public @Nullable InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws SAXException, IOException { if (systemId != null) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java index d5a2122a61..afb1968e0f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/DocumentDefaultsDefinition.java @@ -16,8 +16,9 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.parsing.DefaultsDefinition; -import org.springframework.lang.Nullable; /** * Simple JavaBean that holds the defaults specified at the {@code } @@ -29,26 +30,19 @@ import org.springframework.lang.Nullable; */ public class DocumentDefaultsDefinition implements DefaultsDefinition { - @Nullable - private String lazyInit; + private @Nullable String lazyInit; - @Nullable - private String merge; + private @Nullable String merge; - @Nullable - private String autowire; + private @Nullable String autowire; - @Nullable - private String autowireCandidates; + private @Nullable String autowireCandidates; - @Nullable - private String initMethod; + private @Nullable String initMethod; - @Nullable - private String destroyMethod; + private @Nullable String destroyMethod; - @Nullable - private Object source; + private @Nullable Object source; /** @@ -61,8 +55,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { /** * Return the default lazy-init flag for the document that's currently parsed. */ - @Nullable - public String getLazyInit() { + public @Nullable String getLazyInit() { return this.lazyInit; } @@ -76,8 +69,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { /** * Return the default merge setting for the document that's currently parsed. */ - @Nullable - public String getMerge() { + public @Nullable String getMerge() { return this.merge; } @@ -91,8 +83,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { /** * Return the default autowire setting for the document that's currently parsed. */ - @Nullable - public String getAutowire() { + public @Nullable String getAutowire() { return this.autowire; } @@ -108,8 +99,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { * Return the default autowire-candidate pattern for the document that's currently parsed. * May also return a comma-separated list of patterns. */ - @Nullable - public String getAutowireCandidates() { + public @Nullable String getAutowireCandidates() { return this.autowireCandidates; } @@ -123,8 +113,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { /** * Return the default init-method setting for the document that's currently parsed. */ - @Nullable - public String getInitMethod() { + public @Nullable String getInitMethod() { return this.initMethod; } @@ -138,8 +127,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { /** * Return the default destroy-method setting for the document that's currently parsed. */ - @Nullable - public String getDestroyMethod() { + public @Nullable String getDestroyMethod() { return this.destroyMethod; } @@ -152,8 +140,7 @@ public class DocumentDefaultsDefinition implements DefaultsDefinition { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } 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 fa061fe0c1..2dee6de1a6 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 @@ -16,12 +16,12 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; 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} @@ -69,8 +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); + @Nullable BeanDefinition parse(Element element, ParserContext parserContext); /** * Parse the specified {@link Node} and decorate the supplied @@ -91,7 +90,6 @@ public interface NamespaceHandler { * A {@code null} value is strictly speaking invalid, but will be leniently * treated like the case where the original bean definition gets returned. */ - @Nullable - BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, ParserContext parserContext); + @Nullable BeanDefinitionHolder decorate(Node source, BeanDefinitionHolder definition, 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 2e92b258ca..6707478efe 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,7 +16,7 @@ package org.springframework.beans.factory.xml; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Used by the {@link org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader} to @@ -36,7 +36,6 @@ public interface NamespaceHandlerResolver { * @param namespaceUri the relevant namespace URI * @return the located {@link NamespaceHandler} (may be {@code null}) */ - @Nullable - NamespaceHandler resolve(String namespaceUri); + @Nullable NamespaceHandler resolve(String namespaceUri); } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java index b1eec9bbc9..3715f11815 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/NamespaceHandlerSupport.java @@ -19,13 +19,13 @@ package org.springframework.beans.factory.xml; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; -import org.springframework.lang.Nullable; /** * Support class for implementing custom {@link NamespaceHandler NamespaceHandlers}. @@ -68,8 +68,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler { * registered for that {@link Element}. */ @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinitionParser parser = findParserForElement(element, parserContext); return (parser != null ? parser.parse(element, parserContext) : null); } @@ -78,8 +77,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler { * Locates the {@link BeanDefinitionParser} from the register implementations using * the local name of the supplied {@link Element}. */ - @Nullable - private BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) { + private @Nullable BeanDefinitionParser findParserForElement(Element element, ParserContext parserContext) { String localName = parserContext.getDelegate().getLocalName(element); BeanDefinitionParser parser = this.parsers.get(localName); if (parser == null) { @@ -94,8 +92,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler { * is registered to handle that {@link Node}. */ @Override - @Nullable - public BeanDefinitionHolder decorate( + public @Nullable BeanDefinitionHolder decorate( Node node, BeanDefinitionHolder definition, ParserContext parserContext) { BeanDefinitionDecorator decorator = findDecoratorForNode(node, parserContext); @@ -107,8 +104,7 @@ public abstract class NamespaceHandlerSupport implements NamespaceHandler { * the local name of the supplied {@link Node}. Supports both {@link Element Elements} * and {@link Attr Attrs}. */ - @Nullable - private BeanDefinitionDecorator findDecoratorForNode(Node node, ParserContext parserContext) { + private @Nullable BeanDefinitionDecorator findDecoratorForNode(Node node, ParserContext parserContext) { BeanDefinitionDecorator decorator = null; String localName = parserContext.getDelegate().getLocalName(node); if (node instanceof Element) { diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java index 4bd6ef58e9..db4bad7251 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java @@ -19,13 +19,14 @@ package org.springframework.beans.factory.xml; import java.util.ArrayDeque; import java.util.Deque; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.parsing.ComponentDefinition; import org.springframework.beans.factory.parsing.CompositeComponentDefinition; import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.lang.Nullable; /** * Context that gets passed along a bean definition parsing process, @@ -44,8 +45,7 @@ public final class ParserContext { private final BeanDefinitionParserDelegate delegate; - @Nullable - private BeanDefinition containingBeanDefinition; + private @Nullable BeanDefinition containingBeanDefinition; private final Deque containingComponents = new ArrayDeque<>(); @@ -76,8 +76,7 @@ public final class ParserContext { return this.delegate; } - @Nullable - public BeanDefinition getContainingBeanDefinition() { + public @Nullable BeanDefinition getContainingBeanDefinition() { return this.containingBeanDefinition; } @@ -89,13 +88,11 @@ public final class ParserContext { return BeanDefinitionParserDelegate.TRUE_VALUE.equals(this.delegate.getDefaults().getLazyInit()); } - @Nullable - public Object extractSource(Object sourceCandidate) { + public @Nullable Object extractSource(Object sourceCandidate) { return this.readerContext.extractSource(sourceCandidate); } - @Nullable - public CompositeComponentDefinition getContainingComponent() { + public @Nullable CompositeComponentDefinition getContainingComponent() { return this.containingComponents.peek(); } 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 659b21b40b..bbf56e67b1 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 @@ -24,13 +24,13 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.xml.sax.EntityResolver; 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; @@ -66,14 +66,12 @@ public class PluggableSchemaResolver implements EntityResolver { private static final Log logger = LogFactory.getLog(PluggableSchemaResolver.class); - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final String schemaMappingsLocation; /** Stores the mapping of schema URL → local schema path. */ - @Nullable - private volatile Map schemaMappings; + private volatile @Nullable Map schemaMappings; /** @@ -105,8 +103,7 @@ public class PluggableSchemaResolver implements EntityResolver { @Override - @Nullable - public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException { + public @Nullable InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws IOException { if (logger.isTraceEnabled()) { logger.trace("Trying to resolve XML entity with public id [" + publicId + "] and system id [" + systemId + "]"); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java index 1b348693c9..512f09af5e 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ResourceEntityResolver.java @@ -23,12 +23,12 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.util.ResourceUtils; /** @@ -72,8 +72,7 @@ public class ResourceEntityResolver extends DelegatingEntityResolver { @Override - @Nullable - public InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) + public @Nullable InputSource resolveEntity(@Nullable String publicId, @Nullable String systemId) throws SAXException, IOException { InputSource source = super.resolveEntity(publicId, systemId); @@ -135,8 +134,7 @@ public class ResourceEntityResolver extends DelegatingEntityResolver { * that the parser open a regular URI connection to the system identifier * @since 6.0.4 */ - @Nullable - protected InputSource resolveSchemaEntity(@Nullable String publicId, String systemId) { + protected @Nullable InputSource resolveSchemaEntity(@Nullable String publicId, String systemId) { InputSource source; // External dtd/xsd lookup via https even for canonical http declaration String url = systemId; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java index 7cf160d848..ab956dd83f 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimpleConstructorNamespaceHandler.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory.xml; import java.util.Collection; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.ConstructorArgumentValues.ValueHolder; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.core.Conventions; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -69,8 +69,7 @@ public class SimpleConstructorNamespaceHandler implements NamespaceHandler { } @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { parserContext.getReaderContext().error( "Class [" + getClass().getName() + "] does not support custom elements.", element); return null; diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandler.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandler.java index ec3c1512d8..9ea98fb500 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandler.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/SimplePropertyNamespaceHandler.java @@ -16,6 +16,7 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Attr; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -25,7 +26,6 @@ import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.core.Conventions; -import org.springframework.lang.Nullable; /** * Simple {@code NamespaceHandler} implementation that maps custom attributes @@ -58,8 +58,7 @@ public class SimplePropertyNamespaceHandler implements NamespaceHandler { } @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { parserContext.getReaderContext().error( "Class [" + getClass().getName() + "] does not support custom elements.", element); return null; 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 12232bddf7..e231df3479 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 @@ -24,6 +24,7 @@ import java.util.Set; import javax.xml.parsers.ParserConfigurationException; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.xml.sax.ErrorHandler; @@ -46,7 +47,6 @@ 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; @@ -124,13 +124,11 @@ public class XmlBeanDefinitionReader extends AbstractBeanDefinitionReader { private SourceExtractor sourceExtractor = new NullSourceExtractor(); - @Nullable - private NamespaceHandlerResolver namespaceHandlerResolver; + private @Nullable NamespaceHandlerResolver namespaceHandlerResolver; private DocumentLoader documentLoader = new DefaultDocumentLoader(); - @Nullable - private EntityResolver entityResolver; + private @Nullable EntityResolver entityResolver; private ErrorHandler errorHandler = new SimpleSaxErrorHandler(logger); diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java index a0ca6d0c20..772a96c6e5 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/XmlReaderContext.java @@ -18,6 +18,7 @@ package org.springframework.beans.factory.xml; import java.io.StringReader; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.xml.sax.InputSource; @@ -31,7 +32,6 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.core.env.Environment; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; /** * Extension of {@link org.springframework.beans.factory.parsing.ReaderContext}, @@ -91,8 +91,7 @@ public class XmlReaderContext extends ReaderContext { * @see XmlBeanDefinitionReader#setResourceLoader * @see ResourceLoader#getClassLoader() */ - @Nullable - public final ResourceLoader getResourceLoader() { + public final @Nullable ResourceLoader getResourceLoader() { return this.reader.getResourceLoader(); } @@ -102,8 +101,7 @@ public class XmlReaderContext extends ReaderContext { * as an indication to lazily resolve bean classes. * @see XmlBeanDefinitionReader#setBeanClassLoader */ - @Nullable - public final ClassLoader getBeanClassLoader() { + public final @Nullable ClassLoader getBeanClassLoader() { return this.reader.getBeanClassLoader(); } 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 3dcc0d43ad..8c4648abb0 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,9 +2,7 @@ * Contains an abstract XML-based {@code BeanFactory} implementation, * including a standard "spring-beans" XSD. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.factory.xml; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 1bea8aea45..2cd047cb65 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,9 +9,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java index 14e4c4b809..d2da2bd972 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/ByteArrayPropertyEditor.java @@ -18,7 +18,7 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Editor for byte arrays. Strings will simply be converted to diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java index 705d58fadf..15de6ae489 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharArrayPropertyEditor.java @@ -18,7 +18,7 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Editor for char arrays. Strings will simply be converted to diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java index 727be75c86..1458345191 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CharacterEditor.java @@ -18,7 +18,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** 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 0a2882a988..c8da0425ac 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 @@ -19,7 +19,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -38,8 +39,7 @@ import org.springframework.util.StringUtils; */ public class ClassArrayEditor extends PropertyEditorSupport { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; /** 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 a68d4988e4..5176ea58e0 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,7 +18,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -38,8 +39,7 @@ import org.springframework.util.StringUtils; */ public class ClassEditor extends PropertyEditorSupport { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java index 5d71fca9da..ddc9703cfc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomBooleanEditor.java @@ -18,7 +18,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -79,11 +80,9 @@ public class CustomBooleanEditor extends PropertyEditorSupport { public static final String VALUE_0 = "0"; - @Nullable - private final String trueString; + private final @Nullable String trueString; - @Nullable - private final String falseString; + private final @Nullable String falseString; private final boolean allowEmpty; 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 898adb52ec..ce97ddd021 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,7 +25,8 @@ import java.util.List; import java.util.SortedSet; import java.util.TreeSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -206,8 +207,7 @@ public class CustomCollectionEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override - @Nullable - public String getAsText() { + public @Nullable String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java index fcc3f8290a..34d9d475fc 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomDateEditor.java @@ -21,7 +21,8 @@ import java.text.DateFormat; import java.text.ParseException; import java.util.Date; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** 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 d421a8e25c..b8dddef9a3 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,7 +22,8 @@ import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -196,8 +197,7 @@ public class CustomMapEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override - @Nullable - public String getAsText() { + public @Nullable String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java index e1c8ba3837..fb36494eed 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/CustomNumberEditor.java @@ -19,7 +19,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; import java.text.NumberFormat; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.NumberUtils; import org.springframework.util.StringUtils; @@ -47,8 +48,7 @@ public class CustomNumberEditor extends PropertyEditorSupport { private final Class numberClass; - @Nullable - private final NumberFormat numberFormat; + private final @Nullable NumberFormat numberFormat; private final boolean allowEmpty; 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 303067c5e2..bdf47645ff 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 @@ -19,9 +19,10 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -81,8 +82,7 @@ public class InputStreamEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override - @Nullable - public String getAsText() { + public @Nullable String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java index 03f14d117e..da64aa724a 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PatternEditor.java @@ -19,7 +19,7 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Editor for {@code java.util.regex.Pattern}, to directly populate a Pattern property. diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java index cccb6c6bfa..128b91c739 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/PropertiesEditor.java @@ -23,7 +23,7 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.Properties; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Custom {@link java.beans.PropertyEditor} for {@link Properties} objects. 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 46171fb4b7..676b129ce6 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 @@ -19,10 +19,11 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; import java.io.IOException; +import org.jspecify.annotations.Nullable; + 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; /** @@ -81,8 +82,7 @@ public class ReaderEditor extends PropertyEditorSupport { * there is no appropriate text representation. */ @Override - @Nullable - public String getAsText() { + public @Nullable String getAsText() { return null; } diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java index 7149e931df..742d6e48e3 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringArrayPropertyEditor.java @@ -18,7 +18,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -44,8 +45,7 @@ public class StringArrayPropertyEditor extends PropertyEditorSupport { private final String separator; - @Nullable - private final String charsToDelete; + private final @Nullable String charsToDelete; private final boolean emptyArrayAsNull; diff --git a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java index d97037c563..a87b898d34 100644 --- a/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java +++ b/spring-beans/src/main/java/org/springframework/beans/propertyeditors/StringTrimmerEditor.java @@ -18,7 +18,8 @@ package org.springframework.beans.propertyeditors; import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -32,8 +33,7 @@ import org.springframework.util.StringUtils; */ public class StringTrimmerEditor extends PropertyEditorSupport { - @Nullable - private final String charsToDelete; + private final @Nullable String charsToDelete; private final boolean emptyAsNull; 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 e94e65f5a9..7a7afd2246 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 @@ -21,8 +21,9 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; +import org.jspecify.annotations.Nullable; + 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; @@ -50,8 +51,7 @@ import org.springframework.util.StringUtils; */ public class URIEditor extends PropertyEditorSupport { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final boolean 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 ddb64ffdc1..e1dfba14bc 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,9 +6,7 @@ * "CustomXxxEditor" classes are intended for manual registration in * specific binding processes, as they are localized or the like. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.propertyeditors; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 20dec0c355..bea627e669 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 @@ -19,11 +19,12 @@ package org.springframework.beans.support; import java.beans.PropertyEditor; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + 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.Assert; import org.springframework.util.MethodInvoker; import org.springframework.util.ReflectionUtils; @@ -41,8 +42,7 @@ import org.springframework.util.ReflectionUtils; */ public class ArgumentConvertingMethodInvoker extends MethodInvoker { - @Nullable - private TypeConverter typeConverter; + private @Nullable TypeConverter typeConverter; private boolean useDefaultConverter = true; @@ -67,8 +67,7 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker { * (provided that the present TypeConverter actually implements the * PropertyEditorRegistry interface). */ - @Nullable - public TypeConverter getTypeConverter() { + public @Nullable TypeConverter getTypeConverter() { if (this.typeConverter == null && this.useDefaultConverter) { this.typeConverter = getDefaultTypeConverter(); } @@ -111,8 +110,7 @@ public class ArgumentConvertingMethodInvoker extends MethodInvoker { * @see #doFindMatchingMethod */ @Override - @Nullable - protected Method findMatchingMethod() { + protected @Nullable Method findMatchingMethod() { Method matchingMethod = super.findMatchingMethod(); // Second pass: look for method where arguments can be converted to parameter types. if (matchingMethod == null) { @@ -132,8 +130,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) { + protected @Nullable Method doFindMatchingMethod(Object[] arguments) { TypeConverter converter = getTypeConverter(); if (converter != null) { String targetMethod = getTargetMethod(); diff --git a/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java b/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java index 495072fa36..e6f2835613 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/MutableSortDefinition.java @@ -18,7 +18,8 @@ package org.springframework.beans.support; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** diff --git a/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java b/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java index 063834e1a8..161620a403 100644 --- a/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java +++ b/spring-beans/src/main/java/org/springframework/beans/support/PagedListHolder.java @@ -22,7 +22,8 @@ import java.util.Collections; import java.util.Date; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -66,14 +67,11 @@ public class PagedListHolder implements Serializable { private List source = Collections.emptyList(); - @Nullable - private Date refreshDate; + private @Nullable Date refreshDate; - @Nullable - private SortDefinition sort; + private @Nullable SortDefinition sort; - @Nullable - private SortDefinition sortUsed; + private @Nullable SortDefinition sortUsed; private int pageSize = DEFAULT_PAGE_SIZE; @@ -134,8 +132,7 @@ public class PagedListHolder implements Serializable { /** * Return the last time the list has been fetched from the source provider. */ - @Nullable - public Date getRefreshDate() { + public @Nullable Date getRefreshDate() { return this.refreshDate; } @@ -151,8 +148,7 @@ public class PagedListHolder implements Serializable { /** * Return the sort definition for this holder. */ - @Nullable - public SortDefinition getSort() { + public @Nullable SortDefinition getSort() { return this.sort; } 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 9a9a7d8f30..ad0c58bbcd 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 @@ -23,10 +23,10 @@ import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -108,8 +108,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) { + private @Nullable 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 // first place, let the exception through. 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 326ce25e14..73ea6d22c9 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,9 +2,7 @@ * Classes supporting the org.springframework.beans package, * such as utility classes for sorting and holding lists of beans. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java b/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java index 81c4fab040..f12fd01e99 100644 --- a/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/AbstractPropertyAccessorTests.java @@ -34,6 +34,7 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowire; @@ -49,7 +50,6 @@ import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.GenericConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java b/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java index b700314ba1..cd4bcf9e8e 100644 --- a/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/BeanUtilsTests.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.Locale; import java.util.UUID; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -46,7 +47,6 @@ import org.springframework.cglib.proxy.Enhancer; import org.springframework.cglib.proxy.MethodInterceptor; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceEditor; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -868,13 +868,11 @@ class BeanUtilsTests { this.value = value; } - @Nullable - public Integer getCounter() { + public @Nullable Integer getCounter() { return counter; } - @Nullable - public Boolean isFlag() { + public @Nullable Boolean isFlag() { return flag; } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java index 0621279dc8..6ec9c4d488 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java @@ -39,6 +39,7 @@ import java.util.stream.IntStream; import java.util.stream.Stream; import jakarta.annotation.Priority; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.BeansException; @@ -87,7 +88,6 @@ import org.springframework.core.convert.support.GenericConversionService; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java index 9164284199..9d5b31c8c6 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessorTests.java @@ -40,6 +40,7 @@ import java.util.concurrent.Callable; import java.util.function.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; @@ -73,7 +74,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.Order; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -4294,8 +4294,7 @@ class AutowiredAnnotationBeanPostProcessorTests { static class MixedNullableInjectionBean { - @Nullable - public Integer nullableBean; + public @Nullable Integer nullableBean; public String nonNullBean; @@ -4309,8 +4308,7 @@ class AutowiredAnnotationBeanPostProcessorTests { static class MixedOptionalInjectionBean { - @Nullable - public Integer nullableBean; + public @Nullable Integer nullableBean; public String nonNullBean; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactoryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactoryTests.java index 7f38730c03..154b417078 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactoryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorFactoryTests.java @@ -16,6 +16,7 @@ package org.springframework.beans.factory.aot; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -24,7 +25,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.Ordered; import org.springframework.core.test.io.support.MockSpringFactoriesLoader; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -205,8 +205,7 @@ class BeanDefinitionMethodGeneratorFactoryTests { private final int order; - @Nullable - private RegisteredBean registeredBean; + private @Nullable RegisteredBean registeredBean; MockBeanRegistrationExcludeFilter(boolean excluded, int order) { this.excluded = excluded; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java index 0613281ed8..0a2f316b5a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java @@ -29,6 +29,7 @@ import java.util.function.Supplier; import javax.lang.model.element.Modifier; import org.assertj.core.api.InstanceOfAssertFactories; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; @@ -58,7 +59,6 @@ import org.springframework.core.test.tools.TestCompiler; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; @@ -706,15 +706,13 @@ class BeanDefinitionPropertiesCodeGeneratorTests { this.name = name; } - @Nullable @Override - public String getObject() { + public @Nullable String getObject() { return getPrefix() + " " + getName(); } - @Nullable @Override - public Class getObjectType() { + public @Nullable Class getObjectType() { return String.class; } diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java index 7379fc2226..85ef58b325 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragmentsTests.java @@ -21,6 +21,7 @@ import java.lang.reflect.Executable; import java.lang.reflect.Method; import java.util.function.UnaryOperator; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GenerationContext; @@ -44,7 +45,6 @@ import org.springframework.beans.testfixture.beans.factory.aot.SimpleBeanFactory import org.springframework.core.ResolvableType; import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategyTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategyTests.java index 4c70927242..d5b6ad2dff 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategyTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/CglibSubclassingInstantiationStrategyTests.java @@ -22,10 +22,9 @@ import java.util.regex.Pattern; import java.util.stream.Stream; import org.assertj.core.api.ThrowableAssert.ThrowingCallable; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; - import static org.assertj.core.api.Assertions.assertThatIllegalStateException; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @@ -147,8 +146,7 @@ class CglibSubclassingInstantiationStrategyTests { static class MyReplacer implements MethodReplacer { - @Nullable - Object returnValue; + @Nullable Object returnValue; void reset() { this.returnValue = null; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java index 144bc37564..6c8b10ca7c 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/ConstructorResolverAotTests.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.FactoryBean; @@ -32,7 +33,6 @@ import org.springframework.beans.testfixture.beans.factory.generator.factory.Num import org.springframework.beans.testfixture.beans.factory.generator.factory.SampleFactory; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/xml/ResourceEntityResolverTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/xml/ResourceEntityResolverTests.java index 5229dc46f4..3ca9366496 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/xml/ResourceEntityResolverTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/xml/ResourceEntityResolverTests.java @@ -16,13 +16,13 @@ package org.springframework.beans.factory.xml; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.xml.sax.InputSource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -94,8 +94,7 @@ class ResourceEntityResolverTests { private final boolean shouldThrow; - @Nullable - private final InputSource returnValue; + private final @Nullable InputSource returnValue; boolean fallbackInvoked = false; @@ -112,8 +111,7 @@ class ResourceEntityResolverTests { } @Override - @Nullable - protected InputSource resolveSchemaEntity(String publicId, String systemId) { + protected @Nullable InputSource resolveSchemaEntity(String publicId, String systemId) { this.fallbackInvoked = true; if (this.shouldThrow) { throw new ResolutionRejectedException(); diff --git a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java index 110ea99797..538bc6db47 100644 --- a/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java @@ -19,10 +19,10 @@ package org.springframework.beans.support; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.testfixture.beans.TestBean; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java index 971ac2bdb3..eced628a45 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java @@ -16,7 +16,7 @@ package org.springframework.beans.testfixture.beans; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple nested test bean used for testing bean factories, AOP framework etc. diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/Pet.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/Pet.java index 343c5db3fd..4168a6751c 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/Pet.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/Pet.java @@ -18,7 +18,7 @@ package org.springframework.beans.testfixture.beans; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Rob Harrop diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java index 3ff88b1836..e27ed937ae 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java @@ -18,7 +18,8 @@ package org.springframework.beans.testfixture.beans; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java index 580e117c31..e50b9246aa 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java @@ -27,10 +27,11 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.ObjectUtils; /** diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/DeferredTypeBuilder.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/DeferredTypeBuilder.java index 3d4288278c..e94ceaeaea 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/DeferredTypeBuilder.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/DeferredTypeBuilder.java @@ -18,8 +18,9 @@ package org.springframework.beans.testfixture.beans.factory.aot; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -31,8 +32,7 @@ import org.springframework.util.Assert; */ public class DeferredTypeBuilder implements Consumer { - @Nullable - private Consumer type; + private @Nullable Consumer type; @Override public void accept(TypeSpec.Builder type) { diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/GenericFactoryBean.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/GenericFactoryBean.java index 571b2d1509..693c9173b0 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/GenericFactoryBean.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/GenericFactoryBean.java @@ -16,9 +16,10 @@ package org.springframework.beans.testfixture.beans.factory.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; /** * A public {@link FactoryBean} with a generic type. @@ -33,15 +34,13 @@ public class GenericFactoryBean implements FactoryBean { this.beanType = beanType; } - @Nullable @Override - public T getObject() throws Exception { + public @Nullable T getObject() throws Exception { return BeanUtils.instantiateClass(this.beanType); } - @Nullable @Override - public Class getObjectType() { + public @Nullable Class getObjectType() { return this.beanType; } } diff --git a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/package-info.java b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/package-info.java index dc39666d1a..ee25b9bb9b 100644 --- a/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/package-info.java +++ b/spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/factory/aot/package-info.java @@ -1,9 +1,7 @@ /** * Test fixtures for bean factories AOT support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.beans.testfixture.beans.factory.aot; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java index da4b62e471..f5ffec852a 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java @@ -23,9 +23,9 @@ import java.util.function.Supplier; import com.github.benmanes.caffeine.cache.AsyncCache; import com.github.benmanes.caffeine.cache.LoadingCache; +import org.jspecify.annotations.Nullable; import org.springframework.cache.support.AbstractValueAdaptingCache; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,8 +50,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { private final com.github.benmanes.caffeine.cache.Cache cache; - @Nullable - private AsyncCache asyncCache; + private @Nullable AsyncCache asyncCache; /** @@ -130,14 +129,12 @@ public class CaffeineCache extends AbstractValueAdaptingCache { @SuppressWarnings("unchecked") @Override - @Nullable - public T get(Object key, Callable valueLoader) { + public @Nullable T get(Object key, Callable valueLoader) { return (T) fromStoreValue(this.cache.get(key, new LoadFunction(valueLoader))); } @Override - @Nullable - public CompletableFuture retrieve(Object key) { + public @Nullable CompletableFuture retrieve(Object key) { CompletableFuture result = getAsyncCache().getIfPresent(key); if (result != null && isAllowNullValues()) { result = result.thenApply(this::toValueWrapper); @@ -159,8 +156,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { } @Override - @Nullable - protected Object lookup(Object key) { + protected @Nullable Object lookup(Object key) { if (this.cache instanceof LoadingCache loadingCache) { return loadingCache.get(key); } @@ -173,8 +169,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { } @Override - @Nullable - public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { + public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) { PutIfAbsentFunction callable = new PutIfAbsentFunction(value); Object result = this.cache.get(key, callable); return (callable.called ? null : toValueWrapper(result)); @@ -205,8 +200,7 @@ public class CaffeineCache extends AbstractValueAdaptingCache { private class PutIfAbsentFunction implements Function { - @Nullable - private final Object value; + private final @Nullable Object value; boolean called; 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 2ad316114b..b08f9d376e 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,10 +29,10 @@ import com.github.benmanes.caffeine.cache.AsyncCacheLoader; import com.github.benmanes.caffeine.cache.CacheLoader; import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.CaffeineSpec; +import org.jspecify.annotations.Nullable; 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; @@ -70,8 +70,7 @@ public class CaffeineCacheManager implements CacheManager { private Caffeine cacheBuilder = Caffeine.newBuilder(); - @Nullable - private AsyncCacheLoader cacheLoader; + private @Nullable AsyncCacheLoader cacheLoader; private boolean asyncCacheMode = false; @@ -251,8 +250,7 @@ public class CaffeineCacheManager implements CacheManager { } @Override - @Nullable - public Cache getCache(String name) { + public @Nullable Cache getCache(String name) { Cache cache = this.cacheMap.get(name); if (cache == null && this.dynamic) { cache = this.cacheMap.computeIfAbsent(name, this::createCaffeineCache); 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 864fb2e399..5606a4fdff 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,9 +3,7 @@ * Caffeine library, * allowing to set up Caffeine caches within Spring's cache abstraction. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.caffeine; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java index c870d843d7..724a66d19a 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCache.java @@ -24,8 +24,9 @@ import javax.cache.processor.EntryProcessor; import javax.cache.processor.EntryProcessorException; import javax.cache.processor.MutableEntry; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.support.AbstractValueAdaptingCache; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -79,15 +80,13 @@ public class JCacheCache extends AbstractValueAdaptingCache { } @Override - @Nullable - protected Object lookup(Object key) { + protected @Nullable Object lookup(Object key) { return this.cache.get(key); } @Override - @Nullable @SuppressWarnings("unchecked") - public T get(Object key, Callable valueLoader) { + public @Nullable T get(Object key, Callable valueLoader) { try { return (T) this.cache.invoke(key, this.valueLoaderEntryProcessor, valueLoader); } @@ -102,8 +101,7 @@ public class JCacheCache extends AbstractValueAdaptingCache { } @Override - @Nullable - public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { + public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) { Object previous = this.cache.invoke(key, PutIfAbsentEntryProcessor.INSTANCE, toStoreValue(value)); return (previous != null ? toValueWrapper(previous) : null); } @@ -136,8 +134,7 @@ public class JCacheCache extends AbstractValueAdaptingCache { private static final PutIfAbsentEntryProcessor INSTANCE = new PutIfAbsentEntryProcessor(); @Override - @Nullable - public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException { + public @Nullable Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException { Object existingValue = entry.getValue(); if (existingValue == null) { entry.setValue(arguments[0]); @@ -161,9 +158,8 @@ public class JCacheCache extends AbstractValueAdaptingCache { } @Override - @Nullable @SuppressWarnings("unchecked") - public Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException { + public @Nullable Object process(MutableEntry entry, Object... arguments) throws EntryProcessorException { Callable valueLoader = (Callable) arguments[0]; if (entry.exists()) { return this.fromStoreValue.apply(entry.getValue()); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java index 0e87c8af53..c2e90d6e97 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/JCacheCacheManager.java @@ -22,9 +22,10 @@ import java.util.LinkedHashSet; import javax.cache.CacheManager; import javax.cache.Caching; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.transaction.AbstractTransactionSupportingCacheManager; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -40,8 +41,7 @@ import org.springframework.util.Assert; */ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager { - @Nullable - private CacheManager cacheManager; + private @Nullable CacheManager cacheManager; private boolean allowNullValues = true; @@ -75,8 +75,7 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage /** * Return the backing JCache {@link CacheManager javax.cache.CacheManager}. */ - @Nullable - public CacheManager getCacheManager() { + public @Nullable CacheManager getCacheManager() { return this.cacheManager; } @@ -121,8 +120,7 @@ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManage } @Override - @Nullable - protected Cache getMissingCache(String name) { + protected @Nullable Cache getMissingCache(String name) { CacheManager cacheManager = getCacheManager(); Assert.state(cacheManager != null, "No CacheManager set"); 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 da3a2e1566..29d246a09f 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 @@ -22,11 +22,12 @@ import java.util.Properties; import javax.cache.CacheManager; import javax.cache.Caching; +import org.jspecify.annotations.Nullable; + 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 CacheManager javax.cache.CacheManager}, @@ -43,17 +44,13 @@ import org.springframework.lang.Nullable; public class JCacheManagerFactoryBean implements FactoryBean, BeanClassLoaderAware, InitializingBean, DisposableBean { - @Nullable - private URI cacheManagerUri; + private @Nullable URI cacheManagerUri; - @Nullable - private Properties cacheManagerProperties; + private @Nullable Properties cacheManagerProperties; - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; - @Nullable - private CacheManager cacheManager; + private @Nullable CacheManager cacheManager; /** @@ -86,8 +83,7 @@ public class JCacheManagerFactoryBean @Override - @Nullable - public CacheManager getObject() { + public @Nullable CacheManager getObject() { return this.cacheManager; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java index 793435d03f..4bcc7ab244 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java @@ -18,6 +18,8 @@ package org.springframework.cache.jcache.config; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.cache.annotation.AbstractCachingConfiguration; import org.springframework.cache.interceptor.CacheResolver; @@ -26,7 +28,6 @@ import org.springframework.cache.jcache.interceptor.JCacheOperationSource; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Role; -import org.springframework.lang.Nullable; /** * Abstract JSR-107 specific {@code @Configuration} class providing common @@ -40,8 +41,7 @@ import org.springframework.lang.Nullable; @Configuration(proxyBeanMethods = false) public abstract class AbstractJCacheConfiguration extends AbstractCachingConfiguration { - @Nullable - protected Supplier exceptionCacheResolver; + protected @Nullable Supplier exceptionCacheResolver; @Override diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java index 2690c1ac37..d834cd7c35 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java @@ -16,9 +16,10 @@ package org.springframework.cache.jcache.config; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.interceptor.CacheResolver; -import org.springframework.lang.Nullable; /** * Extension of {@link CachingConfigurer} for the JSR-107 implementation. @@ -57,8 +58,7 @@ public interface JCacheConfigurer extends CachingConfigurer { * * See {@link org.springframework.cache.annotation.EnableCaching} for more complete examples. */ - @Nullable - default CacheResolver exceptionCacheResolver() { + default @Nullable CacheResolver exceptionCacheResolver() { return null; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurerSupport.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurerSupport.java index 76f4b45702..6f991f5f73 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurerSupport.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurerSupport.java @@ -16,9 +16,10 @@ package org.springframework.cache.jcache.config; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.annotation.CachingConfigurerSupport; import org.springframework.cache.interceptor.CacheResolver; -import org.springframework.lang.Nullable; /** * An extension of {@link CachingConfigurerSupport} that also implements @@ -37,8 +38,7 @@ import org.springframework.lang.Nullable; public class JCacheConfigurerSupport extends CachingConfigurerSupport implements JCacheConfigurer { @Override - @Nullable - public CacheResolver exceptionCacheResolver() { + public @Nullable CacheResolver exceptionCacheResolver() { return null; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java index c5adcac5ac..46899ffad1 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java @@ -6,9 +6,7 @@ *

Provides an extension of the {@code CachingConfigurer} that exposes * the exception cache resolver to use (see {@code JCacheConfigurer}). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.jcache.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 06025fc26a..e128f2f366 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 @@ -22,13 +22,13 @@ import java.util.Collection; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cache.Cache; 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; /** @@ -51,8 +51,7 @@ abstract class AbstractCacheInterceptor, A } - @Nullable - protected abstract Object invoke(CacheOperationInvocationContext context, CacheOperationInvoker invoker) + protected abstract @Nullable Object invoke(CacheOperationInvocationContext context, CacheOperationInvoker invoker) throws Throwable; @@ -75,8 +74,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) { + static @Nullable 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 0ff896eb5e..a966402758 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 @@ -23,10 +23,10 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; import org.springframework.core.MethodClassKey; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -59,13 +59,11 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe } @Override - @Nullable - public JCacheOperation getCacheOperation(Method method, @Nullable Class targetClass) { + public @Nullable JCacheOperation getCacheOperation(Method method, @Nullable Class targetClass) { return getCacheOperation(method, targetClass, true); } - @Nullable - private JCacheOperation getCacheOperation(Method method, @Nullable Class targetClass, boolean cacheNull) { + private @Nullable JCacheOperation getCacheOperation(Method method, @Nullable Class targetClass, boolean cacheNull) { if (ReflectionUtils.isObjectMethod(method)) { return null; } @@ -91,8 +89,7 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe } } - @Nullable - private JCacheOperation computeCacheOperation(Method method, @Nullable Class targetClass) { + private @Nullable JCacheOperation computeCacheOperation(Method method, @Nullable Class targetClass) { // Don't allow non-public methods, as configured. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; @@ -126,8 +123,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, @Nullable Class targetType); + protected abstract @Nullable JCacheOperation findCacheOperation(Method method, @Nullable Class targetType); /** * Should only public methods be allowed to have caching semantics? diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheKeyOperation.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheKeyOperation.java index e3ecd6fa3b..00ad1cb5b7 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheKeyOperation.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheKeyOperation.java @@ -23,6 +23,8 @@ import java.util.List; import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheMethodDetails; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; @@ -74,7 +76,7 @@ abstract class AbstractJCacheKeyOperation extends Abstract * @return the {@link CacheInvocationParameter} instances for the parameters to be * used to compute the key */ - public CacheInvocationParameter[] getKeyParameters(Object... values) { + public CacheInvocationParameter[] getKeyParameters(@Nullable Object... values) { List result = new ArrayList<>(); for (CacheParameterDetail keyParameterDetail : this.keyParameterDetails) { int parameterPosition = keyParameterDetail.getParameterPosition(); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java index 036a4f6cb5..8349d2513b 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/AbstractJCacheOperation.java @@ -30,6 +30,8 @@ import javax.cache.annotation.CacheKey; import javax.cache.annotation.CacheMethodDetails; import javax.cache.annotation.CacheValue; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheResolver; import org.springframework.util.Assert; import org.springframework.util.ExceptionTypeFilter; @@ -105,7 +107,8 @@ abstract class AbstractJCacheOperation implements JCacheOp } @Override - public CacheInvocationParameter[] getAllParameters(Object... values) { + @SuppressWarnings("NullAway") + public CacheInvocationParameter[] getAllParameters(@Nullable Object... values) { if (this.allParameterDetails.size() != values.length) { throw new IllegalStateException("Values mismatch, operation has " + this.allParameterDetails.size() + " parameter(s) but got " + values.length + " value(s)"); @@ -200,7 +203,7 @@ abstract class AbstractJCacheOperation implements JCacheOp return this.isValue; } - public CacheInvocationParameter toCacheInvocationParameter(Object value) { + public CacheInvocationParameter toCacheInvocationParameter(@Nullable Object value) { return new CacheInvocationParameterImpl(this, value); } } @@ -213,9 +216,9 @@ abstract class AbstractJCacheOperation implements JCacheOp private final CacheParameterDetail detail; - private final Object value; + private final @Nullable Object value; - public CacheInvocationParameterImpl(CacheParameterDetail detail, Object value) { + public CacheInvocationParameterImpl(CacheParameterDetail detail, @Nullable Object value) { this.detail = detail; this.value = value; } @@ -226,7 +229,7 @@ abstract class AbstractJCacheOperation implements JCacheOp } @Override - public Object getValue() { + public @Nullable Object getValue() { return this.value; } 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 e18941574a..77a989aa10 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,10 +31,11 @@ import javax.cache.annotation.CacheRemoveAll; import javax.cache.annotation.CacheResolverFactory; import javax.cache.annotation.CacheResult; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -58,8 +59,7 @@ public abstract class AnnotationJCacheOperationSource extends AbstractFallbackJC } @Override - @Nullable - protected JCacheOperation findCacheOperation(Method method, @Nullable Class targetType) { + protected @Nullable JCacheOperation findCacheOperation(Method method, @Nullable Class targetType) { CacheResult cacheResult = method.getAnnotation(CacheResult.class); CachePut cachePut = method.getAnnotation(CachePut.class); CacheRemove cacheRemove = method.getAnnotation(CacheRemove.class); @@ -88,8 +88,7 @@ public abstract class AnnotationJCacheOperationSource extends AbstractFallbackJC } } - @Nullable - protected CacheDefaults getCacheDefaults(Method method, @Nullable Class targetType) { + protected @Nullable CacheDefaults getCacheDefaults(Method method, @Nullable Class targetType) { CacheDefaults annotation = method.getDeclaringClass().getAnnotation(CacheDefaults.class); if (annotation != null) { return annotation; @@ -175,8 +174,7 @@ public abstract class AnnotationJCacheOperationSource extends AbstractFallbackJC } } - @Nullable - protected CacheResolverFactory determineCacheResolverFactory( + protected @Nullable CacheResolverFactory determineCacheResolverFactory( @Nullable CacheDefaults defaults, Class candidate) { if (candidate != CacheResolverFactory.class) { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutInterceptor.java index f64c09a336..61dcdfc071 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutInterceptor.java @@ -19,11 +19,12 @@ package org.springframework.cache.jcache.interceptor; import javax.cache.annotation.CacheKeyInvocationContext; import javax.cache.annotation.CachePut; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvoker; -import org.springframework.lang.Nullable; /** * Intercept methods annotated with {@link CachePut}. @@ -40,8 +41,7 @@ class CachePutInterceptor extends AbstractKeyCacheInterceptor context, CacheOperationInvoker invoker) { CachePutOperation operation = context.getOperation(); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutOperation.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutOperation.java index a406418863..d35ddfe715 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutOperation.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CachePutOperation.java @@ -23,9 +23,10 @@ import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheMethodDetails; import javax.cache.annotation.CachePut; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheResolver; import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.lang.Nullable; import org.springframework.util.ExceptionTypeFilter; /** @@ -81,7 +82,7 @@ class CachePutOperation extends AbstractJCacheKeyOperation { * @param values the parameters value for a particular invocation * @return the {@link CacheInvocationParameter} instance for the value parameter */ - public CacheInvocationParameter getValueParameter(Object... values) { + public CacheInvocationParameter getValueParameter(@Nullable Object... values) { int parameterPosition = this.valueParameterDetail.getParameterPosition(); if (parameterPosition >= values.length) { throw new IllegalStateException("Values mismatch, value parameter at position " + @@ -91,8 +92,7 @@ class CachePutOperation extends AbstractJCacheKeyOperation { } - @Nullable - private static CacheParameterDetail initializeValueParameterDetail( + private static @Nullable CacheParameterDetail initializeValueParameterDetail( Method method, List allParameters) { CacheParameterDetail result = null; diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveAllInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveAllInterceptor.java index dfd8f0a4cc..557cc3fd6c 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveAllInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveAllInterceptor.java @@ -18,11 +18,12 @@ package org.springframework.cache.jcache.interceptor; import javax.cache.annotation.CacheRemoveAll; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvoker; -import org.springframework.lang.Nullable; /** * Intercept methods annotated with {@link CacheRemoveAll}. @@ -39,8 +40,7 @@ class CacheRemoveAllInterceptor extends AbstractCacheInterceptor context, CacheOperationInvoker invoker) { CacheRemoveAllOperation operation = context.getOperation(); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveEntryInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveEntryInterceptor.java index a1075785bb..95ac57f666 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveEntryInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheRemoveEntryInterceptor.java @@ -18,11 +18,12 @@ package org.springframework.cache.jcache.interceptor; import javax.cache.annotation.CacheRemove; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvoker; -import org.springframework.lang.Nullable; /** * Intercept methods annotated with {@link CacheRemove}. @@ -39,8 +40,7 @@ class CacheRemoveEntryInterceptor extends AbstractKeyCacheInterceptor context, CacheOperationInvoker invoker) { CacheRemoveOperation operation = context.getOperation(); 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 dbd71ba264..f071be030c 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 @@ -18,12 +18,13 @@ package org.springframework.cache.jcache.interceptor; import javax.cache.annotation.CacheResult; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; 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.Assert; import org.springframework.util.ExceptionTypeFilter; import org.springframework.util.SerializationUtils; @@ -43,8 +44,7 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); @@ -97,8 +97,7 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor context) { + private @Nullable Cache resolveExceptionCache(CacheOperationInvocationContext context) { CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver(); if (exceptionCacheResolver != null) { return extractFrom(exceptionCacheResolver.resolveCaches(context)); @@ -146,8 +145,7 @@ class CacheResultInterceptor extends AbstractKeyCacheInterceptor T cloneException(T exception) { + private static @Nullable T cloneException(T exception) { try { return SerializationUtils.clone(exception); } 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 3f4eedfe10..7435599a7c 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 @@ -19,9 +19,10 @@ package org.springframework.cache.jcache.interceptor; import javax.cache.annotation.CacheMethodDetails; import javax.cache.annotation.CacheResult; +import org.jspecify.annotations.Nullable; + 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; @@ -36,11 +37,9 @@ class CacheResultOperation extends AbstractJCacheKeyOperation { private final ExceptionTypeFilter exceptionTypeFilter; - @Nullable - private final CacheResolver exceptionCacheResolver; + private final @Nullable CacheResolver exceptionCacheResolver; - @Nullable - private final String exceptionCacheName; + private final @Nullable String exceptionCacheName; public CacheResultOperation(CacheMethodDetails methodDetails, CacheResolver cacheResolver, @@ -73,8 +72,7 @@ class CacheResultOperation extends AbstractJCacheKeyOperation { * Return the {@link CacheResolver} instance to use to resolve the cache to * use for matching exceptions thrown by this operation. */ - @Nullable - public CacheResolver getExceptionCacheResolver() { + public @Nullable CacheResolver getExceptionCacheResolver() { return this.exceptionCacheResolver; } @@ -83,8 +81,7 @@ class CacheResultOperation extends AbstractJCacheKeyOperation { * caching exceptions should be disabled. * @see javax.cache.annotation.CacheResult#exceptionCacheName() */ - @Nullable - public String getExceptionCacheName() { + public @Nullable String getExceptionCacheName() { return this.exceptionCacheName; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheInvocationContext.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheInvocationContext.java index 35523c2b46..8509635bec 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheInvocationContext.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheInvocationContext.java @@ -24,6 +24,8 @@ import java.util.Set; import javax.cache.annotation.CacheInvocationContext; import javax.cache.annotation.CacheInvocationParameter; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheOperationInvocationContext; /** @@ -42,12 +44,12 @@ class DefaultCacheInvocationContext private final Object target; - private final Object[] args; + private final @Nullable Object[] args; private final CacheInvocationParameter[] allParameters; - public DefaultCacheInvocationContext(JCacheOperation operation, Object target, Object[] args) { + public DefaultCacheInvocationContext(JCacheOperation operation, Object target, @Nullable Object[] args) { this.operation = operation; this.target = target; this.args = args; @@ -66,7 +68,7 @@ class DefaultCacheInvocationContext } @Override - public Object[] getArgs() { + public @Nullable Object[] getArgs() { return this.args.clone(); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java index 9bd230ab93..4e6a4a4915 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java @@ -21,7 +21,7 @@ import java.lang.annotation.Annotation; import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheKeyInvocationContext; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * The default {@link CacheKeyInvocationContext} implementation. @@ -35,11 +35,10 @@ class DefaultCacheKeyInvocationContext extends DefaultCach private final CacheInvocationParameter[] keyParameters; - @Nullable - private final CacheInvocationParameter valueParameter; + private final @Nullable CacheInvocationParameter valueParameter; - public DefaultCacheKeyInvocationContext(AbstractJCacheKeyOperation operation, Object target, Object[] args) { + public DefaultCacheKeyInvocationContext(AbstractJCacheKeyOperation operation, Object target, @Nullable Object[] args) { super(operation, target, args); this.keyParameters = operation.getKeyParameters(args); if (operation instanceof CachePutOperation cachePutOperation) { @@ -57,8 +56,7 @@ class DefaultCacheKeyInvocationContext extends DefaultCach } @Override - @Nullable - public CacheInvocationParameter getValueParameter() { + public @Nullable CacheInvocationParameter getValueParameter() { return this.valueParameter; } 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 1b93b140ba..6b684b8e61 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 @@ -19,6 +19,8 @@ package org.springframework.cache.jcache.interceptor; import java.util.Collection; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -32,7 +34,6 @@ 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; import org.springframework.util.function.SingletonSupplier; import org.springframework.util.function.SupplierUtils; @@ -49,22 +50,18 @@ import org.springframework.util.function.SupplierUtils; public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSource implements BeanFactoryAware, SmartInitializingSingleton { - @Nullable - private SingletonSupplier cacheManager; + private @Nullable SingletonSupplier cacheManager; - @Nullable - private SingletonSupplier cacheResolver; + private @Nullable SingletonSupplier cacheResolver; - @Nullable - private SingletonSupplier exceptionCacheResolver; + private @Nullable SingletonSupplier exceptionCacheResolver; private SingletonSupplier keyGenerator; private final SingletonSupplier adaptedKeyGenerator = SingletonSupplier.of(() -> new KeyGeneratorAdapter(this, getKeyGenerator())); - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** @@ -103,8 +100,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified cache manager to use, if any. */ - @Nullable - public CacheManager getCacheManager() { + public @Nullable CacheManager getCacheManager() { return SupplierUtils.resolve(this.cacheManager); } @@ -119,8 +115,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified cache resolver to use, if any. */ - @Nullable - public CacheResolver getCacheResolver() { + public @Nullable CacheResolver getCacheResolver() { return SupplierUtils.resolve(this.cacheResolver); } @@ -135,8 +130,7 @@ public class DefaultJCacheOperationSource extends AnnotationJCacheOperationSourc /** * Return the specified exception cache resolver to use, if any. */ - @Nullable - public CacheResolver getExceptionCacheResolver() { + public @Nullable CacheResolver getExceptionCacheResolver() { return SupplierUtils.resolve(this.exceptionCacheResolver); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java index de1ff1a293..6517f57bf5 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheAspectSupport.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopProxyUtils; import org.springframework.beans.factory.InitializingBean; @@ -28,7 +29,6 @@ import org.springframework.cache.interceptor.AbstractCacheInvoker; import org.springframework.cache.interceptor.BasicOperation; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheOperationInvoker; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -53,20 +53,15 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private JCacheOperationSource cacheOperationSource; + private @Nullable JCacheOperationSource cacheOperationSource; - @Nullable - private CacheResultInterceptor cacheResultInterceptor; + private @Nullable CacheResultInterceptor cacheResultInterceptor; - @Nullable - private CachePutInterceptor cachePutInterceptor; + private @Nullable CachePutInterceptor cachePutInterceptor; - @Nullable - private CacheRemoveEntryInterceptor cacheRemoveEntryInterceptor; + private @Nullable CacheRemoveEntryInterceptor cacheRemoveEntryInterceptor; - @Nullable - private CacheRemoveAllInterceptor cacheRemoveAllInterceptor; + private @Nullable CacheRemoveAllInterceptor cacheRemoveAllInterceptor; private boolean initialized = false; @@ -101,8 +96,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial } - @Nullable - protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { + protected @Nullable Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { // Check whether aspect is enabled to cope with cases where the AJ is pulled in automatically if (this.initialized) { Class targetClass = AopProxyUtils.ultimateTargetClass(target); @@ -126,8 +120,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial } @SuppressWarnings("unchecked") - @Nullable - private Object execute(CacheOperationInvocationContext context, CacheOperationInvoker invoker) { + private @Nullable Object execute(CacheOperationInvocationContext context, CacheOperationInvoker invoker) { CacheOperationInvoker adapter = new CacheOperationInvokerAdapter(invoker); BasicOperation operation = context.getOperation(); @@ -165,8 +158,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ - @Nullable - protected Object invokeOperation(CacheOperationInvoker invoker) { + protected @Nullable Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); } @@ -180,8 +172,7 @@ public class JCacheAspectSupport extends AbstractCacheInvoker implements Initial } @Override - @Nullable - public Object invoke() throws ThrowableWrapper { + public @Nullable Object invoke() throws ThrowableWrapper { return invokeOperation(this.delegate); } } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java index 81e65d1a1c..79dce59d98 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheInterceptor.java @@ -22,11 +22,11 @@ import java.util.function.Supplier; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheOperationInvoker; import org.springframework.cache.interceptor.SimpleCacheErrorHandler; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.function.SingletonSupplier; @@ -66,8 +66,7 @@ public class JCacheInterceptor extends JCacheAspectSupport implements MethodInte @Override - @Nullable - public Object invoke(final MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(final MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); CacheOperationInvoker aopAllianceInvoker = () -> { diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperation.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperation.java index 00c5ef91e9..9781d4016a 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperation.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperation.java @@ -21,6 +21,8 @@ import java.lang.annotation.Annotation; import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheMethodDetails; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.BasicOperation; import org.springframework.cache.interceptor.CacheResolver; @@ -48,6 +50,6 @@ public interface JCacheOperation extends BasicOperation, C *

The method arguments must match the signature of the related method invocation * @param values the parameters value for a particular invocation */ - CacheInvocationParameter[] getAllParameters(Object... values); + CacheInvocationParameter[] getAllParameters(@Nullable Object... values); } 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 686066c602..9cdf04c93f 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,7 +18,7 @@ package org.springframework.cache.jcache.interceptor; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface used by {@link JCacheInterceptor}. Implementations know how to source @@ -70,7 +70,6 @@ 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 */ - @Nullable - JCacheOperation getCacheOperation(Method method, @Nullable 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 bfd4bda19d..7f41c18767 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 @@ -19,10 +19,11 @@ package org.springframework.cache.jcache.interceptor; import java.io.Serializable; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; import org.springframework.aop.support.StaticMethodMatcherPointcut; import org.springframework.cache.CacheManager; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -35,8 +36,7 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") final class JCacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { - @Nullable - private JCacheOperationSource cacheOperationSource; + private @Nullable JCacheOperationSource cacheOperationSource; public JCacheOperationSourcePointcut() { @@ -85,8 +85,7 @@ final class JCacheOperationSourcePointcut extends StaticMethodMatcherPointcut im return (cacheOperationSource == null || cacheOperationSource.isCandidateClass(clazz)); } - @Nullable - private JCacheOperationSource getCacheOperationSource() { + private @Nullable JCacheOperationSource getCacheOperationSource() { return cacheOperationSource; } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java index 3fcfe9fc58..756464fcc3 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/KeyGeneratorAdapter.java @@ -25,8 +25,9 @@ import javax.cache.annotation.CacheInvocationParameter; import javax.cache.annotation.CacheKeyGenerator; import javax.cache.annotation.CacheKeyInvocationContext; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -43,11 +44,9 @@ class KeyGeneratorAdapter implements KeyGenerator { private final JCacheOperationSource cacheOperationSource; - @Nullable - private KeyGenerator keyGenerator; + private @Nullable KeyGenerator keyGenerator; - @Nullable - private CacheKeyGenerator cacheKeyGenerator; + private @Nullable CacheKeyGenerator cacheKeyGenerator; /** @@ -85,7 +84,8 @@ class KeyGeneratorAdapter implements KeyGenerator { } @Override - public Object generate(Object target, Method method, Object... params) { + @SuppressWarnings("NullAway") + public Object generate(Object target, Method method, @Nullable Object... params) { JCacheOperation operation = this.cacheOperationSource.getCacheOperation(method, target.getClass()); if (!(operation instanceof AbstractJCacheKeyOperation)) { throw new IllegalStateException("Invalid operation, should be a key-based operation " + operation); @@ -119,7 +119,7 @@ class KeyGeneratorAdapter implements KeyGenerator { @SuppressWarnings("unchecked") private CacheKeyInvocationContext createCacheKeyInvocationContext( - Object target, JCacheOperation operation, Object[] params) { + Object target, JCacheOperation operation, @Nullable Object[] params) { AbstractJCacheKeyOperation keyCacheOperation = (AbstractJCacheKeyOperation) operation; return new DefaultCacheKeyInvocationContext<>(keyCacheOperation, target, params); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java index 70eca3aad5..b35ff8dbd0 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java @@ -19,12 +19,13 @@ package org.springframework.cache.jcache.interceptor; import java.util.Collection; import java.util.Collections; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.CacheManager; import org.springframework.cache.interceptor.AbstractCacheResolver; import org.springframework.cache.interceptor.BasicOperation; import org.springframework.cache.interceptor.CacheOperationInvocationContext; import org.springframework.cache.interceptor.CacheResolver; -import org.springframework.lang.Nullable; /** * A simple {@link CacheResolver} that resolves the exception cache @@ -42,8 +43,7 @@ public class SimpleExceptionCacheResolver extends AbstractCacheResolver { } @Override - @Nullable - protected Collection getCacheNames(CacheOperationInvocationContext context) { + protected @Nullable Collection getCacheNames(CacheOperationInvocationContext context) { BasicOperation operation = context.getOperation(); if (!(operation instanceof CacheResultOperation cacheResultOperation)) { throw new IllegalStateException("Could not extract exception cache name from " + operation); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/package-info.java index c752c806b9..d834a07365 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/package-info.java @@ -7,9 +7,7 @@ *

Builds on the AOP infrastructure in org.springframework.aop.framework. * Any POJO can be cache-advised with Spring. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.jcache.interceptor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 e8b5c89807..568feb8512 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,9 +4,7 @@ * and {@link org.springframework.cache.Cache Cache} implementation for * use in a Spring context, using a JSR-107 compliant cache provider. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.jcache; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheDecorator.java b/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheDecorator.java index 45b5870dfe..107529bf1a 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheDecorator.java +++ b/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheDecorator.java @@ -20,8 +20,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -77,26 +78,22 @@ public class TransactionAwareCacheDecorator implements Cache { } @Override - @Nullable - public ValueWrapper get(Object key) { + public @Nullable ValueWrapper get(Object key) { return this.targetCache.get(key); } @Override - @Nullable - public T get(Object key, @Nullable Class type) { + public @Nullable T get(Object key, @Nullable Class type) { return this.targetCache.get(key, type); } @Override - @Nullable - public T get(Object key, Callable valueLoader) { + public @Nullable T get(Object key, Callable valueLoader) { return this.targetCache.get(key, valueLoader); } @Override - @Nullable - public CompletableFuture retrieve(Object key) { + public @Nullable CompletableFuture retrieve(Object key) { return this.targetCache.retrieve(key); } @@ -106,7 +103,7 @@ public class TransactionAwareCacheDecorator implements Cache { } @Override - public void put(final Object key, @Nullable final Object value) { + public void put(final Object key, final @Nullable Object value) { if (TransactionSynchronizationManager.isSynchronizationActive()) { TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() { @Override @@ -121,8 +118,7 @@ public class TransactionAwareCacheDecorator implements Cache { } @Override - @Nullable - public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { + public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) { return this.targetCache.putIfAbsent(key, value); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheManagerProxy.java b/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheManagerProxy.java index faf432e389..889b2fddca 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheManagerProxy.java +++ b/spring-context-support/src/main/java/org/springframework/cache/transaction/TransactionAwareCacheManagerProxy.java @@ -18,10 +18,11 @@ package org.springframework.cache.transaction; import java.util.Collection; +import org.jspecify.annotations.Nullable; + 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; /** @@ -39,8 +40,7 @@ import org.springframework.util.Assert; */ public class TransactionAwareCacheManagerProxy implements CacheManager, InitializingBean { - @Nullable - private CacheManager targetCacheManager; + private @Nullable CacheManager targetCacheManager; /** @@ -76,8 +76,7 @@ public class TransactionAwareCacheManagerProxy implements CacheManager, Initiali @Override - @Nullable - public Cache getCache(String name) { + public @Nullable Cache getCache(String name) { Assert.state(this.targetCacheManager != null, "No target CacheManager set"); Cache targetCache = this.targetCacheManager.getCache(name); return (targetCache != null ? new TransactionAwareCacheDecorator(targetCache) : null); 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 340f019698..0a873930c1 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,9 +2,7 @@ * Transaction-aware decorators for the org.springframework.cache package. * Provides synchronization of put operations with Spring-managed transactions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.transaction; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context-support/src/main/java/org/springframework/mail/MailException.java b/spring-context-support/src/main/java/org/springframework/mail/MailException.java index 0761369558..c966ce7b5b 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/MailException.java +++ b/spring-context-support/src/main/java/org/springframework/mail/MailException.java @@ -16,8 +16,9 @@ package org.springframework.mail; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Base class for all mail exceptions. diff --git a/spring-context-support/src/main/java/org/springframework/mail/MailSendException.java b/spring-context-support/src/main/java/org/springframework/mail/MailSendException.java index af7f0417f2..a7218bf2a3 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/MailSendException.java +++ b/spring-context-support/src/main/java/org/springframework/mail/MailSendException.java @@ -21,7 +21,8 @@ import java.io.PrintWriter; import java.util.LinkedHashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -36,8 +37,7 @@ public class MailSendException extends MailException { private final transient Map failedMessages; - @Nullable - private final Exception[] messageExceptions; + private final Exception @Nullable [] messageExceptions; /** @@ -124,8 +124,7 @@ public class MailSendException extends MailException { @Override - @Nullable - public String getMessage() { + public @Nullable String getMessage() { if (ObjectUtils.isEmpty(this.messageExceptions)) { return super.getMessage(); } diff --git a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java index d86db63adb..997b20356d 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java +++ b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java @@ -19,7 +19,8 @@ package org.springframework.mail; import java.io.Serializable; import java.util.Date; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -44,29 +45,21 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public class SimpleMailMessage implements MailMessage, Serializable { - @Nullable - private String from; + private @Nullable String from; - @Nullable - private String replyTo; + private @Nullable String replyTo; - @Nullable - private String[] to; + private String @Nullable [] to; - @Nullable - private String[] cc; + private String @Nullable [] cc; - @Nullable - private String[] bcc; + private String @Nullable [] bcc; - @Nullable - private Date sentDate; + private @Nullable Date sentDate; - @Nullable - private String subject; + private @Nullable String subject; - @Nullable - private String text; + private @Nullable String text; /** @@ -97,8 +90,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { this.from = from; } - @Nullable - public String getFrom() { + public @Nullable String getFrom() { return this.from; } @@ -107,8 +99,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { this.replyTo = replyTo; } - @Nullable - public String getReplyTo() { + public @Nullable String getReplyTo() { return this.replyTo; } @@ -122,8 +113,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { this.to = to; } - @Nullable - public String[] getTo() { + public String @Nullable [] getTo() { return this.to; } @@ -133,12 +123,11 @@ public class SimpleMailMessage implements MailMessage, Serializable { } @Override - public void setCc(@Nullable String... cc) { + public void setCc(String @Nullable ... cc) { this.cc = cc; } - @Nullable - public String[] getCc() { + public String @Nullable [] getCc() { return this.cc; } @@ -148,12 +137,11 @@ public class SimpleMailMessage implements MailMessage, Serializable { } @Override - public void setBcc(@Nullable String... bcc) { + public void setBcc(String @Nullable ... bcc) { this.bcc = bcc; } - @Nullable - public String[] getBcc() { + public String @Nullable [] getBcc() { return this.bcc; } @@ -162,8 +150,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { this.sentDate = sentDate; } - @Nullable - public Date getSentDate() { + public @Nullable Date getSentDate() { return this.sentDate; } @@ -172,8 +159,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { this.subject = subject; } - @Nullable - public String getSubject() { + public @Nullable String getSubject() { return this.subject; } @@ -182,8 +168,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { this.text = text; } - @Nullable - public String getText() { + public @Nullable String getText() { return this.text; } @@ -255,8 +240,7 @@ public class SimpleMailMessage implements MailMessage, Serializable { } - @Nullable - private static String[] copyOrNull(@Nullable String[] state) { + private static String @Nullable [] copyOrNull(String @Nullable [] state) { if (state == null) { return null; } 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 7fe0a9aca8..97771d8523 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 @@ -22,11 +22,11 @@ import java.io.InputStream; import jakarta.activation.FileTypeMap; import jakarta.activation.MimetypesFileTypeMap; +import org.jspecify.annotations.Nullable; 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 @@ -70,15 +70,13 @@ public class ConfigurableMimeFileTypeMap extends FileTypeMap implements Initiali /** * Used to configure additional mappings. */ - @Nullable - private String[] mappings; + private String @Nullable [] mappings; /** * The delegate FileTypeMap, compiled from the mappings in the mapping file * and the entries in the {@code mappings} property. */ - @Nullable - private FileTypeMap fileTypeMap; + private @Nullable FileTypeMap fileTypeMap; /** @@ -143,7 +141,7 @@ public class ConfigurableMimeFileTypeMap extends FileTypeMap implements Initiali * @see jakarta.activation.MimetypesFileTypeMap#MimetypesFileTypeMap(java.io.InputStream) * @see jakarta.activation.MimetypesFileTypeMap#addMimeTypes(String) */ - protected FileTypeMap createFileTypeMap(@Nullable Resource mappingLocation, @Nullable String[] mappings) throws IOException { + protected FileTypeMap createFileTypeMap(@Nullable Resource mappingLocation, String @Nullable [] mappings) throws IOException { MimetypesFileTypeMap fileTypeMap = null; if (mappingLocation != null) { try (InputStream is = mappingLocation.getInputStream()) { diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailMimeTypesRuntimeHints.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailMimeTypesRuntimeHints.java index 1650098560..a21665ec3d 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailMimeTypesRuntimeHints.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/JavaMailMimeTypesRuntimeHints.java @@ -16,9 +16,10 @@ package org.springframework.mail.javamail; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that makes sure mime types 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 333da35987..e89cd78e06 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 @@ -32,8 +32,8 @@ import jakarta.mail.NoSuchProviderException; import jakarta.mail.Session; import jakarta.mail.Transport; import jakarta.mail.internet.MimeMessage; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mail.MailAuthenticationException; import org.springframework.mail.MailException; import org.springframework.mail.MailParseException; @@ -80,28 +80,21 @@ public class JavaMailSenderImpl implements JavaMailSender { private Properties javaMailProperties = new Properties(); - @Nullable - private Session session; + private @Nullable Session session; - @Nullable - private String protocol; + private @Nullable String protocol; - @Nullable - private String host; + private @Nullable String host; private int port = DEFAULT_PORT; - @Nullable - private String username; + private @Nullable String username; - @Nullable - private String password; + private @Nullable String password; - @Nullable - private String defaultEncoding; + private @Nullable String defaultEncoding; - @Nullable - private FileTypeMap defaultFileTypeMap; + private @Nullable FileTypeMap defaultFileTypeMap; /** @@ -174,8 +167,7 @@ public class JavaMailSenderImpl implements JavaMailSender { /** * Return the mail protocol. */ - @Nullable - public String getProtocol() { + public @Nullable String getProtocol() { return this.protocol; } @@ -190,8 +182,7 @@ public class JavaMailSenderImpl implements JavaMailSender { /** * Return the mail server host. */ - @Nullable - public String getHost() { + public @Nullable String getHost() { return this.host; } @@ -229,8 +220,7 @@ public class JavaMailSenderImpl implements JavaMailSender { /** * Return the username for the account at the mail host. */ - @Nullable - public String getUsername() { + public @Nullable String getUsername() { return this.username; } @@ -252,8 +242,7 @@ public class JavaMailSenderImpl implements JavaMailSender { /** * Return the password for the account at the mail host. */ - @Nullable - public String getPassword() { + public @Nullable String getPassword() { return this.password; } @@ -270,8 +259,7 @@ public class JavaMailSenderImpl implements JavaMailSender { * Return the default encoding for {@link MimeMessage MimeMessages}, * or {@code null} if none. */ - @Nullable - public String getDefaultEncoding() { + public @Nullable String getDefaultEncoding() { return this.defaultEncoding; } @@ -296,8 +284,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() { + public @Nullable FileTypeMap getDefaultFileTypeMap() { return this.defaultFileTypeMap; } @@ -377,7 +364,7 @@ public class JavaMailSenderImpl implements JavaMailSender { * @throws org.springframework.mail.MailSendException * in case of failure when sending a message */ - protected void doSend(MimeMessage[] mimeMessages, @Nullable Object[] originalMessages) throws MailException { + protected void doSend(MimeMessage[] mimeMessages, Object @Nullable [] originalMessages) throws MailException { Map failedMessages = new LinkedHashMap<>(); Transport transport = null; 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 302a401f73..eea388cc1f 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 @@ -38,10 +38,10 @@ import jakarta.mail.internet.MimeMessage; import jakarta.mail.internet.MimeMultipart; import jakarta.mail.internet.MimePart; import jakarta.mail.internet.MimeUtility; +import org.jspecify.annotations.Nullable; 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.MimeTypeUtils; @@ -165,14 +165,11 @@ public class MimeMessageHelper { private final MimeMessage mimeMessage; - @Nullable - private MimeMultipart rootMimeMultipart; + private @Nullable MimeMultipart rootMimeMultipart; - @Nullable - private MimeMultipart mimeMultipart; + private @Nullable MimeMultipart mimeMultipart; - @Nullable - private final String encoding; + private final @Nullable String encoding; private FileTypeMap fileTypeMap; @@ -426,8 +423,7 @@ public class MimeMessageHelper { * @return the default encoding associated with the MimeMessage, * or {@code null} if none found */ - @Nullable - protected String getDefaultEncoding(MimeMessage mimeMessage) { + protected @Nullable String getDefaultEncoding(MimeMessage mimeMessage) { if (mimeMessage instanceof SmartMimeMessage smartMimeMessage) { return smartMimeMessage.getDefaultEncoding(); } @@ -437,8 +433,7 @@ public class MimeMessageHelper { /** * Return the specific character encoding used for this message, if any. */ - @Nullable - public String getEncoding() { + public @Nullable 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 e41d4a2265..09625057a8 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 @@ -19,8 +19,7 @@ package org.springframework.mail.javamail; import jakarta.activation.FileTypeMap; import jakarta.mail.Session; import jakarta.mail.internet.MimeMessage; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Special subclass of the standard JavaMail {@link MimeMessage}, carrying a @@ -39,11 +38,9 @@ import org.springframework.lang.Nullable; */ class SmartMimeMessage extends MimeMessage { - @Nullable - private final String defaultEncoding; + private final @Nullable String defaultEncoding; - @Nullable - private final FileTypeMap defaultFileTypeMap; + private final @Nullable FileTypeMap defaultFileTypeMap; /** @@ -64,16 +61,14 @@ class SmartMimeMessage extends MimeMessage { /** * Return the default encoding of this message, or {@code null} if none. */ - @Nullable - public final String getDefaultEncoding() { + public final @Nullable String getDefaultEncoding() { return this.defaultEncoding; } /** * Return the default FileTypeMap of this message, or {@code null} if none. */ - @Nullable - public final FileTypeMap getDefaultFileTypeMap() { + public final @Nullable 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 e5114480e0..280fd4f1d4 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,9 +3,7 @@ * Provides an extended JavaMailSender interface and a MimeMessageHelper * class for convenient population of a JavaMail MimeMessage. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mail.javamail; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a5d452deb9..fce30404d9 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,9 +2,7 @@ * Spring's generic mail infrastructure. * Concrete implementations are provided in the subpackages. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mail; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java index 73d12fab69..fe86676a7e 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java @@ -21,6 +21,7 @@ import java.util.Date; import java.util.Map; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; import org.quartz.CronTrigger; import org.quartz.JobDataMap; import org.quartz.JobDetail; @@ -30,7 +31,6 @@ import org.quartz.impl.triggers.CronTriggerImpl; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,43 +70,33 @@ public class CronTriggerFactoryBean implements FactoryBean, BeanNam ); - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String group; + private @Nullable String group; - @Nullable - private JobDetail jobDetail; + private @Nullable JobDetail jobDetail; private JobDataMap jobDataMap = new JobDataMap(); - @Nullable - private Date startTime; + private @Nullable Date startTime; private long startDelay = 0; - @Nullable - private String cronExpression; + private @Nullable String cronExpression; - @Nullable - private TimeZone timeZone; + private @Nullable TimeZone timeZone; - @Nullable - private String calendarName; + private @Nullable String calendarName; private int priority; private int misfireInstruction = CronTrigger.MISFIRE_INSTRUCTION_SMART_POLICY; - @Nullable - private String description; + private @Nullable String description; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private CronTrigger cronTrigger; + private @Nullable CronTrigger cronTrigger; /** @@ -281,8 +271,7 @@ public class CronTriggerFactoryBean implements FactoryBean, BeanNam @Override - @Nullable - public CronTrigger getObject() { + public @Nullable CronTrigger getObject() { return this.cronTrigger; } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java index 32ee0b90de..dc15170e86 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/JobDetailFactoryBean.java @@ -18,6 +18,7 @@ package org.springframework.scheduling.quartz; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobDetail; @@ -29,7 +30,6 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,14 +50,11 @@ import org.springframework.util.Assert; public class JobDetailFactoryBean implements FactoryBean, BeanNameAware, ApplicationContextAware, InitializingBean { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String group; + private @Nullable String group; - @Nullable - private Class jobClass; + private @Nullable Class jobClass; private JobDataMap jobDataMap = new JobDataMap(); @@ -65,20 +62,15 @@ public class JobDetailFactoryBean private boolean requestsRecovery = false; - @Nullable - private String description; + private @Nullable String description; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private String applicationContextJobDataKey; + private @Nullable String applicationContextJobDataKey; - @Nullable - private JobDetail jobDetail; + private @Nullable JobDetail jobDetail; /** @@ -218,8 +210,7 @@ public class JobDetailFactoryBean @Override - @Nullable - public JobDetail getObject() { + public @Nullable JobDetail getObject() { return this.jobDetail; } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java index fc8875b581..a12b979781 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalDataSourceJobStore.java @@ -23,6 +23,7 @@ import java.util.Locale; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; import org.quartz.SchedulerConfigException; import org.quartz.impl.jdbcjobstore.JobStoreCMT; import org.quartz.impl.jdbcjobstore.SimpleSemaphore; @@ -34,7 +35,6 @@ import org.quartz.utils.DBConnectionManager; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.MetaDataAccessException; -import org.springframework.lang.Nullable; /** * Subclass of Quartz's {@link JobStoreCMT} class that delegates to a Spring-managed @@ -86,8 +86,7 @@ public class LocalDataSourceJobStore extends JobStoreCMT { public static final String NON_TX_DATA_SOURCE_PREFIX = "springNonTxDataSource."; - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; @Override diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java index 6034e47822..23476846ae 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/LocalTaskExecutorThreadPool.java @@ -21,11 +21,11 @@ import java.util.concurrent.RejectedExecutionException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.quartz.SchedulerConfigException; import org.quartz.spi.ThreadPool; import org.springframework.aot.hint.annotation.Reflective; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -41,8 +41,7 @@ public class LocalTaskExecutorThreadPool implements ThreadPool { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Executor taskExecutor; + private @Nullable Executor taskExecutor; @Override diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java index d692c4bf74..1185b80508 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java @@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.quartz.DisallowConcurrentExecution; import org.quartz.Job; import org.quartz.JobDetail; @@ -36,7 +37,6 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.support.ArgumentConvertingMethodInvoker; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MethodInvoker; @@ -78,27 +78,21 @@ import org.springframework.util.MethodInvoker; public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethodInvoker implements FactoryBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, InitializingBean { - @Nullable - private String name; + private @Nullable String name; private String group = Scheduler.DEFAULT_GROUP; private boolean concurrent = true; - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private JobDetail jobDetail; + private @Nullable JobDetail jobDetail; /** @@ -199,8 +193,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod * Overridden to support the {@link #setTargetBeanName "targetBeanName"} feature. */ @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { Class targetClass = super.getTargetClass(); if (targetClass == null && this.targetBeanName != null) { Assert.state(this.beanFactory != null, "BeanFactory must be set when using 'targetBeanName'"); @@ -213,8 +206,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod * Overridden to support the {@link #setTargetBeanName "targetBeanName"} feature. */ @Override - @Nullable - public Object getTargetObject() { + public @Nullable Object getTargetObject() { Object targetObject = super.getTargetObject(); if (targetObject == null && this.targetBeanName != null) { Assert.state(this.beanFactory != null, "BeanFactory must be set when using 'targetBeanName'"); @@ -225,8 +217,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod @Override - @Nullable - public JobDetail getObject() { + public @Nullable JobDetail getObject() { return this.jobDetail; } @@ -249,8 +240,7 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod protected static final Log logger = LogFactory.getLog(MethodInvokingJob.class); - @Nullable - private MethodInvoker methodInvoker; + private @Nullable MethodInvoker methodInvoker; /** * Set the MethodInvoker to use. 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 996a598460..8be7e10533 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 @@ -22,12 +22,12 @@ import java.net.URL; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -44,8 +44,7 @@ public class ResourceLoaderClassLoadHelper implements ClassLoadHelper { protected static final Log logger = LogFactory.getLog(ResourceLoaderClassLoadHelper.class); - @Nullable - private ResourceLoader resourceLoader; + private @Nullable ResourceLoader resourceLoader; /** @@ -88,8 +87,7 @@ public class ResourceLoaderClassLoadHelper implements ClassLoadHelper { } @Override - @Nullable - public URL getResource(String name) { + public @Nullable URL getResource(String name) { Assert.state(this.resourceLoader != null, "ResourceLoaderClassLoadHelper not initialized"); Resource resource = this.resourceLoader.getResource(name); if (resource.exists()) { @@ -109,8 +107,7 @@ public class ResourceLoaderClassLoadHelper implements ClassLoadHelper { } @Override - @Nullable - public InputStream getResourceAsStream(String name) { + public @Nullable InputStream getResourceAsStream(String name) { Assert.state(this.resourceLoader != null, "ResourceLoaderClassLoadHelper not initialized"); Resource resource = this.resourceLoader.getResource(name); if (resource.exists()) { diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java index e6b1c7aa54..5947404b03 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.quartz.Calendar; import org.quartz.JobDetail; import org.quartz.JobListener; @@ -38,7 +39,6 @@ import org.quartz.xml.XMLSchedulingDataProcessor; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -63,32 +63,23 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { private boolean overwriteExistingJobs = false; - @Nullable - private String[] jobSchedulingDataLocations; + private String @Nullable [] jobSchedulingDataLocations; - @Nullable - private List jobDetails; + private @Nullable List jobDetails; - @Nullable - private Map calendars; + private @Nullable Map calendars; - @Nullable - private List triggers; + private @Nullable List triggers; - @Nullable - private SchedulerListener[] schedulerListeners; + private SchedulerListener @Nullable [] schedulerListeners; - @Nullable - private JobListener[] globalJobListeners; + private JobListener @Nullable [] globalJobListeners; - @Nullable - private TriggerListener[] globalTriggerListeners; + private TriggerListener @Nullable [] globalTriggerListeners; - @Nullable - private PlatformTransactionManager transactionManager; + private @Nullable PlatformTransactionManager transactionManager; - @Nullable - protected ResourceLoader resourceLoader; + protected @Nullable ResourceLoader resourceLoader; /** diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java index 83a8b47112..2893a8635d 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java @@ -16,6 +16,7 @@ package org.springframework.scheduling.quartz; +import org.jspecify.annotations.Nullable; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.impl.SchedulerRepository; @@ -24,7 +25,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -40,14 +40,11 @@ import org.springframework.util.Assert; */ public class SchedulerAccessorBean extends SchedulerAccessor implements BeanFactoryAware, InitializingBean { - @Nullable - private String schedulerName; + private @Nullable String schedulerName; - @Nullable - private Scheduler scheduler; + private @Nullable Scheduler scheduler; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java index ddc740a25b..30b6bee93b 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBean.java @@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.SchedulerFactory; @@ -44,7 +45,6 @@ import org.springframework.context.SmartLifecycle; 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.scheduling.SchedulingException; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -119,8 +119,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe * @see #setApplicationContext * @see ResourceLoaderClassLoadHelper */ - @Nullable - public static ResourceLoader getConfigTimeResourceLoader() { + public static @Nullable ResourceLoader getConfigTimeResourceLoader() { return configTimeResourceLoaderHolder.get(); } @@ -133,8 +132,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe * @see #setTaskExecutor * @see LocalTaskExecutorThreadPool */ - @Nullable - public static Executor getConfigTimeTaskExecutor() { + public static @Nullable Executor getConfigTimeTaskExecutor() { return configTimeTaskExecutorHolder.get(); } @@ -147,8 +145,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe * @see #setDataSource * @see LocalDataSourceJobStore */ - @Nullable - public static DataSource getConfigTimeDataSource() { + public static @Nullable DataSource getConfigTimeDataSource() { return configTimeDataSourceHolder.get(); } @@ -161,43 +158,32 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe * @see #setNonTransactionalDataSource * @see LocalDataSourceJobStore */ - @Nullable - public static DataSource getConfigTimeNonTransactionalDataSource() { + public static @Nullable DataSource getConfigTimeNonTransactionalDataSource() { return configTimeNonTransactionalDataSourceHolder.get(); } - @Nullable - private SchedulerFactory schedulerFactory; + private @Nullable SchedulerFactory schedulerFactory; private Class schedulerFactoryClass = StdSchedulerFactory.class; - @Nullable - private String schedulerName; + private @Nullable String schedulerName; - @Nullable - private Resource configLocation; + private @Nullable Resource configLocation; - @Nullable - private Properties quartzProperties; + private @Nullable Properties quartzProperties; - @Nullable - private Executor taskExecutor; + private @Nullable Executor taskExecutor; - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; - @Nullable - private DataSource nonTransactionalDataSource; + private @Nullable DataSource nonTransactionalDataSource; - @Nullable - private Map schedulerContextMap; + private @Nullable Map schedulerContextMap; - @Nullable - private String applicationContextSchedulerContextKey; + private @Nullable String applicationContextSchedulerContextKey; - @Nullable - private JobFactory jobFactory; + private @Nullable JobFactory jobFactory; private boolean jobFactorySet = false; @@ -211,14 +197,11 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe private boolean waitForJobsToCompleteOnShutdown = false; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private Scheduler scheduler; + private @Nullable Scheduler scheduler; /** @@ -773,8 +756,7 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe } @Override - @Nullable - public Scheduler getObject() { + public @Nullable Scheduler getObject() { return this.scheduler; } diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java index ee5e43c05c..9030a61b04 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerFactoryBeanRuntimeHints.java @@ -16,13 +16,14 @@ package org.springframework.scheduling.quartz; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint.Builder; import org.springframework.aot.hint.TypeReference; import org.springframework.aot.hint.annotation.ReflectiveRuntimeHintsRegistrar; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java index e16a32f596..fe230490c4 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java @@ -19,6 +19,7 @@ package org.springframework.scheduling.quartz; import java.util.Date; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.quartz.Scheduler; @@ -28,7 +29,6 @@ import org.quartz.impl.triggers.SimpleTriggerImpl; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -77,19 +77,15 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT ); - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String group; + private @Nullable String group; - @Nullable - private JobDetail jobDetail; + private @Nullable JobDetail jobDetail; private JobDataMap jobDataMap = new JobDataMap(); - @Nullable - private Date startTime; + private @Nullable Date startTime; private long startDelay; @@ -101,14 +97,11 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea private int misfireInstruction = SimpleTrigger.MISFIRE_INSTRUCTION_SMART_POLICY; - @Nullable - private String description; + private @Nullable String description; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private SimpleTrigger simpleTrigger; + private @Nullable SimpleTrigger simpleTrigger; /** @@ -275,8 +268,7 @@ public class SimpleTriggerFactoryBean implements FactoryBean, Bea @Override - @Nullable - public SimpleTrigger getObject() { + public @Nullable SimpleTrigger getObject() { return this.simpleTrigger; } 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 2d48a2258a..cc20770935 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 @@ -16,6 +16,7 @@ package org.springframework.scheduling.quartz; +import org.jspecify.annotations.Nullable; import org.quartz.SchedulerContext; import org.quartz.spi.TriggerFiredBundle; @@ -24,7 +25,6 @@ import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.lang.Nullable; /** * Subclass of {@link AdaptableJobFactory} that also supports Spring-style @@ -46,14 +46,11 @@ import org.springframework.lang.Nullable; public class SpringBeanJobFactory extends AdaptableJobFactory implements ApplicationContextAware, SchedulerContextAware { - @Nullable - private String[] ignoredUnknownProperties; + private String @Nullable [] ignoredUnknownProperties; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private SchedulerContext schedulerContext; + private @Nullable SchedulerContext schedulerContext; /** 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 6ca38a3196..a7bbe32ec8 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,9 +5,7 @@ * Triggers as beans in a Spring context. Also provides * convenience classes for implementing Quartz Jobs. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling.quartz; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 5b0405c5f4..be9a8f1db7 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 @@ -33,12 +33,12 @@ import freemarker.template.SimpleHash; import freemarker.template.TemplateException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; /** @@ -81,28 +81,21 @@ public class FreeMarkerConfigurationFactory { protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Resource configLocation; + private @Nullable Resource configLocation; - @Nullable - private Properties freemarkerSettings; + private @Nullable Properties freemarkerSettings; - @Nullable - private Map freemarkerVariables; + private @Nullable Map freemarkerVariables; - @Nullable - private String defaultEncoding; + private @Nullable String defaultEncoding; private final List templateLoaders = new ArrayList<>(); - @Nullable - private List preTemplateLoaders; + private @Nullable List preTemplateLoaders; - @Nullable - private List postTemplateLoaders; + private @Nullable List postTemplateLoaders; - @Nullable - private String[] templateLoaderPaths; + private String @Nullable [] templateLoaderPaths; private ResourceLoader resourceLoader = new DefaultResourceLoader(); @@ -418,8 +411,7 @@ public class FreeMarkerConfigurationFactory { * @param templateLoaders the final List of {@code TemplateLoader} instances * @return the aggregate TemplateLoader */ - @Nullable - protected TemplateLoader getAggregateTemplateLoader(List templateLoaders) { + protected @Nullable TemplateLoader getAggregateTemplateLoader(List templateLoaders) { return switch (templateLoaders.size()) { case 0 -> { logger.debug("No FreeMarker TemplateLoaders specified"); diff --git a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactoryBean.java b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactoryBean.java index 6a35e066ec..796dc4bc6a 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/ui/freemarker/FreeMarkerConfigurationFactoryBean.java @@ -20,11 +20,11 @@ import java.io.IOException; import freemarker.template.Configuration; import freemarker.template.TemplateException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ResourceLoaderAware; -import org.springframework.lang.Nullable; /** * Factory bean that creates a FreeMarker {@link Configuration} and provides it @@ -57,8 +57,7 @@ import org.springframework.lang.Nullable; public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory implements FactoryBean, InitializingBean, ResourceLoaderAware { - @Nullable - private Configuration configuration; + private @Nullable Configuration configuration; @Override @@ -68,8 +67,7 @@ public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationF @Override - @Nullable - public Configuration getObject() { + public @Nullable Configuration getObject() { return this.configuration; } diff --git a/spring-context-support/src/main/java/org/springframework/ui/freemarker/SpringTemplateLoader.java b/spring-context-support/src/main/java/org/springframework/ui/freemarker/SpringTemplateLoader.java index 1749b0a37d..f58470949a 100644 --- a/spring-context-support/src/main/java/org/springframework/ui/freemarker/SpringTemplateLoader.java +++ b/spring-context-support/src/main/java/org/springframework/ui/freemarker/SpringTemplateLoader.java @@ -23,10 +23,10 @@ import java.io.Reader; import freemarker.cache.TemplateLoader; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; /** * FreeMarker {@link TemplateLoader} adapter that loads template files via a @@ -68,8 +68,7 @@ public class SpringTemplateLoader implements TemplateLoader { @Override - @Nullable - public Object findTemplateSource(String name) throws IOException { + public @Nullable Object findTemplateSource(String name) throws IOException { if (logger.isDebugEnabled()) { logger.debug("Looking for FreeMarker template with name [" + name + "]"); } 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 492946e899..20352c9f84 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,9 +3,7 @@ * FreeMarker * within a Spring application context. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.ui.freemarker; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 171616604d..03ae0ead6f 100644 --- a/spring-context/src/main/java/org/springframework/cache/Cache.java +++ b/spring-context/src/main/java/org/springframework/cache/Cache.java @@ -20,7 +20,7 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that defines common cache operations. @@ -65,8 +65,7 @@ public interface Cache { * @see #get(Object, Class) * @see #get(Object, Callable) */ - @Nullable - ValueWrapper get(Object key); + @Nullable ValueWrapper get(Object key); /** * Return the value to which this cache maps the specified key, @@ -86,8 +85,7 @@ public interface Cache { * @since 4.0 * @see #get(Object) */ - @Nullable - T get(Object key, @Nullable Class type); + @Nullable T get(Object key, @Nullable Class type); /** * Return the value to which this cache maps the specified key, obtaining @@ -105,8 +103,7 @@ public interface Cache { * @since 4.3 * @see #get(Object) */ - @Nullable - T get(Object key, Callable valueLoader); + @Nullable T get(Object key, Callable valueLoader); /** * Return the value to which this cache maps the specified key, @@ -136,8 +133,7 @@ public interface Cache { * @since 6.1 * @see #retrieve(Object, Supplier) */ - @Nullable - default CompletableFuture retrieve(Object key) { + default @Nullable CompletableFuture retrieve(Object key) { throw new UnsupportedOperationException( getClass().getName() + " does not support CompletableFuture-based retrieval"); } @@ -214,8 +210,7 @@ public interface Cache { * @since 4.1 * @see #put(Object, Object) */ - @Nullable - default ValueWrapper putIfAbsent(Object key, @Nullable Object value) { + default @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) { ValueWrapper existingValue = get(key); if (existingValue == null) { put(key, value); @@ -299,8 +294,7 @@ public interface Cache { /** * Return the actual value in the cache. */ - @Nullable - Object get(); + @Nullable Object get(); } @@ -312,16 +306,14 @@ public interface Cache { @SuppressWarnings("serial") class ValueRetrievalException extends RuntimeException { - @Nullable - private final Object key; + private final @Nullable Object key; public ValueRetrievalException(@Nullable Object key, Callable loader, @Nullable 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() { + public @Nullable 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 833715c63c..ca7af761d1 100644 --- a/spring-context/src/main/java/org/springframework/cache/CacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/CacheManager.java @@ -18,7 +18,7 @@ package org.springframework.cache; import java.util.Collection; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Spring's central cache manager SPI. @@ -39,8 +39,7 @@ public interface CacheManager { * @return the associated cache, or {@code null} if such a cache * does not exist or could be not created */ - @Nullable - Cache getCache(String name); + @Nullable Cache getCache(String name); /** * Get a collection of the cache names known by this manager. diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java b/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java index 37eede6f2a..a84df83d3d 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/AbstractCachingConfiguration.java @@ -20,6 +20,8 @@ import java.util.List; import java.util.function.Function; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.CacheManager; @@ -30,7 +32,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportAware; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.function.SingletonSupplier; @@ -47,20 +48,15 @@ import org.springframework.util.function.SingletonSupplier; @Configuration(proxyBeanMethods = false) public abstract class AbstractCachingConfiguration implements ImportAware { - @Nullable - protected AnnotationAttributes enableCaching; + protected @Nullable AnnotationAttributes enableCaching; - @Nullable - protected Supplier cacheManager; + protected @Nullable Supplier cacheManager; - @Nullable - protected Supplier cacheResolver; + protected @Nullable Supplier cacheResolver; - @Nullable - protected Supplier keyGenerator; + protected @Nullable Supplier keyGenerator; - @Nullable - protected Supplier errorHandler; + protected @Nullable Supplier errorHandler; @Override @@ -119,8 +115,7 @@ public abstract class AbstractCachingConfiguration implements ImportAware { * @param the type of the supplier * @return another supplier mapped by the specified function */ - @Nullable - public Supplier adapt(Function provider) { + public @Nullable Supplier adapt(Function provider) { return () -> { CachingConfigurer cachingConfigurer = this.supplier.get(); return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null); 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 8f26e688a6..439721958f 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 @@ -23,9 +23,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.AbstractFallbackCacheOperationSource; import org.springframework.cache.interceptor.CacheOperation; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -120,14 +121,12 @@ public class AnnotationCacheOperationSource extends AbstractFallbackCacheOperati } @Override - @Nullable - protected Collection findCacheOperations(Class clazz) { + protected @Nullable Collection findCacheOperations(Class clazz) { return determineCacheOperations(parser -> parser.parseCacheAnnotations(clazz)); } @Override - @Nullable - protected Collection findCacheOperations(Method method) { + protected @Nullable Collection findCacheOperations(Method method) { return determineCacheOperations(parser -> parser.parseCacheAnnotations(method)); } @@ -140,8 +139,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) { + protected @Nullable Collection determineCacheOperations(CacheOperationProvider provider) { Collection ops = null; for (CacheAnnotationParser parser : this.annotationParsers) { Collection annOps = provider.getCacheOperations(parser); @@ -195,8 +193,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); + @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 10231a1571..158da40e6d 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 @@ -19,8 +19,9 @@ package org.springframework.cache.annotation; import java.lang.reflect.Method; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheOperation; -import org.springframework.lang.Nullable; /** * Strategy interface for parsing known caching annotation types. @@ -64,8 +65,7 @@ public interface CacheAnnotationParser { * @return the configured caching operation, or {@code null} if none found * @see AnnotationCacheOperationSource#findCacheOperations(Class) */ - @Nullable - Collection parseCacheAnnotations(Class type); + @Nullable Collection parseCacheAnnotations(Class type); /** * Parse the cache definition for the given method, @@ -76,7 +76,6 @@ public interface CacheAnnotationParser { * @return the configured caching operation, or {@code null} if none found * @see AnnotationCacheOperationSource#findCacheOperations(Method) */ - @Nullable - Collection parseCacheAnnotations(Method 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 26b3afb46a..1d70fa54a2 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 @@ -16,11 +16,12 @@ package org.springframework.cache.annotation; +import org.jspecify.annotations.Nullable; + 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 @@ -66,8 +67,7 @@ public interface CachingConfigurer { * * See @{@link EnableCaching} for more complete examples. */ - @Nullable - default CacheManager cacheManager() { + default @Nullable CacheManager cacheManager() { return null; } @@ -94,8 +94,7 @@ public interface CachingConfigurer { * * See {@link EnableCaching} for more complete examples. */ - @Nullable - default CacheResolver cacheResolver() { + default @Nullable CacheResolver cacheResolver() { return null; } @@ -105,8 +104,7 @@ public interface CachingConfigurer { * is used. * See @{@link EnableCaching} for more complete examples. */ - @Nullable - default KeyGenerator keyGenerator() { + default @Nullable KeyGenerator keyGenerator() { return null; } @@ -116,8 +114,7 @@ public interface CachingConfigurer { * is used, which throws the exception back at the client. * See @{@link EnableCaching} for more complete examples. */ - @Nullable - default CacheErrorHandler errorHandler() { + default @Nullable CacheErrorHandler errorHandler() { return null; } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java index 16886ff13f..33aadd02c3 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurerSupport.java @@ -16,11 +16,12 @@ package org.springframework.cache.annotation; +import org.jspecify.annotations.Nullable; + 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; /** * An implementation of {@link CachingConfigurer} with empty methods allowing @@ -35,26 +36,22 @@ import org.springframework.lang.Nullable; public class CachingConfigurerSupport implements CachingConfigurer { @Override - @Nullable - public CacheManager cacheManager() { + public @Nullable CacheManager cacheManager() { return null; } @Override - @Nullable - public CacheResolver cacheResolver() { + public @Nullable CacheResolver cacheResolver() { return null; } @Override - @Nullable - public KeyGenerator keyGenerator() { + public @Nullable KeyGenerator keyGenerator() { return null; } @Override - @Nullable - public CacheErrorHandler errorHandler() { + public @Nullable CacheErrorHandler errorHandler() { return null; } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java index 49bf01e26d..5851f46bd0 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/SpringCacheAnnotationParser.java @@ -24,13 +24,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.interceptor.CacheEvictOperation; import org.springframework.cache.interceptor.CacheOperation; import org.springframework.cache.interceptor.CachePutOperation; import org.springframework.cache.interceptor.CacheableOperation; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -58,21 +59,18 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria } @Override - @Nullable - public Collection parseCacheAnnotations(Class type) { + public @Nullable Collection parseCacheAnnotations(Class type) { DefaultCacheConfig defaultConfig = new DefaultCacheConfig(type); return parseCacheAnnotations(defaultConfig, type); } @Override - @Nullable - public Collection parseCacheAnnotations(Method method) { + public @Nullable Collection parseCacheAnnotations(Method method) { DefaultCacheConfig defaultConfig = new DefaultCacheConfig(method.getDeclaringClass()); return parseCacheAnnotations(defaultConfig, method); } - @Nullable - private Collection parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) { + private @Nullable Collection parseCacheAnnotations(DefaultCacheConfig cachingConfig, AnnotatedElement ae) { Collection ops = parseCacheAnnotations(cachingConfig, ae, false); if (ops != null && ops.size() > 1) { // More than one operation found -> local declarations override interface-declared ones... @@ -84,8 +82,7 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria return ops; } - @Nullable - private Collection parseCacheAnnotations( + private @Nullable Collection parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection annotations = (localOnly ? @@ -232,17 +229,13 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria private final Class target; - @Nullable - private String[] cacheNames; + private String @Nullable [] cacheNames; - @Nullable - private String keyGenerator; + private @Nullable String keyGenerator; - @Nullable - private String cacheManager; + private @Nullable String cacheManager; - @Nullable - private String cacheResolver; + private @Nullable String cacheResolver; private boolean initialized = false; 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 0a53f33ac3..3c980e2b01 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,9 +3,7 @@ * Hooked into Spring's cache interception infrastructure via * {@link org.springframework.cache.interceptor.CacheOperationSource}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 0facea830e..d73913e336 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 @@ -23,9 +23,10 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ForkJoinPool; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.support.AbstractValueAdaptingCache; import org.springframework.core.serializer.support.SerializationDelegate; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -57,8 +58,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { private final ConcurrentMap store; - @Nullable - private final SerializationDelegate serialization; + private final @Nullable SerializationDelegate serialization; /** @@ -137,15 +137,13 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { } @Override - @Nullable - protected Object lookup(Object key) { + protected @Nullable Object lookup(Object key) { return this.store.get(key); } @SuppressWarnings("unchecked") @Override - @Nullable - public T get(Object key, Callable valueLoader) { + public @Nullable T get(Object key, Callable valueLoader) { return (T) fromStoreValue(this.store.computeIfAbsent(key, k -> { try { return toStoreValue(valueLoader.call()); @@ -157,8 +155,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { } @Override - @Nullable - public CompletableFuture retrieve(Object key) { + public @Nullable CompletableFuture retrieve(Object key) { Object value = lookup(key); return (value != null ? CompletableFuture.completedFuture( isAllowNullValues() ? toValueWrapper(value) : fromStoreValue(value)) : null); @@ -177,8 +174,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { } @Override - @Nullable - public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { + public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) { Object existing = this.store.putIfAbsent(key, toStoreValue(value)); return toValueWrapper(existing); } @@ -223,8 +219,7 @@ public class ConcurrentMapCache extends AbstractValueAdaptingCache { } @Override - @Nullable - protected Object fromStoreValue(@Nullable Object storeValue) { + protected @Nullable Object fromStoreValue(@Nullable Object storeValue) { if (storeValue != null && this.serialization != null) { try { return super.fromStoreValue(this.serialization.deserializeFromByteArray((byte[]) storeValue)); diff --git a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheFactoryBean.java b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheFactoryBean.java index b559e10b3d..ad8023f802 100644 --- a/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/cache/concurrent/ConcurrentMapCacheFactoryBean.java @@ -18,10 +18,11 @@ package org.springframework.cache.concurrent; import java.util.concurrent.ConcurrentMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -42,13 +43,11 @@ public class ConcurrentMapCacheFactoryBean private String name = ""; - @Nullable - private ConcurrentMap store; + private @Nullable ConcurrentMap store; private boolean allowNullValues = true; - @Nullable - private ConcurrentMapCache cache; + private @Nullable ConcurrentMapCache cache; /** @@ -92,8 +91,7 @@ public class ConcurrentMapCacheFactoryBean @Override - @Nullable - public ConcurrentMapCache getObject() { + public @Nullable ConcurrentMapCache getObject() { return this.cache; } 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 6dfa5a4eda..ef4a269360 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 @@ -24,11 +24,12 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + 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} @@ -60,8 +61,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA private boolean storeByValue = false; - @Nullable - private SerializationDelegate serialization; + private @Nullable SerializationDelegate serialization; /** @@ -166,8 +166,7 @@ public class ConcurrentMapCacheManager implements CacheManager, BeanClassLoaderA } @Override - @Nullable - public Cache getCache(String name) { + public @Nullable Cache getCache(String name) { Cache cache = this.cacheMap.get(name); if (cache == null && this.dynamic) { cache = this.cacheMap.computeIfAbsent(name, this::createConcurrentMapCache); 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 5c5feb58e6..fd7f64befa 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.cache.concurrent; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java index f2768059a0..c2e12c08ee 100644 --- a/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/cache/config/AnnotationDrivenCacheBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.cache.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.aop.config.AopNamespaceUtils; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.cache.interceptor.BeanFactoryCacheOperationSourceAdvisor; import org.springframework.cache.interceptor.CacheInterceptor; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -79,8 +79,7 @@ class AnnotationDrivenCacheBeanDefinitionParser implements BeanDefinitionParser * register an AutoProxyCreator} with the container as necessary. */ @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { String mode = element.getAttribute("mode"); if ("aspectj".equals(mode)) { // mode="aspectj" 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 c85dcad906..23a260609d 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 @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.TypedStringValue; @@ -36,7 +37,6 @@ 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; @@ -185,8 +185,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser { private final String method; - @Nullable - private String[] caches; + private String @Nullable [] caches; Props(Element root) { String defaultCache = root.getAttribute("cache"); @@ -231,8 +230,7 @@ class CacheAdviceParser extends AbstractSingleBeanDefinitionParser { return builder; } - @Nullable - String merge(Element element, ReaderContext readerCtx) { + @Nullable String merge(Element element, ReaderContext readerCtx) { String method = element.getAttribute(METHOD_ATTRIBUTE); if (StringUtils.hasText(method)) { return method.trim(); 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 b26305693b..39e10f5ebd 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,9 +4,7 @@ * org.springframework.cache.annotation.EnableCaching EnableCaching} * for details on code-based configuration without XML. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 84e36757d6..d8a3cc5675 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 @@ -20,8 +20,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; import org.springframework.util.function.SingletonSupplier; /** @@ -72,8 +73,7 @@ public abstract class AbstractCacheInvoker { * miss in case of error. * @see Cache#get(Object) */ - @Nullable - protected Cache.ValueWrapper doGet(Cache cache, Object key) { + protected Cache.@Nullable ValueWrapper doGet(Cache cache, Object key) { try { return cache.get(key); } @@ -91,8 +91,7 @@ public abstract class AbstractCacheInvoker { * @since 6.2 * @see Cache#get(Object, Callable) */ - @Nullable - protected T doGet(Cache cache, Object key, Callable valueLoader) { + protected @Nullable T doGet(Cache cache, Object key, Callable valueLoader) { try { return cache.get(key, valueLoader); } @@ -119,8 +118,7 @@ public abstract class AbstractCacheInvoker { * @since 6.2 * @see Cache#retrieve(Object) */ - @Nullable - protected CompletableFuture doRetrieve(Cache cache, Object key) { + protected @Nullable CompletableFuture doRetrieve(Cache cache, Object key) { try { return cache.retrieve(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 a54ed05f17..4cb9d228a4 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 @@ -20,10 +20,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import org.jspecify.annotations.Nullable; + 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; /** @@ -37,8 +38,7 @@ import org.springframework.util.Assert; */ public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean { - @Nullable - private CacheManager cacheManager; + private @Nullable CacheManager cacheManager; /** @@ -103,7 +103,6 @@ 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); + protected abstract @Nullable 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 2657232886..7928cdfd9c 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 @@ -25,10 +25,10 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; import org.springframework.core.MethodClassKey; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; @@ -78,8 +78,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera } @Override - @Nullable - public Collection getCacheOperations(Method method, @Nullable Class targetClass) { + public @Nullable Collection getCacheOperations(Method method, @Nullable Class targetClass) { return getCacheOperations(method, targetClass, true); } @@ -92,8 +91,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera * @return {@link CacheOperation} for this method, or {@code null} if the method * is not cacheable */ - @Nullable - private Collection getCacheOperations( + private @Nullable Collection getCacheOperations( Method method, @Nullable Class targetClass, boolean cacheNull) { if (ReflectionUtils.isObjectMethod(method)) { @@ -133,8 +131,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera return new MethodClassKey(method, targetClass); } - @Nullable - private Collection computeCacheOperations(Method method, @Nullable Class targetClass) { + private @Nullable Collection computeCacheOperations(Method method, @Nullable Class targetClass) { // Don't allow non-public methods, as configured. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; @@ -179,8 +176,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera * @param clazz the class to retrieve the cache operations for * @return all cache operations associated with this class, or {@code null} if none */ - @Nullable - protected abstract Collection findCacheOperations(Class clazz); + protected abstract @Nullable Collection findCacheOperations(Class clazz); /** * Subclasses need to implement this to return the cache operations for the @@ -188,8 +184,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera * @param method the method to retrieve the cache operations for * @return all cache operations associated with this method, or {@code null} if none */ - @Nullable - protected abstract Collection findCacheOperations(Method method); + protected abstract @Nullable Collection findCacheOperations(Method method); /** * Should only public methods be allowed to have caching semantics? 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 8f97d45f70..8928382553 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 @@ -30,6 +30,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.publisher.Flux; @@ -55,7 +56,6 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.SpringProperties; import org.springframework.expression.EvaluationContext; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -129,19 +129,15 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker private final CacheOperationExpressionEvaluator evaluator = new CacheOperationExpressionEvaluator( new CacheEvaluationContextFactory(this.originalEvaluationContext)); - @Nullable - private final ReactiveCachingHandler reactiveCachingHandler; + private final @Nullable ReactiveCachingHandler reactiveCachingHandler; - @Nullable - private CacheOperationSource cacheOperationSource; + private @Nullable CacheOperationSource cacheOperationSource; private SingletonSupplier keyGenerator = SingletonSupplier.of(SimpleKeyGenerator::new); - @Nullable - private SingletonSupplier cacheResolver; + private @Nullable SingletonSupplier cacheResolver; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; private boolean initialized = false; @@ -192,8 +188,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker /** * Return the CacheOperationSource for this cache aspect. */ - @Nullable - public CacheOperationSource getCacheOperationSource() { + public @Nullable CacheOperationSource getCacheOperationSource() { return this.cacheOperationSource; } @@ -228,8 +223,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker /** * Return the default {@link CacheResolver} that this cache aspect delegates to. */ - @Nullable - public CacheResolver getCacheResolver() { + public @Nullable CacheResolver getCacheResolver() { return SupplierUtils.resolve(this.cacheResolver); } @@ -397,8 +391,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker this.evaluator.clear(); } - @Nullable - protected Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { + protected @Nullable Object execute(CacheOperationInvoker invoker, Object target, Method method, Object[] args) { // Check whether aspect is enabled (to cope with cases where the AJ is pulled in automatically) if (this.initialized) { Class targetClass = AopProxyUtils.ultimateTargetClass(target); @@ -425,13 +418,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker * @return the result of the invocation * @see CacheOperationInvoker#invoke() */ - @Nullable - protected Object invokeOperation(CacheOperationInvoker invoker) { + protected @Nullable Object invokeOperation(CacheOperationInvoker invoker) { return invoker.invoke(); } - @Nullable - private Object execute(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { + private @Nullable Object execute(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { if (contexts.isSynchronized()) { // Special handling of synchronized invocation return executeSynchronized(invoker, method, contexts); @@ -449,8 +440,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return cacheHit; } - @Nullable - private Object executeSynchronized(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { + private @Nullable Object executeSynchronized(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { CacheOperationContext context = contexts.get(CacheableOperation.class).iterator().next(); if (isConditionPassing(context, CacheOperationExpressionEvaluator.NO_RESULT)) { Object key = generateKey(context, CacheOperationExpressionEvaluator.NO_RESULT); @@ -487,8 +477,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker * @return a {@link Cache.ValueWrapper} holding the cached value, * or {@code null} if none is found */ - @Nullable - private Object findCachedValue(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { + private @Nullable Object findCachedValue(CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { for (CacheOperationContext context : contexts.get(CacheableOperation.class)) { if (isConditionPassing(context, CacheOperationExpressionEvaluator.NO_RESULT)) { Object key = generateKey(context, CacheOperationExpressionEvaluator.NO_RESULT); @@ -509,8 +498,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return null; } - @Nullable - private Object findInCaches(CacheOperationContext context, Object key, + private @Nullable Object findInCaches(CacheOperationContext context, Object key, CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { for (Cache cache : context.getCaches()) { @@ -543,8 +531,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return null; } - @Nullable - private Object evaluate(@Nullable Object cacheHit, CacheOperationInvoker invoker, Method method, + private @Nullable Object evaluate(@Nullable Object cacheHit, CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { // Re-invocation in reactive pipeline after late cache hit determination? @@ -596,13 +583,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return returnValue; } - @Nullable - private Object unwrapCacheValue(@Nullable Object cacheValue) { + private @Nullable Object unwrapCacheValue(@Nullable Object cacheValue) { return (cacheValue instanceof Cache.ValueWrapper wrapper ? wrapper.get() : cacheValue); } - @Nullable - private Object wrapCacheValue(Method method, @Nullable Object cacheValue) { + private @Nullable Object wrapCacheValue(Method method, @Nullable Object cacheValue) { if (method.getReturnType() == Optional.class && (cacheValue == null || cacheValue.getClass() != Optional.class)) { return Optional.ofNullable(cacheValue); @@ -610,8 +595,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return cacheValue; } - @Nullable - private Object unwrapReturnValue(@Nullable Object returnValue) { + private @Nullable Object unwrapReturnValue(@Nullable Object returnValue) { return ObjectUtils.unwrapOptional(returnValue); } @@ -633,8 +617,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return (cachePutContexts.size() != excluded.size()); } - @Nullable - private Object processCacheEvicts(Collection contexts, boolean beforeInvocation, + private @Nullable Object processCacheEvicts(Collection contexts, boolean beforeInvocation, @Nullable Object result) { if (contexts.isEmpty()) { @@ -841,7 +824,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker private final CacheOperationMetadata metadata; - private final Object[] args; + private final @Nullable Object[] args; private final Object target; @@ -849,13 +832,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker private final Collection cacheNames; - @Nullable - private Boolean conditionPassing; + private @Nullable Boolean conditionPassing; - @Nullable - private Object key; + private @Nullable Object key; - public CacheOperationContext(CacheOperationMetadata metadata, Object[] args, Object target) { + public CacheOperationContext(CacheOperationMetadata metadata, @Nullable Object[] args, Object target) { this.metadata = metadata; this.args = extractArgs(metadata.method, args); this.target = target; @@ -879,11 +860,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } @Override - public Object[] getArgs() { + public @Nullable Object[] getArgs() { return this.args; } - private Object[] extractArgs(Method method, Object[] args) { + private @Nullable Object[] extractArgs(Method method, @Nullable Object[] args) { if (!method.isVarArgs()) { return args; } @@ -926,8 +907,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker /** * Compute the key for the given caching operation. */ - @Nullable - protected Object generateKey(@Nullable Object result) { + protected @Nullable Object generateKey(@Nullable Object result) { if (StringUtils.hasText(this.metadata.operation.getKey())) { EvaluationContext evaluationContext = createEvaluationContext(result); this.key = evaluator.key(this.metadata.operation.getKey(), this.metadata.methodKey, evaluationContext); @@ -943,8 +923,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker * @return generated key * @since 6.1.2 */ - @Nullable - protected Object getGeneratedKey() { + protected @Nullable Object getGeneratedKey() { return this.key; } @@ -1018,8 +997,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker this.context = context; } - @Nullable - public Object apply(@Nullable Object result) { + public @Nullable Object apply(@Nullable Object result) { if (result instanceof CompletableFuture future) { return future.whenComplete((value, ex) -> { if (ex == null) { @@ -1097,8 +1075,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker private final ReactiveAdapterRegistry registry = ReactiveAdapterRegistry.getSharedInstance(); - @Nullable - public Object executeSynchronized(CacheOperationInvoker invoker, Method method, Cache cache, Object key) { + public @Nullable Object executeSynchronized(CacheOperationInvoker invoker, Method method, Cache cache, Object key) { ReactiveAdapter adapter = this.registry.getAdapter(method.getReturnType()); if (adapter != null) { if (adapter.isMultiValue()) { @@ -1127,8 +1104,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker return NOT_HANDLED; } - @Nullable - public Object processCacheEvicts(List contexts, @Nullable Object result) { + public @Nullable Object processCacheEvicts(List contexts, @Nullable Object result) { ReactiveAdapter adapter = (result != null ? this.registry.getAdapter(result.getClass()) : null); if (adapter != null) { return adapter.fromPublisher(Mono.from(adapter.toPublisher(result)) @@ -1138,8 +1114,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker } @SuppressWarnings({ "unchecked", "rawtypes" }) - @Nullable - public Object findInCaches(CacheOperationContext context, Cache cache, Object key, + public @Nullable Object findInCaches(CacheOperationContext context, Cache cache, Object key, CacheOperationInvoker invoker, Method method, CacheOperationContexts contexts) { ReactiveAdapter adapter = this.registry.getAdapter(context.getMethod().getReturnType()); @@ -1188,8 +1163,7 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker (data != null ? Flux.just(data) : Flux.empty())); } - @Nullable - public Object processPutRequest(CachePutRequest request, @Nullable Object result) { + public @Nullable Object processPutRequest(CachePutRequest request, @Nullable Object result) { ReactiveAdapter adapter = (result != null ? this.registry.getAdapter(result.getClass()) : null); if (adapter != null) { if (adapter.isMultiValue()) { diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheErrorHandler.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheErrorHandler.java index a31ad42731..20b33f5e0b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheErrorHandler.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheErrorHandler.java @@ -16,8 +16,9 @@ package org.springframework.cache.interceptor; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; /** * A strategy for handling cache-related errors. In most cases, any diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContext.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContext.java index 29604d91b6..d00f8cf903 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContext.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContext.java @@ -20,9 +20,10 @@ import java.lang.reflect.Method; import java.util.HashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.context.expression.MethodBasedEvaluationContext; import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.lang.Nullable; /** * Cache-specific evaluation context that adds method parameters as SpEL @@ -47,7 +48,7 @@ class CacheEvaluationContext extends MethodBasedEvaluationContext { private final Set unavailableVariables = new HashSet<>(1); - CacheEvaluationContext(Object rootObject, Method method, Object[] arguments, + CacheEvaluationContext(Object rootObject, Method method, @Nullable Object[] arguments, ParameterNameDiscoverer parameterNameDiscoverer) { super(rootObject, method, arguments, parameterNameDiscoverer); @@ -70,8 +71,7 @@ class CacheEvaluationContext extends MethodBasedEvaluationContext { * Load the param information only when needed. */ @Override - @Nullable - public Object lookupVariable(String name) { + public @Nullable Object lookupVariable(String name) { if (this.unavailableVariables.contains(name)) { throw new VariableNotAvailableException(name); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContextFactory.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContextFactory.java index 327cfd4d97..d417f4b80b 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContextFactory.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheEvaluationContextFactory.java @@ -19,10 +19,11 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.function.SingletonSupplier; /** @@ -36,8 +37,7 @@ class CacheEvaluationContextFactory { private final StandardEvaluationContext originalContext; - @Nullable - private Supplier parameterNameDiscoverer; + private @Nullable Supplier parameterNameDiscoverer; CacheEvaluationContextFactory(StandardEvaluationContext originalContext) { this.originalContext = originalContext; @@ -62,7 +62,7 @@ class CacheEvaluationContextFactory { * @return a context suitable for this cache operation */ public CacheEvaluationContext forOperation(CacheExpressionRootObject rootObject, - Method targetMethod, Object[] args) { + Method targetMethod, @Nullable Object[] args) { CacheEvaluationContext evaluationContext = new CacheEvaluationContext( rootObject, targetMethod, args, getParameterNameDiscoverer()); diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheExpressionRootObject.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheExpressionRootObject.java index 32f55cf775..7fc9db8786 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheExpressionRootObject.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheExpressionRootObject.java @@ -19,6 +19,8 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; /** @@ -34,7 +36,7 @@ class CacheExpressionRootObject { private final Method method; - private final Object[] args; + private final @Nullable Object[] args; private final Object target; @@ -42,7 +44,7 @@ class CacheExpressionRootObject { public CacheExpressionRootObject( - Collection caches, Method method, Object[] args, Object target, Class targetClass) { + Collection caches, Method method, @Nullable Object[] args, Object target, Class targetClass) { this.method = method; this.target = target; @@ -64,7 +66,7 @@ class CacheExpressionRootObject { return this.method.getName(); } - public Object[] getArgs() { + public @Nullable Object[] getArgs() { return this.args; } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java index 2f1f56f14a..cc06a5e275 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheInterceptor.java @@ -21,8 +21,8 @@ import java.lang.reflect.Method; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -46,8 +46,7 @@ import org.springframework.util.Assert; public class CacheInterceptor extends CacheAspectSupport implements MethodInterceptor, Serializable { @Override - @Nullable - public Object invoke(final MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(final MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); CacheOperationInvoker aopAllianceInvoker = () -> { diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java index a906e895b3..52f2a50402 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperation.java @@ -19,7 +19,8 @@ package org.springframework.cache.interceptor; import java.util.Collections; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; 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 13a49ea102..9a68c438bd 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 @@ -21,12 +21,13 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.context.expression.AnnotatedElementKey; 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. @@ -85,7 +86,7 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator { * @return the evaluation context */ public EvaluationContext createEvaluationContext(Collection caches, - Method method, Object[] args, Object target, Class targetClass, Method targetMethod, + Method method, @Nullable Object[] args, Object target, Class targetClass, Method targetMethod, @Nullable Object result) { CacheExpressionRootObject rootObject = new CacheExpressionRootObject( @@ -101,8 +102,7 @@ class CacheOperationExpressionEvaluator extends CachedExpressionEvaluator { return evaluationContext; } - @Nullable - public Object key(String keyExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) { + public @Nullable Object key(String keyExpression, AnnotatedElementKey methodKey, EvaluationContext evalContext) { return getExpression(this.keyCache, methodKey, keyExpression).getValue(evalContext); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvocationContext.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvocationContext.java index c459a09aea..6db02e3c97 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvocationContext.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvocationContext.java @@ -18,6 +18,8 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + /** * Representation of the context of the invocation of a cache operation. * @@ -48,6 +50,6 @@ public interface CacheOperationInvocationContext { /** * Return the argument list used to invoke the method. */ - Object[] getArgs(); + @Nullable Object[] getArgs(); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java index e37736480e..00144c97b2 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheOperationInvoker.java @@ -16,7 +16,7 @@ package org.springframework.cache.interceptor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract the invocation of a cache operation. @@ -38,8 +38,7 @@ public interface CacheOperationInvoker { * @return the result of the operation * @throws ThrowableWrapper if an error occurred while invoking the operation */ - @Nullable - Object invoke() throws ThrowableWrapper; + @Nullable Object invoke() throws ThrowableWrapper; /** 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 601fd4dbb4..6a923fcdee 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,7 +19,8 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; import java.util.Collection; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; /** @@ -72,7 +73,6 @@ 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 */ - @Nullable - Collection getCacheOperations(Method method, @Nullable 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 4b9054b10e..a90daa6616 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 @@ -19,10 +19,11 @@ package org.springframework.cache.interceptor; import java.io.Serializable; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; import org.springframework.aop.support.StaticMethodMatcherPointcut; import org.springframework.cache.CacheManager; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -37,8 +38,7 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") final class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { - @Nullable - private CacheOperationSource cacheOperationSource; + private @Nullable CacheOperationSource cacheOperationSource; public CacheOperationSourcePointcut() { @@ -87,8 +87,7 @@ final class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut imp return (cacheOperationSource == null || cacheOperationSource.isCandidateClass(clazz)); } - @Nullable - private CacheOperationSource getCacheOperationSource() { + private @Nullable CacheOperationSource getCacheOperationSource() { return cacheOperationSource; } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CachePutOperation.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CachePutOperation.java index 4b94ac5edf..29e1948acc 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CachePutOperation.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CachePutOperation.java @@ -16,7 +16,7 @@ package org.springframework.cache.interceptor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Class describing a cache 'put' operation. @@ -28,8 +28,7 @@ import org.springframework.lang.Nullable; */ public class CachePutOperation extends CacheOperation { - @Nullable - private final String unless; + private final @Nullable String unless; /** @@ -42,8 +41,7 @@ public class CachePutOperation extends CacheOperation { } - @Nullable - public String getUnless() { + public @Nullable String getUnless() { return this.unless; } @@ -54,8 +52,7 @@ public class CachePutOperation extends CacheOperation { */ public static class Builder extends CacheOperation.Builder { - @Nullable - private String unless; + private @Nullable String unless; public void setUnless(String unless) { this.unless = unless; diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheableOperation.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheableOperation.java index 9f7fcc2e97..02a71682c7 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CacheableOperation.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CacheableOperation.java @@ -16,7 +16,7 @@ package org.springframework.cache.interceptor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Class describing a cache 'cacheable' operation. @@ -28,8 +28,7 @@ import org.springframework.lang.Nullable; */ public class CacheableOperation extends CacheOperation { - @Nullable - private final String unless; + private final @Nullable String unless; private final boolean sync; @@ -45,8 +44,7 @@ public class CacheableOperation extends CacheOperation { } - @Nullable - public String getUnless() { + public @Nullable String getUnless() { return this.unless; } @@ -61,8 +59,7 @@ public class CacheableOperation extends CacheOperation { */ public static class Builder extends CacheOperation.Builder { - @Nullable - private String unless; + private @Nullable String unless; private boolean sync; diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/CompositeCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/CompositeCacheOperationSource.java index 9e1387a9ca..b54d75083d 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/CompositeCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/CompositeCacheOperationSource.java @@ -21,7 +21,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -77,8 +78,7 @@ public class CompositeCacheOperationSource implements CacheOperationSource, Seri } @Override - @Nullable - public Collection getCacheOperations(Method method, @Nullable Class targetClass) { + public @Nullable Collection getCacheOperations(Method method, @Nullable Class targetClass) { Collection ops = null; for (CacheOperationSource source : this.cacheOperationSources) { Collection cacheOperations = source.getCacheOperations(method, targetClass); diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/KeyGenerator.java b/spring-context/src/main/java/org/springframework/cache/interceptor/KeyGenerator.java index 2d99e4994d..a767b339f3 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/KeyGenerator.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/KeyGenerator.java @@ -18,6 +18,8 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + /** * Cache key generator. Used for creating a key based on the given method * (used as context) and its parameters. @@ -37,6 +39,6 @@ public interface KeyGenerator { * @param params the method parameters (with any var-args expanded) * @return a generated key */ - Object generate(Object target, Method method, Object... params); + Object generate(Object target, Method method, @Nullable Object... params); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java b/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java index a0d2a4ccd7..5f71eb7612 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/LoggingCacheErrorHandler.java @@ -20,9 +20,9 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java b/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java index 67644f5e92..6798ba797a 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/NameMatchCacheOperationSource.java @@ -24,8 +24,8 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.PatternMatchUtils; @@ -75,8 +75,7 @@ public class NameMatchCacheOperationSource implements CacheOperationSource, Seri } @Override - @Nullable - public Collection getCacheOperations(Method method, @Nullable Class targetClass) { + public @Nullable Collection getCacheOperations(Method method, @Nullable Class targetClass) { // look for direct name match String methodName = method.getName(); Collection ops = this.nameMap.get(methodName); diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java b/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java index 61cfc4b469..71b681ba27 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/NamedCacheResolver.java @@ -19,8 +19,9 @@ package org.springframework.cache.interceptor; import java.util.Collection; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.CacheManager; -import org.springframework.lang.Nullable; /** * A {@link CacheResolver} that forces the resolution to a configurable @@ -31,8 +32,7 @@ import org.springframework.lang.Nullable; */ public class NamedCacheResolver extends AbstractCacheResolver { - @Nullable - private Collection cacheNames; + private @Nullable Collection cacheNames; public NamedCacheResolver() { @@ -52,8 +52,7 @@ public class NamedCacheResolver extends AbstractCacheResolver { } @Override - @Nullable - protected Collection getCacheNames(CacheOperationInvocationContext context) { + protected @Nullable Collection getCacheNames(CacheOperationInvocationContext context) { return this.cacheNames; } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheErrorHandler.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheErrorHandler.java index 99ba252371..9c3dc0b6de 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheErrorHandler.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheErrorHandler.java @@ -16,8 +16,9 @@ package org.springframework.cache.interceptor; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; /** * A simple {@link CacheErrorHandler} that does not handle the diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheResolver.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheResolver.java index 3c22f3e328..1edd47cd2a 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheResolver.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleCacheResolver.java @@ -18,9 +18,10 @@ package org.springframework.cache.interceptor; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; -import org.springframework.lang.Nullable; /** * A simple {@link CacheResolver} that resolves the {@link Cache} instance(s) @@ -62,8 +63,7 @@ public class SimpleCacheResolver extends AbstractCacheResolver { * @return the SimpleCacheResolver ({@code null} if the CacheManager was {@code null}) * @since 5.1 */ - @Nullable - static SimpleCacheResolver of(@Nullable CacheManager cacheManager) { + static @Nullable SimpleCacheResolver of(@Nullable CacheManager cacheManager) { return (cacheManager != null ? new SimpleCacheResolver(cacheManager) : null); } diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java index d0f2a64ce8..760a7f7dbe 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKey.java @@ -21,7 +21,8 @@ import java.io.ObjectInputStream; import java.io.Serializable; import java.util.Arrays; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -41,7 +42,7 @@ public class SimpleKey implements Serializable { public static final SimpleKey EMPTY = new SimpleKey(); - private final Object[] params; + private final @Nullable Object[] params; // Effectively final, just re-calculated on deserialization private transient int hashCode; @@ -51,7 +52,7 @@ public class SimpleKey implements Serializable { * Create a new {@link SimpleKey} instance. * @param elements the elements of the key */ - public SimpleKey(Object... elements) { + public SimpleKey(@Nullable Object... elements) { Assert.notNull(elements, "Elements must not be null"); this.params = elements.clone(); // Pre-calculate hashCode field diff --git a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java index c2365ad9e6..aa16ae05c2 100644 --- a/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java +++ b/spring-context/src/main/java/org/springframework/cache/interceptor/SimpleKeyGenerator.java @@ -19,6 +19,8 @@ package org.springframework.cache.interceptor; import java.lang.reflect.Method; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + import org.springframework.core.KotlinDetector; /** @@ -41,7 +43,8 @@ import org.springframework.core.KotlinDetector; public class SimpleKeyGenerator implements KeyGenerator { @Override - public Object generate(Object target, Method method, Object... params) { + @SuppressWarnings("NullAway") + public Object generate(Object target, Method method, @Nullable Object... params) { return generateKey((KotlinDetector.isSuspendingFunction(method) ? Arrays.copyOf(params, params.length - 1) : params)); } @@ -49,7 +52,7 @@ public class SimpleKeyGenerator implements KeyGenerator { /** * Generate a key based on the specified parameters. */ - public static Object generateKey(Object... params) { + public static Object generateKey(@Nullable Object... params) { if (params.length == 0) { return SimpleKey.EMPTY; } 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 97810d21f6..6ec6cba01b 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,9 +3,7 @@ * Builds on the AOP infrastructure in org.springframework.aop.framework. * Any POJO can be cache-advised with Spring. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.interceptor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 dbb69eaa2f..cd14eb950c 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,9 +2,7 @@ * Spring's generic cache abstraction. * Concrete implementations are provided in the subpackages. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d1e7decdd9..b0eab7674e 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 @@ -23,10 +23,11 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.jspecify.annotations.Nullable; + 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.CollectionUtils; /** @@ -86,8 +87,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing // Lazy cache initialization on access @Override - @Nullable - public Cache getCache(String name) { + public @Nullable Cache getCache(String name) { // Quick check for existing cache... Cache cache = this.cacheMap.get(name); if (cache != null) { @@ -128,8 +128,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing * @see #getCache(String) * @see #getMissingCache(String) */ - @Nullable - protected final Cache lookupCache(String name) { + protected final @Nullable Cache lookupCache(String name) { return this.cacheMap.get(name); } @@ -172,8 +171,7 @@ public abstract class AbstractCacheManager implements CacheManager, Initializing * @since 4.1 * @see #getCache(String) */ - @Nullable - protected Cache getMissingCache(String name) { + protected @Nullable 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 e9a5d4f081..e5012b5422 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 @@ -16,8 +16,9 @@ package org.springframework.cache.support; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; /** * Common base class for {@link Cache} implementations that need to adapt @@ -53,15 +54,13 @@ public abstract class AbstractValueAdaptingCache implements Cache { } @Override - @Nullable - public ValueWrapper get(Object key) { + public @Nullable ValueWrapper get(Object key) { return toValueWrapper(lookup(key)); } @Override @SuppressWarnings("unchecked") - @Nullable - public T get(Object key, @Nullable Class type) { + public @Nullable T get(Object key, @Nullable Class type) { Object value = fromStoreValue(lookup(key)); if (value != null && type != null && !type.isInstance(value)) { throw new IllegalStateException( @@ -75,8 +74,7 @@ public abstract class AbstractValueAdaptingCache implements Cache { * @param key the key whose associated value is to be returned * @return the raw store value for the key, or {@code null} if none */ - @Nullable - protected abstract Object lookup(Object key); + protected abstract @Nullable Object lookup(Object key); /** @@ -85,8 +83,7 @@ public abstract class AbstractValueAdaptingCache implements Cache { * @param storeValue the store value * @return the value to return to the user */ - @Nullable - protected Object fromStoreValue(@Nullable Object storeValue) { + protected @Nullable Object fromStoreValue(@Nullable Object storeValue) { if (this.allowNullValues && storeValue == NullValue.INSTANCE) { return null; } @@ -117,8 +114,7 @@ public abstract class AbstractValueAdaptingCache implements Cache { * @param storeValue the original value * @return the wrapped value */ - @Nullable - protected Cache.ValueWrapper toValueWrapper(@Nullable Object storeValue) { + protected Cache.@Nullable ValueWrapper toValueWrapper(@Nullable Object storeValue) { return (storeValue != null ? new SimpleValueWrapper(fromStoreValue(storeValue)) : null); } diff --git a/spring-context/src/main/java/org/springframework/cache/support/CompositeCacheManager.java b/spring-context/src/main/java/org/springframework/cache/support/CompositeCacheManager.java index 25f0bf12ad..f4f051a7f2 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/CompositeCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/support/CompositeCacheManager.java @@ -24,10 +24,11 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; -import org.springframework.lang.Nullable; /** * Composite {@link CacheManager} implementation that iterates over @@ -99,8 +100,7 @@ public class CompositeCacheManager implements CacheManager, InitializingBean { @Override - @Nullable - public Cache getCache(String name) { + public @Nullable Cache getCache(String name) { for (CacheManager cacheManager : this.cacheManagers) { Cache cache = cacheManager.getCache(name); if (cache != null) { diff --git a/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java b/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java index b8746e97f9..115eedb5e8 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NoOpCache.java @@ -20,8 +20,9 @@ import java.util.concurrent.Callable; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -60,20 +61,17 @@ public class NoOpCache implements Cache { } @Override - @Nullable - public ValueWrapper get(Object key) { + public @Nullable ValueWrapper get(Object key) { return null; } @Override - @Nullable - public T get(Object key, @Nullable Class type) { + public @Nullable T get(Object key, @Nullable Class type) { return null; } @Override - @Nullable - public T get(Object key, Callable valueLoader) { + public @Nullable T get(Object key, Callable valueLoader) { try { return valueLoader.call(); } @@ -83,8 +81,7 @@ public class NoOpCache implements Cache { } @Override - @Nullable - public CompletableFuture retrieve(Object key) { + public @Nullable CompletableFuture retrieve(Object key) { return null; } @@ -98,8 +95,7 @@ public class NoOpCache implements Cache { } @Override - @Nullable - public ValueWrapper putIfAbsent(Object key, @Nullable Object value) { + public @Nullable ValueWrapper putIfAbsent(Object key, @Nullable Object value) { return null; } diff --git a/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java b/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java index 58d914717d..ff2e8bbabd 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NoOpCacheManager.java @@ -23,9 +23,10 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; -import org.springframework.lang.Nullable; /** * A basic, no operation {@link CacheManager} implementation suitable @@ -51,8 +52,7 @@ public class NoOpCacheManager implements CacheManager { * Additionally, the request cache will be remembered by the manager for consistency. */ @Override - @Nullable - public Cache getCache(String name) { + public @Nullable Cache getCache(String name) { Cache cache = this.caches.get(name); if (cache == null) { this.caches.computeIfAbsent(name, NoOpCache::new); diff --git a/spring-context/src/main/java/org/springframework/cache/support/NullValue.java b/spring-context/src/main/java/org/springframework/cache/support/NullValue.java index cc60aa47f8..01938a06d3 100644 --- a/spring-context/src/main/java/org/springframework/cache/support/NullValue.java +++ b/spring-context/src/main/java/org/springframework/cache/support/NullValue.java @@ -18,7 +18,7 @@ package org.springframework.cache.support; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple serializable class that serves as a {@code null} replacement 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 460d27a049..0eb7c3c525 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 @@ -18,8 +18,9 @@ package org.springframework.cache.support; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache.ValueWrapper; -import org.springframework.lang.Nullable; /** * Straightforward implementation of {@link org.springframework.cache.Cache.ValueWrapper}, @@ -30,8 +31,7 @@ import org.springframework.lang.Nullable; */ public class SimpleValueWrapper implements ValueWrapper { - @Nullable - private final Object value; + private final @Nullable Object value; /** @@ -47,8 +47,7 @@ public class SimpleValueWrapper implements ValueWrapper { * Simply returns the value as given at construction time. */ @Override - @Nullable - public Object get() { + public @Nullable Object get() { return this.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 8e82da0127..8b3a4173c7 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,9 +2,7 @@ * Support classes for the org.springframework.cache package. * Provides abstract classes for cache managers and caches. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.cache.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ed5270db78..1c22b0d5fc 100644 --- a/spring-context/src/main/java/org/springframework/context/ApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ApplicationContext.java @@ -16,12 +16,13 @@ package org.springframework.context; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.HierarchicalBeanFactory; 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. @@ -62,8 +63,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(); + @Nullable String getId(); /** * Return a name for the deployed application that this context belongs to. @@ -88,8 +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(); + @Nullable ApplicationContext getParent(); /** * Expose AutowireCapableBeanFactory functionality for this context. 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 2861196a54..d33f146834 100644 --- a/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/ConfigurableApplicationContext.java @@ -19,6 +19,8 @@ package org.springframework.context; import java.io.Closeable; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanFactoryPostProcessor; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -26,7 +28,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; import org.springframework.core.io.ProtocolResolver; import org.springframework.core.metrics.ApplicationStartup; -import org.springframework.lang.Nullable; /** * SPI interface to be implemented by most if not all application contexts. 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 2949a99c79..8e30cae763 100644 --- a/spring-context/src/main/java/org/springframework/context/HierarchicalMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/HierarchicalMessageSource.java @@ -16,7 +16,7 @@ package org.springframework.context; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Sub-interface of MessageSource to be implemented by objects that @@ -39,7 +39,6 @@ public interface HierarchicalMessageSource extends MessageSource { /** * Return the parent of this MessageSource, or {@code null} if none. */ - @Nullable - MessageSource getParentMessageSource(); + @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 fd7ecbe23b..629ae459f2 100644 --- a/spring-context/src/main/java/org/springframework/context/MessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/MessageSource.java @@ -18,7 +18,7 @@ package org.springframework.context; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for resolving messages, with support for the parameterization @@ -54,8 +54,7 @@ public interface MessageSource { * @see #getMessage(MessageSourceResolvable, Locale) * @see java.text.MessageFormat */ - @Nullable - String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale); + @Nullable String getMessage(String code, Object @Nullable [] args, @Nullable String defaultMessage, Locale locale); /** * Try to resolve the message. Treat as an error if the message can't be found. @@ -71,7 +70,7 @@ public interface MessageSource { * @see #getMessage(MessageSourceResolvable, Locale) * @see java.text.MessageFormat */ - String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException; + String getMessage(String code, Object @Nullable [] 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 6908b85edd..11486fd6dc 100644 --- a/spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java +++ b/spring-context/src/main/java/org/springframework/context/MessageSourceResolvable.java @@ -16,7 +16,7 @@ package org.springframework.context; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface for objects that are suitable for message resolution in a @@ -37,8 +37,7 @@ public interface MessageSourceResolvable { * they should get tried. The last code will therefore be the default one. * @return a String array of codes which are associated with this message */ - @Nullable - String[] getCodes(); + String @Nullable [] getCodes(); /** * Return the array of arguments to be used to resolve this message. @@ -47,8 +46,7 @@ public interface MessageSourceResolvable { * placeholders within the message text * @see java.text.MessageFormat */ - @Nullable - default Object[] getArguments() { + default Object @Nullable [] getArguments() { return null; } @@ -61,8 +59,7 @@ public interface MessageSourceResolvable { * for this particular message. * @return the default message, or {@code null} if no default */ - @Nullable - default String getDefaultMessage() { + default @Nullable String getDefaultMessage() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/PayloadApplicationEvent.java b/spring-context/src/main/java/org/springframework/context/PayloadApplicationEvent.java index c737fc8764..dd91d5aff1 100644 --- a/spring-context/src/main/java/org/springframework/context/PayloadApplicationEvent.java +++ b/spring-context/src/main/java/org/springframework/context/PayloadApplicationEvent.java @@ -18,9 +18,10 @@ package org.springframework.context; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableTypeProvider; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 bc2def951f..69ccfe579a 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 @@ -18,10 +18,11 @@ package org.springframework.context.annotation; import java.lang.annotation.Annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.GenericTypeResolver; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -92,7 +93,6 @@ 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); + protected abstract String @Nullable [] 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 6b156b4ebb..109eec9fd2 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 @@ -19,6 +19,8 @@ package org.springframework.context.annotation; import java.lang.annotation.Annotation; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionCustomizer; @@ -30,7 +32,6 @@ 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; /** @@ -247,8 +248,8 @@ public class AnnotatedBeanDefinitionReader { * @since 5.0 */ private void doRegisterBean(Class beanClass, @Nullable String name, - @Nullable Class[] qualifiers, @Nullable Supplier supplier, - @Nullable BeanDefinitionCustomizer[] customizers) { + Class @Nullable [] qualifiers, @Nullable Supplier supplier, + BeanDefinitionCustomizer @Nullable [] customizers) { AnnotatedGenericBeanDefinition abd = new AnnotatedGenericBeanDefinition(beanClass); 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 d8bb37df83..9c51343bc0 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 @@ -28,6 +28,7 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; @@ -38,7 +39,6 @@ import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotation.Adapt; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -119,8 +119,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) { + protected @Nullable String determineBeanNameFromAnnotation(AnnotatedBeanDefinition annotatedDef) { AnnotationMetadata metadata = annotatedDef.getMetadata(); String beanName = getExplicitBeanName(metadata); @@ -185,8 +184,7 @@ public class AnnotationBeanNameGenerator implements BeanNameGenerator { * @since 6.1 * @see org.springframework.stereotype.Component#value() */ - @Nullable - private String getExplicitBeanName(AnnotationMetadata metadata) { + private @Nullable String getExplicitBeanName(AnnotationMetadata metadata) { List names = metadata.getAnnotations().stream(COMPONENT_ANNOTATION_CLASSNAME) .map(annotation -> annotation.getString(MergedAnnotation.VALUE)) .filter(StringUtils::hasText) 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 207722a4c5..814d9d0aea 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 @@ -19,13 +19,14 @@ package org.springframework.context.annotation; import java.util.Arrays; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinitionCustomizer; 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.core.metrics.StartupStep; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigBeanDefinitionParser.java index 878d545def..4296cdecbb 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/AnnotationConfigBeanDefinitionParser.java @@ -18,6 +18,7 @@ package org.springframework.context.annotation; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -26,7 +27,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.parsing.CompositeComponentDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.lang.Nullable; /** * Parser for the <context:annotation-config/> element. @@ -40,8 +40,7 @@ import org.springframework.lang.Nullable; public class AnnotationConfigBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Obtain bean definitions for all relevant BeanPostProcessors. 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 540515fdf2..ba1214b0e6 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 @@ -20,6 +20,8 @@ import java.lang.annotation.Annotation; import java.util.Set; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor; import org.springframework.beans.factory.config.BeanDefinition; @@ -35,7 +37,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.MergedAnnotation; 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.CollectionUtils; @@ -210,8 +211,7 @@ public abstract class AnnotationConfigUtils { return new BeanDefinitionHolder(definition, beanName); } - @Nullable - private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) { + private static @Nullable DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) { if (registry instanceof DefaultListableBeanFactory dlbf) { return dlbf; } @@ -271,13 +271,11 @@ public abstract class AnnotationConfigUtils { return ScopedProxyCreator.createScopedProxy(definition, registry, proxyTargetClass); } - @Nullable - static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, Class annotationType) { + static @Nullable AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, Class annotationType) { return attributesFor(metadata, annotationType.getName()); } - @Nullable - static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationTypeName) { + static @Nullable AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationTypeName) { return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationTypeName)); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java b/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java index cd4d187244..71f449ce7a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/BeanMethod.java @@ -18,11 +18,12 @@ package org.springframework.context.annotation; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.parsing.Problem; import org.springframework.beans.factory.parsing.ProblemReporter; import org.springframework.core.type.MethodMetadata; -import org.springframework.lang.Nullable; /** * Represents a {@link Configuration @Configuration} class method annotated with diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java index bee5d806d1..5292105c71 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ClassPathBeanDefinitionScanner.java @@ -19,6 +19,8 @@ package org.springframework.context.annotation; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinitionHolder; @@ -31,7 +33,6 @@ import org.springframework.core.env.Environment; import org.springframework.core.env.EnvironmentCapable; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.PatternMatchUtils; @@ -66,8 +67,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo private BeanDefinitionDefaults beanDefinitionDefaults = new BeanDefinitionDefaults(); - @Nullable - private String[] autowireCandidatePatterns; + private String @Nullable [] autowireCandidatePatterns; private BeanNameGenerator beanNameGenerator = AnnotationBeanNameGenerator.INSTANCE; @@ -199,7 +199,7 @@ public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateCo * Set the name-matching patterns for determining autowire candidates. * @param autowireCandidatePatterns the patterns to match against */ - public void setAutowireCandidatePatterns(@Nullable String... autowireCandidatePatterns) { + public void setAutowireCandidatePatterns(String @Nullable ... autowireCandidatePatterns) { this.autowireCandidatePatterns = autowireCandidatePatterns; } 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 6016fcf655..c59c7a943b 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 @@ -27,6 +27,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; @@ -54,7 +55,6 @@ 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; @@ -116,20 +116,15 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC private final List excludeFilters = new ArrayList<>(); - @Nullable - private Environment environment; + private @Nullable Environment environment; - @Nullable - private ConditionEvaluator conditionEvaluator; + private @Nullable ConditionEvaluator conditionEvaluator; - @Nullable - private ResourcePatternResolver resourcePatternResolver; + private @Nullable ResourcePatternResolver resourcePatternResolver; - @Nullable - private MetadataReaderFactory metadataReaderFactory; + private @Nullable MetadataReaderFactory metadataReaderFactory; - @Nullable - private CandidateComponentsIndex componentsIndex; + private @Nullable CandidateComponentsIndex componentsIndex; /** @@ -255,8 +250,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC /** * Return the {@link BeanDefinitionRegistry} used by this scanner, if any. */ - @Nullable - protected BeanDefinitionRegistry getRegistry() { + protected @Nullable BeanDefinitionRegistry getRegistry() { return null; } @@ -368,8 +362,7 @@ public class ClassPathScanningCandidateComponentProvider implements EnvironmentC * @since 5.0 * @see #indexSupportsIncludeFilter(TypeFilter) */ - @Nullable - private String extractStereotype(TypeFilter filter) { + private @Nullable String extractStereotype(TypeFilter filter) { if (filter instanceof AnnotationTypeFilter annotationTypeFilter) { return annotationTypeFilter.getAnnotationType().getName(); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java index 7e65b98cdb..8b30c0431f 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.java @@ -34,6 +34,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aot.generate.AccessControl; @@ -68,7 +70,6 @@ import org.springframework.core.annotation.AnnotationUtils; import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; import org.springframework.jndi.support.SimpleJndiBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -146,11 +147,9 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean private static final Set> resourceAnnotationTypes = CollectionUtils.newLinkedHashSet(3); - @Nullable - private static final Class jakartaResourceType; + private static final @Nullable Class jakartaResourceType; - @Nullable - private static final Class ejbAnnotationType; + private static final @Nullable Class ejbAnnotationType; static { jakartaResourceType = loadAnnotationType("jakarta.annotation.Resource"); @@ -171,17 +170,13 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean private boolean alwaysUseJndiLookup = false; - @Nullable - private transient BeanFactory jndiFactory; + private transient @Nullable BeanFactory jndiFactory; - @Nullable - private transient BeanFactory resourceFactory; + private transient @Nullable BeanFactory resourceFactory; - @Nullable - private transient BeanFactory beanFactory; + private transient @Nullable BeanFactory beanFactory; - @Nullable - private transient StringValueResolver embeddedValueResolver; + private transient @Nullable StringValueResolver embeddedValueResolver; private final transient Map injectionMetadataCache = new ConcurrentHashMap<>(256); @@ -298,8 +293,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { BeanRegistrationAotContribution parentAotContribution = super.processAheadOfTime(registeredBean); Class beanClass = registeredBean.getBeanClass(); String beanName = registeredBean.getBeanName(); @@ -316,8 +310,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean return parentAotContribution; } - @Nullable - private AutowireCandidateResolver getAutowireCandidateResolver(RegisteredBean registeredBean) { + private @Nullable AutowireCandidateResolver getAutowireCandidateResolver(RegisteredBean registeredBean) { if (registeredBean.getBeanFactory() instanceof DefaultListableBeanFactory lbf) { return lbf.getAutowireCandidateResolver(); } @@ -335,8 +328,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean } @Override - @Nullable - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) { + public @Nullable Object postProcessBeforeInstantiation(Class beanClass, String beanName) { return null; } @@ -585,8 +577,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean @SuppressWarnings("unchecked") - @Nullable - private static Class loadAnnotationType(String name) { + private static @Nullable Class loadAnnotationType(String name) { try { return (Class) ClassUtils.forName(name, CommonAnnotationBeanPostProcessor.class.getClassLoader()); @@ -609,8 +600,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean protected Class lookupType = Object.class; - @Nullable - protected String mappedName; + protected @Nullable String mappedName; public LookupElement(Member member, @Nullable PropertyDescriptor pd) { super(member, pd); @@ -775,8 +765,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean private final Collection lookupElements; - @Nullable - private final AutowireCandidateResolver candidateResolver; + private final @Nullable AutowireCandidateResolver candidateResolver; AotContribution(Class target, Collection lookupElements, @Nullable AutowireCandidateResolver candidateResolver) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java index d38a670c95..3a1a9ed2cc 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ComponentScanBeanDefinitionParser.java @@ -20,6 +20,7 @@ import java.lang.annotation.Annotation; import java.util.Set; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -39,7 +40,6 @@ import org.springframework.core.type.filter.AspectJTypeFilter; import org.springframework.core.type.filter.AssignableTypeFilter; import org.springframework.core.type.filter.RegexPatternTypeFilter; import org.springframework.core.type.filter.TypeFilter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -79,8 +79,7 @@ public class ComponentScanBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { String basePackage = element.getAttribute(BASE_PACKAGE_ATTRIBUTE); basePackage = parserContext.getReaderContext().getEnvironment().resolvePlaceholders(basePackage); String[] basePackages = StringUtils.tokenizeToStringArray(basePackage, 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 e28dfda7a3..cdf0cee02e 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 @@ -16,11 +16,12 @@ package org.springframework.context.annotation; +import org.jspecify.annotations.Nullable; + 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} implementations. @@ -44,8 +45,7 @@ public interface ConditionContext { * definition should the condition match, or {@code null} if the bean factory is * not available (or not downcastable to {@code ConfigurableListableBeanFactory}). */ - @Nullable - ConfigurableListableBeanFactory getBeanFactory(); + @Nullable ConfigurableListableBeanFactory getBeanFactory(); /** * Return the {@link Environment} for which the current application is running. @@ -62,7 +62,6 @@ public interface ConditionContext { * (only {@code null} if even the system ClassLoader isn't accessible). * @see org.springframework.util.ClassUtils#forName(String, ClassLoader) */ - @Nullable - ClassLoader getClassLoader(); + @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 bccce9326f..40b007001f 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 @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; @@ -33,7 +35,6 @@ import org.springframework.core.io.DefaultResourceLoader; 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; @@ -144,18 +145,15 @@ class ConditionEvaluator { */ private static class ConditionContextImpl implements ConditionContext { - @Nullable - private final BeanDefinitionRegistry registry; + private final @Nullable BeanDefinitionRegistry registry; - @Nullable - private final ConfigurableListableBeanFactory beanFactory; + private final @Nullable ConfigurableListableBeanFactory beanFactory; private final Environment environment; private final ResourceLoader resourceLoader; - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; public ConditionContextImpl(@Nullable BeanDefinitionRegistry registry, @Nullable Environment environment, @Nullable ResourceLoader resourceLoader) { @@ -167,8 +165,7 @@ class ConditionEvaluator { this.classLoader = deduceClassLoader(resourceLoader, this.beanFactory); } - @Nullable - private static ConfigurableListableBeanFactory deduceBeanFactory(@Nullable BeanDefinitionRegistry source) { + private static @Nullable ConfigurableListableBeanFactory deduceBeanFactory(@Nullable BeanDefinitionRegistry source) { if (source instanceof ConfigurableListableBeanFactory configurableListableBeanFactory) { return configurableListableBeanFactory; } @@ -192,8 +189,7 @@ class ConditionEvaluator { return new DefaultResourceLoader(); } - @Nullable - private static ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader, + private static @Nullable ClassLoader deduceClassLoader(@Nullable ResourceLoader resourceLoader, @Nullable ConfigurableListableBeanFactory beanFactory) { if (resourceLoader != null) { @@ -215,8 +211,7 @@ class ConditionEvaluator { } @Override - @Nullable - public ConfigurableListableBeanFactory getBeanFactory() { + public @Nullable ConfigurableListableBeanFactory getBeanFactory() { return this.beanFactory; } @@ -231,8 +226,7 @@ class ConditionEvaluator { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return this.classLoader; } } 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 7664cb6981..d4d5a536c6 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 @@ -22,6 +22,8 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.parsing.Location; import org.springframework.beans.factory.parsing.Problem; import org.springframework.beans.factory.parsing.ProblemReporter; @@ -31,7 +33,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -53,8 +54,7 @@ final class ConfigurationClass { private final Resource resource; - @Nullable - private String beanName; + private @Nullable String beanName; private boolean scanned = false; @@ -154,8 +154,7 @@ final class ConfigurationClass { this.beanName = beanName; } - @Nullable - String getBeanName() { + @Nullable String getBeanName() { return this.beanName; } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java index 0634bd6edc..1775d7de29 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassBeanDefinitionReader.java @@ -26,6 +26,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.NonNull; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; @@ -51,7 +52,6 @@ import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; import org.springframework.core.type.StandardAnnotationMetadata; import org.springframework.core.type.StandardMethodMetadata; -import org.springframework.lang.NonNull; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -448,8 +448,7 @@ class ConfigurationClassBeanDefinitionReader { } @Override - @NonNull - public MethodMetadata getFactoryMethodMetadata() { + public @NonNull MethodMetadata getFactoryMethodMetadata() { return this.factoryMethodMetadata; } 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 113e0d3007..51a5990a2f 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 @@ -24,6 +24,7 @@ import java.util.Arrays; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.scope.ScopedProxyFactoryBean; import org.springframework.asm.Opcodes; @@ -50,7 +51,6 @@ import org.springframework.cglib.proxy.NoOp; import org.springframework.cglib.transform.ClassEmitterTransformer; import org.springframework.cglib.transform.TransformingClassGenerator; import org.springframework.core.SmartClassLoader; -import org.springframework.lang.Nullable; import org.springframework.objenesis.ObjenesisException; import org.springframework.objenesis.SpringObjenesis; import org.springframework.util.Assert; @@ -254,8 +254,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 { + public @Nullable 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"); field.set(obj, args[0]); @@ -297,8 +296,7 @@ class ConfigurationClassEnhancer { * super implementation of the proxied method i.e., the actual {@code @Bean} method */ @Override - @Nullable - public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs, + public @Nullable Object intercept(Object enhancedConfigInstance, Method beanMethod, Object[] beanMethodArgs, MethodProxy cglibMethodProxy) throws Throwable { ConfigurableBeanFactory beanFactory = getBeanFactory(enhancedConfigInstance); @@ -351,8 +349,7 @@ class ConfigurationClassEnhancer { return resolveBeanReference(beanMethod, beanMethodArgs, beanFactory, beanName); } - @Nullable - private Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs, + private @Nullable Object resolveBeanReference(Method beanMethod, Object[] beanMethodArgs, ConfigurableBeanFactory beanFactory, String beanName) { // The user (i.e. not the factory) is requesting this bean through a call to 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 7fd102e2a9..6d90351956 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 @@ -37,6 +37,7 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; @@ -69,7 +70,6 @@ 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.stereotype.Component; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -122,8 +122,7 @@ class ConfigurationClassParser { private final ResourceLoader resourceLoader; - @Nullable - private final PropertySourceRegistry propertySourceRegistry; + private final @Nullable PropertySourceRegistry propertySourceRegistry; private final BeanDefinitionRegistry registry; @@ -284,8 +283,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( + protected final @Nullable SourceClass doProcessConfigurationClass( ConfigurationClass configClass, SourceClass sourceClass, Predicate filter) throws IOException { @@ -707,8 +705,7 @@ class ConfigurationClassParser { return allConditions.stream().filter(REGISTER_BEAN_CONDITION_FILTER).toList(); } - @Nullable - private ConfigurationClass getEnclosingConfigurationClass(ConfigurationClass configurationClass) { + private @Nullable ConfigurationClass getEnclosingConfigurationClass(ConfigurationClass configurationClass) { String enclosingClassName = configurationClass.getMetadata().getEnclosingClassName(); if (enclosingClassName != null) { return configurationClass.getImportedBy().stream() @@ -729,8 +726,7 @@ class ConfigurationClassParser { } @Override - @Nullable - public AnnotationMetadata getImportingClassFor(String importedClass) { + public @Nullable AnnotationMetadata getImportingClassFor(String importedClass) { return CollectionUtils.lastElement(this.imports.get(importedClass)); } @@ -769,8 +765,7 @@ class ConfigurationClassParser { private class DeferredImportSelectorHandler { - @Nullable - private List deferredImportSelectors = new ArrayList<>(); + private @Nullable List deferredImportSelectors = new ArrayList<>(); /** * Handle the specified {@link DeferredImportSelector}. If deferred import diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java index 7988295f33..4787f83216 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassPostProcessor.java @@ -36,6 +36,7 @@ import javax.lang.model.element.Modifier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.autoproxy.AutoProxyUtils; import org.springframework.aot.generate.GeneratedMethod; @@ -102,7 +103,6 @@ import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.CodeBlock.Builder; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -152,13 +152,11 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo private ProblemReporter problemReporter = new FailFastProblemReporter(); - @Nullable - private Environment environment; + private @Nullable Environment environment; private ResourceLoader resourceLoader = new DefaultResourceLoader(); - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private MetadataReaderFactory metadataReaderFactory = new CachingMetadataReaderFactory(); @@ -168,8 +166,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo private final Set factoriesPostProcessed = new HashSet<>(); - @Nullable - private ConfigurationClassBeanDefinitionReader reader; + private @Nullable ConfigurationClassBeanDefinitionReader reader; private boolean localBeanNameGeneratorSet = false; @@ -181,8 +178,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo private ApplicationStartup applicationStartup = ApplicationStartup.DEFAULT; - @Nullable - private List propertySourceDescriptors; + private @Nullable List propertySourceDescriptors; @Override @@ -311,9 +307,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo beanFactory.addBeanPostProcessor(new ImportAwareBeanPostProcessor(beanFactory)); } - @Nullable @Override - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Object configClassAttr = registeredBean.getMergedBeanDefinition() .getAttribute(ConfigurationClassUtils.CONFIGURATION_CLASS_ATTRIBUTE); if (ConfigurationClassUtils.CONFIGURATION_CLASS_FULL.equals(configClassAttr)) { @@ -324,9 +319,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } @Override - @Nullable @SuppressWarnings("NullAway") - public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { + public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { boolean hasPropertySourceDescriptors = !CollectionUtils.isEmpty(this.propertySourceDescriptors); boolean hasImportRegistry = beanFactory.containsBean(IMPORT_REGISTRY_BEAN_NAME); if (hasPropertySourceDescriptors || hasImportRegistry) { @@ -343,8 +337,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo return null; } - @Nullable - private Resource resolvePropertySourceLocation(String location) { + private @Nullable Resource resolvePropertySourceLocation(String location) { try { String resolvedLocation = (this.environment != null ? this.environment.resolveRequiredPlaceholders(location) : location); @@ -557,8 +550,7 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo } @Override - @Nullable - public PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) { + public @Nullable PropertyValues postProcessProperties(@Nullable PropertyValues pvs, Object bean, String beanName) { // Inject the BeanFactory before AutowiredAnnotationBeanPostProcessor's // postProcessProperties method attempts to autowire other configuration beans. if (bean instanceof EnhancedConfiguration enhancedConfiguration) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java index 4d557ae9ea..381af86d0b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassUtils.java @@ -22,6 +22,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopInfrastructureBean; import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; @@ -38,7 +39,6 @@ import org.springframework.core.annotation.Order; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; /** @@ -207,8 +207,7 @@ public abstract class ConfigurationClassUtils { * or {@code Ordered.LOWEST_PRECEDENCE} if none declared * @since 5.0 */ - @Nullable - public static Integer getOrder(AnnotationMetadata metadata) { + public static @Nullable Integer getOrder(AnnotationMetadata metadata) { Map orderAttributes = metadata.getAnnotationAttributes(Order.class.getName()); return (orderAttributes != null ? ((Integer) orderAttributes.get(AnnotationUtils.VALUE)) : null); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java b/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java index bc012d0580..f4d1b8bbb2 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ContextAnnotationAutowireCandidateResolver.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -34,7 +36,6 @@ import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; /** * Complete implementation of the @@ -48,14 +49,12 @@ import org.springframework.lang.Nullable; public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotationAutowireCandidateResolver { @Override - @Nullable - public Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { + public @Nullable Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor, @Nullable String beanName) { return (isLazy(descriptor) ? buildLazyResolutionProxy(descriptor, beanName) : null); } @Override - @Nullable - public Class getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) { + public @Nullable Class getLazyResolutionProxyClass(DependencyDescriptor descriptor, @Nullable String beanName) { return (isLazy(descriptor) ? (Class) buildLazyResolutionProxy(descriptor, beanName, true) : null); } @@ -110,11 +109,9 @@ public class ContextAnnotationAutowireCandidateResolver extends QualifierAnnotat private final DependencyDescriptor descriptor; - @Nullable - private final String beanName; + private final @Nullable String beanName; - @Nullable - private transient volatile Object cachedTarget; + private transient volatile @Nullable Object cachedTarget; public LazyDependencyTargetSource(DefaultListableBeanFactory beanFactory, DependencyDescriptor descriptor, @Nullable String beanName) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java b/spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java index dedb068b64..c55a548ce4 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/DeferredImportSelector.java @@ -16,8 +16,9 @@ package org.springframework.context.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; /** * A variation of {@link ImportSelector} that runs after all {@code @Configuration} beans @@ -43,8 +44,7 @@ public interface DeferredImportSelector extends ImportSelector { * @return the import group class, or {@code null} if none * @since 5.0 */ - @Nullable - default Class getImportGroup() { + default @Nullable Class getImportGroup() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ImportAwareAotBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/context/annotation/ImportAwareAotBeanPostProcessor.java index 24f422e1e8..c026153a9b 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ImportAwareAotBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ImportAwareAotBeanPostProcessor.java @@ -19,13 +19,14 @@ package org.springframework.context.annotation; import java.io.IOException; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -75,8 +76,7 @@ public final class ImportAwareAotBeanPostProcessor implements BeanPostProcessor, } } - @Nullable - private String getImportingClassFor(ImportAware instance) { + private @Nullable String getImportingClassFor(ImportAware instance) { String target = ClassUtils.getUserClass(instance).getName(); return this.importsMapping.get(target); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ImportRegistry.java b/spring-context/src/main/java/org/springframework/context/annotation/ImportRegistry.java index 779bbc3058..335f7fe80a 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ImportRegistry.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ImportRegistry.java @@ -16,8 +16,9 @@ package org.springframework.context.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; /** * Registry of imported class {@link AnnotationMetadata}. @@ -27,8 +28,7 @@ import org.springframework.lang.Nullable; */ interface ImportRegistry { - @Nullable - AnnotationMetadata getImportingClassFor(String importedClass); + @Nullable AnnotationMetadata getImportingClassFor(String importedClass); void removeImportingClass(String importingClass); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java b/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java index 7ae3423ec5..804fb337be 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ImportSelector.java @@ -18,8 +18,9 @@ package org.springframework.context.annotation; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; /** * Interface to be implemented by types that determine which @{@link Configuration} @@ -77,8 +78,7 @@ public interface ImportSelector { * of transitively imported configuration classes, or {@code null} if none * @since 5.2.4 */ - @Nullable - default Predicate getExclusionFilter() { + default @Nullable Predicate getExclusionFilter() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/Jsr330ScopeMetadataResolver.java b/spring-context/src/main/java/org/springframework/context/annotation/Jsr330ScopeMetadataResolver.java index 06ab3313ec..45100980c2 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/Jsr330ScopeMetadataResolver.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/Jsr330ScopeMetadataResolver.java @@ -20,9 +20,10 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.lang.Nullable; /** * Simple {@link ScopeMetadataResolver} implementation that follows JSR-330 scoping rules: @@ -77,8 +78,7 @@ public class Jsr330ScopeMetadataResolver implements ScopeMetadataResolver { * @param annotationType the JSR-330 annotation type * @return the Spring scope name */ - @Nullable - protected String resolveScopeName(String annotationType) { + protected @Nullable String resolveScopeName(String annotationType) { return this.scopeMap.get(annotationType); } diff --git a/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java b/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java index 86b1ede8f7..064bd1ac28 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/LoadTimeWeavingConfiguration.java @@ -16,6 +16,8 @@ package org.springframework.context.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; @@ -26,7 +28,6 @@ import org.springframework.context.weaving.DefaultContextLoadTimeWeaver; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; import org.springframework.instrument.classloading.LoadTimeWeaver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -45,14 +46,11 @@ import org.springframework.util.Assert; @Role(BeanDefinition.ROLE_INFRASTRUCTURE) public class LoadTimeWeavingConfiguration implements ImportAware, BeanClassLoaderAware { - @Nullable - private AnnotationAttributes enableLTW; + private @Nullable AnnotationAttributes enableLTW; - @Nullable - private LoadTimeWeavingConfigurer ltwConfigurer; + private @Nullable LoadTimeWeavingConfigurer ltwConfigurer; - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; @Override 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 25715f82ca..d680e4729b 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 @@ -20,6 +20,8 @@ import java.util.Map; import javax.management.MBeanServer; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.config.BeanDefinition; @@ -29,7 +31,6 @@ import org.springframework.core.env.Environment; import org.springframework.core.type.AnnotationMetadata; import org.springframework.jmx.export.annotation.AnnotationMBeanExporter; import org.springframework.jmx.support.RegistrationPolicy; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -50,14 +51,11 @@ public class MBeanExportConfiguration implements ImportAware, EnvironmentAware, private static final String MBEAN_EXPORTER_BEAN_NAME = "mbeanExporter"; - @Nullable - private AnnotationAttributes enableMBeanExport; + private @Nullable AnnotationAttributes enableMBeanExport; - @Nullable - private Environment environment; + private @Nullable Environment environment; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; @Override diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java b/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java index adbfbecb45..20cdd84beb 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ParserStrategyUtils.java @@ -18,6 +18,8 @@ package org.springframework.context.annotation; import java.lang.reflect.Constructor; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.Aware; @@ -30,7 +32,6 @@ import org.springframework.context.EnvironmentAware; import org.springframework.context.ResourceLoaderAware; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -98,8 +99,7 @@ abstract class ParserStrategyUtils { return parameters; } - @Nullable - private static Object resolveParameter(Class parameterType, + private static @Nullable Object resolveParameter(Class parameterType, Environment environment, ResourceLoader resourceLoader, BeanDefinitionRegistry registry, @Nullable ClassLoader classLoader) { diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ResourceElementResolver.java b/spring-context/src/main/java/org/springframework/context/annotation/ResourceElementResolver.java index d3a78ea91b..eaf2a86d75 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ResourceElementResolver.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ResourceElementResolver.java @@ -23,6 +23,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -30,7 +32,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -115,9 +116,8 @@ public abstract class ResourceElementResolver { * @param registeredBean the registered bean * @return the resolved field or method parameter value */ - @Nullable @SuppressWarnings("unchecked") - public T resolve(RegisteredBean registeredBean) { + public @Nullable T resolve(RegisteredBean registeredBean) { Assert.notNull(registeredBean, "'registeredBean' must not be null"); return (T) (isLazyLookup(registeredBean) ? buildLazyResourceProxy(registeredBean) : resolveValue(registeredBean)); diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ScannedGenericBeanDefinition.java b/spring-context/src/main/java/org/springframework/context/annotation/ScannedGenericBeanDefinition.java index 26e603bbf2..b9fbdab9c5 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ScannedGenericBeanDefinition.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ScannedGenericBeanDefinition.java @@ -16,13 +16,14 @@ package org.springframework.context.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; import org.springframework.core.type.classreading.MetadataReader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,8 +71,7 @@ public class ScannedGenericBeanDefinition extends GenericBeanDefinition implemen } @Override - @Nullable - public MethodMetadata getFactoryMethodMetadata() { + public @Nullable MethodMetadata getFactoryMethodMetadata() { return null; } 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 d40f541f12..cc6e50066b 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,9 +3,7 @@ * annotations, component-scanning, and Java-based metadata for creating * Spring-managed objects. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/context/aot/AbstractAotProcessor.java b/spring-context/src/main/java/org/springframework/context/aot/AbstractAotProcessor.java index 58c63fc117..d7cce932a3 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/AbstractAotProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/aot/AbstractAotProcessor.java @@ -19,11 +19,12 @@ package org.springframework.context.aot; import java.io.IOException; import java.nio.file.Path; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.FileSystemGeneratedFiles; import org.springframework.aot.generate.GeneratedFiles.Kind; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.nativex.FileNativeConfigurationWriter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FileSystemUtils; @@ -197,20 +198,15 @@ public abstract class AbstractAotProcessor { */ public static final class Builder { - @Nullable - private Path sourceOutput; + private @Nullable Path sourceOutput; - @Nullable - private Path resourceOutput; + private @Nullable Path resourceOutput; - @Nullable - private Path classOutput; + private @Nullable Path classOutput; - @Nullable - private String groupId; + private @Nullable String groupId; - @Nullable - private String artifactId; + private @Nullable String artifactId; private Builder() { // internal constructor diff --git a/spring-context/src/main/java/org/springframework/context/aot/AotApplicationContextInitializer.java b/spring-context/src/main/java/org/springframework/context/aot/AotApplicationContextInitializer.java index 47744cb6f7..8d7f7c6e61 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/AotApplicationContextInitializer.java +++ b/spring-context/src/main/java/org/springframework/context/aot/AotApplicationContextInitializer.java @@ -18,13 +18,13 @@ package org.springframework.context.aot; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.log.LogMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; diff --git a/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextInitializationCodeGenerator.java b/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextInitializationCodeGenerator.java index 5305508b9d..e74a416cf5 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextInitializationCodeGenerator.java +++ b/spring-context/src/main/java/org/springframework/context/aot/ApplicationContextInitializationCodeGenerator.java @@ -23,6 +23,8 @@ import java.util.function.Function; import javax.lang.model.element.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GeneratedClass; import org.springframework.aot.generate.GeneratedMethods; import org.springframework.aot.generate.GenerationContext; @@ -44,7 +46,6 @@ import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; import org.springframework.javapoet.TypeName; import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; /** * Internal code generator to create the {@link ApplicationContextInitializer}. @@ -142,13 +143,11 @@ class ApplicationContextInitializationCodeGenerator implements BeanFactoryInitia private static class InitializerMethodArgumentCodeGenerator implements Function { @Override - @Nullable - public CodeBlock apply(TypeName typeName) { + public @Nullable CodeBlock apply(TypeName typeName) { return (typeName instanceof ClassName className ? apply(className) : null); } - @Nullable - private CodeBlock apply(ClassName className) { + private @Nullable CodeBlock apply(ClassName className) { String name = className.canonicalName(); if (name.equals(DefaultListableBeanFactory.class.getName()) || name.equals(ConfigurableListableBeanFactory.class.getName())) { diff --git a/spring-context/src/main/java/org/springframework/context/aot/BeanFactoryInitializationAotContributions.java b/spring-context/src/main/java/org/springframework/context/aot/BeanFactoryInitializationAotContributions.java index d2d5ec73be..f549ae4656 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/BeanFactoryInitializationAotContributions.java +++ b/spring-context/src/main/java/org/springframework/context/aot/BeanFactoryInitializationAotContributions.java @@ -20,6 +20,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GenerationContext; import org.springframework.beans.factory.aot.AotException; import org.springframework.beans.factory.aot.AotProcessingException; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContrib import org.springframework.beans.factory.aot.BeanFactoryInitializationAotProcessor; import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.lang.Nullable; /** * A collection of {@link BeanFactoryInitializationAotContribution AOT @@ -74,8 +75,7 @@ class BeanFactoryInitializationAotContributions { return Collections.unmodifiableList(contributions); } - @Nullable - private BeanFactoryInitializationAotContribution processAheadOfTime(BeanFactoryInitializationAotProcessor processor, + private @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(BeanFactoryInitializationAotProcessor processor, DefaultListableBeanFactory beanFactory) { try { diff --git a/spring-context/src/main/java/org/springframework/context/aot/KotlinReflectionBeanRegistrationAotProcessor.java b/spring-context/src/main/java/org/springframework/context/aot/KotlinReflectionBeanRegistrationAotProcessor.java index e8bcb76963..9820b07bcd 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/KotlinReflectionBeanRegistrationAotProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/aot/KotlinReflectionBeanRegistrationAotProcessor.java @@ -16,6 +16,8 @@ package org.springframework.context.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.RuntimeHints; import org.springframework.beans.factory.aot.BeanRegistrationAotContribution; @@ -23,7 +25,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor; import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.KotlinDetector; -import org.springframework.lang.Nullable; /** * AOT {@code BeanRegistrationAotProcessor} that adds additional hints @@ -35,8 +36,7 @@ import org.springframework.lang.Nullable; class KotlinReflectionBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); if (KotlinDetector.isKotlinType(beanClass)) { return new AotContribution(beanClass); diff --git a/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilder.java b/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilder.java index 4b6a7b7918..579e73e93f 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilder.java +++ b/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilder.java @@ -22,6 +22,8 @@ import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.StreamSupport; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.annotation.Reflective; @@ -33,7 +35,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContrib import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -95,8 +96,7 @@ public class ReflectiveProcessorAotContributionBuilder { return withClasses(scanner.scan(packageNames)); } - @Nullable - public BeanFactoryInitializationAotContribution build() { + public @Nullable BeanFactoryInitializationAotContribution build() { return (!this.classes.isEmpty() ? new AotContribution(this.classes) : null); } @@ -118,8 +118,7 @@ public class ReflectiveProcessorAotContributionBuilder { private static class ReflectiveClassPathScanner extends ClassPathScanningCandidateComponentProvider { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; ReflectiveClassPathScanner(@Nullable ClassLoader classLoader) { super(false); diff --git a/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessor.java b/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessor.java index 0ba81ec971..193a201f51 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/aot/ReflectiveProcessorBeanFactoryInitializationAotProcessor.java @@ -21,6 +21,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.annotation.Reflective; import org.springframework.aot.hint.annotation.ReflectiveProcessor; import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; @@ -29,7 +31,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.context.annotation.ReflectiveScan; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -43,8 +44,7 @@ import org.springframework.util.ClassUtils; class ReflectiveProcessorBeanFactoryInitializationAotProcessor implements BeanFactoryInitializationAotProcessor { @Override - @Nullable - public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { + public @Nullable BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableListableBeanFactory beanFactory) { Class[] beanClasses = Arrays.stream(beanFactory.getBeanDefinitionNames()) .map(beanName -> RegisteredBean.of(beanFactory, beanName).getBeanClass()) .toArray(Class[]::new); diff --git a/spring-context/src/main/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessor.java b/spring-context/src/main/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessor.java index 75fa1bb2c6..d79a7c8926 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessor.java @@ -23,6 +23,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.RuntimeHints; @@ -35,7 +36,6 @@ import org.springframework.beans.factory.aot.BeanFactoryInitializationCode; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.core.log.LogMessage; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -94,8 +94,7 @@ class RuntimeHintsBeanFactoryInitializationAotProcessor implements BeanFactoryIn private final Iterable registrars; - @Nullable - private final ClassLoader beanClassLoader; + private final @Nullable ClassLoader beanClassLoader; RuntimeHintsRegistrarContribution(Iterable registrars, @Nullable ClassLoader beanClassLoader) { diff --git a/spring-context/src/main/java/org/springframework/context/aot/package-info.java b/spring-context/src/main/java/org/springframework/context/aot/package-info.java index abb1763028..c9da373f17 100644 --- a/spring-context/src/main/java/org/springframework/context/aot/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/aot/package-info.java @@ -1,9 +1,7 @@ /** * AOT support for application contexts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.aot; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/context/config/LoadTimeWeaverBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/config/LoadTimeWeaverBeanDefinitionParser.java index e21b5fe2fd..8246b6497d 100644 --- a/spring-context/src/main/java/org/springframework/context/config/LoadTimeWeaverBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/config/LoadTimeWeaverBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.context.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -27,7 +28,6 @@ import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.weaving.AspectJWeavingEnabler; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** diff --git a/spring-context/src/main/java/org/springframework/context/config/SpringConfiguredBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/context/config/SpringConfiguredBeanDefinitionParser.java index 2fd447a835..3f797dce89 100644 --- a/spring-context/src/main/java/org/springframework/context/config/SpringConfiguredBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/context/config/SpringConfiguredBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.context.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -23,7 +24,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; 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; /** * {@link BeanDefinitionParser} responsible for parsing the @@ -45,8 +45,7 @@ class SpringConfiguredBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { if (!parserContext.getRegistry().containsBeanDefinition(BEAN_CONFIGURER_ASPECT_BEAN_NAME)) { RootBeanDefinition def = new RootBeanDefinition(); def.setBeanClassName(BEAN_CONFIGURER_ASPECT_CLASS_NAME); 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 08b96ec341..65c0cc7fff 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,9 +2,7 @@ * Support package for advanced application context configuration, * with XML schema being the primary configuration format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java index c552e57915..b46b19b7fd 100644 --- a/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/AbstractApplicationEventMulticaster.java @@ -26,6 +26,8 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopProxyUtils; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.BeanFactory; @@ -37,7 +39,6 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -70,11 +71,9 @@ public abstract class AbstractApplicationEventMulticaster final Map retrieverCache = new ConcurrentHashMap<>(64); - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; - @Nullable - private ConfigurableBeanFactory beanFactory; + private @Nullable ConfigurableBeanFactory beanFactory; @Override @@ -407,8 +406,7 @@ public abstract class AbstractApplicationEventMulticaster private final ResolvableType eventType; - @Nullable - private final Class sourceType; + private final @Nullable Class sourceType; public ListenerCacheKey(ResolvableType eventType, @Nullable Class sourceType) { Assert.notNull(eventType, "Event type must not be null"); @@ -457,14 +455,11 @@ public abstract class AbstractApplicationEventMulticaster */ private class CachedListenerRetriever { - @Nullable - public volatile Set> applicationListeners; + public volatile @Nullable Set> applicationListeners; - @Nullable - public volatile Set applicationListenerBeans; + public volatile @Nullable Set applicationListenerBeans; - @Nullable - public Collection> getApplicationListeners() { + public @Nullable Collection> getApplicationListeners() { Set> applicationListeners = this.applicationListeners; Set applicationListenerBeans = this.applicationListenerBeans; if (applicationListeners == null || applicationListenerBeans == null) { 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 cfbdd769a2..2052d32b9a 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 @@ -18,10 +18,11 @@ package org.springframework.context.event; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + 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 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 5858784906..97fedefef2 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 @@ -29,6 +29,7 @@ import java.util.concurrent.CompletionStage; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -46,7 +47,7 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.Order; -import org.springframework.lang.Nullable; +import org.springframework.lang.Contract; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -88,21 +89,17 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe private final List declaredEventTypes; - @Nullable - private final String condition; + private final @Nullable String condition; private final boolean defaultExecution; private final int order; - @Nullable - private volatile String listenerId; + private volatile @Nullable String listenerId; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private EventExpressionEvaluator evaluator; + private @Nullable EventExpressionEvaluator evaluator; /** @@ -249,7 +246,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe * @param event the event to process through the listener method */ public void processEvent(ApplicationEvent event) { - Object[] args = resolveArguments(event); + @Nullable Object[] args = resolveArguments(event); if (shouldHandle(event, args)) { Object result = doInvoke(args); if (result != null) { @@ -271,7 +268,8 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe return shouldHandle(event, resolveArguments(event)); } - private boolean shouldHandle(ApplicationEvent event, @Nullable Object[] args) { + @Contract("_, null -> false") + private boolean shouldHandle(ApplicationEvent event, @Nullable Object @Nullable [] args) { if (args == null) { return false; } @@ -290,8 +288,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe * Can 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) { + protected @Nullable Object @Nullable [] resolveArguments(ApplicationEvent event) { ResolvableType declaredEventType = getResolvableType(event); if (declaredEventType == null) { return null; @@ -362,8 +359,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe /** * Invoke the event listener method with the given argument values. */ - @Nullable - protected Object doInvoke(@Nullable Object... args) { + protected @Nullable Object doInvoke(@Nullable Object... args) { Object bean = getTargetBean(); // Detect package-protected NullBean instance through equals(null) check if (bean.equals(null)) { @@ -419,8 +415,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe * annotation or any matching attribute on a composed annotation that * is meta-annotated with {@code @EventListener}. */ - @Nullable - protected String getCondition() { + protected @Nullable String getCondition() { return this.condition; } @@ -456,8 +451,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe } } - @SuppressWarnings("NullAway") - private String getInvocationErrorMessage(Object bean, @Nullable String message, @Nullable Object[] resolvedArgs) { + private String getInvocationErrorMessage(Object bean, @Nullable String message, @Nullable Object [] resolvedArgs) { StringBuilder sb = new StringBuilder(getDetailedErrorMessage(bean, message)); sb.append("Resolved arguments: \n"); for (int i = 0; i < resolvedArgs.length; i++) { @@ -473,8 +467,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe return sb.toString(); } - @Nullable - private ResolvableType getResolvableType(ApplicationEvent event) { + private @Nullable ResolvableType getResolvableType(ApplicationEvent event) { ResolvableType payloadType = null; if (event instanceof PayloadApplicationEvent payloadEvent) { ResolvableType eventType = payloadEvent.getResolvableType(); diff --git a/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java index acef8846be..385288989a 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventExpressionEvaluator.java @@ -20,6 +20,8 @@ import java.lang.reflect.Method; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; import org.springframework.context.expression.AnnotatedElementKey; import org.springframework.context.expression.CachedExpressionEvaluator; @@ -51,7 +53,7 @@ class EventExpressionEvaluator extends CachedExpressionEvaluator { * to {@code true}. */ public boolean condition(String conditionExpression, ApplicationEvent event, Method targetMethod, - AnnotatedElementKey methodKey, Object[] args) { + AnnotatedElementKey methodKey, @Nullable Object[] args) { EventExpressionRootObject rootObject = new EventExpressionRootObject(event, args); EvaluationContext evaluationContext = createEvaluationContext(rootObject, targetMethod, args); @@ -60,7 +62,7 @@ class EventExpressionEvaluator extends CachedExpressionEvaluator { } private EvaluationContext createEvaluationContext(EventExpressionRootObject rootObject, - Method method, Object[] args) { + Method method, @Nullable Object[] args) { MethodBasedEvaluationContext evaluationContext = new MethodBasedEvaluationContext(rootObject, method, args, getParameterNameDiscoverer()); diff --git a/spring-context/src/main/java/org/springframework/context/event/EventExpressionRootObject.java b/spring-context/src/main/java/org/springframework/context/event/EventExpressionRootObject.java index fca84af09e..c04acd0978 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventExpressionRootObject.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventExpressionRootObject.java @@ -16,6 +16,8 @@ package org.springframework.context.event; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; /** @@ -28,5 +30,5 @@ import org.springframework.context.ApplicationEvent; * @param args the arguments supplied to the listener method * @see EventListener#condition() */ -record EventExpressionRootObject(ApplicationEvent event, Object[] args) { +record EventExpressionRootObject(ApplicationEvent event, @Nullable Object[] args) { } diff --git a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java index 5f330e7545..de3db6c05d 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java @@ -25,6 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.autoproxy.AutoProxyUtils; import org.springframework.aop.scope.ScopedObject; @@ -44,7 +45,6 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -67,19 +67,15 @@ public class EventListenerMethodProcessor protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ConfigurableApplicationContext applicationContext; + private @Nullable ConfigurableApplicationContext applicationContext; - @Nullable - private ConfigurableListableBeanFactory beanFactory; + private @Nullable ConfigurableListableBeanFactory beanFactory; - @Nullable - private List eventListenerFactories; + private @Nullable List eventListenerFactories; private final StandardEvaluationContext originalEvaluationContext; - @Nullable - private final EventExpressionEvaluator evaluator; + private final @Nullable EventExpressionEvaluator evaluator; private final Set> nonAnnotatedClasses = ConcurrentHashMap.newKeySet(64); diff --git a/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java b/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java index ef5c2e6e36..324c24240b 100644 --- a/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java +++ b/spring-context/src/main/java/org/springframework/context/event/EventPublicationInterceptor.java @@ -20,12 +20,12 @@ import java.lang.reflect.Constructor; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,11 +50,9 @@ import org.springframework.util.Assert; public class EventPublicationInterceptor implements MethodInterceptor, ApplicationEventPublisherAware, InitializingBean { - @Nullable - private Constructor applicationEventClassConstructor; + private @Nullable Constructor applicationEventClassConstructor; - @Nullable - private ApplicationEventPublisher applicationEventPublisher; + private @Nullable ApplicationEventPublisher applicationEventPublisher; /** @@ -94,8 +92,7 @@ public class EventPublicationInterceptor @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { Object retVal = invocation.proceed(); Assert.state(this.applicationEventClassConstructor != null, "No ApplicationEvent class set"); 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 a0ac143fa3..ec22230acb 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 @@ -18,12 +18,13 @@ package org.springframework.context.event; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.support.AopUtils; 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; import org.springframework.util.ConcurrentReferenceHashMap; @@ -43,8 +44,7 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList private final ApplicationListener delegate; - @Nullable - private final ResolvableType declaredEventType; + private final @Nullable ResolvableType declaredEventType; /** @@ -95,8 +95,7 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList } - @Nullable - private static ResolvableType resolveDeclaredEventType(ApplicationListener listener) { + private static @Nullable ResolvableType resolveDeclaredEventType(ApplicationListener listener) { ResolvableType declaredEventType = resolveDeclaredEventType(listener.getClass()); if (declaredEventType == null || declaredEventType.isAssignableFrom(ApplicationEvent.class)) { Class targetClass = AopUtils.getTargetClass(listener); @@ -107,8 +106,7 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList return declaredEventType; } - @Nullable - static ResolvableType resolveDeclaredEventType(Class listenerType) { + static @Nullable ResolvableType resolveDeclaredEventType(Class listenerType) { ResolvableType eventType = eventTypeCache.get(listenerType); if (eventType == null) { eventType = ResolvableType.forClass(listenerType).as(ApplicationListener.class).getGeneric(); diff --git a/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java b/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java index d2fe7feb5c..6b60b7d68b 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java +++ b/spring-context/src/main/java/org/springframework/context/event/SimpleApplicationEventMulticaster.java @@ -21,13 +21,13 @@ import java.util.concurrent.RejectedExecutionException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.PayloadApplicationEvent; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.ErrorHandler; /** @@ -51,14 +51,11 @@ import org.springframework.util.ErrorHandler; */ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventMulticaster { - @Nullable - private Executor taskExecutor; + private @Nullable Executor taskExecutor; - @Nullable - private ErrorHandler errorHandler; + private @Nullable ErrorHandler errorHandler; - @Nullable - private volatile Log lazyLogger; + private volatile @Nullable Log lazyLogger; /** @@ -100,8 +97,7 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM * Return the current task executor for this multicaster. * @since 2.0 */ - @Nullable - protected Executor getTaskExecutor() { + protected @Nullable Executor getTaskExecutor() { return this.taskExecutor; } @@ -128,8 +124,7 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM * Return the current error handler for this multicaster. * @since 4.1 */ - @Nullable - protected ErrorHandler getErrorHandler() { + protected @Nullable ErrorHandler getErrorHandler() { return this.errorHandler; } diff --git a/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java b/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java index c56dd33b33..24767a5f91 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java +++ b/spring-context/src/main/java/org/springframework/context/event/SmartApplicationListener.java @@ -16,10 +16,11 @@ package org.springframework.context.event; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; /** * Extended variant of the standard {@link ApplicationListener} interface, diff --git a/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java b/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java index 7170931aaa..14ce1f25d3 100644 --- a/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java +++ b/spring-context/src/main/java/org/springframework/context/event/SourceFilteringListener.java @@ -16,11 +16,12 @@ package org.springframework.context.event; +import org.jspecify.annotations.Nullable; + 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; /** * {@link org.springframework.context.ApplicationListener} decorator that filters @@ -38,8 +39,7 @@ public class SourceFilteringListener implements GenericApplicationListener { private final Object source; - @Nullable - private GenericApplicationListener delegate; + private @Nullable GenericApplicationListener delegate; /** 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 79cccd7a46..381af6a5db 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,9 +2,7 @@ * Support classes for application events, like standard context events. * To be supported by all major application context implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.event; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java index 08673db5e6..901486b982 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java +++ b/spring-context/src/main/java/org/springframework/context/expression/AnnotatedElementKey.java @@ -18,7 +18,8 @@ package org.springframework.context.expression; import java.lang.reflect.AnnotatedElement; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -35,8 +36,7 @@ public final class AnnotatedElementKey implements Comparable targetClass; + private final @Nullable Class targetClass; /** diff --git a/spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java b/spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java index 961f79de3f..adb4d12682 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/expression/BeanExpressionContextAccessor.java @@ -16,12 +16,13 @@ package org.springframework.context.expression; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java b/spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java index 2f7f162d10..ef5a6e0079 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/expression/BeanFactoryAccessor.java @@ -16,12 +16,13 @@ package org.springframework.context.expression; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java b/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java index 8cdea248a6..ba52e13b95 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java +++ b/spring-context/src/main/java/org/springframework/context/expression/CachedExpressionEvaluator.java @@ -18,11 +18,12 @@ package org.springframework.context.expression; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.Expression; import org.springframework.expression.spel.standard.SpelExpressionParser; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/context/expression/EnvironmentAccessor.java b/spring-context/src/main/java/org/springframework/context/expression/EnvironmentAccessor.java index 7b7fda7452..aca1b2085e 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/EnvironmentAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/expression/EnvironmentAccessor.java @@ -16,12 +16,13 @@ package org.springframework.context.expression; +import org.jspecify.annotations.Nullable; + import org.springframework.core.env.Environment; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.PropertyAccessor; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java b/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java index e630c8cc27..38053c2506 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/expression/MapAccessor.java @@ -18,6 +18,8 @@ package org.springframework.context.expression; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; @@ -25,7 +27,6 @@ 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.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java b/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java index c98d60fa59..5daf2fe3ea 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java +++ b/spring-context/src/main/java/org/springframework/context/expression/MethodBasedEvaluationContext.java @@ -19,10 +19,11 @@ package org.springframework.context.expression; import java.lang.reflect.Method; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + import org.springframework.core.KotlinDetector; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -45,14 +46,14 @@ public class MethodBasedEvaluationContext extends StandardEvaluationContext { private final Method method; - private final Object[] arguments; + private final @Nullable Object[] arguments; private final ParameterNameDiscoverer parameterNameDiscoverer; private boolean argumentsLoaded = false; - public MethodBasedEvaluationContext(Object rootObject, Method method, Object[] arguments, + public MethodBasedEvaluationContext(Object rootObject, Method method, @Nullable Object[] arguments, ParameterNameDiscoverer parameterNameDiscoverer) { super(rootObject); @@ -64,8 +65,7 @@ public class MethodBasedEvaluationContext extends StandardEvaluationContext { @Override - @Nullable - public Object lookupVariable(String name) { + public @Nullable Object lookupVariable(String name) { Object variable = super.lookupVariable(name); if (variable != null) { return variable; diff --git a/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java b/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java index 8b03a9f25d..2851ebc83e 100644 --- a/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java +++ b/spring-context/src/main/java/org/springframework/context/expression/StandardBeanExpressionResolver.java @@ -19,6 +19,8 @@ package org.springframework.context.expression; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanExpressionException; import org.springframework.beans.factory.config.BeanExpressionContext; @@ -36,7 +38,6 @@ import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeConverter; import org.springframework.expression.spel.support.StandardTypeLocator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -155,8 +156,7 @@ public class StandardBeanExpressionResolver implements BeanExpressionResolver { @Override - @Nullable - public Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException { + public @Nullable Object evaluate(@Nullable String value, BeanExpressionContext beanExpressionContext) throws BeansException { if (!StringUtils.hasLength(value)) { return value; } 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 f08c49a0e6..cca8a5d237 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,9 +1,7 @@ /** * Expression parsing support within a Spring application context. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.expression; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f10305c831..5d5bb2b87e 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,7 +18,7 @@ package org.springframework.context.i18n; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for determining the current Locale. @@ -38,7 +38,6 @@ public interface LocaleContext { * depending on the implementation strategy. * @return the current Locale, or {@code null} if no specific Locale associated */ - @Nullable - Locale getLocale(); + @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 97a2a2f1ec..e54c5d6572 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 @@ -19,9 +19,10 @@ package org.springframework.context.i18n; import java.util.Locale; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedInheritableThreadLocal; import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; /** * Simple holder class that associates a LocaleContext instance @@ -51,12 +52,10 @@ public final class LocaleContextHolder { new NamedInheritableThreadLocal<>("LocaleContext"); // Shared default locale at the framework level - @Nullable - private static Locale defaultLocale; + private static @Nullable Locale defaultLocale; // Shared default time zone at the framework level - @Nullable - private static TimeZone defaultTimeZone; + private static @Nullable TimeZone defaultTimeZone; private LocaleContextHolder() { @@ -116,8 +115,7 @@ public final 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() { + public static @Nullable LocaleContext getLocaleContext() { LocaleContext localeContext = localeContextHolder.get(); if (localeContext == null) { localeContext = inheritableLocaleContextHolder.get(); diff --git a/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextThreadLocalAccessor.java b/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextThreadLocalAccessor.java index 5d31165db8..769a14ad4c 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextThreadLocalAccessor.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/LocaleContextThreadLocalAccessor.java @@ -17,8 +17,7 @@ package org.springframework.context.i18n; import io.micrometer.context.ThreadLocalAccessor; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Adapt {@link LocaleContextHolder} to the {@link ThreadLocalAccessor} contract @@ -42,8 +41,7 @@ public class LocaleContextThreadLocalAccessor implements ThreadLocalAccessor beanFactoryPostProcessors = new ArrayList<>(); @@ -212,27 +210,22 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader private final Lock startupShutdownLock = new ReentrantLock(); /** Currently active startup/shutdown thread. */ - @Nullable - private volatile Thread startupShutdownThread; + private volatile @Nullable Thread startupShutdownThread; /** Reference to the JVM shutdown hook, if registered. */ - @Nullable - private Thread shutdownHook; + private @Nullable Thread shutdownHook; /** ResourcePatternResolver used by this context. */ private final ResourcePatternResolver resourcePatternResolver; /** LifecycleProcessor for managing the lifecycle of beans within this context. */ - @Nullable - private LifecycleProcessor lifecycleProcessor; + private @Nullable LifecycleProcessor lifecycleProcessor; /** MessageSource we delegate our implementation of this interface to. */ - @Nullable - private MessageSource messageSource; + private @Nullable MessageSource messageSource; /** Helper class used in event publishing. */ - @Nullable - private ApplicationEventMulticaster applicationEventMulticaster; + private @Nullable ApplicationEventMulticaster applicationEventMulticaster; /** Application startup metrics. */ private ApplicationStartup applicationStartup = ApplicationStartup.DEFAULT; @@ -241,12 +234,10 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader private final Set> applicationListeners = new LinkedHashSet<>(); /** Local listeners registered before refresh. */ - @Nullable - private Set> earlyApplicationListeners; + private @Nullable Set> earlyApplicationListeners; /** ApplicationEvents published before the multicaster setup. */ - @Nullable - private Set earlyApplicationEvents; + private @Nullable Set earlyApplicationEvents; /** @@ -315,8 +306,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader * (that is, this context is the root of the context hierarchy). */ @Override - @Nullable - public ApplicationContext getParent() { + public @Nullable ApplicationContext getParent() { return this.parent; } @@ -1279,7 +1269,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } @Override - public Object getBean(String name, Object... args) throws BeansException { + public Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException { assertBeanFactoryActive(); return getBeanFactory().getBean(name, args); } @@ -1291,7 +1281,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } @Override - public T getBean(Class requiredType, Object... args) throws BeansException { + public T getBean(Class requiredType, @Nullable Object @Nullable ... args) throws BeansException { assertBeanFactoryActive(); return getBeanFactory().getBean(requiredType, args); } @@ -1338,15 +1328,13 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } @Override - @Nullable - public Class getType(String name) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name) throws NoSuchBeanDefinitionException { assertBeanFactoryActive(); return getBeanFactory().getType(name); } @Override - @Nullable - public Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { assertBeanFactoryActive(); return getBeanFactory().getType(name, allowFactoryBeanInit); } @@ -1441,8 +1429,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } @Override - @Nullable - public A findAnnotationOnBean(String beanName, Class annotationType) + public @Nullable A findAnnotationOnBean(String beanName, Class annotationType) throws NoSuchBeanDefinitionException { assertBeanFactoryActive(); @@ -1450,8 +1437,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader } @Override - @Nullable - public A findAnnotationOnBean( + public @Nullable A findAnnotationOnBean( String beanName, Class annotationType, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { @@ -1474,8 +1460,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader //--------------------------------------------------------------------- @Override - @Nullable - public BeanFactory getParentBeanFactory() { + public @Nullable BeanFactory getParentBeanFactory() { return getParent(); } @@ -1489,8 +1474,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader * ConfigurableApplicationContext; else, return the parent context itself. * @see org.springframework.context.ConfigurableApplicationContext#getBeanFactory */ - @Nullable - protected BeanFactory getInternalParentBeanFactory() { + protected @Nullable BeanFactory getInternalParentBeanFactory() { return (getParent() instanceof ConfigurableApplicationContext cac ? cac.getBeanFactory() : getParent()); } @@ -1501,13 +1485,12 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader //--------------------------------------------------------------------- @Override - @Nullable - public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) { + public @Nullable String getMessage(String code, Object @Nullable [] args, @Nullable String defaultMessage, Locale locale) { return getMessageSource().getMessage(code, args, defaultMessage, locale); } @Override - public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args, Locale locale) throws NoSuchMessageException { return getMessageSource().getMessage(code, args, locale); } @@ -1533,8 +1516,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader * Return the internal message source of the parent context if it is an * AbstractApplicationContext too; else, return the parent context itself. */ - @Nullable - protected MessageSource getInternalParentMessageSource() { + protected @Nullable MessageSource getInternalParentMessageSource() { return (getParent() instanceof AbstractApplicationContext abstractApplicationContext ? abstractApplicationContext.messageSource : getParent()); } 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 cb51fe9def..c483820ac1 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 @@ -22,11 +22,12 @@ import java.util.List; import java.util.Locale; import java.util.Properties; +import org.jspecify.annotations.Nullable; + 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; /** @@ -64,11 +65,9 @@ import org.springframework.util.ObjectUtils; */ public abstract class AbstractMessageSource extends MessageSourceSupport implements HierarchicalMessageSource { - @Nullable - private MessageSource parentMessageSource; + private @Nullable MessageSource parentMessageSource; - @Nullable - private Properties commonMessages; + private @Nullable Properties commonMessages; private boolean useCodeAsDefaultMessage = false; @@ -79,8 +78,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme } @Override - @Nullable - public MessageSource getParentMessageSource() { + public @Nullable MessageSource getParentMessageSource() { return this.parentMessageSource; } @@ -97,8 +95,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme /** * Return a Properties object defining locale-independent common messages, if any. */ - @Nullable - protected Properties getCommonMessages() { + protected @Nullable Properties getCommonMessages() { return this.commonMessages; } @@ -137,8 +134,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme @Override - @Nullable - public final String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) { + public final @Nullable String getMessage(String code, Object @Nullable [] args, @Nullable String defaultMessage, Locale locale) { String msg = getMessageInternal(code, args, locale); if (msg != null) { return msg; @@ -150,7 +146,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme } @Override - public final String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException { + public final String getMessage(String code, Object @Nullable [] args, Locale locale) throws NoSuchMessageException { String msg = getMessageInternal(code, args, locale); if (msg != null) { return msg; @@ -195,8 +191,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @see #getMessage(MessageSourceResolvable, Locale) * @see #setUseCodeAsDefaultMessage */ - @Nullable - protected String getMessageInternal(@Nullable String code, @Nullable Object[] args, @Nullable Locale locale) { + protected @Nullable String getMessageInternal(@Nullable String code, Object @Nullable [] args, @Nullable Locale locale) { if (code == null) { return null; } @@ -252,8 +247,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, @Nullable Object[] args, Locale locale) { + protected @Nullable String getMessageFromParent(String code, Object @Nullable [] args, Locale locale) { MessageSource parent = getParentMessageSource(); if (parent != null) { if (parent instanceof AbstractMessageSource abstractMessageSource) { @@ -283,8 +277,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @see #renderDefaultMessage(String, Object[], Locale) * @see #getDefaultMessage(String) */ - @Nullable - protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) { + protected @Nullable String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) { String defaultMessage = resolvable.getDefaultMessage(); String[] codes = resolvable.getCodes(); if (defaultMessage != null) { @@ -313,8 +306,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) { + protected @Nullable String getDefaultMessage(String code) { if (isUseCodeAsDefaultMessage()) { return code; } @@ -331,7 +323,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @return an array of arguments with any MessageSourceResolvables resolved */ @Override - protected Object[] resolveArguments(@Nullable Object[] args, Locale locale) { + protected Object[] resolveArguments(Object @Nullable [] args, Locale locale) { if (ObjectUtils.isEmpty(args)) { return super.resolveArguments(args, locale); } @@ -364,8 +356,7 @@ public abstract class AbstractMessageSource extends MessageSourceSupport impleme * @see #resolveCode * @see java.text.MessageFormat */ - @Nullable - protected String resolveCodeWithoutArguments(String code, Locale locale) { + protected @Nullable String resolveCodeWithoutArguments(String code, Locale locale) { MessageFormat messageFormat = resolveCode(code, locale); if (messageFormat != null) { synchronized (messageFormat) { @@ -388,7 +379,6 @@ 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); + protected abstract @Nullable MessageFormat resolveCode(String code, Locale locale); } diff --git a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java index 5acf9148f2..30d06cc26b 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java @@ -18,12 +18,13 @@ package org.springframework.context.support; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextException; -import org.springframework.lang.Nullable; /** * Base class for {@link org.springframework.context.ApplicationContext} @@ -64,15 +65,12 @@ import org.springframework.lang.Nullable; */ public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext { - @Nullable - private Boolean allowBeanDefinitionOverriding; + private @Nullable Boolean allowBeanDefinitionOverriding; - @Nullable - private Boolean allowCircularReferences; + private @Nullable Boolean allowCircularReferences; /** Bean factory for this context. */ - @Nullable - private volatile DefaultListableBeanFactory beanFactory; + private volatile @Nullable DefaultListableBeanFactory beanFactory; /** 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 901e715230..ac63bcd5c5 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 @@ -16,10 +16,11 @@ package org.springframework.context.support; +import org.jspecify.annotations.Nullable; + 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; @@ -39,8 +40,7 @@ import org.springframework.util.StringUtils; public abstract class AbstractRefreshableConfigApplicationContext extends AbstractRefreshableApplicationContext implements BeanNameAware, InitializingBean { - @Nullable - private String[] configLocations; + private String @Nullable [] configLocations; private boolean setIdCalled = false; @@ -73,7 +73,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra * Set the config locations for this application context. *

If not set, the implementation may use a default as appropriate. */ - public void setConfigLocations(@Nullable String... locations) { + public void setConfigLocations(String @Nullable ... locations) { if (locations != null) { Assert.noNullElements(locations, "Config locations must not be null"); this.configLocations = new String[locations.length]; @@ -96,8 +96,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra * @see #getResources * @see #getResourcePatternResolver */ - @Nullable - protected String[] getConfigLocations() { + protected String @Nullable [] getConfigLocations() { return (this.configLocations != null ? this.configLocations : getDefaultConfigLocations()); } @@ -109,8 +108,7 @@ public abstract class AbstractRefreshableConfigApplicationContext extends Abstra * @return an array of default config locations, if any * @see #setConfigLocations */ - @Nullable - protected String[] getDefaultConfigLocations() { + protected String @Nullable [] 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 0a0f8bd0be..45dafd462d 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 @@ -20,7 +20,8 @@ import java.util.LinkedHashSet; import java.util.Locale; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -39,13 +40,11 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage private final Set basenameSet = new LinkedHashSet<>(4); - @Nullable - private String defaultEncoding; + private @Nullable String defaultEncoding; private boolean fallbackToSystemLocale = true; - @Nullable - private Locale defaultLocale; + private @Nullable Locale defaultLocale; private long cacheMillis = -1; @@ -134,8 +133,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() { + protected @Nullable String getDefaultEncoding() { return this.defaultEncoding; } @@ -187,8 +185,7 @@ public abstract class AbstractResourceBasedMessageSource extends AbstractMessage * @see #setFallbackToSystemLocale * @see Locale#getDefault() */ - @Nullable - protected Locale getDefaultLocale() { + protected @Nullable Locale getDefaultLocale() { if (this.defaultLocale != null) { return this.defaultLocale; } 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 961704adcf..372f9bc939 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 @@ -18,6 +18,8 @@ package org.springframework.context.support; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.xml.BeanDefinitionDocumentReader; @@ -25,7 +27,6 @@ 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} @@ -139,8 +140,7 @@ public abstract class AbstractXmlApplicationContext extends AbstractRefreshableC * @return an array of Resource objects, or {@code null} if none * @see #getConfigLocations() */ - @Nullable - protected Resource[] getConfigResources() { + protected Resource @Nullable [] getConfigResources() { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java b/spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java index 1da55ce8fe..7e1124ead0 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/ApplicationContextAwareProcessor.java @@ -16,6 +16,8 @@ package org.springframework.context.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.Aware; import org.springframework.beans.factory.config.BeanPostProcessor; @@ -28,7 +30,6 @@ import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.context.EnvironmentAware; import org.springframework.context.MessageSourceAware; import org.springframework.context.ResourceLoaderAware; -import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; /** @@ -79,8 +80,7 @@ class ApplicationContextAwareProcessor implements BeanPostProcessor { @Override - @Nullable - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + public @Nullable Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof Aware) { invokeAwareInterfaces(bean); } diff --git a/spring-context/src/main/java/org/springframework/context/support/ApplicationListenerDetector.java b/spring-context/src/main/java/org/springframework/context/support/ApplicationListenerDetector.java index 342839892a..62a3765f73 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ApplicationListenerDetector.java +++ b/spring-context/src/main/java/org/springframework/context/support/ApplicationListenerDetector.java @@ -22,13 +22,13 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; import org.springframework.beans.factory.support.MergedBeanDefinitionPostProcessor; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ApplicationEventMulticaster; -import org.springframework.lang.Nullable; /** * {@code BeanPostProcessor} that detects beans which implement the {@code ApplicationListener} diff --git a/spring-context/src/main/java/org/springframework/context/support/ApplicationObjectSupport.java b/spring-context/src/main/java/org/springframework/context/support/ApplicationObjectSupport.java index 73d37a4aa2..44fbdce7b2 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ApplicationObjectSupport.java +++ b/spring-context/src/main/java/org/springframework/context/support/ApplicationObjectSupport.java @@ -18,12 +18,12 @@ package org.springframework.context.support; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationContextException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,12 +52,10 @@ public abstract class ApplicationObjectSupport implements ApplicationContextAwar protected final Log logger = LogFactory.getLog(getClass()); /** ApplicationContext this object runs in. */ - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; /** MessageSourceAccessor for easy message access. */ - @Nullable - private MessageSourceAccessor messageSourceAccessor; + private @Nullable MessageSourceAccessor messageSourceAccessor; @Override @@ -140,8 +138,7 @@ public abstract class ApplicationObjectSupport implements ApplicationContextAwar * Return the ApplicationContext that this object is associated with. * @throws IllegalStateException if not running in an ApplicationContext */ - @Nullable - public final ApplicationContext getApplicationContext() throws IllegalStateException { + public final @Nullable ApplicationContext getApplicationContext() throws IllegalStateException { if (this.applicationContext == null && isContextRequired()) { throw new IllegalStateException( "ApplicationObjectSupport instance [" + this + "] does not run in an ApplicationContext"); @@ -166,8 +163,7 @@ public abstract class ApplicationObjectSupport implements ApplicationContextAwar * used by this object, for easy message access. * @throws IllegalStateException if not running in an ApplicationContext */ - @Nullable - protected final MessageSourceAccessor getMessageSourceAccessor() throws IllegalStateException { + protected final @Nullable MessageSourceAccessor getMessageSourceAccessor() throws IllegalStateException { if (this.messageSourceAccessor == null && isContextRequired()) { throw new IllegalStateException( "ApplicationObjectSupport instance [" + this + "] does not run in an ApplicationContext"); diff --git a/spring-context/src/main/java/org/springframework/context/support/ClassPathXmlApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/ClassPathXmlApplicationContext.java index 57fa661285..bdb2736f35 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ClassPathXmlApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/ClassPathXmlApplicationContext.java @@ -16,11 +16,12 @@ package org.springframework.context.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -51,8 +52,7 @@ import org.springframework.util.Assert; */ public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext { - @Nullable - private Resource[] configResources; + private Resource @Nullable [] configResources; /** @@ -204,8 +204,7 @@ public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContex @Override - @Nullable - protected Resource[] getConfigResources() { + protected Resource @Nullable [] getConfigResources() { return this.configResources; } diff --git a/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java b/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java index 525d916ca0..531feb00c9 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java +++ b/spring-context/src/main/java/org/springframework/context/support/ContextTypeMatchClassLoader.java @@ -22,11 +22,11 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.DecoratingClassLoader; import org.springframework.core.OverridingClassLoader; import org.springframework.core.SmartClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -47,8 +47,7 @@ class ContextTypeMatchClassLoader extends DecoratingClassLoader implements Smart } - @Nullable - private static final Method findLoadedClassMethod; + private static final @Nullable Method findLoadedClassMethod; static { // Try to enable findLoadedClass optimization which allows us to selectively @@ -123,8 +122,7 @@ class ContextTypeMatchClassLoader extends DecoratingClassLoader implements Smart } @Override - @Nullable - protected Class loadClassForOverriding(String name) throws ClassNotFoundException { + protected @Nullable Class loadClassForOverriding(String name) throws ClassNotFoundException { byte[] bytes = bytesCache.get(name); if (bytes == null) { bytes = loadBytesForClass(name); diff --git a/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java b/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java index f04f33d2fc..3ca93ab825 100644 --- a/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/context/support/ConversionServiceFactoryBean.java @@ -18,13 +18,14 @@ package org.springframework.context.support; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.ConversionServiceFactory; import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.core.convert.support.GenericConversionService; -import org.springframework.lang.Nullable; /** * A factory providing convenient access to a ConversionService configured with @@ -50,11 +51,9 @@ import org.springframework.lang.Nullable; */ public class ConversionServiceFactoryBean implements FactoryBean, InitializingBean { - @Nullable - private Set converters; + private @Nullable Set converters; - @Nullable - private GenericConversionService conversionService; + private @Nullable GenericConversionService conversionService; /** @@ -87,8 +86,7 @@ public class ConversionServiceFactoryBean implements FactoryBean stoppedBeans; + private volatile @Nullable Set stoppedBeans; // Just for keeping a strong reference to the registered CRaC Resource, if any - @Nullable - private Object cracResource; + private @Nullable Object cracResource; public DefaultLifecycleProcessor() { @@ -592,8 +589,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor */ private class CracResourceAdapter implements org.crac.Resource { - @Nullable - private CyclicBarrier barrier; + private @Nullable CyclicBarrier barrier; @Override public void beforeCheckpoint(org.crac.Context context) { diff --git a/spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java b/spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java index df09bc8957..1d0bf70ae4 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java +++ b/spring-context/src/main/java/org/springframework/context/support/DefaultMessageSourceResolvable.java @@ -18,8 +18,9 @@ package org.springframework.context.support; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSourceResolvable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -35,14 +36,11 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public class DefaultMessageSourceResolvable implements MessageSourceResolvable, Serializable { - @Nullable - private final String[] codes; + private final String @Nullable [] codes; - @Nullable - private final Object[] arguments; + private final Object @Nullable [] arguments; - @Nullable - private final String defaultMessage; + private final @Nullable String defaultMessage; /** @@ -86,7 +84,7 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable, * @param defaultMessage the default message to be used to resolve this message */ public DefaultMessageSourceResolvable( - @Nullable String[] codes, @Nullable Object[] arguments, @Nullable String defaultMessage) { + String @Nullable [] codes, Object @Nullable [] arguments, @Nullable String defaultMessage) { this.codes = codes; this.arguments = arguments; @@ -106,26 +104,22 @@ public class DefaultMessageSourceResolvable implements MessageSourceResolvable, * Return the default code of this resolvable, that is, * the last one in the codes array. */ - @Nullable - public String getCode() { + public @Nullable String getCode() { return (this.codes != null && this.codes.length > 0 ? this.codes[this.codes.length - 1] : null); } @Override - @Nullable - public String[] getCodes() { + public String @Nullable [] getCodes() { return this.codes; } @Override - @Nullable - public Object[] getArguments() { + public Object @Nullable [] getArguments() { return this.arguments; } @Override - @Nullable - public String getDefaultMessage() { + public @Nullable String getDefaultMessage() { return this.defaultMessage; } diff --git a/spring-context/src/main/java/org/springframework/context/support/DelegatingMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/DelegatingMessageSource.java index afe4db3e89..23359724f6 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DelegatingMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/DelegatingMessageSource.java @@ -18,11 +18,12 @@ package org.springframework.context.support; import java.util.Locale; +import org.jspecify.annotations.Nullable; + 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; /** * Empty {@link MessageSource} that delegates all calls to the parent MessageSource. @@ -37,8 +38,7 @@ import org.springframework.lang.Nullable; */ public class DelegatingMessageSource extends MessageSourceSupport implements HierarchicalMessageSource { - @Nullable - private MessageSource parentMessageSource; + private @Nullable MessageSource parentMessageSource; @Override @@ -47,15 +47,13 @@ public class DelegatingMessageSource extends MessageSourceSupport implements Hie } @Override - @Nullable - public MessageSource getParentMessageSource() { + public @Nullable MessageSource getParentMessageSource() { return this.parentMessageSource; } @Override - @Nullable - public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) { + public @Nullable String getMessage(String code, Object @Nullable [] args, @Nullable String defaultMessage, Locale locale) { if (this.parentMessageSource != null) { return this.parentMessageSource.getMessage(code, args, defaultMessage, locale); } @@ -68,7 +66,7 @@ public class DelegatingMessageSource extends MessageSourceSupport implements Hie } @Override - public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args, Locale locale) throws NoSuchMessageException { if (this.parentMessageSource != null) { return this.parentMessageSource.getMessage(code, args, locale); } diff --git a/spring-context/src/main/java/org/springframework/context/support/EmbeddedValueResolutionSupport.java b/spring-context/src/main/java/org/springframework/context/support/EmbeddedValueResolutionSupport.java index dc85006c5d..6f9948e7dc 100644 --- a/spring-context/src/main/java/org/springframework/context/support/EmbeddedValueResolutionSupport.java +++ b/spring-context/src/main/java/org/springframework/context/support/EmbeddedValueResolutionSupport.java @@ -16,8 +16,9 @@ package org.springframework.context.support; +import org.jspecify.annotations.Nullable; + import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; /** @@ -29,8 +30,7 @@ import org.springframework.util.StringValueResolver; */ public class EmbeddedValueResolutionSupport implements EmbeddedValueResolverAware { - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; @Override @@ -44,8 +44,7 @@ public class EmbeddedValueResolutionSupport implements EmbeddedValueResolverAwar * @return the resolved value, or always the original value if no resolver is available * @see #setEmbeddedValueResolver */ - @Nullable - protected String resolveEmbeddedValue(String value) { + protected @Nullable String resolveEmbeddedValue(String value) { return (this.embeddedValueResolver != null ? this.embeddedValueResolver.resolveStringValue(value) : value); } diff --git a/spring-context/src/main/java/org/springframework/context/support/FileSystemXmlApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/FileSystemXmlApplicationContext.java index c9166da801..556d077fee 100644 --- a/spring-context/src/main/java/org/springframework/context/support/FileSystemXmlApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/FileSystemXmlApplicationContext.java @@ -16,11 +16,12 @@ package org.springframework.context.support; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Standalone XML application context, taking the context definition files 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 f76668f4eb..954877fdf1 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 @@ -23,6 +23,8 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.support.ClassHintUtils; import org.springframework.beans.BeanUtils; @@ -45,7 +47,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.metrics.ApplicationStartup; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -107,8 +108,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem private final DefaultListableBeanFactory beanFactory; - @Nullable - private ResourceLoader resourceLoader; + private @Nullable ResourceLoader resourceLoader; private boolean customClassLoader = false; @@ -270,8 +270,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { if (this.resourceLoader != null && !this.customClassLoader) { return this.resourceLoader.getClassLoader(); } @@ -612,8 +611,7 @@ public class GenericApplicationContext extends AbstractApplicationContext implem } @Override - @Nullable - public Constructor[] getPreferredConstructors() { + public Constructor @Nullable [] getPreferredConstructors() { Constructor[] fromAttribute = super.getPreferredConstructors(); if (fromAttribute != null) { return fromAttribute; diff --git a/spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java index e164165074..355986bbc0 100644 --- a/spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/GenericGroovyApplicationContext.java @@ -19,6 +19,7 @@ package org.springframework.context.support; import groovy.lang.GroovyObject; import groovy.lang.GroovySystem; import groovy.lang.MetaClass; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * An {@link org.springframework.context.ApplicationContext} implementation that extends @@ -251,8 +251,7 @@ public class GenericGroovyApplicationContext extends GenericApplicationContext i } @Override - @Nullable - public Object getProperty(String property) { + public @Nullable Object getProperty(String property) { if (containsBean(property)) { return getBean(property); } 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 ba3f7b7c9b..508f468d76 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 @@ -18,11 +18,12 @@ package org.springframework.context.support; import java.util.Locale; +import org.jspecify.annotations.Nullable; + 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, @@ -39,8 +40,7 @@ public class MessageSourceAccessor { private final MessageSource messageSource; - @Nullable - private final Locale defaultLocale; + private final @Nullable Locale defaultLocale; /** @@ -107,7 +107,7 @@ public class MessageSourceAccessor { * @param defaultMessage the String to return if the lookup fails * @return the message */ - public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { + public String getMessage(String code, Object @Nullable [] args, String defaultMessage) { String msg = this.messageSource.getMessage(code, args, defaultMessage, getDefaultLocale()); return (msg != null ? msg : ""); } @@ -120,7 +120,7 @@ public class MessageSourceAccessor { * @param locale the Locale in which to do lookup * @return the message */ - public String getMessage(String code, @Nullable Object[] args, String defaultMessage, Locale locale) { + public String getMessage(String code, Object @Nullable [] args, String defaultMessage, Locale locale) { String msg = this.messageSource.getMessage(code, args, defaultMessage, locale); return (msg != null ? msg : ""); } @@ -153,7 +153,7 @@ public class MessageSourceAccessor { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args) throws NoSuchMessageException { return this.messageSource.getMessage(code, args, getDefaultLocale()); } @@ -165,7 +165,7 @@ public class MessageSourceAccessor { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] 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 b860a38082..29fd34b1f3 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 @@ -20,9 +20,10 @@ import java.util.Enumeration; import java.util.Locale; import java.util.ResourceBundle; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSource; import org.springframework.context.NoSuchMessageException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -71,8 +72,7 @@ public class MessageSourceResourceBundle extends ResourceBundle { * Returns {@code null} if the message could not be resolved. */ @Override - @Nullable - protected Object handleGetObject(String key) { + protected @Nullable 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 9aaaf33bcd..96b633b476 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 @@ -23,8 +23,8 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -98,7 +98,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, @Nullable Object[] args, Locale locale) { + protected String renderDefaultMessage(String defaultMessage, Object @Nullable [] args, Locale locale) { return formatMessage(defaultMessage, args, locale); } @@ -112,7 +112,7 @@ public abstract class MessageSourceSupport { * @param locale the Locale used for formatting * @return the formatted message (with resolved arguments) */ - protected String formatMessage(String msg, @Nullable Object[] args, Locale locale) { + protected String formatMessage(String msg, Object @Nullable [] args, Locale locale) { if (!isAlwaysUseMessageFormat() && ObjectUtils.isEmpty(args)) { return msg; } @@ -158,7 +158,7 @@ public abstract class MessageSourceSupport { * @param locale the Locale to resolve against * @return the resolved argument array */ - protected Object[] resolveArguments(@Nullable Object[] args, Locale locale) { + protected Object[] resolveArguments(Object @Nullable [] args, Locale locale) { return (args != null ? args : new Object[0]); } diff --git a/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java b/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java index 5d6784191a..00d783a977 100644 --- a/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java +++ b/spring-context/src/main/java/org/springframework/context/support/PostProcessorRegistrationDelegate.java @@ -27,6 +27,7 @@ import java.util.function.BiConsumer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.PropertyValue; import org.springframework.beans.factory.config.BeanDefinition; @@ -49,7 +50,6 @@ import org.springframework.core.Ordered; import org.springframework.core.PriorityOrdered; import org.springframework.core.metrics.ApplicationStartup; import org.springframework.core.metrics.StartupStep; -import org.springframework.lang.Nullable; /** * Delegate for AbstractApplicationContext's post-processor handling. diff --git a/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java b/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java index 31d1652542..36ee67f3a9 100644 --- a/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java +++ b/spring-context/src/main/java/org/springframework/context/support/PropertySourcesPlaceholderConfigurer.java @@ -19,6 +19,8 @@ package org.springframework.context.support; import java.io.IOException; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -33,7 +35,6 @@ import org.springframework.core.env.PropertyResolver; import org.springframework.core.env.PropertySource; import org.springframework.core.env.PropertySources; import org.springframework.core.env.PropertySourcesPropertyResolver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringValueResolver; @@ -80,14 +81,11 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS public static final String ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME = "environmentProperties"; - @Nullable - private MutablePropertySources propertySources; + private @Nullable MutablePropertySources propertySources; - @Nullable - private PropertySources appliedPropertySources; + private @Nullable PropertySources appliedPropertySources; - @Nullable - private Environment environment; + private @Nullable Environment environment; /** @@ -148,8 +146,7 @@ public class PropertySourcesPlaceholderConfigurer extends PlaceholderConfigurerS this.propertySources.addLast( new PropertySource<>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) { @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return propertyResolverToUse.getProperty(key); } } 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 3f70d04943..d79fde8e40 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 @@ -31,11 +31,12 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.jspecify.annotations.Nullable; + 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.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.DefaultPropertiesPersister; @@ -97,8 +98,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased private List fileExtensions = List.of(".properties", XML_EXTENSION); - @Nullable - private Properties fileEncodings; + private @Nullable Properties fileEncodings; private boolean concurrentRefresh = true; @@ -191,8 +191,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased * returning the value found in the bundle as-is (without MessageFormat parsing). */ @Override - @Nullable - protected String resolveCodeWithoutArguments(String code, Locale locale) { + protected @Nullable String resolveCodeWithoutArguments(String code, Locale locale) { if (getCacheMillis() < 0) { PropertiesHolder propHolder = getMergedProperties(locale); String result = propHolder.getProperty(code); @@ -220,8 +219,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased * using a cached MessageFormat instance per message code. */ @Override - @Nullable - protected MessageFormat resolveCode(String code, Locale locale) { + protected @Nullable MessageFormat resolveCode(String code, Locale locale) { if (getCacheMillis() < 0) { PropertiesHolder propHolder = getMergedProperties(locale); MessageFormat result = propHolder.getMessageFormat(code, locale); @@ -542,8 +540,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased * @return the {@code Resource} to use, or {@code null} if none found * @since 6.1 */ - @Nullable - protected Resource resolveResource(String filename) { + protected @Nullable Resource resolveResource(String filename) { for (String fileExtension : this.fileExtensions) { Resource resource = this.resourceLoader.getResource(filename + fileExtension); if (resource.exists()) { @@ -645,8 +642,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased */ protected class PropertiesHolder { - @Nullable - private final Properties properties; + private final @Nullable Properties properties; private final long fileTimestamp; @@ -668,8 +664,7 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased this.fileTimestamp = fileTimestamp; } - @Nullable - public Properties getProperties() { + public @Nullable Properties getProperties() { return this.properties; } @@ -685,16 +680,14 @@ public class ReloadableResourceBundleMessageSource extends AbstractResourceBased return this.refreshTimestamp; } - @Nullable - public String getProperty(String code) { + public @Nullable String getProperty(String code) { if (this.properties == null) { return null; } return this.properties.getProperty(code); } - @Nullable - public MessageFormat getMessageFormat(String code, Locale locale) { + public @Nullable 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 bc3393ebb6..3b325e831d 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 @@ -31,8 +31,9 @@ import java.util.ResourceBundle; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -76,11 +77,9 @@ import org.springframework.util.ClassUtils; */ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSource implements BeanClassLoaderAware { - @Nullable - private ClassLoader bundleClassLoader; + private @Nullable ClassLoader bundleClassLoader; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); /** * Cache to hold loaded ResourceBundles. @@ -103,8 +102,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou private final Map>> cachedBundleMessageFormats = new ConcurrentHashMap<>(); - @Nullable - private volatile MessageSourceControl control = new MessageSourceControl(); + private volatile @Nullable MessageSourceControl control = new MessageSourceControl(); public ResourceBundleMessageSource() { @@ -129,8 +127,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou *

Default is the containing BeanFactory's bean ClassLoader. * @see #setBundleClassLoader */ - @Nullable - protected ClassLoader getBundleClassLoader() { + protected @Nullable ClassLoader getBundleClassLoader() { return (this.bundleClassLoader != null ? this.bundleClassLoader : this.beanClassLoader); } @@ -145,8 +142,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou * returning the value found in the bundle as-is (without MessageFormat parsing). */ @Override - @Nullable - protected String resolveCodeWithoutArguments(String code, Locale locale) { + protected @Nullable String resolveCodeWithoutArguments(String code, Locale locale) { Set basenames = getBasenameSet(); for (String basename : basenames) { ResourceBundle bundle = getResourceBundle(basename, locale); @@ -165,8 +161,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou * using a cached MessageFormat instance per message code. */ @Override - @Nullable - protected MessageFormat resolveCode(String code, Locale locale) { + protected @Nullable MessageFormat resolveCode(String code, Locale locale) { Set basenames = getBasenameSet(); for (String basename : basenames) { ResourceBundle bundle = getResourceBundle(basename, locale); @@ -189,8 +184,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) { + protected @Nullable ResourceBundle getResourceBundle(String basename, Locale locale) { if (getCacheMillis() >= 0) { // Fresh ResourceBundle.getBundle call in order to let ResourceBundle // do its native caching, at the expense of more extensive lookup steps. @@ -311,8 +305,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) + protected @Nullable MessageFormat getMessageFormat(ResourceBundle bundle, String code, Locale locale) throws MissingResourceException { Map> codeMap = this.cachedBundleMessageFormats.get(bundle); @@ -357,8 +350,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou * @see ResourceBundle#getString(String) * @see ResourceBundle#containsKey(String) */ - @Nullable - protected String getStringOrNull(ResourceBundle bundle, String key) { + protected @Nullable String getStringOrNull(ResourceBundle bundle, String key) { if (bundle.containsKey(key)) { try { return bundle.getString(key); @@ -388,8 +380,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou private class MessageSourceControl extends ResourceBundle.Control { @Override - @Nullable - public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) + public @Nullable ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader, boolean reload) throws IllegalAccessException, InstantiationException, IOException { // Special handling of default encoding @@ -436,8 +427,7 @@ public class ResourceBundleMessageSource extends AbstractResourceBasedMessageSou } @Override - @Nullable - public Locale getFallbackLocale(String baseName, Locale locale) { + public @Nullable Locale getFallbackLocale(String baseName, Locale locale) { Locale defaultLocale = getDefaultLocale(); return (defaultLocale != null && !defaultLocale.equals(locale) ? defaultLocale : null); } diff --git a/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java b/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java index 00af013192..67bad8cae5 100644 --- a/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java +++ b/spring-context/src/main/java/org/springframework/context/support/SimpleThreadScope.java @@ -21,11 +21,11 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.Scope; import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; /** * A simple thread-backed {@link Scope} implementation. @@ -72,8 +72,7 @@ public class SimpleThreadScope implements Scope { } @Override - @Nullable - public Object remove(String name) { + public @Nullable Object remove(String name) { Map scope = this.threadScope.get(); return scope.remove(name); } @@ -85,8 +84,7 @@ public class SimpleThreadScope implements Scope { } @Override - @Nullable - public Object resolveContextualObject(String key) { + public @Nullable Object resolveContextualObject(String key) { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/support/StaticApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/StaticApplicationContext.java index fc58e3f503..2ede88fd56 100644 --- a/spring-context/src/main/java/org/springframework/context/support/StaticApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/StaticApplicationContext.java @@ -18,12 +18,13 @@ package org.springframework.context.support; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.MutablePropertyValues; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.support.GenericBeanDefinition; import org.springframework.context.ApplicationContext; -import org.springframework.lang.Nullable; /** * {@link org.springframework.context.ApplicationContext} implementation diff --git a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java index 9f8ace3ab2..44105778d9 100644 --- a/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java +++ b/spring-context/src/main/java/org/springframework/context/support/StaticMessageSource.java @@ -21,7 +21,8 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -40,8 +41,7 @@ public class StaticMessageSource extends AbstractMessageSource { @Override - @Nullable - protected String resolveCodeWithoutArguments(String code, Locale locale) { + protected @Nullable String resolveCodeWithoutArguments(String code, Locale locale) { Map localeMap = this.messageMap.get(code); if (localeMap == null) { return null; @@ -54,8 +54,7 @@ public class StaticMessageSource extends AbstractMessageSource { } @Override - @Nullable - protected MessageFormat resolveCode(String code, Locale locale) { + protected @Nullable MessageFormat resolveCode(String code, Locale locale) { Map localeMap = this.messageMap.get(code); if (localeMap == null) { return null; @@ -107,8 +106,7 @@ public class StaticMessageSource extends AbstractMessageSource { private final Locale locale; - @Nullable - private volatile MessageFormat cachedFormat; + private volatile @Nullable MessageFormat cachedFormat; public MessageHolder(String message, Locale locale) { this.message = message; 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 2ec0ef5153..fabae8e747 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,9 +3,7 @@ * such as abstract base classes for ApplicationContext * implementations and a MessageSource implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 db73317d36..47a35f9397 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 @@ -21,6 +21,7 @@ import java.lang.instrument.IllegalClassFormatException; import java.security.ProtectionDomain; import org.aspectj.weaver.loadtime.ClassPreProcessorAgentAdapter; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanClassLoaderAware; @@ -29,7 +30,6 @@ 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 @@ -50,11 +50,9 @@ public class AspectJWeavingEnabler public static final String ASPECTJ_AOP_XML_RESOURCE = "META-INF/aop.xml"; - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; - @Nullable - private LoadTimeWeaver loadTimeWeaver; + private @Nullable LoadTimeWeaver loadTimeWeaver; @Override 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 9a815627fb..927ce20540 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 @@ -20,6 +20,7 @@ import java.lang.instrument.ClassFileTransformer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.DisposableBean; @@ -30,7 +31,6 @@ import org.springframework.instrument.classloading.ReflectiveLoadTimeWeaver; import org.springframework.instrument.classloading.glassfish.GlassFishLoadTimeWeaver; import org.springframework.instrument.classloading.jboss.JBossLoadTimeWeaver; import org.springframework.instrument.classloading.tomcat.TomcatLoadTimeWeaver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -57,8 +57,7 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private LoadTimeWeaver loadTimeWeaver; + private @Nullable LoadTimeWeaver loadTimeWeaver; public DefaultContextLoadTimeWeaver() { @@ -104,8 +103,7 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo * determining a load-time weaver based on the ClassLoader name alone may * legitimately fail due to other mismatches. */ - @Nullable - protected LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) { + protected @Nullable LoadTimeWeaver createServerSpecificLoadTimeWeaver(ClassLoader classLoader) { String name = classLoader.getClass().getName(); try { if (name.startsWith("org.apache.catalina")) { 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 bb045de9a6..2b06c262ff 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 @@ -16,13 +16,14 @@ package org.springframework.context.weaving; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; 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; /** @@ -43,11 +44,9 @@ import org.springframework.util.Assert; */ public class LoadTimeWeaverAwareProcessor implements BeanPostProcessor, BeanFactoryAware { - @Nullable - private LoadTimeWeaver loadTimeWeaver; + private @Nullable LoadTimeWeaver loadTimeWeaver; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** 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 889d99ed2c..4dccb6742c 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,9 +2,7 @@ * Load-time weaving support for a Spring application context, building on Spring's * {@link org.springframework.instrument.classloading.LoadTimeWeaver} abstraction. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.weaving; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 501900852b..4439dd3250 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,9 +2,7 @@ * Support package for EJB/Jakarta EE-related configuration, * with XML schema being the primary configuration format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.ejb.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java b/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java index 60813fc909..a9fb8adae5 100644 --- a/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java +++ b/spring-context/src/main/java/org/springframework/format/annotation/DurationFormat.java @@ -25,7 +25,7 @@ import java.time.Duration; import java.time.temporal.ChronoUnit; import java.util.function.Function; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Declares that a field or method parameter should be formatted as a 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 207316bb12..473eac4515 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,9 +1,7 @@ /** * Annotations for declaratively configuring field and parameter formatting rules. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java index ff6a5cce22..32ba16381d 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatter.java @@ -28,10 +28,11 @@ import java.util.Map; import java.util.Set; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.format.Formatter; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -76,25 +77,19 @@ public class DateFormatter implements Formatter { } - @Nullable - private Object source; + private @Nullable Object source; - @Nullable - private String pattern; + private @Nullable String pattern; - @Nullable - private String[] fallbackPatterns; + private String @Nullable [] fallbackPatterns; private int style = DateFormat.DEFAULT; - @Nullable - private String stylePattern; + private @Nullable String stylePattern; - @Nullable - private ISO iso; + private @Nullable ISO iso; - @Nullable - private TimeZone timeZone; + private @Nullable TimeZone timeZone; private boolean lenient = false; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java index 2c165c5c0f..0e0c37cd1c 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/DateFormatterRegistrar.java @@ -19,11 +19,12 @@ package org.springframework.format.datetime; import java.util.Calendar; import java.util.Date; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterRegistry; import org.springframework.format.FormatterRegistrar; import org.springframework.format.FormatterRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,8 +43,7 @@ import org.springframework.util.Assert; */ public class DateFormatterRegistrar implements FormatterRegistrar { - @Nullable - private DateFormatter dateFormatter; + private @Nullable DateFormatter dateFormatter; /** 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 b6f4686c34..a56e0229c4 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,9 +1,7 @@ /** * Formatters for {@code java.util.Date} properties. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format.datetime; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 9e2f2668ec..7ef08ebee3 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 @@ -21,10 +21,11 @@ import java.time.chrono.Chronology; import java.time.format.DateTimeFormatter; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + 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 @@ -37,11 +38,9 @@ import org.springframework.lang.Nullable; */ public class DateTimeContext { - @Nullable - private Chronology chronology; + private @Nullable Chronology chronology; - @Nullable - private ZoneId timeZone; + private @Nullable ZoneId timeZone; /** @@ -54,8 +53,7 @@ public class DateTimeContext { /** * Return the user's chronology (calendar system), if any. */ - @Nullable - public Chronology getChronology() { + public @Nullable Chronology getChronology() { return this.chronology; } @@ -74,8 +72,7 @@ public class DateTimeContext { /** * Return the user's time zone, if any. */ - @Nullable - public ZoneId getTimeZone() { + public @Nullable 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 aa5a5223ef..6fd18beef0 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 @@ -19,8 +19,9 @@ package org.springframework.format.datetime.standard; import java.time.format.DateTimeFormatter; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; /** * A holder for a thread-local user {@link DateTimeContext}. @@ -64,8 +65,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() { + public static @Nullable DateTimeContext getDateTimeContext() { return dateTimeContextHolder.get(); } 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 f58b7d6021..8613ac1790 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 @@ -20,8 +20,9 @@ import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.format.annotation.DateTimeFormat.ISO; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -46,20 +47,15 @@ import org.springframework.util.StringUtils; */ public class DateTimeFormatterFactory { - @Nullable - private String pattern; + private @Nullable String pattern; - @Nullable - private ISO iso; + private @Nullable ISO iso; - @Nullable - private FormatStyle dateStyle; + private @Nullable FormatStyle dateStyle; - @Nullable - private FormatStyle timeStyle; + private @Nullable FormatStyle timeStyle; - @Nullable - private TimeZone timeZone; + private @Nullable TimeZone timeZone; /** @@ -137,8 +133,7 @@ public class DateTimeFormatterFactory { this.timeStyle = convertStyleCharacter(style.charAt(1)); } - @Nullable - private FormatStyle convertStyleCharacter(char c) { + private @Nullable FormatStyle convertStyleCharacter(char c) { return switch (c) { case 'S' -> FormatStyle.SHORT; case 'M' -> FormatStyle.MEDIUM; diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryBean.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryBean.java index 1a48b8c52b..35282f4680 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DateTimeFormatterFactoryBean.java @@ -18,9 +18,10 @@ package org.springframework.format.datetime.standard; import java.time.format.DateTimeFormatter; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * {@link FactoryBean} that creates a JSR-310 {@link java.time.format.DateTimeFormatter}. @@ -37,8 +38,7 @@ import org.springframework.lang.Nullable; public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory implements FactoryBean, InitializingBean { - @Nullable - private DateTimeFormatter dateTimeFormatter; + private @Nullable DateTimeFormatter dateTimeFormatter; @Override @@ -47,8 +47,7 @@ public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory } @Override - @Nullable - public DateTimeFormatter getObject() { + public @Nullable DateTimeFormatter getObject() { return this.dateTimeFormatter; } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java index ee9a53a36c..cc920c7d7d 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatter.java @@ -20,9 +20,10 @@ import java.text.ParseException; import java.time.Duration; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.format.Formatter; import org.springframework.format.annotation.DurationFormat; -import org.springframework.lang.Nullable; /** * {@link Formatter} implementation for a JSR-310 {@link Duration}, @@ -37,8 +38,8 @@ import org.springframework.lang.Nullable; public class DurationFormatter implements Formatter { private final DurationFormat.Style style; - @Nullable - private final DurationFormat.Unit defaultUnit; + + private final DurationFormat.@Nullable Unit defaultUnit; /** * Create a {@code DurationFormatter} following JSR-310's parsing rules for a Duration @@ -69,7 +70,7 @@ public class DurationFormatter implements Formatter { * @param style the {@code DurationStyle} to use * @param defaultUnit the {@code DurationFormat.Unit} to fall back to when parsing and printing */ - public DurationFormatter(DurationFormat.Style style, @Nullable DurationFormat.Unit defaultUnit) { + public DurationFormatter(DurationFormat.Style style, DurationFormat.@Nullable Unit defaultUnit) { this.style = style; this.defaultUnit = defaultUnit; } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java index b1f5f3e58b..d9266eb91d 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/DurationFormatterUtils.java @@ -20,8 +20,9 @@ import java.time.Duration; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.format.annotation.DurationFormat; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -61,7 +62,7 @@ public abstract class DurationFormatterUtils { * will default to ms) * @return a duration */ - public static Duration parse(String value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) { + public static Duration parse(String value, DurationFormat.Style style, DurationFormat.@Nullable Unit unit) { Assert.hasText(value, () -> "Value must not be empty"); return switch (style) { case ISO8601 -> parseIso8601(value); @@ -88,7 +89,7 @@ public abstract class DurationFormatterUtils { * to ms) * @return the printed result */ - public static String print(Duration value, DurationFormat.Style style, @Nullable DurationFormat.Unit unit) { + public static String print(Duration value, DurationFormat.Style style, DurationFormat.@Nullable Unit unit) { return switch (style) { case ISO8601 -> value.toString(); case SIMPLE -> printSimple(value, unit); @@ -116,7 +117,7 @@ public abstract class DurationFormatterUtils { * @throws IllegalArgumentException if the value is not a known style or cannot be * parsed */ - public static Duration detectAndParse(String value, @Nullable DurationFormat.Unit unit) { + public static Duration detectAndParse(String value, DurationFormat.@Nullable Unit unit) { return parse(value, detect(value), unit); } @@ -155,7 +156,7 @@ public abstract class DurationFormatterUtils { } } - private static Duration parseSimple(String text, @Nullable DurationFormat.Unit fallbackUnit) { + private static Duration parseSimple(String text, DurationFormat.@Nullable Unit fallbackUnit) { try { Matcher matcher = SIMPLE_PATTERN.matcher(text); Assert.state(matcher.matches(), "Does not match simple duration pattern"); @@ -171,7 +172,7 @@ public abstract class DurationFormatterUtils { } } - private static String printSimple(Duration duration, @Nullable DurationFormat.Unit unit) { + private static String printSimple(Duration duration, DurationFormat.@Nullable Unit unit) { unit = (unit == null ? DurationFormat.Unit.MILLIS : unit); return unit.print(duration); } diff --git a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java index eec58f9eac..0bac06c965 100644 --- a/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java +++ b/spring-context/src/main/java/org/springframework/format/datetime/standard/TemporalAccessorParser.java @@ -31,8 +31,9 @@ import java.time.format.DateTimeParseException; import java.time.temporal.TemporalAccessor; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.format.Parser; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -59,11 +60,9 @@ public final class TemporalAccessorParser implements Parser { private final DateTimeFormatter formatter; - @Nullable - private final String[] fallbackPatterns; + private final String @Nullable [] fallbackPatterns; - @Nullable - private final Object source; + private final @Nullable Object source; /** @@ -77,7 +76,7 @@ public final class TemporalAccessorParser implements Parser { } TemporalAccessorParser(Class temporalAccessorType, DateTimeFormatter formatter, - @Nullable String[] fallbackPatterns, @Nullable Object source) { + String @Nullable [] fallbackPatterns, @Nullable Object source) { this.temporalAccessorType = temporalAccessorType; this.formatter = formatter; 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 fd73fe6cb3..ddd7544867 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,9 +1,7 @@ /** * Integration with the JSR-310 java.time package in JDK 8. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format.datetime.standard; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java b/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java index 6c030d0786..94f37a4458 100644 --- a/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/number/CurrencyStyleFormatter.java @@ -24,7 +24,7 @@ import java.text.ParseException; import java.util.Currency; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A BigDecimal formatter for number values in currency style. @@ -43,14 +43,11 @@ public class CurrencyStyleFormatter extends AbstractNumberFormatter { private int fractionDigits = 2; - @Nullable - private RoundingMode roundingMode; + private @Nullable RoundingMode roundingMode; - @Nullable - private Currency currency; + private @Nullable Currency currency; - @Nullable - private String pattern; + private @Nullable String pattern; /** diff --git a/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java b/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java index 1597180306..8bc858a2d9 100644 --- a/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/number/NumberStyleFormatter.java @@ -20,7 +20,7 @@ import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A general-purpose number formatter using NumberFormat's number style. @@ -38,8 +38,7 @@ import org.springframework.lang.Nullable; */ public class NumberStyleFormatter extends AbstractNumberFormatter { - @Nullable - private String pattern; + private @Nullable String pattern; /** diff --git a/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java b/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java index 1127b9299c..5e51eaefd3 100644 --- a/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java +++ b/spring-context/src/main/java/org/springframework/format/number/money/MonetaryAmountFormatter.java @@ -22,8 +22,9 @@ import javax.money.MonetaryAmount; import javax.money.format.MonetaryAmountFormat; import javax.money.format.MonetaryFormats; +import org.jspecify.annotations.Nullable; + import org.springframework.format.Formatter; -import org.springframework.lang.Nullable; /** * Formatter for JSR-354 {@link javax.money.MonetaryAmount} values, @@ -36,8 +37,7 @@ import org.springframework.lang.Nullable; */ public class MonetaryAmountFormatter implements Formatter { - @Nullable - private String formatName; + private @Nullable String formatName; /** 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 91fbcd0f4c..79e044d413 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,9 +1,7 @@ /** * Integration with the JSR-354 javax.money package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format.number.money; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 7fffd8adbb..6c3fb15ecb 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,9 +1,7 @@ /** * Formatters for {@code java.lang.Number} properties. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format.number; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 727b1ad0a9..a8e517b5a3 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,9 +1,7 @@ /** * An API for defining Formatters to format field model values for display in a UI. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java index b3bd23631f..50667bd8c7 100644 --- a/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java +++ b/spring-context/src/main/java/org/springframework/format/support/DefaultFormattingConversionService.java @@ -16,6 +16,8 @@ package org.springframework.format.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.format.FormatterRegistry; import org.springframework.format.datetime.DateFormatterRegistrar; @@ -24,7 +26,6 @@ import org.springframework.format.number.NumberFormatAnnotationFormatterFactory; import org.springframework.format.number.money.CurrencyUnitFormatter; import org.springframework.format.number.money.Jsr354NumberFormatAnnotationFormatterFactory; import org.springframework.format.number.money.MonetaryAmountFormatter; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringValueResolver; diff --git a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java index 54ec2a76e9..11de9d0647 100644 --- a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java +++ b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionService.java @@ -22,6 +22,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.DecoratingProxy; @@ -36,7 +38,6 @@ import org.springframework.format.Formatter; import org.springframework.format.FormatterRegistry; import org.springframework.format.Parser; import org.springframework.format.Printer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -53,8 +54,7 @@ import org.springframework.util.StringValueResolver; public class FormattingConversionService extends GenericConversionService implements FormatterRegistry, EmbeddedValueResolverAware { - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private final Map cachedPrinters = new ConcurrentHashMap<>(64); @@ -174,8 +174,7 @@ public class FormattingConversionService extends GenericConversionService return this.printer.print(source, LocaleContextHolder.getLocale()); } - @Nullable - private Class resolvePrinterObjectType(Printer printer) { + private @Nullable Class resolvePrinterObjectType(Printer printer) { return GenericTypeResolver.resolveTypeArgument(printer.getClass(), Printer.class); } @@ -206,8 +205,7 @@ public class FormattingConversionService extends GenericConversionService } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { String text = (String) source; if (!StringUtils.hasText(text)) { return null; @@ -265,8 +263,7 @@ public class FormattingConversionService extends GenericConversionService @Override @SuppressWarnings("unchecked") - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { Annotation ann = sourceType.getAnnotation(this.annotationType); if (ann == null) { throw new IllegalStateException( @@ -320,8 +317,7 @@ public class FormattingConversionService extends GenericConversionService @Override @SuppressWarnings("unchecked") - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { Annotation ann = targetType.getAnnotation(this.annotationType); if (ann == null) { throw new IllegalStateException( diff --git a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceFactoryBean.java b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceFactoryBean.java index c4e0ca1a27..075250cbf5 100644 --- a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceFactoryBean.java @@ -18,6 +18,8 @@ package org.springframework.format.support; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.EmbeddedValueResolverAware; @@ -28,7 +30,6 @@ import org.springframework.format.FormatterRegistrar; import org.springframework.format.FormatterRegistry; import org.springframework.format.Parser; import org.springframework.format.Printer; -import org.springframework.lang.Nullable; import org.springframework.util.StringValueResolver; /** @@ -59,22 +60,17 @@ import org.springframework.util.StringValueResolver; public class FormattingConversionServiceFactoryBean implements FactoryBean, EmbeddedValueResolverAware, InitializingBean { - @Nullable - private Set converters; + private @Nullable Set converters; - @Nullable - private Set formatters; + private @Nullable Set formatters; - @Nullable - private Set formatterRegistrars; + private @Nullable Set formatterRegistrars; private boolean registerDefaultFormatters = true; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; - @Nullable - private FormattingConversionService conversionService; + private @Nullable FormattingConversionService conversionService; /** @@ -162,8 +158,7 @@ public class FormattingConversionServiceFactoryBean @Override - @Nullable - public FormattingConversionService getObject() { + public @Nullable FormattingConversionService getObject() { return this.conversionService; } diff --git a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceRuntimeHints.java b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceRuntimeHints.java index d1f41d84fc..a0aebe73f3 100644 --- a/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceRuntimeHints.java +++ b/spring-context/src/main/java/org/springframework/format/support/FormattingConversionServiceRuntimeHints.java @@ -16,10 +16,11 @@ package org.springframework.format.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for {@link DefaultFormattingConversionService}. 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 27db8d50e5..0e6e1a4723 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,9 +2,7 @@ * Support classes for the formatting package, * providing common implementations as well as adapters. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.format.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 b3b57cab05..7fda4a4d42 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 @@ -23,8 +23,9 @@ import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.instrument.InstrumentationSavingAgent; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -56,11 +57,9 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { InstrumentationLoadTimeWeaver.class.getClassLoader()); - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; - @Nullable - private final Instrumentation instrumentation; + private final @Nullable Instrumentation instrumentation; private final List transformers = new ArrayList<>(4); @@ -142,8 +141,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { * @return the Instrumentation instance, or {@code null} if none found * @see #isInstrumentationAvailable() */ - @Nullable - private static Instrumentation getInstrumentation() { + private static @Nullable Instrumentation getInstrumentation() { if (AGENT_CLASS_PRESENT) { return InstrumentationAccessor.getInstrumentation(); } @@ -171,8 +169,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { private final ClassFileTransformer targetTransformer; - @Nullable - private final ClassLoader targetClassLoader; + private final @Nullable ClassLoader targetClassLoader; public FilteringClassFileTransformer( ClassFileTransformer targetTransformer, @Nullable ClassLoader targetClassLoader) { @@ -182,8 +179,7 @@ public class InstrumentationLoadTimeWeaver implements LoadTimeWeaver { } @Override - @Nullable - public byte[] transform(ClassLoader loader, String className, Class classBeingRedefined, + public byte @Nullable [] transform(ClassLoader loader, String className, Class classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { if (this.targetClassLoader != loader) { diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java index ba6fe60842..ccbd18233c 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/ReflectiveLoadTimeWeaver.java @@ -21,10 +21,10 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.DecoratingClassLoader; import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -73,8 +73,7 @@ public class ReflectiveLoadTimeWeaver implements LoadTimeWeaver { private final Method addTransformerMethod; - @Nullable - private final Method getThrowawayClassLoaderMethod; + private final @Nullable Method getThrowawayClassLoaderMethod; /** diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/ResourceOverridingShadowingClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/ResourceOverridingShadowingClassLoader.java index 21b75d9c2f..fcd07532e3 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/ResourceOverridingShadowingClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/ResourceOverridingShadowingClassLoader.java @@ -23,7 +23,8 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -105,8 +106,7 @@ public class ResourceOverridingShadowingClassLoader extends ShadowingClassLoader } @Override - @Nullable - public InputStream getResourceAsStream(String requestedPath) { + public @Nullable InputStream getResourceAsStream(String requestedPath) { if (this.overrides.containsKey(requestedPath)) { String overriddenPath = this.overrides.get(requestedPath); return (overriddenPath != null ? super.getResourceAsStream(overriddenPath) : null); diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java index 0512d51de3..448be7e92b 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/ShadowingClassLoader.java @@ -27,8 +27,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.DecoratingClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; @@ -191,8 +192,7 @@ public class ShadowingClassLoader extends DecoratingClassLoader { } @Override - @Nullable - public InputStream getResourceAsStream(String name) { + public @Nullable InputStream getResourceAsStream(String name) { return this.enclosingClassLoader.getResourceAsStream(name); } diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java index b61cceb02e..c4debbcaed 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleInstrumentableClassLoader.java @@ -18,8 +18,9 @@ package org.springframework.instrument.classloading; import java.lang.instrument.ClassFileTransformer; +import org.jspecify.annotations.Nullable; + import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.Nullable; /** * Simplistic implementation of an instrumentable {@code ClassLoader}. diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java index a4329ae2a2..44f4ebeba4 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/SimpleThrowawayClassLoader.java @@ -16,8 +16,9 @@ package org.springframework.instrument.classloading; +import org.jspecify.annotations.Nullable; + import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.Nullable; /** * ClassLoader that can be used to load classes without bringing them diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/WeavingTransformer.java b/spring-context/src/main/java/org/springframework/instrument/classloading/WeavingTransformer.java index 7f9a06d52d..8188b5a71e 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/WeavingTransformer.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/WeavingTransformer.java @@ -22,7 +22,8 @@ import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -40,8 +41,7 @@ import org.springframework.util.StringUtils; */ public class WeavingTransformer { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final List transformers = new ArrayList<>(); diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java index 6df3504ca9..a1ddc170dc 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/glassfish/GlassFishLoadTimeWeaver.java @@ -20,9 +20,10 @@ import java.lang.instrument.ClassFileTransformer; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.core.OverridingClassLoader; import org.springframework.instrument.classloading.LoadTimeWeaver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; 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 7ab813fa0a..9977331aa4 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,9 +1,7 @@ /** * Support for class instrumentation on GlassFish. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.instrument.classloading.glassfish; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java index f6db661d97..7f98672b30 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/jboss/JBossLoadTimeWeaver.java @@ -21,9 +21,10 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.instrument.classloading.LoadTimeWeaver; import org.springframework.instrument.classloading.SimpleThrowawayClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; 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 7456195473..b758412f73 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,9 +1,7 @@ /** * Support for class instrumentation on JBoss AS 6 and 7. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.instrument.classloading.jboss; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 82ed42c3b6..73711875a1 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,9 +2,7 @@ * Support package for load time weaving based on class loaders, * as required by JPA providers (but not JPA-specific). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.instrument.classloading; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java b/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java index a22203404e..96032cfe54 100644 --- a/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java +++ b/spring-context/src/main/java/org/springframework/instrument/classloading/tomcat/TomcatLoadTimeWeaver.java @@ -20,9 +20,10 @@ import java.lang.instrument.ClassFileTransformer; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.core.OverridingClassLoader; import org.springframework.instrument.classloading.LoadTimeWeaver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; 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 c1ac847dad..8f2e06a38d 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,9 +1,7 @@ /** * Support for class instrumentation on Tomcat. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.instrument.classloading.tomcat; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a6e8a89c82..c51a956268 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 @@ -26,10 +26,10 @@ import javax.management.remote.JMXServiceURL; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jmx.MBeanServerNotFoundException; import org.springframework.jmx.support.JmxUtils; -import org.springframework.lang.Nullable; /** * Internal helper class for managing a JMX connector. @@ -41,8 +41,7 @@ class ConnectorDelegate { private static final Log logger = LogFactory.getLog(ConnectorDelegate.class); - @Nullable - private JMXConnector connector; + private @Nullable JMXConnector connector; /** diff --git a/spring-context/src/main/java/org/springframework/jmx/access/InvalidInvocationException.java b/spring-context/src/main/java/org/springframework/jmx/access/InvalidInvocationException.java index 2cd42366d2..55494b1ce5 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/InvalidInvocationException.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/InvalidInvocationException.java @@ -18,7 +18,7 @@ package org.springframework.jmx.access; import javax.management.JMRuntimeException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Thrown when trying to invoke an operation on a proxy that is not exposed 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 063993eb09..f160509d16 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 @@ -53,6 +53,7 @@ import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanClassLoaderAware; @@ -63,7 +64,6 @@ 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -97,40 +97,31 @@ public class MBeanClientInterceptor /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private MBeanServerConnection server; + private @Nullable MBeanServerConnection server; - @Nullable - private JMXServiceURL serviceUrl; + private @Nullable JMXServiceURL serviceUrl; - @Nullable - private Map environment; + private @Nullable Map environment; - @Nullable - private String agentId; + private @Nullable String agentId; private boolean connectOnStartup = true; private boolean refreshOnConnectFailure = false; - @Nullable - private ObjectName objectName; + private @Nullable ObjectName objectName; private boolean useStrictCasing = true; - @Nullable - private Class managementInterface; + private @Nullable Class managementInterface; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private final ConnectorDelegate connector = new ConnectorDelegate(); - @Nullable - private MBeanServerConnection serverToUse; + private @Nullable MBeanServerConnection serverToUse; - @Nullable - private MBeanServerInvocationHandler invocationHandler; + private @Nullable MBeanServerInvocationHandler invocationHandler; private Map allowedAttributes = Collections.emptyMap(); @@ -171,8 +162,7 @@ public class MBeanClientInterceptor * {@code environment[myKey]}. This is particularly useful for * adding or overriding entries in child bean definitions. */ - @Nullable - public Map getEnvironment() { + public @Nullable Map getEnvironment() { return this.environment; } @@ -239,8 +229,7 @@ public class MBeanClientInterceptor * Return the management interface of the target MBean, * or {@code null} if none specified. */ - @Nullable - protected final Class getManagementInterface() { + protected final @Nullable Class getManagementInterface() { return this.managementInterface; } @@ -356,8 +345,7 @@ public class MBeanClientInterceptor * @see #handleConnectFailure */ @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { // Lazily connect to MBeanServer if necessary. synchronized (this.preparationMonitor) { if (!isPrepared()) { @@ -384,8 +372,7 @@ public class MBeanClientInterceptor * @see #setRefreshOnConnectFailure * @see #doInvoke */ - @Nullable - protected Object handleConnectFailure(MethodInvocation invocation, Exception ex) throws Throwable { + protected @Nullable Object handleConnectFailure(MethodInvocation invocation, Exception ex) throws Throwable { if (this.refreshOnConnectFailure) { String msg = "Could not connect to JMX server - retrying"; if (logger.isDebugEnabled()) { @@ -410,8 +397,7 @@ public class MBeanClientInterceptor * @return the value returned as a result of the re-routed invocation * @throws Throwable an invocation error propagated to the user */ - @Nullable - protected Object doInvoke(MethodInvocation invocation) throws Throwable { + protected @Nullable Object doInvoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); try { Object result; @@ -477,8 +463,7 @@ public class MBeanClientInterceptor } } - @Nullable - private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) + private @Nullable Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation) throws JMException, IOException { Assert.state(this.serverToUse != null, "No MBeanServerConnection available"); @@ -552,8 +537,7 @@ public class MBeanClientInterceptor * @return the converted result object, or the passed-in object if no conversion * is necessary */ - @Nullable - protected Object convertResultValueIfNecessary(@Nullable Object result, MethodParameter parameter) { + protected @Nullable Object convertResultValueIfNecessary(@Nullable Object result, MethodParameter parameter) { Class targetClass = parameter.getParameterType(); try { if (result == null) { @@ -648,7 +632,7 @@ public class MBeanClientInterceptor * @param name the name of the method * @param parameterTypes the arguments in the method signature */ - public MethodCacheKey(String name, @Nullable Class[] parameterTypes) { + public MethodCacheKey(String name, Class @Nullable [] parameterTypes) { this.name = name; this.parameterTypes = (parameterTypes != null ? parameterTypes : new Class[0]); } diff --git a/spring-context/src/main/java/org/springframework/jmx/access/MBeanProxyFactoryBean.java b/spring-context/src/main/java/org/springframework/jmx/access/MBeanProxyFactoryBean.java index b0c62aa13a..77e671667e 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/MBeanProxyFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/MBeanProxyFactoryBean.java @@ -16,12 +16,13 @@ package org.springframework.jmx.access; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.jmx.MBeanServerNotFoundException; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -49,14 +50,11 @@ import org.springframework.util.ClassUtils; public class MBeanProxyFactoryBean extends MBeanClientInterceptor implements FactoryBean, BeanClassLoaderAware, InitializingBean { - @Nullable - private Class proxyInterface; + private @Nullable Class proxyInterface; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private Object mbeanProxy; + private @Nullable Object mbeanProxy; /** @@ -102,14 +100,12 @@ public class MBeanProxyFactoryBean extends MBeanClientInterceptor @Override - @Nullable - public Object getObject() { + public @Nullable Object getObject() { return this.mbeanProxy; } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return this.proxyInterface; } diff --git a/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java b/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java index 159e067e61..c2f18b3ee8 100644 --- a/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java +++ b/spring-context/src/main/java/org/springframework/jmx/access/NotificationListenerRegistrar.java @@ -27,13 +27,13 @@ import javax.management.remote.JMXServiceURL; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.jmx.JmxException; import org.springframework.jmx.MBeanServerNotFoundException; import org.springframework.jmx.support.NotificationListenerHolder; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -55,20 +55,15 @@ public class NotificationListenerRegistrar extends NotificationListenerHolder private final ConnectorDelegate connector = new ConnectorDelegate(); - @Nullable - private MBeanServerConnection server; + private @Nullable MBeanServerConnection server; - @Nullable - private JMXServiceURL serviceUrl; + private @Nullable JMXServiceURL serviceUrl; - @Nullable - private Map environment; + private @Nullable Map environment; - @Nullable - private String agentId; + private @Nullable String agentId; - @Nullable - private ObjectName[] actualObjectNames; + private ObjectName @Nullable [] actualObjectNames; /** @@ -94,8 +89,7 @@ public class NotificationListenerRegistrar extends NotificationListenerHolder * {@code environment[myKey]}. This is particularly useful for * adding or overriding entries in child bean definitions. */ - @Nullable - public Map getEnvironment() { + public @Nullable Map getEnvironment() { return this.environment; } 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 adac687a46..70e314fd65 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,9 +1,7 @@ /** * Provides support for accessing remote MBean resources. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.access; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ec845f54d8..030f94263c 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 @@ -38,6 +38,8 @@ import javax.management.modelmbean.ModelMBean; import javax.management.modelmbean.ModelMBeanInfo; import javax.management.modelmbean.RequiredModelMBean; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.aop.support.AopUtils; @@ -62,7 +64,6 @@ 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; @@ -154,12 +155,10 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo /** The beans to be exposed as JMX managed resources, with JMX names as keys. */ - @Nullable - private Map beans; + private @Nullable Map beans; /** The autodetect mode to use for this MBeanExporter. */ - @Nullable - Integer autodetectMode; + @Nullable Integer autodetectMode; /** Whether to eagerly initialize candidate beans when auto-detecting MBeans. */ private boolean allowEagerInit = false; @@ -180,23 +179,19 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo private final Set excludedBeans = new HashSet<>(); /** The MBeanExporterListeners registered with this exporter. */ - @Nullable - private MBeanExporterListener[] listeners; + private MBeanExporterListener @Nullable [] listeners; /** The NotificationListeners to register for the MBeans registered by this exporter. */ - @Nullable - private NotificationListenerBean[] notificationListeners; + private NotificationListenerBean @Nullable [] notificationListeners; /** Map of actually registered NotificationListeners. */ private final Map registeredNotificationListeners = new LinkedHashMap<>(); /** Stores the ClassLoader to use for generating lazy-init proxies. */ - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); /** Stores the BeanFactory for use in auto-detection process. */ - @Nullable - private ListableBeanFactory beanFactory; + private @Nullable ListableBeanFactory beanFactory; /** @@ -794,8 +789,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 { + protected @Nullable DynamicMBean adaptMBeanIfPossible(Object bean) throws JMException { Class targetClass = AopUtils.getTargetClass(bean); if (targetClass != bean.getClass()) { Class ifc = JmxUtils.getMXBeanInterface(targetClass); @@ -1097,11 +1091,9 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo @SuppressWarnings("serial") private class NotificationPublisherAwareLazyTargetSource extends LazyInitTargetSource { - @Nullable - private ModelMBean modelMBean; + private @Nullable ModelMBean modelMBean; - @Nullable - private ObjectName objectName; + private @Nullable ObjectName objectName; public void setModelMBean(ModelMBean modelMBean) { this.modelMBean = modelMBean; diff --git a/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java b/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java index 3398cc8803..b190f21966 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/annotation/AnnotationJmxAttributeSource.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; import org.springframework.beans.MutablePropertyValues; @@ -42,7 +44,6 @@ import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.RepeatableContainers; import org.springframework.jmx.export.metadata.InvalidMetadataException; import org.springframework.jmx.export.metadata.JmxAttributeSource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.util.StringValueResolver; @@ -61,8 +62,7 @@ import org.springframework.util.StringValueResolver; */ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFactoryAware { - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; @Override @@ -74,8 +74,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac @Override - @Nullable - public org.springframework.jmx.export.metadata.ManagedResource getManagedResource(Class beanClass) throws InvalidMetadataException { + public org.springframework.jmx.export.metadata.@Nullable ManagedResource getManagedResource(Class beanClass) throws InvalidMetadataException { MergedAnnotation ann = MergedAnnotations.from(beanClass, SearchStrategy.TYPE_HIERARCHY) .get(ManagedResource.class).withNonMergedAttributes(); if (!ann.isPresent()) { @@ -104,8 +103,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac } @Override - @Nullable - public org.springframework.jmx.export.metadata.ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { + public org.springframework.jmx.export.metadata.@Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException { MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(ManagedAttribute.class).withNonMergedAttributes(); if (!ann.isPresent()) { @@ -125,8 +123,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac } @Override - @Nullable - public org.springframework.jmx.export.metadata.ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { + public org.springframework.jmx.export.metadata.@Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException { MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(ManagedMetric.class).withNonMergedAttributes(); @@ -134,8 +131,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac } @Override - @Nullable - public org.springframework.jmx.export.metadata.ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException { + public org.springframework.jmx.export.metadata.@Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException { MergedAnnotation ann = MergedAnnotations.from(method, SearchStrategy.TYPE_HIERARCHY) .get(ManagedOperation.class).withNonMergedAttributes(); @@ -187,8 +183,7 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac return beans; } - @Nullable - private static T copyPropertiesToBean(MergedAnnotation ann, Class beanClass) { + private static @Nullable T copyPropertiesToBean(MergedAnnotation ann, Class beanClass) { if (!ann.isPresent()) { return null; } 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 ee176795f6..19719ff672 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 @@ -4,9 +4,7 @@ *

Hooked into Spring's JMX export infrastructure via a special * {@link org.springframework.jmx.export.metadata.JmxAttributeSource} implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.export.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java index dba27a1205..663164005e 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/AbstractConfigurableMBeanInfoAssembler.java @@ -24,9 +24,10 @@ import java.util.Map; import javax.management.modelmbean.ModelMBeanNotificationInfo; +import org.jspecify.annotations.Nullable; + import org.springframework.jmx.export.metadata.JmxMetadataUtils; import org.springframework.jmx.export.metadata.ManagedNotification; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -39,8 +40,7 @@ import org.springframework.util.StringUtils; */ public abstract class AbstractConfigurableMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssembler { - @Nullable - private ModelMBeanNotificationInfo[] notificationInfos; + private ModelMBeanNotificationInfo @Nullable [] notificationInfos; private final Map notificationInfoMappings = new HashMap<>(); 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 11902dea73..58b1460de8 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 @@ -28,13 +28,14 @@ import javax.management.MBeanParameterInfo; import javax.management.modelmbean.ModelMBeanAttributeInfo; import javax.management.modelmbean.ModelMBeanOperationInfo; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopProxyUtils; import org.springframework.aop.support.AopUtils; 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 @@ -173,8 +174,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean /** * Default value for the JMX field "currencyTimeLimit". */ - @Nullable - private Integer defaultCurrencyTimeLimit; + private @Nullable Integer defaultCurrencyTimeLimit; /** * Indicates whether strict casing is being used for attributes. @@ -183,8 +183,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean private boolean exposeClassDescriptor = false; - @Nullable - private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); + private @Nullable ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); /** @@ -214,8 +213,7 @@ public abstract class AbstractReflectiveMBeanInfoAssembler extends AbstractMBean /** * Return default value for the JMX field "currencyTimeLimit", if any. */ - @Nullable - protected Integer getDefaultCurrencyTimeLimit() { + protected @Nullable Integer getDefaultCurrencyTimeLimit() { return this.defaultCurrencyTimeLimit; } @@ -277,8 +275,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() { + protected @Nullable ParameterNameDiscoverer getParameterNameDiscoverer() { return this.parameterNameDiscoverer; } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java index 4be4b5e050..8a838f4a3f 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/InterfaceBasedMBeanInfoAssembler.java @@ -23,9 +23,10 @@ import java.util.Enumeration; import java.util.Map; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -61,19 +62,15 @@ import org.springframework.util.StringUtils; public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanInfoAssembler implements BeanClassLoaderAware, InitializingBean { - @Nullable - private Class[] managedInterfaces; + private Class @Nullable [] managedInterfaces; /** Mappings of bean keys to an array of classes. */ - @Nullable - private Properties interfaceMappings; + private @Nullable Properties interfaceMappings; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); /** Mappings of bean keys to an array of classes. */ - @Nullable - private Map[]> resolvedInterfaceMappings; + private @Nullable Map[]> resolvedInterfaceMappings; /** @@ -84,7 +81,7 @@ public class InterfaceBasedMBeanInfoAssembler extends AbstractConfigurableMBeanI * Each entry MUST be an interface. * @see #setInterfaceMappings */ - public void setManagedInterfaces(@Nullable Class... managedInterfaces) { + public void setManagedInterfaces(Class @Nullable ... managedInterfaces) { if (managedInterfaces != null) { for (Class ifc : managedInterfaces) { if (!ifc.isInterface()) { diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java index 86d0cca923..f12552047e 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MetadataMBeanInfoAssembler.java @@ -23,6 +23,8 @@ import javax.management.Descriptor; import javax.management.MBeanParameterInfo; import javax.management.modelmbean.ModelMBeanNotificationInfo; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.support.AopUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.InitializingBean; @@ -35,7 +37,6 @@ import org.springframework.jmx.export.metadata.ManagedNotification; import org.springframework.jmx.export.metadata.ManagedOperation; import org.springframework.jmx.export.metadata.ManagedOperationParameter; import org.springframework.jmx.export.metadata.ManagedResource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -59,8 +60,7 @@ import org.springframework.util.StringUtils; public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler, InitializingBean { - @Nullable - private JmxAttributeSource attributeSource; + private @Nullable JmxAttributeSource attributeSource; /** @@ -428,8 +428,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem * @param setter the Object value associated with the set method * @return the appropriate Object to use as the value for the descriptor */ - @Nullable - private Object resolveObjectDescriptor(@Nullable Object getter, @Nullable Object setter) { + private @Nullable Object resolveObjectDescriptor(@Nullable Object getter, @Nullable Object setter) { return (getter != null ? getter : setter); } @@ -443,8 +442,7 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssem * @param setter the String value associated with the set method * @return the appropriate String to use as the value for the descriptor */ - @Nullable - private String resolveStringDescriptor(@Nullable String getter, @Nullable String setter) { + private @Nullable String resolveStringDescriptor(@Nullable String getter, @Nullable String setter) { return (StringUtils.hasLength(getter) ? getter : setter); } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodExclusionMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodExclusionMBeanInfoAssembler.java index af780d54a8..3e54718a56 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodExclusionMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodExclusionMBeanInfoAssembler.java @@ -23,7 +23,8 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -56,11 +57,9 @@ import org.springframework.util.StringUtils; */ public class MethodExclusionMBeanInfoAssembler extends AbstractConfigurableMBeanInfoAssembler { - @Nullable - private Set ignoredMethods; + private @Nullable Set ignoredMethods; - @Nullable - private Map> ignoredMethodMappings; + private @Nullable Map> ignoredMethodMappings; /** diff --git a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java index f0d1392d57..5035644867 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/assembler/MethodNameBasedMBeanInfoAssembler.java @@ -23,7 +23,8 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -56,14 +57,12 @@ public class MethodNameBasedMBeanInfoAssembler extends AbstractConfigurableMBean /** * Stores the set of method names to use for creating the management interface. */ - @Nullable - private Set managedMethods; + private @Nullable Set managedMethods; /** * Stores the mappings of bean keys to an array of method names. */ - @Nullable - private Map> methodMappings; + private @Nullable Map> methodMappings; /** 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 cb5997945d..b144b30663 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,9 +2,7 @@ * Provides a strategy for MBeanInfo assembly. Used by MBeanExporter to * determine the attributes and operations to expose for Spring-managed beans. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.export.assembler; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 3921d12250..43b557a9dc 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,7 +18,7 @@ package org.springframework.jmx.export.metadata; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface used by the {@code MetadataMBeanInfoAssembler} to @@ -40,8 +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; + @Nullable ManagedResource getManagedResource(Class clazz) throws InvalidMetadataException; /** * Implementations should return an instance of {@code ManagedAttribute} @@ -51,8 +50,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; + @Nullable ManagedAttribute getManagedAttribute(Method method) throws InvalidMetadataException; /** * Implementations should return an instance of {@code ManagedMetric} @@ -62,8 +60,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; + @Nullable ManagedMetric getManagedMetric(Method method) throws InvalidMetadataException; /** * Implementations should return an instance of {@code ManagedOperation} @@ -73,8 +70,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; + @Nullable ManagedOperation getManagedOperation(Method method) throws InvalidMetadataException; /** * Implementations should return an array of {@code ManagedOperationParameter} diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedAttribute.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedAttribute.java index d7139b411d..947aebcb43 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedAttribute.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedAttribute.java @@ -16,7 +16,7 @@ package org.springframework.jmx.export.metadata; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Metadata that indicates to expose a given bean property as JMX attribute. @@ -35,11 +35,9 @@ public class ManagedAttribute extends AbstractJmxAttribute { public static final ManagedAttribute EMPTY = new ManagedAttribute(); - @Nullable - private Object defaultValue; + private @Nullable Object defaultValue; - @Nullable - private String persistPolicy; + private @Nullable String persistPolicy; private int persistPeriod = -1; @@ -54,8 +52,7 @@ public class ManagedAttribute extends AbstractJmxAttribute { /** * Return the default value of this attribute. */ - @Nullable - public Object getDefaultValue() { + public @Nullable Object getDefaultValue() { return this.defaultValue; } @@ -63,8 +60,7 @@ public class ManagedAttribute extends AbstractJmxAttribute { this.persistPolicy = persistPolicy; } - @Nullable - public String getPersistPolicy() { + public @Nullable String getPersistPolicy() { return this.persistPolicy; } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java index 495fb5c24b..b3b9fd1221 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedMetric.java @@ -16,8 +16,9 @@ package org.springframework.jmx.export.metadata; +import org.jspecify.annotations.Nullable; + import org.springframework.jmx.support.MetricType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -31,21 +32,17 @@ import org.springframework.util.Assert; */ public class ManagedMetric extends AbstractJmxAttribute { - @Nullable - private String category; + private @Nullable String category; - @Nullable - private String displayName; + private @Nullable String displayName; private MetricType metricType = MetricType.GAUGE; private int persistPeriod = -1; - @Nullable - private String persistPolicy; + private @Nullable String persistPolicy; - @Nullable - private String unit; + private @Nullable String unit; /** @@ -58,8 +55,7 @@ public class ManagedMetric extends AbstractJmxAttribute { /** * The category of this metric (ex. throughput, performance, utilization). */ - @Nullable - public String getCategory() { + public @Nullable String getCategory() { return this.category; } @@ -73,8 +69,7 @@ public class ManagedMetric extends AbstractJmxAttribute { /** * A display name for this metric. */ - @Nullable - public String getDisplayName() { + public @Nullable String getDisplayName() { return this.displayName; } @@ -117,8 +112,7 @@ public class ManagedMetric extends AbstractJmxAttribute { /** * The persist policy for this metric. */ - @Nullable - public String getPersistPolicy() { + public @Nullable String getPersistPolicy() { return this.persistPolicy; } @@ -132,8 +126,7 @@ public class ManagedMetric extends AbstractJmxAttribute { /** * The expected unit of measurement values. */ - @Nullable - public String getUnit() { + public @Nullable String getUnit() { return this.unit; } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedNotification.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedNotification.java index 3512b26bb2..5446d806ff 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedNotification.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedNotification.java @@ -16,7 +16,8 @@ package org.springframework.jmx.export.metadata; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -27,14 +28,11 @@ import org.springframework.util.StringUtils; */ public class ManagedNotification { - @Nullable - private String[] notificationTypes; + private String @Nullable [] notificationTypes; - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String description; + private @Nullable String description; /** @@ -48,15 +46,14 @@ public class ManagedNotification { /** * Set a list of notification types. */ - public void setNotificationTypes(@Nullable String... notificationTypes) { + public void setNotificationTypes(String @Nullable ... notificationTypes) { this.notificationTypes = notificationTypes; } /** * Return the list of notification types. */ - @Nullable - public String[] getNotificationTypes() { + public String @Nullable [] getNotificationTypes() { return this.notificationTypes; } @@ -70,8 +67,7 @@ public class ManagedNotification { /** * Return the name of this notification. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -85,8 +81,7 @@ public class ManagedNotification { /** * Return a description for this notification. */ - @Nullable - public String getDescription() { + public @Nullable String getDescription() { return this.description; } diff --git a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedResource.java b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedResource.java index e85bda8c7d..4d99558fcf 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedResource.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/metadata/ManagedResource.java @@ -16,7 +16,7 @@ package org.springframework.jmx.export.metadata; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Metadata indicating that instances of an annotated class @@ -31,24 +31,19 @@ import org.springframework.lang.Nullable; */ public class ManagedResource extends AbstractJmxAttribute { - @Nullable - private String objectName; + private @Nullable String objectName; private boolean log = false; - @Nullable - private String logFile; + private @Nullable String logFile; - @Nullable - private String persistPolicy; + private @Nullable String persistPolicy; private int persistPeriod = -1; - @Nullable - private String persistName; + private @Nullable String persistName; - @Nullable - private String persistLocation; + private @Nullable String persistLocation; /** @@ -61,8 +56,7 @@ public class ManagedResource extends AbstractJmxAttribute { /** * Return the JMX ObjectName of this managed resource. */ - @Nullable - public String getObjectName() { + public @Nullable String getObjectName() { return this.objectName; } @@ -78,8 +72,7 @@ public class ManagedResource extends AbstractJmxAttribute { this.logFile = logFile; } - @Nullable - public String getLogFile() { + public @Nullable String getLogFile() { return this.logFile; } @@ -87,8 +80,7 @@ public class ManagedResource extends AbstractJmxAttribute { this.persistPolicy = persistPolicy; } - @Nullable - public String getPersistPolicy() { + public @Nullable String getPersistPolicy() { return this.persistPolicy; } @@ -104,8 +96,7 @@ public class ManagedResource extends AbstractJmxAttribute { this.persistName = persistName; } - @Nullable - public String getPersistName() { + public @Nullable String getPersistName() { return this.persistName; } @@ -113,8 +104,7 @@ public class ManagedResource extends AbstractJmxAttribute { this.persistLocation = persistLocation; } - @Nullable - public String getPersistLocation() { + public @Nullable String getPersistLocation() { return this.persistLocation; } 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 1163b2280f..2edf716cb8 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,9 +2,7 @@ * Provides generic JMX metadata classes and basic support for reading * JMX metadata in a provider-agnostic manner. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.export.metadata; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/jmx/export/naming/IdentityNamingStrategy.java b/spring-context/src/main/java/org/springframework/jmx/export/naming/IdentityNamingStrategy.java index 3c8aafe623..3bc1221a35 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/naming/IdentityNamingStrategy.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/naming/IdentityNamingStrategy.java @@ -21,8 +21,9 @@ import java.util.Hashtable; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import org.jspecify.annotations.Nullable; + import org.springframework.jmx.support.ObjectNameManager; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; diff --git a/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java b/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java index 60edf694fb..5a145df7e0 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/naming/KeyNamingStrategy.java @@ -24,12 +24,12 @@ import javax.management.ObjectName; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.jmx.support.ObjectNameManager; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -62,23 +62,20 @@ public class KeyNamingStrategy implements ObjectNamingStrategy, InitializingBean /** * Stores the mappings of bean key to {@code ObjectName}. */ - @Nullable - private Properties mappings; + private @Nullable Properties mappings; /** * Stores the {@code Resource}s containing properties that should be loaded * into the final merged set of {@code Properties} used for {@code ObjectName} * resolution. */ - @Nullable - private Resource[] mappingLocations; + private Resource @Nullable [] mappingLocations; /** * Stores the result of merging the {@code mappings} {@code Properties} * with the properties stored in the resources defined by {@code mappingLocations}. */ - @Nullable - private Properties mergedMappings; + private @Nullable Properties mergedMappings; /** diff --git a/spring-context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java b/spring-context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java index ea4792a14b..4d97025ff2 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/naming/MetadataNamingStrategy.java @@ -21,12 +21,13 @@ import java.util.Hashtable; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.jmx.export.metadata.JmxAttributeSource; import org.springframework.jmx.export.metadata.ManagedResource; import org.springframework.jmx.support.ObjectNameManager; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -56,11 +57,9 @@ public class MetadataNamingStrategy implements ObjectNamingStrategy, Initializin /** * The {@code JmxAttributeSource} implementation to use for reading metadata. */ - @Nullable - private JmxAttributeSource attributeSource; + private @Nullable JmxAttributeSource attributeSource; - @Nullable - private String defaultDomain; + private @Nullable String defaultDomain; /** diff --git a/spring-context/src/main/java/org/springframework/jmx/export/naming/ObjectNamingStrategy.java b/spring-context/src/main/java/org/springframework/jmx/export/naming/ObjectNamingStrategy.java index 8a75e8d702..7616732af0 100644 --- a/spring-context/src/main/java/org/springframework/jmx/export/naming/ObjectNamingStrategy.java +++ b/spring-context/src/main/java/org/springframework/jmx/export/naming/ObjectNamingStrategy.java @@ -19,7 +19,7 @@ package org.springframework.jmx.export.naming; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface that encapsulates the creation of {@code ObjectName} instances. 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 98056c2903..a47fbcd74c 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,9 +2,7 @@ * Provides a strategy for ObjectName creation. Used by MBeanExporter * to determine the JMX names to use for exported Spring-managed beans. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.export.naming; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 10056eb132..97aa54e3e5 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,9 +2,7 @@ * Provides supporting infrastructure to allow Spring-created MBeans * to send JMX notifications. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.export.notification; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 5adaaf68c7..6aec88a496 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,9 +2,7 @@ * This package provides declarative creation and registration of * Spring-managed beans as JMX MBeans. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.export; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 65922f4b75..4e0d43ecc4 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.jmx; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java b/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java index 799c5c8cbb..475e1ac65d 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/ConnectorServerFactoryBean.java @@ -30,11 +30,12 @@ import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; import javax.management.remote.MBeanServerForwarder; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.jmx.JmxException; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -65,18 +66,15 @@ public class ConnectorServerFactoryBean extends MBeanRegistrationSupport private final Map environment = new HashMap<>(); - @Nullable - private MBeanServerForwarder forwarder; + private @Nullable MBeanServerForwarder forwarder; - @Nullable - private ObjectName objectName; + private @Nullable ObjectName objectName; private boolean threaded = false; private boolean daemon = false; - @Nullable - private JMXConnectorServer connectorServer; + private @Nullable JMXConnectorServer connectorServer; /** @@ -207,8 +205,7 @@ public class ConnectorServerFactoryBean extends MBeanRegistrationSupport @Override - @Nullable - public JMXConnectorServer getObject() { + public @Nullable JMXConnectorServer getObject() { return this.connectorServer; } 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 43cb7e719a..6b39dd7bdd 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 @@ -32,9 +32,9 @@ import javax.management.ObjectName; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jmx.MBeanServerNotFoundException; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -136,8 +136,7 @@ public abstract class JmxUtils { * @return the parameter types as classes * @throws ClassNotFoundException if a parameter type could not be resolved */ - @Nullable - public static Class[] parameterInfoToTypes(@Nullable MBeanParameterInfo[] paramInfo) + public static Class @Nullable [] parameterInfoToTypes(MBeanParameterInfo @Nullable [] paramInfo) throws ClassNotFoundException { return parameterInfoToTypes(paramInfo, ClassUtils.getDefaultClassLoader()); @@ -151,9 +150,8 @@ public abstract class JmxUtils { * @return the parameter types as classes * @throws ClassNotFoundException if a parameter type could not be resolved */ - @Nullable - public static Class[] parameterInfoToTypes( - @Nullable MBeanParameterInfo[] paramInfo, @Nullable ClassLoader classLoader) + public static Class @Nullable [] parameterInfoToTypes( + MBeanParameterInfo @Nullable [] paramInfo, @Nullable ClassLoader classLoader) throws ClassNotFoundException { Class[] types = null; @@ -273,8 +271,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(@Nullable Class clazz) { + public static @Nullable Class getMBeanInterface(@Nullable Class clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } @@ -295,8 +292,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(@Nullable Class clazz) { + public static @Nullable Class getMXBeanInterface(@Nullable Class clazz) { if (clazz == null || clazz.getSuperclass() == null) { return null; } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java b/spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java index 26c696d1f2..b187eb6bf8 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/MBeanRegistrationSupport.java @@ -28,8 +28,8 @@ import javax.management.ObjectName; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -77,8 +77,7 @@ public class MBeanRegistrationSupport { /** * The {@code MBeanServer} instance being used to register beans. */ - @Nullable - protected MBeanServer server; + protected @Nullable MBeanServer server; /** * The beans that have been registered by this exporter. @@ -104,8 +103,7 @@ public class MBeanRegistrationSupport { /** * Return the {@code MBeanServer} that the beans will be registered with. */ - @Nullable - public final MBeanServer getServer() { + public final @Nullable MBeanServer getServer() { return this.server; } diff --git a/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBean.java b/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBean.java index dfaf6d7afc..3759f61f9d 100644 --- a/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/jmx/support/MBeanServerConnectionFactoryBean.java @@ -27,6 +27,8 @@ import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.target.AbstractLazyCreationTargetSource; @@ -34,7 +36,6 @@ 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; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -55,24 +56,19 @@ import org.springframework.util.CollectionUtils; public class MBeanServerConnectionFactoryBean implements FactoryBean, BeanClassLoaderAware, InitializingBean, DisposableBean { - @Nullable - private JMXServiceURL serviceUrl; + private @Nullable JMXServiceURL serviceUrl; private final Map environment = new HashMap<>(); private boolean connectOnStartup = true; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private JMXConnector connector; + private @Nullable JMXConnector connector; - @Nullable - private MBeanServerConnection connection; + private @Nullable MBeanServerConnection connection; - @Nullable - private JMXConnectorLazyInitTargetSource connectorTargetSource; + private @Nullable JMXConnectorLazyInitTargetSource connectorTargetSource; /** @@ -159,8 +155,7 @@ public class MBeanServerConnectionFactoryBean @Override - @Nullable - public MBeanServerConnection getObject() { + public @Nullable MBeanServerConnection getObject() { return this.connection; } 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 259bc23b50..930b9a4dbd 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 @@ -21,12 +21,12 @@ import javax.management.MBeanServerFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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 a {@link javax.management.MBeanServer} reference @@ -59,16 +59,13 @@ public class MBeanServerFactoryBean implements FactoryBean, Initial private boolean locateExistingServerIfPossible = false; - @Nullable - private String agentId; + private @Nullable String agentId; - @Nullable - private String defaultDomain; + private @Nullable String defaultDomain; private boolean registerWithFactory = true; - @Nullable - private MBeanServer server; + private @Nullable MBeanServer server; private boolean newlyRegistered = false; @@ -187,8 +184,7 @@ public class MBeanServerFactoryBean implements FactoryBean, Initial @Override - @Nullable - public MBeanServer getObject() { + public @Nullable MBeanServer getObject() { return this.server; } 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 9244be32ce..012cd6312c 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 @@ -26,7 +26,8 @@ import javax.management.NotificationFilter; import javax.management.NotificationListener; import javax.management.ObjectName; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -42,17 +43,13 @@ import org.springframework.util.ObjectUtils; */ public class NotificationListenerHolder { - @Nullable - private NotificationListener notificationListener; + private @Nullable NotificationListener notificationListener; - @Nullable - private NotificationFilter notificationFilter; + private @Nullable NotificationFilter notificationFilter; - @Nullable - private Object handback; + private @Nullable Object handback; - @Nullable - protected Set mappedObjectNames; + protected @Nullable Set mappedObjectNames; /** @@ -65,8 +62,7 @@ public class NotificationListenerHolder { /** * Get the {@link javax.management.NotificationListener}. */ - @Nullable - public NotificationListener getNotificationListener() { + public @Nullable NotificationListener getNotificationListener() { return this.notificationListener; } @@ -84,8 +80,7 @@ public class NotificationListenerHolder { * with the encapsulated {@link #getNotificationListener() NotificationListener}. *

May be {@code null}. */ - @Nullable - public NotificationFilter getNotificationFilter() { + public @Nullable NotificationFilter getNotificationFilter() { return this.notificationFilter; } @@ -107,8 +102,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() { + public @Nullable Object getHandback() { return this.handback; } @@ -141,8 +135,7 @@ public class NotificationListenerHolder { * be registered as a listener for {@link javax.management.Notification Notifications}. * @throws MalformedObjectNameException if an {@code ObjectName} is malformed */ - @Nullable - public ObjectName[] getResolvedObjectNames() throws MalformedObjectNameException { + public ObjectName @Nullable [] getResolvedObjectNames() throws MalformedObjectNameException { if (this.mappedObjectNames == null) { return null; } 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 d648547da2..1e287db019 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,9 +2,7 @@ * Contains support classes for connecting to local and remote {@code MBeanServer}s * and for exposing an {@code MBeanServer} to remote clients. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jmx.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiAccessor.java b/spring-context/src/main/java/org/springframework/jndi/JndiAccessor.java index 44ed724aff..ae20c8d0ed 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiAccessor.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiAccessor.java @@ -20,8 +20,7 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Convenient superclass for JNDI accessors, providing "jndiTemplate" @@ -70,8 +69,7 @@ public class JndiAccessor { /** * Return the JNDI environment to use for JNDI lookups. */ - @Nullable - public Properties getJndiEnvironment() { + public @Nullable Properties getJndiEnvironment() { return this.jndiTemplate.getEnvironment(); } 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 cf53e20a47..36948c6b49 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiCallback.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiCallback.java @@ -19,7 +19,7 @@ package org.springframework.jndi; import javax.naming.Context; import javax.naming.NamingException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Callback interface to be implemented by classes that need to perform an @@ -47,8 +47,7 @@ public interface JndiCallback { * @return a result object, or {@code null} * @throws NamingException if thrown by JNDI methods */ - @Nullable - T doInContext(Context ctx) throws NamingException; + @Nullable T doInContext(Context ctx) throws NamingException; } diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiLocatorDelegate.java b/spring-context/src/main/java/org/springframework/jndi/JndiLocatorDelegate.java index c46b2fa940..ae34d6dc11 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiLocatorDelegate.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiLocatorDelegate.java @@ -19,8 +19,9 @@ package org.springframework.jndi; import javax.naming.InitialContext; import javax.naming.NamingException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.SpringProperties; -import org.springframework.lang.Nullable; /** * {@link JndiLocatorSupport} subclass with public lookup methods, diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiLocatorSupport.java b/spring-context/src/main/java/org/springframework/jndi/JndiLocatorSupport.java index 7e255cc688..e2b5d5530d 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiLocatorSupport.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiLocatorSupport.java @@ -18,7 +18,8 @@ package org.springframework.jndi; import javax.naming.NamingException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiObjectFactoryBean.java b/spring-context/src/main/java/org/springframework/jndi/JndiObjectFactoryBean.java index bba7d9b44a..60f36355d8 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiObjectFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiObjectFactoryBean.java @@ -24,6 +24,7 @@ import javax.naming.NamingException; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.SimpleTypeConverter; @@ -34,7 +35,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.config.ConfigurableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -73,8 +73,7 @@ import org.springframework.util.ClassUtils; public class JndiObjectFactoryBean extends JndiObjectLocator implements FactoryBean, BeanFactoryAware, BeanClassLoaderAware { - @Nullable - private Class[] proxyInterfaces; + private Class @Nullable [] proxyInterfaces; private boolean lookupOnStartup = true; @@ -82,17 +81,13 @@ public class JndiObjectFactoryBean extends JndiObjectLocator private boolean exposeAccessContext = false; - @Nullable - private Object defaultObject; + private @Nullable Object defaultObject; - @Nullable - private ConfigurableBeanFactory beanFactory; + private @Nullable ConfigurableBeanFactory beanFactory; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private Object jndiObject; + private @Nullable Object jndiObject; /** @@ -267,14 +262,12 @@ public class JndiObjectFactoryBean extends JndiObjectLocator * Return the singleton JNDI object. */ @Override - @Nullable - public Object getObject() { + public @Nullable Object getObject() { return this.jndiObject; } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { if (this.proxyInterfaces != null) { if (this.proxyInterfaces.length == 1) { return this.proxyInterfaces[0]; @@ -369,8 +362,7 @@ public class JndiObjectFactoryBean extends JndiObjectLocator } @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { Context ctx = (isEligible(invocation.getMethod()) ? this.jndiTemplate.getContext() : null); try { return invocation.proceed(); 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 1bdecce4b9..fea6a6aab1 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiObjectLocator.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiObjectLocator.java @@ -18,8 +18,9 @@ package org.springframework.jndi; import javax.naming.NamingException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -49,11 +50,9 @@ import org.springframework.util.StringUtils; */ public abstract class JndiObjectLocator extends JndiLocatorSupport implements InitializingBean { - @Nullable - private String jndiName; + private @Nullable String jndiName; - @Nullable - private Class expectedType; + private @Nullable Class expectedType; /** @@ -69,8 +68,7 @@ public abstract class JndiObjectLocator extends JndiLocatorSupport implements In /** * Return the JNDI name to look up. */ - @Nullable - public String getJndiName() { + public @Nullable String getJndiName() { return this.jndiName; } @@ -86,8 +84,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() { + public @Nullable Class getExpectedType() { return this.expectedType; } diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiObjectTargetSource.java b/spring-context/src/main/java/org/springframework/jndi/JndiObjectTargetSource.java index cc8e392a77..6afc62f3fd 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiObjectTargetSource.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiObjectTargetSource.java @@ -18,8 +18,9 @@ package org.springframework.jndi; import javax.naming.NamingException; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.TargetSource; -import org.springframework.lang.Nullable; /** * AOP {@link org.springframework.aop.TargetSource} that provides @@ -65,11 +66,9 @@ public class JndiObjectTargetSource extends JndiObjectLocator implements TargetS private boolean cache = true; - @Nullable - private Object cachedObject; + private @Nullable Object cachedObject; - @Nullable - private Class targetClass; + private @Nullable Class targetClass; /** @@ -109,8 +108,7 @@ public class JndiObjectTargetSource extends JndiObjectLocator implements TargetS @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { if (this.cachedObject != null) { return this.cachedObject.getClass(); } @@ -128,8 +126,7 @@ public class JndiObjectTargetSource extends JndiObjectLocator implements TargetS } @Override - @Nullable - public Object getTarget() { + public @Nullable Object getTarget() { try { if (this.lookupOnStartup || !this.cache) { return (this.cachedObject != null ? this.cachedObject : lookup()); diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiPropertySource.java b/spring-context/src/main/java/org/springframework/jndi/JndiPropertySource.java index 88a4aa4c06..31efaff386 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiPropertySource.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiPropertySource.java @@ -18,8 +18,9 @@ package org.springframework.jndi; import javax.naming.NamingException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.env.PropertySource; -import org.springframework.lang.Nullable; /** * {@link PropertySource} implementation that reads properties from an underlying Spring @@ -78,8 +79,7 @@ public class JndiPropertySource extends PropertySource { * {@code null} and issues a DEBUG-level log statement with the exception message. */ @Override - @Nullable - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { if (getSource().isResourceRef() && name.indexOf(':') != -1) { // We're in resource-ref (prefixing with "java:comp/env") mode. Let's not bother // with property names with a colon it since they're probably just containing a 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 e08829e70c..5936b42158 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiTemplate.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiTemplate.java @@ -26,8 +26,8 @@ import javax.naming.NamingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -44,8 +44,7 @@ public class JndiTemplate { protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Properties environment; + private @Nullable Properties environment; /** @@ -72,8 +71,7 @@ public class JndiTemplate { /** * Return the environment for the JNDI InitialContext, if any. */ - @Nullable - public Properties getEnvironment() { + public @Nullable Properties getEnvironment() { return this.environment; } @@ -85,8 +83,7 @@ public class JndiTemplate { * @throws NamingException thrown by the callback implementation * @see #createInitialContext */ - @Nullable - public T execute(JndiCallback contextCallback) throws NamingException { + public @Nullable T execute(JndiCallback contextCallback) throws NamingException { Context ctx = getContext(); try { return contextCallback.doInContext(ctx); diff --git a/spring-context/src/main/java/org/springframework/jndi/JndiTemplateEditor.java b/spring-context/src/main/java/org/springframework/jndi/JndiTemplateEditor.java index a5931d894f..b64874545e 100644 --- a/spring-context/src/main/java/org/springframework/jndi/JndiTemplateEditor.java +++ b/spring-context/src/main/java/org/springframework/jndi/JndiTemplateEditor.java @@ -19,8 +19,9 @@ package org.springframework.jndi; import java.beans.PropertyEditorSupport; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.propertyeditors.PropertiesEditor; -import org.springframework.lang.Nullable; /** * Properties editor for JndiTemplate objects. Allows properties of type 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 1ef8b64ac1..1c833c4868 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,9 +7,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jndi; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java b/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java index beb5489863..5d3ff1e140 100644 --- a/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java +++ b/spring-context/src/main/java/org/springframework/jndi/support/SimpleJndiBeanFactory.java @@ -25,6 +25,8 @@ import java.util.Set; import javax.naming.NameNotFoundException; import javax.naming.NamingException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanDefinitionStoreException; import org.springframework.beans.factory.BeanFactory; @@ -35,7 +37,6 @@ import org.springframework.beans.factory.ObjectProvider; import org.springframework.core.ResolvableType; import org.springframework.jndi.JndiLocatorSupport; import org.springframework.jndi.TypeMismatchNamingException; -import org.springframework.lang.Nullable; /** * Simple JNDI-based implementation of Spring's @@ -131,7 +132,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac } @Override - public Object getBean(String name, @Nullable Object... args) throws BeansException { + public Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException { if (args != null) { throw new UnsupportedOperationException( "SimpleJndiBeanFactory does not support explicit bean creation arguments"); @@ -145,7 +146,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac } @Override - public T getBean(Class requiredType, @Nullable Object... args) throws BeansException { + public T getBean(Class requiredType, @Nullable Object @Nullable ... args) throws BeansException { if (args != null) { throw new UnsupportedOperationException( "SimpleJndiBeanFactory does not support explicit bean creation arguments"); @@ -165,8 +166,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac return getBean(requiredType, args); } @Override - @Nullable - public T getIfAvailable() throws BeansException { + public @Nullable T getIfAvailable() throws BeansException { try { return getBean(requiredType); } @@ -178,8 +178,7 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac } } @Override - @Nullable - public T getIfUnique() throws BeansException { + public @Nullable T getIfUnique() throws BeansException { try { return getBean(requiredType); } @@ -233,14 +232,12 @@ public class SimpleJndiBeanFactory extends JndiLocatorSupport implements BeanFac } @Override - @Nullable - public Class getType(String name) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name) throws NoSuchBeanDefinitionException { return getType(name, true); } @Override - @Nullable - public Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { try { return doGetType(name); } 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 3669b23b62..ba21e4d457 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,9 +2,7 @@ * Support classes for JNDI usage, * including a JNDI-based BeanFactory implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jndi.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/scheduling/SchedulingAwareRunnable.java b/spring-context/src/main/java/org/springframework/scheduling/SchedulingAwareRunnable.java index e1b2349ea8..bee6db2559 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/SchedulingAwareRunnable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/SchedulingAwareRunnable.java @@ -16,7 +16,7 @@ package org.springframework.scheduling; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Extension of the {@link Runnable} interface, adding special callbacks @@ -58,8 +58,7 @@ public interface SchedulingAwareRunnable extends Runnable { * @since 6.1 * @see org.springframework.scheduling.annotation.Scheduled#scheduler() */ - @Nullable - default String getQualifier() { + default @Nullable String getQualifier() { return null; } 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 a25739772f..07b77bd64c 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/TaskScheduler.java @@ -22,7 +22,7 @@ import java.time.Instant; import java.util.Date; import java.util.concurrent.ScheduledFuture; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Task scheduler interface that abstracts the scheduling of @@ -75,8 +75,7 @@ public interface TaskScheduler { * for internal reasons (for example, a pool overload handling policy or a pool shutdown in progress) * @see org.springframework.scheduling.support.CronTrigger */ - @Nullable - ScheduledFuture schedule(Runnable task, Trigger trigger); + @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger); /** * Schedule the given {@link Runnable}, invoking it at the specified execution time. 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 4739ecf2b4..5de2fca118 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/Trigger.java +++ b/spring-context/src/main/java/org/springframework/scheduling/Trigger.java @@ -19,7 +19,7 @@ package org.springframework.scheduling; import java.time.Instant; import java.util.Date; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Common interface for trigger objects that determine the next execution time @@ -42,8 +42,7 @@ public interface Trigger { * @deprecated as of 6.0, in favor of {@link #nextExecution(TriggerContext)} */ @Deprecated(since = "6.0") - @Nullable - default Date nextExecutionTime(TriggerContext triggerContext) { + default @Nullable Date nextExecutionTime(TriggerContext triggerContext) { Instant instant = nextExecution(triggerContext); return (instant != null ? Date.from(instant) : null); } @@ -56,7 +55,6 @@ public interface Trigger { * or {@code null} if the trigger won't fire anymore * @since 6.0 */ - @Nullable - Instant nextExecution(TriggerContext triggerContext); + @Nullable Instant nextExecution(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 d2fc96d677..5db303df14 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/TriggerContext.java +++ b/spring-context/src/main/java/org/springframework/scheduling/TriggerContext.java @@ -20,7 +20,7 @@ import java.time.Clock; import java.time.Instant; import java.util.Date; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Context object encapsulating last execution times and last completion time @@ -48,9 +48,8 @@ public interface TriggerContext { *

The default implementation delegates to {@link #lastScheduledExecution()}. * @deprecated as of 6.0, in favor on {@link #lastScheduledExecution()} */ - @Nullable @Deprecated(since = "6.0") - default Date lastScheduledExecutionTime() { + default @Nullable Date lastScheduledExecutionTime() { Instant instant = lastScheduledExecution(); return (instant != null ? Date.from(instant) : null); } @@ -60,8 +59,7 @@ public interface TriggerContext { * or {@code null} if not scheduled before. * @since 6.0 */ - @Nullable - Instant lastScheduledExecution(); + @Nullable Instant lastScheduledExecution(); /** * Return the last actual execution time of the task, @@ -69,9 +67,8 @@ public interface TriggerContext { *

The default implementation delegates to {@link #lastActualExecution()}. * @deprecated as of 6.0, in favor on {@link #lastActualExecution()} */ - @Nullable @Deprecated(since = "6.0") - default Date lastActualExecutionTime() { + default @Nullable Date lastActualExecutionTime() { Instant instant = lastActualExecution(); return (instant != null ? Date.from(instant) : null); } @@ -81,8 +78,7 @@ public interface TriggerContext { * or {@code null} if not scheduled before. * @since 6.0 */ - @Nullable - Instant lastActualExecution(); + @Nullable Instant lastActualExecution(); /** * Return the last completion time of the task, @@ -91,8 +87,7 @@ public interface TriggerContext { * @deprecated as of 6.0, in favor on {@link #lastCompletion()} */ @Deprecated(since = "6.0") - @Nullable - default Date lastCompletionTime() { + default @Nullable Date lastCompletionTime() { Instant instant = lastCompletion(); return (instant != null ? Date.from(instant) : null); } @@ -102,7 +97,6 @@ public interface TriggerContext { * or {@code null} if not scheduled before. * @since 6.0 */ - @Nullable - Instant lastCompletion(); + @Nullable Instant lastCompletion(); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java index 35e08bec19..f851696c43 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AbstractAsyncConfiguration.java @@ -21,6 +21,8 @@ import java.util.concurrent.Executor; import java.util.function.Function; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.annotation.Autowired; @@ -28,7 +30,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportAware; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.function.SingletonSupplier; @@ -45,14 +46,11 @@ import org.springframework.util.function.SingletonSupplier; @Configuration(proxyBeanMethods = false) public abstract class AbstractAsyncConfiguration implements ImportAware { - @Nullable - protected AnnotationAttributes enableAsync; + protected @Nullable AnnotationAttributes enableAsync; - @Nullable - protected Supplier executor; + protected @Nullable Supplier executor; - @Nullable - protected Supplier exceptionHandler; + protected @Nullable Supplier exceptionHandler; @Override diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java index ae9a987b52..8b3f44c35a 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AnnotationAsyncExecutionInterceptor.java @@ -19,10 +19,11 @@ package org.springframework.scheduling.annotation; import java.lang.reflect.Method; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.interceptor.AsyncExecutionInterceptor; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; /** * Specialization of {@link AsyncExecutionInterceptor} that delegates method execution to @@ -79,8 +80,7 @@ public class AnnotationAsyncExecutionInterceptor extends AsyncExecutionIntercept * @see #determineAsyncExecutor(Method) */ @Override - @Nullable - protected String getExecutorQualifier(Method method) { + protected @Nullable String getExecutorQualifier(Method method) { // Maintainer's note: changes made here should also be made in // AnnotationAsyncExecutionAspect#getExecutorQualifier Async async = AnnotatedElementUtils.findMergedAnnotation(method, Async.class); 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 f88cd4acf2..818043f28a 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 @@ -23,6 +23,7 @@ import java.util.concurrent.Executor; import java.util.function.Supplier; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.Pointcut; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; @@ -31,7 +32,6 @@ 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; import org.springframework.util.CollectionUtils; diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java index 9d8f801590..9d7c859715 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessor.java @@ -22,12 +22,12 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.autoproxy.AbstractBeanFactoryAwareAdvisingPostProcessor; import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.beans.factory.BeanFactory; import org.springframework.core.task.TaskExecutor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.function.SingletonSupplier; @@ -77,14 +77,11 @@ public class AsyncAnnotationBeanPostProcessor extends AbstractBeanFactoryAwareAd protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Supplier executor; + private @Nullable Supplier executor; - @Nullable - private Supplier exceptionHandler; + private @Nullable Supplier exceptionHandler; - @Nullable - private Class asyncAnnotationType; + private @Nullable Class asyncAnnotationType; diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java index c7f50aed70..a69a43b561 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurationSelector.java @@ -16,9 +16,10 @@ package org.springframework.scheduling.annotation; +import org.jspecify.annotations.NonNull; + import org.springframework.context.annotation.AdviceMode; import org.springframework.context.annotation.AdviceModeImportSelector; -import org.springframework.lang.NonNull; /** * Selects which implementation of {@link AbstractAsyncConfiguration} should @@ -43,8 +44,7 @@ public class AsyncConfigurationSelector extends AdviceModeImportSelector new String[] {ProxyAsyncConfiguration.class.getName()}; case ASPECTJ -> new String[] {ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME}; diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java index 488297171b..a840df3fe3 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java @@ -18,8 +18,9 @@ package org.springframework.scheduling.annotation; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; -import org.springframework.lang.Nullable; /** * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration @@ -42,8 +43,7 @@ public interface AsyncConfigurer { * The {@link Executor} instance to be used when processing async * method invocations. */ - @Nullable - default Executor getAsyncExecutor() { + default @Nullable Executor getAsyncExecutor() { return null; } @@ -52,8 +52,7 @@ public interface AsyncConfigurer { * when an exception is thrown during an asynchronous method execution * with {@code void} return type. */ - @Nullable - default AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + default @Nullable AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return null; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurerSupport.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurerSupport.java index 4c1e831468..4c2a0a9521 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurerSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurerSupport.java @@ -18,8 +18,9 @@ package org.springframework.scheduling.annotation; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; -import org.springframework.lang.Nullable; /** * A convenience {@link AsyncConfigurer} that implements all methods @@ -34,14 +35,12 @@ import org.springframework.lang.Nullable; public class AsyncConfigurerSupport implements AsyncConfigurer { @Override - @Nullable - public Executor getAsyncExecutor() { + public @Nullable Executor getAsyncExecutor() { return null; } @Override - @Nullable - public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { + public @Nullable AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() { return null; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java index 85ba965e07..7f9f391399 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncResult.java @@ -21,7 +21,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A pass-through {@code Future} handle that can be used for method signatures @@ -39,11 +39,9 @@ import org.springframework.lang.Nullable; @Deprecated(since = "6.0") public class AsyncResult implements Future { - @Nullable - private final V value; + private final @Nullable V value; - @Nullable - private final Throwable executionException; + private final @Nullable Throwable executionException; /** @@ -80,8 +78,7 @@ public class AsyncResult implements Future { } @Override - @Nullable - public V get() throws ExecutionException { + public @Nullable V get() throws ExecutionException { if (this.executionException != null) { throw (this.executionException instanceof ExecutionException execEx ? execEx : new ExecutionException(this.executionException)); @@ -90,8 +87,7 @@ public class AsyncResult implements Future { } @Override - @Nullable - public V get(long timeout, TimeUnit unit) throws ExecutionException { + public @Nullable V get(long timeout, TimeUnit unit) throws ExecutionException { return get(); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java index 17178ba0f3..060e4191e5 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationBeanPostProcessor.java @@ -33,6 +33,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopInfrastructureBean; import org.springframework.aop.framework.AopProxyUtils; @@ -61,7 +62,6 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.format.annotation.DurationFormat; import org.springframework.format.datetime.standard.DurationFormatterUtils; -import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.config.CronTask; @@ -134,23 +134,17 @@ public class ScheduledAnnotationBeanPostProcessor private final ScheduledTaskRegistrar registrar; - @Nullable - private Object scheduler; + private @Nullable Object scheduler; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private TaskSchedulerRouter localScheduler; + private @Nullable TaskSchedulerRouter localScheduler; private final Set> nonAnnotatedClasses = ConcurrentHashMap.newKeySet(64); @@ -554,8 +548,7 @@ public class ScheduledAnnotationBeanPostProcessor * @deprecated in favor of {@link #createRunnable(Object, Method, String)} */ @Deprecated(since = "6.1") - @Nullable - protected Runnable createRunnable(Object target, Method method) { + protected @Nullable Runnable createRunnable(Object target, Method method) { return null; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java index a51af6a215..6f2d2705da 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/ScheduledAnnotationReactiveSupport.java @@ -27,6 +27,7 @@ import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -37,7 +38,6 @@ import org.springframework.core.CoroutinesUtils; import org.springframework.core.KotlinDetector; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.scheduling.support.DefaultScheduledTaskObservationConvention; import org.springframework.scheduling.support.ScheduledTaskObservationContext; @@ -195,8 +195,7 @@ abstract class ScheduledAnnotationReactiveSupport { final String displayName; - @Nullable - private final String qualifier; + private final @Nullable String qualifier; private final List subscriptionTrackerRegistry; @@ -219,8 +218,7 @@ abstract class ScheduledAnnotationReactiveSupport { } @Override - @Nullable - public String getQualifier() { + public @Nullable String getQualifier() { return this.qualifier; } @@ -276,15 +274,13 @@ abstract class ScheduledAnnotationReactiveSupport { private final Observation observation; - @Nullable - private final CountDownLatch blockingLatch; + private final @Nullable CountDownLatch blockingLatch; // Implementation note: since this is created last-minute when subscribing, // there shouldn't be a way to cancel the tracker externally from the // ScheduledAnnotationBeanProcessor before the #setSubscription(Subscription) // method is called. - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; TrackingSubscriber(List subscriptionTrackerRegistry, Observation observation) { this(subscriptionTrackerRegistry, observation, null); 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 e876e68edf..8247daf25a 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,9 +1,7 @@ /** * Annotation support for asynchronous method execution. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java index 7bda93c2e9..322ced233a 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskExecutor.java @@ -25,11 +25,11 @@ import java.util.concurrent.Future; import jakarta.enterprise.concurrent.ManagedExecutors; import jakarta.enterprise.concurrent.ManagedTask; +import org.jspecify.annotations.Nullable; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.support.TaskExecutorAdapter; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.util.ClassUtils; @@ -68,8 +68,7 @@ public class ConcurrentTaskExecutor implements AsyncTaskExecutor, SchedulingTask throw new IllegalStateException("Executor not configured"); }); - @Nullable - private static Class managedExecutorServiceClass; + private static @Nullable Class managedExecutorServiceClass; static { try { @@ -88,8 +87,7 @@ public class ConcurrentTaskExecutor implements AsyncTaskExecutor, SchedulingTask private TaskExecutorAdapter adaptedExecutor = new TaskExecutorAdapter(STUB_EXECUTOR); - @Nullable - private TaskDecorator taskDecorator; + private @Nullable TaskDecorator taskDecorator; /** diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java index b004b0d5c3..2d2322b0b5 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java @@ -31,9 +31,9 @@ import java.util.concurrent.TimeUnit; import jakarta.enterprise.concurrent.LastExecution; import jakarta.enterprise.concurrent.ManagedScheduledExecutorService; +import org.jspecify.annotations.Nullable; import org.springframework.core.task.TaskRejectedException; -import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.TriggerContext; @@ -75,8 +75,7 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T private static final TimeUnit NANO = TimeUnit.NANOSECONDS; - @Nullable - private static Class managedScheduledExecutorServiceClass; + private static @Nullable Class managedScheduledExecutorServiceClass; static { try { @@ -91,13 +90,11 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T } - @Nullable - private ScheduledExecutorService scheduledExecutor; + private @Nullable ScheduledExecutorService scheduledExecutor; private boolean enterpriseConcurrentScheduler = false; - @Nullable - private ErrorHandler errorHandler; + private @Nullable ErrorHandler errorHandler; private Clock clock = Clock.systemDefaultZone(); @@ -219,8 +216,7 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T } @Override - @Nullable - public ScheduledFuture schedule(Runnable task, Trigger trigger) { + public @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger) { ScheduledExecutorService scheduleExecutorToUse = getScheduledExecutor(); try { if (this.enterpriseConcurrentScheduler) { @@ -332,8 +328,7 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T } @Override - @Nullable - public Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) { + public @Nullable Date getNextRunTime(@Nullable LastExecution le, Date taskScheduledTime) { Instant instant = this.adaptee.nextExecution(new LastExecutionAdapter(le)); return (instant != null ? Date.from(instant) : null); } @@ -346,33 +341,28 @@ public class ConcurrentTaskScheduler extends ConcurrentTaskExecutor implements T private static class LastExecutionAdapter implements TriggerContext { - @Nullable - private final LastExecution le; + private final @Nullable LastExecution le; public LastExecutionAdapter(@Nullable LastExecution le) { this.le = le; } @Override - @Nullable - public Instant lastScheduledExecution() { + public @Nullable Instant lastScheduledExecution() { return (this.le != null ? toInstant(this.le.getScheduledStart()) : null); } @Override - @Nullable - public Instant lastActualExecution() { + public @Nullable Instant lastActualExecution() { return (this.le != null ? toInstant(this.le.getRunStart()) : null); } @Override - @Nullable - public Instant lastCompletion() { + public @Nullable Instant lastCompletion() { return (this.le != null ? toInstant(this.le.getRunEnd()) : null); } - @Nullable - private static Instant toInstant(@Nullable Date date) { + private static @Nullable Instant toInstant(@Nullable Date date) { return (date != null ? date.toInstant() : null); } } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java index 417a542c68..04e4dfd2ad 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DefaultManagedAwareThreadFactory.java @@ -23,11 +23,11 @@ import javax.naming.NamingException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.jndi.JndiLocatorDelegate; import org.springframework.jndi.JndiTemplate; -import org.springframework.lang.Nullable; /** * JNDI-based variant of {@link CustomizableThreadFactory}, performing a default lookup @@ -53,11 +53,9 @@ public class DefaultManagedAwareThreadFactory extends CustomizableThreadFactory private final JndiLocatorDelegate jndiLocator = new JndiLocatorDelegate(); - @Nullable - private String jndiName = "java:comp/DefaultManagedThreadFactory"; + private @Nullable String jndiName = "java:comp/DefaultManagedThreadFactory"; - @Nullable - private ThreadFactory threadFactory; + private @Nullable ThreadFactory threadFactory; /** diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DelegatingErrorHandlingCallable.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DelegatingErrorHandlingCallable.java index c30f209c53..fd2c3ac3f8 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/DelegatingErrorHandlingCallable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/DelegatingErrorHandlingCallable.java @@ -19,7 +19,8 @@ package org.springframework.scheduling.concurrent; import java.lang.reflect.UndeclaredThrowableException; import java.util.concurrent.Callable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.support.TaskUtils; import org.springframework.util.ErrorHandler; import org.springframework.util.ReflectionUtils; @@ -46,8 +47,7 @@ class DelegatingErrorHandlingCallable implements Callable { @Override - @Nullable - public V call() throws Exception { + public @Nullable V call() throws Exception { try { return this.delegate.call(); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java index 99f22d71a0..9a0b820e61 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorConfigurationSupport.java @@ -26,6 +26,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; @@ -38,7 +39,6 @@ import org.springframework.context.SmartLifecycle; import org.springframework.context.event.ContextClosedEvent; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.VirtualThreadTaskExecutor; -import org.springframework.lang.Nullable; /** * Base class for setting up a {@link java.util.concurrent.ExecutorService} @@ -93,17 +93,13 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac private int phase = DEFAULT_PHASE; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private ExecutorService executor; + private @Nullable ExecutorService executor; - @Nullable - private ExecutorLifecycleDelegate lifecycleDelegate; + private @Nullable ExecutorLifecycleDelegate lifecycleDelegate; private volatile boolean lateShutdown; diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java index e8e705fc21..3a49ca6ef2 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ExecutorLifecycleDelegate.java @@ -21,8 +21,9 @@ import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.jspecify.annotations.Nullable; + import org.springframework.context.SmartLifecycle; -import org.springframework.lang.Nullable; /** * An internal delegate for common {@link ExecutorService} lifecycle management @@ -47,8 +48,7 @@ final class ExecutorLifecycleDelegate implements SmartLifecycle { private int executingTaskCount = 0; - @Nullable - private Runnable stopCallback; + private @Nullable Runnable stopCallback; public ExecutorLifecycleDelegate(ExecutorService executor) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java index 26b1165201..2de78626fd 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ForkJoinPoolFactoryBean.java @@ -19,10 +19,11 @@ package org.springframework.scheduling.concurrent; import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * A Spring {@link FactoryBean} that builds and exposes a preconfigured {@link ForkJoinPool}. @@ -38,15 +39,13 @@ public class ForkJoinPoolFactoryBean implements FactoryBean, Initi private ForkJoinPool.ForkJoinWorkerThreadFactory threadFactory = ForkJoinPool.defaultForkJoinWorkerThreadFactory; - @Nullable - private Thread.UncaughtExceptionHandler uncaughtExceptionHandler; + private Thread.@Nullable UncaughtExceptionHandler uncaughtExceptionHandler; private boolean asyncMode = false; private int awaitTerminationSeconds = 0; - @Nullable - private ForkJoinPool forkJoinPool; + private @Nullable ForkJoinPool forkJoinPool; /** @@ -128,8 +127,7 @@ public class ForkJoinPoolFactoryBean implements FactoryBean, Initi @Override - @Nullable - public ForkJoinPool getObject() { + public @Nullable ForkJoinPool getObject() { return this.forkJoinPool; } 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 c14be23fd5..d5aab59378 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 @@ -26,7 +26,8 @@ import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.Trigger; import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable; import org.springframework.scheduling.support.SimpleTriggerContext; @@ -53,11 +54,9 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc private final ScheduledExecutorService executor; - @Nullable - private ScheduledFuture currentFuture; + private @Nullable ScheduledFuture currentFuture; - @Nullable - private Instant scheduledExecutionTime; + private @Nullable Instant scheduledExecutionTime; private final Object triggerContextMonitor = new Object(); @@ -72,8 +71,7 @@ class ReschedulingRunnable extends DelegatingErrorHandlingRunnable implements Sc } - @Nullable - public ScheduledFuture schedule() { + public @Nullable ScheduledFuture schedule() { synchronized (this.triggerContextMonitor) { this.scheduledExecutionTime = this.trigger.nextExecution(this.triggerContext); if (this.scheduledExecutionTime == null) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java index c41101b499..dfdf377df7 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorFactoryBean.java @@ -23,8 +23,9 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable; import org.springframework.scheduling.support.TaskUtils; import org.springframework.util.Assert; @@ -76,8 +77,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport private int poolSize = 1; - @Nullable - private ScheduledExecutorTask[] scheduledExecutorTasks; + private ScheduledExecutorTask @Nullable [] scheduledExecutorTasks; private boolean removeOnCancelPolicy = false; @@ -85,8 +85,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport private boolean exposeUnconfigurableExecutor = false; - @Nullable - private ScheduledExecutorService exposedExecutor; + private @Nullable ScheduledExecutorService exposedExecutor; /** @@ -241,8 +240,7 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport @Override - @Nullable - public ScheduledExecutorService getObject() { + public @Nullable ScheduledExecutorService getObject() { return this.exposedExecutor; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorTask.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorTask.java index 7e55e5eecf..dc2b55d421 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorTask.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ScheduledExecutorTask.java @@ -18,7 +18,8 @@ package org.springframework.scheduling.concurrent; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -41,8 +42,7 @@ import org.springframework.util.Assert; */ public class ScheduledExecutorTask { - @Nullable - private Runnable runnable; + private @Nullable Runnable runnable; private long delay = 0; diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java index ebba610599..21cb4cc686 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/SimpleAsyncTaskScheduler.java @@ -29,6 +29,7 @@ import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -37,7 +38,6 @@ import org.springframework.context.SmartLifecycle; import org.springframework.context.event.ContextClosedEvent; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskRejectedException; -import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; import org.springframework.scheduling.support.DelegatingErrorHandlingRunnable; @@ -122,18 +122,15 @@ public class SimpleAsyncTaskScheduler extends SimpleAsyncTaskExecutor implements private final ExecutorLifecycleDelegate fixedDelayLifecycle = new ExecutorLifecycleDelegate(this.fixedDelayExecutor); - @Nullable - private ErrorHandler errorHandler; + private @Nullable ErrorHandler errorHandler; private Clock clock = Clock.systemDefaultZone(); private int phase = DEFAULT_PHASE; - @Nullable - private Executor targetTaskExecutor; + private @Nullable Executor targetTaskExecutor; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; /** @@ -270,8 +267,7 @@ public class SimpleAsyncTaskScheduler extends SimpleAsyncTaskExecutor implements } @Override - @Nullable - public ScheduledFuture schedule(Runnable task, Trigger trigger) { + public @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger) { try { Runnable delegate = scheduledTask(task); ErrorHandler errorHandler = diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBean.java index 7680a2634f..d57c979ecc 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolExecutorFactoryBean.java @@ -26,8 +26,9 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; /** * JavaBean that allows for configuring a {@link java.util.concurrent.ThreadPoolExecutor} @@ -81,8 +82,7 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport private boolean exposeUnconfigurableExecutor = false; - @Nullable - private ExecutorService exposedExecutor; + private @Nullable ExecutorService exposedExecutor; /** @@ -245,8 +245,7 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport @Override - @Nullable - public ExecutorService getObject() { + public @Nullable ExecutorService getObject() { return this.exposedExecutor; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java index 9451b64839..f4999fb431 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskExecutor.java @@ -30,10 +30,11 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskRejectedException; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -98,11 +99,9 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport private boolean strictEarlyShutdown = false; - @Nullable - private TaskDecorator taskDecorator; + private @Nullable TaskDecorator taskDecorator; - @Nullable - private ThreadPoolExecutor threadPoolExecutor; + private @Nullable ThreadPoolExecutor threadPoolExecutor; // Runnable decorator to user-level FutureTask, if different private final Map decoratedTaskMap = diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java index 581e1d4852..b0d754cc67 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java @@ -35,10 +35,11 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskRejectedException; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; @@ -85,16 +86,13 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport private volatile boolean executeExistingDelayedTasksAfterShutdownPolicy = true; - @Nullable - private TaskDecorator taskDecorator; + private @Nullable TaskDecorator taskDecorator; - @Nullable - private volatile ErrorHandler errorHandler; + private volatile @Nullable ErrorHandler errorHandler; private Clock clock = Clock.systemDefaultZone(); - @Nullable - private ScheduledExecutorService scheduledExecutor; + private @Nullable ScheduledExecutorService scheduledExecutor; /** @@ -353,8 +351,7 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport // TaskScheduler implementation @Override - @Nullable - public ScheduledFuture schedule(Runnable task, Trigger trigger) { + public @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger) { ScheduledExecutorService executor = getScheduledExecutor(); try { ErrorHandler errorHandler = this.errorHandler; 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 7caa0796d9..435f8199d2 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,9 +5,7 @@ * context. Provides support for the native {@code java.util.concurrent} * interfaces as well as the Spring {@code TaskExecutor} mechanism. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling.concurrent; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/AnnotationDrivenBeanDefinitionParser.java b/spring-context/src/main/java/org/springframework/scheduling/config/AnnotationDrivenBeanDefinitionParser.java index 8f09ae665a..c10e3d64ed 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/AnnotationDrivenBeanDefinitionParser.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/AnnotationDrivenBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.scheduling.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.aop.config.AopNamespaceUtils; @@ -27,7 +28,6 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -47,8 +47,7 @@ public class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParse @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register component for the surrounding element. diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java index 4f0265237e..14062c14b5 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/ScheduledTask.java @@ -20,7 +20,7 @@ import java.time.Instant; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A representation of a scheduled task at runtime, @@ -38,8 +38,7 @@ public final class ScheduledTask { private final Task task; - @Nullable - volatile ScheduledFuture future; + volatile @Nullable ScheduledFuture future; ScheduledTask(Task task) { @@ -84,8 +83,7 @@ public final class ScheduledTask { * if the task has been cancelled or no new execution is scheduled. * @since 6.2 */ - @Nullable - public Instant nextExecution() { + public @Nullable Instant nextExecution() { ScheduledFuture future = this.future; if (future != null && !future.isCancelled()) { long delay = future.getDelay(TimeUnit.MILLISECONDS); 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 700c0e9e27..49f5d455d1 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,10 +29,10 @@ import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; 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; @@ -74,29 +74,21 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing public static final String CRON_DISABLED = "-"; - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; - @Nullable - private ScheduledExecutorService localExecutor; + private @Nullable ScheduledExecutorService localExecutor; - @Nullable - private ObservationRegistry observationRegistry; + private @Nullable ObservationRegistry observationRegistry; - @Nullable - private List triggerTasks; + private @Nullable List triggerTasks; - @Nullable - private List cronTasks; + private @Nullable List cronTasks; - @Nullable - private List fixedRateTasks; + private @Nullable List fixedRateTasks; - @Nullable - private List fixedDelayTasks; + private @Nullable List fixedDelayTasks; - @Nullable - private List oneTimeTasks; + private @Nullable List oneTimeTasks; private final Map unresolvedTasks = new HashMap<>(16); @@ -134,8 +126,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing /** * Return the {@link TaskScheduler} instance for this registrar (may be {@code null}). */ - @Nullable - public TaskScheduler getScheduler() { + public @Nullable TaskScheduler getScheduler() { return this.taskScheduler; } @@ -151,8 +142,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing * Return the {@link ObservationRegistry} for this registrar. * @since 6.1 */ - @Nullable - public ObservationRegistry getObservationRegistry() { + public @Nullable ObservationRegistry getObservationRegistry() { return this.observationRegistry; } @@ -485,8 +475,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing * @return a handle to the scheduled task, allowing to cancel it * @since 4.3 */ - @Nullable - public ScheduledTask scheduleTriggerTask(TriggerTask task) { + public @Nullable ScheduledTask scheduleTriggerTask(TriggerTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; if (scheduledTask == null) { @@ -510,8 +499,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing * (or {@code null} if processing a previously registered task) * @since 4.3 */ - @Nullable - public ScheduledTask scheduleCronTask(CronTask task) { + public @Nullable ScheduledTask scheduleCronTask(CronTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; if (scheduledTask == null) { @@ -535,8 +523,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing * (or {@code null} if processing a previously registered task) * @since 5.0.2 */ - @Nullable - public ScheduledTask scheduleFixedRateTask(FixedRateTask task) { + public @Nullable ScheduledTask scheduleFixedRateTask(FixedRateTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; if (scheduledTask == null) { @@ -569,8 +556,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing * (or {@code null} if processing a previously registered task) * @since 5.0.2 */ - @Nullable - public ScheduledTask scheduleFixedDelayTask(FixedDelayTask task) { + public @Nullable ScheduledTask scheduleFixedDelayTask(FixedDelayTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; if (scheduledTask == null) { @@ -603,8 +589,7 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing * (or {@code null} if processing a previously registered task) * @since 6.1 */ - @Nullable - public ScheduledTask scheduleOneTimeTask(OneTimeTask task) { + public @Nullable ScheduledTask scheduleOneTimeTask(OneTimeTask task) { ScheduledTask scheduledTask = this.unresolvedTasks.remove(task); boolean newTask = false; if (scheduledTask == null) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/Task.java b/spring-context/src/main/java/org/springframework/scheduling/config/Task.java index ae14768a7d..ef9c9042d5 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/Task.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/Task.java @@ -18,7 +18,8 @@ package org.springframework.scheduling.config; import java.time.Instant; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.util.Assert; @@ -99,9 +100,8 @@ public class Task { return SchedulingAwareRunnable.super.isLongLived(); } - @Nullable @Override - public String getQualifier() { + public @Nullable String getQualifier() { if (this.runnable instanceof SchedulingAwareRunnable sar) { return sar.getQualifier(); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutionOutcome.java b/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutionOutcome.java index cbb6e1ec4c..b049296dc0 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutionOutcome.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutionOutcome.java @@ -18,7 +18,8 @@ package org.springframework.scheduling.config; import java.time.Instant; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java b/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java index b065156dd0..6566263f62 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/TaskExecutorFactoryBean.java @@ -18,12 +18,13 @@ package org.springframework.scheduling.config; import java.util.concurrent.RejectedExecutionHandler; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.task.TaskExecutor; -import org.springframework.lang.Nullable; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.util.StringUtils; @@ -38,23 +39,17 @@ import org.springframework.util.StringUtils; public class TaskExecutorFactoryBean implements FactoryBean, BeanNameAware, InitializingBean, DisposableBean { - @Nullable - private String poolSize; + private @Nullable String poolSize; - @Nullable - private Integer queueCapacity; + private @Nullable Integer queueCapacity; - @Nullable - private RejectedExecutionHandler rejectedExecutionHandler; + private @Nullable RejectedExecutionHandler rejectedExecutionHandler; - @Nullable - private Integer keepAliveSeconds; + private @Nullable Integer keepAliveSeconds; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ThreadPoolTaskExecutor target; + private @Nullable ThreadPoolTaskExecutor target; public void setPoolSize(String poolSize) { @@ -144,8 +139,7 @@ public class TaskExecutorFactoryBean implements @Override - @Nullable - public TaskExecutor getObject() { + public @Nullable TaskExecutor getObject() { return this.target; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/config/TaskSchedulerRouter.java b/spring-context/src/main/java/org/springframework/scheduling/config/TaskSchedulerRouter.java index 21898b50ef..0a4080d2d0 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/config/TaskSchedulerRouter.java +++ b/spring-context/src/main/java/org/springframework/scheduling/config/TaskSchedulerRouter.java @@ -25,6 +25,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -38,7 +39,6 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.EmbeddedValueResolver; import org.springframework.beans.factory.config.NamedBeanHolder; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; @@ -69,19 +69,15 @@ public class TaskSchedulerRouter implements TaskScheduler, BeanNameAware, BeanFa protected static final Log logger = LogFactory.getLog(TaskSchedulerRouter.class); - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private final Supplier defaultScheduler = SingletonSupplier.of(this::determineDefaultScheduler); - @Nullable - private volatile ScheduledExecutorService localExecutor; + private volatile @Nullable ScheduledExecutorService localExecutor; /** @@ -106,8 +102,7 @@ public class TaskSchedulerRouter implements TaskScheduler, BeanNameAware, BeanFa @Override - @Nullable - public ScheduledFuture schedule(Runnable task, Trigger trigger) { + public @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger) { return determineTargetScheduler(task).schedule(task, trigger); } @@ -150,8 +145,7 @@ public class TaskSchedulerRouter implements TaskScheduler, BeanNameAware, BeanFa } } - @Nullable - protected String determineQualifier(Runnable task) { + protected @Nullable String determineQualifier(Runnable task) { return (task instanceof SchedulingAwareRunnable sar ? sar.getQualifier() : null); } 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 3ddfc3ca96..962ffb54bf 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,9 +2,7 @@ * Support package for declarative scheduling configuration, * with XML schema being the primary configuration format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 8880b4ba37..950be25069 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,9 +2,7 @@ * General exceptions for Spring's scheduling support, * independent of any specific scheduling system. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java b/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java index 3ef274e63c..5b662d3bf9 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java @@ -20,7 +20,8 @@ import java.time.DateTimeException; import java.time.temporal.Temporal; import java.time.temporal.ValueRange; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -170,9 +171,8 @@ final class BitsCronField extends CronField { } - @Nullable @Override - public > T nextOrSame(T temporal) { + public > @Nullable T nextOrSame(T temporal) { int current = type().get(temporal); int next = nextSetBit(current); if (next == -1) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/CompositeCronField.java b/spring-context/src/main/java/org/springframework/scheduling/support/CompositeCronField.java index c69fdb12ff..8560581895 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/CompositeCronField.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/CompositeCronField.java @@ -18,7 +18,8 @@ package org.springframework.scheduling.support; import java.time.temporal.Temporal; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -56,9 +57,8 @@ final class CompositeCronField extends CronField { } - @Nullable @Override - public > T nextOrSame(T temporal) { + public > @Nullable T nextOrSame(T temporal) { T result = null; for (CronField field : this.fields) { T candidate = field.nextOrSame(temporal); diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/CronExpression.java b/spring-context/src/main/java/org/springframework/scheduling/support/CronExpression.java index 47b5db1a2c..bdb5249ea3 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/CronExpression.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/CronExpression.java @@ -20,7 +20,8 @@ import java.time.temporal.ChronoUnit; import java.time.temporal.Temporal; import java.util.Arrays; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -236,14 +237,12 @@ public final class CronExpression { * @return the next temporal that matches this expression, or {@code null} * if no such temporal can be found */ - @Nullable - public > T next(T temporal) { + public > @Nullable T next(T temporal) { return nextOrSame(ChronoUnit.NANOS.addTo(temporal, 1)); } - @Nullable - private > T nextOrSame(T temporal) { + private > @Nullable T nextOrSame(T temporal) { for (int i = 0; i < MAX_ATTEMPTS; i++) { T result = nextOrSameInternal(temporal); if (result == null || result.equals(temporal)) { @@ -254,8 +253,7 @@ public final class CronExpression { return null; } - @Nullable - private > T nextOrSameInternal(T temporal) { + private > @Nullable T nextOrSameInternal(T temporal) { for (CronField field : this.fields) { temporal = field.nextOrSame(temporal); if (temporal == null) { diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/CronField.java b/spring-context/src/main/java/org/springframework/scheduling/support/CronField.java index e1702c9a54..31161c85b3 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/CronField.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/CronField.java @@ -24,7 +24,8 @@ import java.time.temporal.ValueRange; import java.util.Locale; import java.util.function.BiFunction; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -159,8 +160,7 @@ abstract class CronField { * @param temporal the seed value * @return the next or same temporal matching the pattern */ - @Nullable - public abstract > T nextOrSame(T temporal); + public abstract > @Nullable T nextOrSame(T temporal); protected Type type() { diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java b/spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java index dc8c9a4ab5..8aab327bf5 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/CronTrigger.java @@ -21,7 +21,8 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.util.TimeZone; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.Trigger; import org.springframework.scheduling.TriggerContext; import org.springframework.util.Assert; @@ -45,8 +46,7 @@ public class CronTrigger implements Trigger { private final CronExpression expression; - @Nullable - private final ZoneId zoneId; + private final @Nullable ZoneId zoneId; /** @@ -112,8 +112,7 @@ public class CronTrigger implements Trigger { * previous execution; therefore, overlapping executions won't occur. */ @Override - @Nullable - public Instant nextExecution(TriggerContext triggerContext) { + public @Nullable Instant nextExecution(TriggerContext triggerContext) { Instant timestamp = determineLatestTimestamp(triggerContext); ZoneId zone = (this.zoneId != null ? this.zoneId : triggerContext.getClock().getZone()); ZonedDateTime zonedTimestamp = ZonedDateTime.ofInstant(timestamp, zone); diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/MethodInvokingRunnable.java b/spring-context/src/main/java/org/springframework/scheduling/support/MethodInvokingRunnable.java index 8b354ebec3..067d295400 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/MethodInvokingRunnable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/MethodInvokingRunnable.java @@ -20,11 +20,11 @@ import java.lang.reflect.InvocationTargetException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.support.ArgumentConvertingMethodInvoker; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -43,8 +43,7 @@ public class MethodInvokingRunnable extends ArgumentConvertingMethodInvoker protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); @Override diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/NoOpTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/support/NoOpTaskScheduler.java index c2733dd86e..cf5680de94 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/NoOpTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/NoOpTaskScheduler.java @@ -23,7 +23,8 @@ import java.util.concurrent.Delayed; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.Trigger; @@ -39,8 +40,7 @@ import org.springframework.scheduling.Trigger; public class NoOpTaskScheduler implements TaskScheduler { @Override - @Nullable - public ScheduledFuture schedule(Runnable task, Trigger trigger) { + public @Nullable ScheduledFuture schedule(Runnable task, Trigger trigger) { Instant nextExecution = trigger.nextExecution(new SimpleTriggerContext(getClock())); return (nextExecution != null ? new NoOpScheduledFuture<>() : null); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java index 71096a8934..fa075a2762 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/PeriodicTrigger.java @@ -21,7 +21,8 @@ import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.Trigger; import org.springframework.scheduling.TriggerContext; import org.springframework.util.Assert; @@ -51,11 +52,9 @@ public class PeriodicTrigger implements Trigger { private final Duration period; - @Nullable - private final ChronoUnit chronoUnit; + private final @Nullable ChronoUnit chronoUnit; - @Nullable - private volatile Duration initialDelay; + private volatile @Nullable Duration initialDelay; private volatile boolean fixedRate; @@ -197,8 +196,7 @@ public class PeriodicTrigger implements Trigger { * Return the initial delay, or {@code null} if none. * @since 6.0 */ - @Nullable - public Duration getInitialDelayDuration() { + public @Nullable Duration getInitialDelayDuration() { return this.initialDelay; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/QuartzCronField.java b/spring-context/src/main/java/org/springframework/scheduling/support/QuartzCronField.java index 8c0873d151..19ddf63da0 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/QuartzCronField.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/QuartzCronField.java @@ -24,7 +24,8 @@ import java.time.temporal.Temporal; import java.time.temporal.TemporalAdjuster; import java.time.temporal.TemporalAdjusters; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -338,8 +339,7 @@ final class QuartzCronField extends CronField { @Override - @Nullable - public > T nextOrSame(T temporal) { + public > @Nullable T nextOrSame(T temporal) { T result = adjust(temporal); if (result != null) { if (result.compareTo(temporal) < 0) { @@ -354,9 +354,8 @@ final class QuartzCronField extends CronField { return result; } - @Nullable @SuppressWarnings("unchecked") - private > T adjust(T temporal) { + private > @Nullable T adjust(T temporal) { return (T) this.adjuster.adjustInto(temporal); } diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java b/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java index 87412218f9..57312e3c41 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/ScheduledMethodRunnable.java @@ -23,8 +23,8 @@ import java.util.function.Supplier; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.util.ReflectionUtils; @@ -47,8 +47,7 @@ public class ScheduledMethodRunnable implements SchedulingAwareRunnable { private final Method method; - @Nullable - private final String qualifier; + private final @Nullable String qualifier; private final Supplier observationRegistrySupplier; @@ -109,8 +108,7 @@ public class ScheduledMethodRunnable implements SchedulingAwareRunnable { } @Override - @Nullable - public String getQualifier() { + public @Nullable String getQualifier() { return this.qualifier; } diff --git a/spring-context/src/main/java/org/springframework/scheduling/support/SimpleTriggerContext.java b/spring-context/src/main/java/org/springframework/scheduling/support/SimpleTriggerContext.java index 52088fb41d..519a19aa86 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/support/SimpleTriggerContext.java +++ b/spring-context/src/main/java/org/springframework/scheduling/support/SimpleTriggerContext.java @@ -20,7 +20,8 @@ import java.time.Clock; import java.time.Instant; import java.util.Date; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.TriggerContext; /** @@ -33,14 +34,11 @@ public class SimpleTriggerContext implements TriggerContext { private final Clock clock; - @Nullable - private volatile Instant lastScheduledExecution; + private volatile @Nullable Instant lastScheduledExecution; - @Nullable - private volatile Instant lastActualExecution; + private volatile @Nullable Instant lastActualExecution; - @Nullable - private volatile Instant lastCompletion; + private volatile @Nullable Instant lastCompletion; /** @@ -66,8 +64,7 @@ public class SimpleTriggerContext implements TriggerContext { this(toInstant(lastScheduledExecutionTime), toInstant(lastActualExecutionTime), toInstant(lastCompletionTime)); } - @Nullable - private static Instant toInstant(@Nullable Date date) { + private static @Nullable Instant toInstant(@Nullable Date date) { return (date != null ? date.toInstant() : null); } @@ -134,20 +131,17 @@ public class SimpleTriggerContext implements TriggerContext { } @Override - @Nullable - public Instant lastScheduledExecution() { + public @Nullable Instant lastScheduledExecution() { return this.lastScheduledExecution; } @Override - @Nullable - public Instant lastActualExecution() { + public @Nullable Instant lastActualExecution() { return this.lastActualExecution; } @Override - @Nullable - public Instant lastCompletion() { + public @Nullable Instant lastCompletion() { return this.lastCompletion; } 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 7a286639e3..3d8a068fe6 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 @@ -20,8 +20,8 @@ import java.util.concurrent.Future; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ErrorHandler; import org.springframework.util.ReflectionUtils; 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 228c69c6a9..485d125060 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,9 +2,7 @@ * Generic support classes for scheduling. * Provides a Runnable adapter for Spring's MethodInvoker. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scheduling.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 25e4b08151..91e8107de2 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptCompilationException.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptCompilationException.java @@ -16,8 +16,9 @@ package org.springframework.scripting; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Exception to be thrown on script compilation failure. @@ -28,8 +29,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ScriptCompilationException extends NestedRuntimeException { - @Nullable - private final ScriptSource scriptSource; + private final @Nullable ScriptSource scriptSource; /** @@ -88,8 +88,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() { + public @Nullable 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 762a2282e7..3fa401bcc8 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptEvaluator.java @@ -18,7 +18,7 @@ package org.springframework.scripting; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Spring's strategy interface for evaluating a script. @@ -40,8 +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; + @Nullable Object evaluate(ScriptSource script) throws ScriptCompilationException; /** * Evaluate the given script with the given arguments. @@ -52,7 +51,6 @@ public interface ScriptEvaluator { * @throws ScriptCompilationException if the evaluator failed to read, * compile or evaluate the script */ - @Nullable - Object evaluate(ScriptSource script, @Nullable 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 5c535c36f0..fb60a7ce31 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptFactory.java @@ -18,7 +18,7 @@ package org.springframework.scripting; import java.io.IOException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Script definition interface, encapsulating the configuration @@ -51,8 +51,7 @@ public interface ScriptFactory { * its Java interfaces (such as in the case of Groovy). * @return the interfaces for the script */ - @Nullable - Class[] getScriptInterfaces(); + Class @Nullable [] getScriptInterfaces(); /** * Return whether the script requires a config interface to be @@ -78,8 +77,7 @@ public interface ScriptFactory { * @throws IOException if script retrieval failed * @throws ScriptCompilationException if script compilation failed */ - @Nullable - Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... actualInterfaces) + @Nullable Object getScriptedObject(ScriptSource scriptSource, Class @Nullable ... actualInterfaces) throws IOException, ScriptCompilationException; /** @@ -95,8 +93,7 @@ public interface ScriptFactory { * @throws ScriptCompilationException if script compilation failed * @since 2.0.3 */ - @Nullable - Class getScriptedObjectType(ScriptSource scriptSource) + @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 87e6954704..75515cc0d1 100644 --- a/spring-context/src/main/java/org/springframework/scripting/ScriptSource.java +++ b/spring-context/src/main/java/org/springframework/scripting/ScriptSource.java @@ -18,7 +18,7 @@ package org.springframework.scripting; import java.io.IOException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that defines the source of a script. @@ -49,7 +49,6 @@ 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(); + @Nullable String suggestedClassName(); } diff --git a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptEvaluator.java b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptEvaluator.java index 07697f0d08..b6aef2c71f 100644 --- a/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptEvaluator.java +++ b/spring-context/src/main/java/org/springframework/scripting/bsh/BshScriptEvaluator.java @@ -22,9 +22,9 @@ import java.util.Map; import bsh.EvalError; import bsh.Interpreter; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.ScriptEvaluator; import org.springframework.scripting.ScriptSource; @@ -38,8 +38,7 @@ import org.springframework.scripting.ScriptSource; */ public class BshScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware { - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; /** @@ -64,14 +63,12 @@ public class BshScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware @Override - @Nullable - public Object evaluate(ScriptSource script) { + public @Nullable Object evaluate(ScriptSource script) { return evaluate(script, null); } @Override - @Nullable - public Object evaluate(ScriptSource script, @Nullable Map arguments) { + public @Nullable Object evaluate(ScriptSource script, @Nullable Map arguments) { try { Interpreter interpreter = new Interpreter(); interpreter.setClassLoader(this.classLoader); 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 235593df9e..4d355ffa30 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 @@ -19,9 +19,9 @@ package org.springframework.scripting.bsh; import java.io.IOException; import bsh.EvalError; +import org.jspecify.annotations.Nullable; 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; @@ -47,14 +47,11 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { private final String scriptSourceLocator; - @Nullable - private final Class[] scriptInterfaces; + private final Class @Nullable [] scriptInterfaces; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private Class scriptClass; + private @Nullable Class scriptClass; private final Object scriptClassMonitor = new Object(); @@ -85,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, @Nullable Class... scriptInterfaces) { + public BshScriptFactory(String scriptSourceLocator, Class @Nullable ... scriptInterfaces) { Assert.hasText(scriptSourceLocator, "'scriptSourceLocator' must not be empty"); this.scriptSourceLocator = scriptSourceLocator; this.scriptInterfaces = scriptInterfaces; @@ -104,8 +101,7 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { } @Override - @Nullable - public Class[] getScriptInterfaces() { + public Class @Nullable [] getScriptInterfaces() { return this.scriptInterfaces; } @@ -122,8 +118,7 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { * @see BshScriptUtils#createBshObject(String, Class[], ClassLoader) */ @Override - @Nullable - public Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... actualInterfaces) + public @Nullable Object getScriptedObject(ScriptSource scriptSource, Class @Nullable ... actualInterfaces) throws IOException, ScriptCompilationException { Class clazz; @@ -181,8 +176,7 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware { } @Override - @Nullable - public Class getScriptedObjectType(ScriptSource scriptSource) + public @Nullable Class getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException { synchronized (this.scriptClassMonitor) { 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 8469e4884c..308ea1950f 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 @@ -24,9 +24,9 @@ import bsh.EvalError; import bsh.Interpreter; import bsh.Primitive; import bsh.XThis; +import org.jspecify.annotations.Nullable; import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -68,7 +68,7 @@ public abstract class BshScriptUtils { * @throws EvalError in case of BeanShell parsing failure * @see #createBshObject(String, Class[], ClassLoader) */ - public static Object createBshObject(String scriptSource, @Nullable Class... scriptInterfaces) throws EvalError { + public static Object createBshObject(String scriptSource, Class @Nullable ... scriptInterfaces) throws EvalError { return createBshObject(scriptSource, scriptInterfaces, ClassUtils.getDefaultClassLoader()); } @@ -86,7 +86,7 @@ public abstract class BshScriptUtils { * @return the scripted Java object * @throws EvalError in case of BeanShell parsing failure */ - public static Object createBshObject(String scriptSource, @Nullable Class[] scriptInterfaces, @Nullable ClassLoader classLoader) + public static Object createBshObject(String scriptSource, Class @Nullable [] scriptInterfaces, @Nullable ClassLoader classLoader) throws EvalError { Object result = evaluateBshScript(scriptSource, scriptInterfaces, classLoader); @@ -114,8 +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, @Nullable ClassLoader classLoader) throws EvalError { + static @Nullable Class determineBshObjectType(String scriptSource, @Nullable ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); Interpreter interpreter = new Interpreter(); if (classLoader != null) { @@ -149,7 +148,7 @@ public abstract class BshScriptUtils { * @throws EvalError in case of BeanShell parsing failure */ static Object evaluateBshScript( - String scriptSource, @Nullable Class[] scriptInterfaces, @Nullable ClassLoader classLoader) + String scriptSource, Class @Nullable [] scriptInterfaces, @Nullable ClassLoader classLoader) throws EvalError { Assert.hasText(scriptSource, "Script source must not be empty"); @@ -183,8 +182,7 @@ public abstract class BshScriptUtils { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable 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 eb70e4afb8..d5e2fb0d27 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,9 +4,7 @@ * (and BeanShell2) * into Spring's scripting infrastructure. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scripting.bsh; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 06d6cd7727..47c0a447f9 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 @@ -18,6 +18,7 @@ package org.springframework.scripting.config; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.ConstructorArgumentValues; @@ -29,7 +30,6 @@ 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; @@ -104,8 +104,7 @@ class ScriptBeanDefinitionParser extends AbstractBeanDefinitionParser { */ @Override @SuppressWarnings("deprecation") - @Nullable - protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + protected @Nullable AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { // Engine attribute only supported for String engine = element.getAttribute(ENGINE_ATTRIBUTE); @@ -215,8 +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) { + private @Nullable String resolveScriptSource(Element element, XmlReaderContext readerContext) { boolean hasScriptSource = element.hasAttribute(SCRIPT_SOURCE_ATTRIBUTE); List elements = DomUtils.getChildElementsByTagName(element, INLINE_SCRIPT_ELEMENT); if (hasScriptSource && !elements.isEmpty()) { diff --git a/spring-context/src/main/java/org/springframework/scripting/config/ScriptingDefaultsParser.java b/spring-context/src/main/java/org/springframework/scripting/config/ScriptingDefaultsParser.java index f4068e09cb..60b3ec1b99 100644 --- a/spring-context/src/main/java/org/springframework/scripting/config/ScriptingDefaultsParser.java +++ b/spring-context/src/main/java/org/springframework/scripting/config/ScriptingDefaultsParser.java @@ -16,13 +16,13 @@ package org.springframework.scripting.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.TypedStringValue; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -39,8 +39,7 @@ class ScriptingDefaultsParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { BeanDefinition bd = LangNamespaceUtils.registerScriptFactoryPostProcessorIfNecessary(parserContext.getRegistry()); String refreshCheckDelay = element.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE); 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 0d2c295d5b..e10b2dde00 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,9 +2,7 @@ * Support package for Spring's dynamic language machinery, * with XML schema being the primary configuration format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scripting.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptEvaluator.java b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptEvaluator.java index 21a34f10a3..e63945ee87 100644 --- a/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptEvaluator.java +++ b/spring-context/src/main/java/org/springframework/scripting/groovy/GroovyScriptEvaluator.java @@ -24,9 +24,9 @@ import groovy.lang.GroovyRuntimeException; import groovy.lang.GroovyShell; import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.customizers.CompilationCustomizer; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; -import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.ScriptEvaluator; import org.springframework.scripting.ScriptSource; @@ -41,8 +41,7 @@ import org.springframework.scripting.support.ResourceScriptSource; */ public class GroovyScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware { - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; private CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); @@ -98,14 +97,12 @@ public class GroovyScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAw @Override - @Nullable - public Object evaluate(ScriptSource script) { + public @Nullable Object evaluate(ScriptSource script) { return evaluate(script, null); } @Override - @Nullable - public Object evaluate(ScriptSource script, @Nullable Map arguments) { + public @Nullable Object evaluate(ScriptSource script, @Nullable Map arguments) { GroovyShell groovyShell = new GroovyShell( this.classLoader, new Binding(arguments), this.compilerConfiguration); try { 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 2165186068..d3faceca89 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 @@ -26,12 +26,12 @@ import groovy.lang.Script; import org.codehaus.groovy.control.CompilationFailedException; import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.customizers.CompilationCustomizer; +import org.jspecify.annotations.Nullable; 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; @@ -61,23 +61,17 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea private final String scriptSourceLocator; - @Nullable - private GroovyObjectCustomizer groovyObjectCustomizer; + private @Nullable GroovyObjectCustomizer groovyObjectCustomizer; - @Nullable - private CompilerConfiguration compilerConfiguration; + private @Nullable CompilerConfiguration compilerConfiguration; - @Nullable - private GroovyClassLoader groovyClassLoader; + private @Nullable GroovyClassLoader groovyClassLoader; - @Nullable - private Class scriptClass; + private @Nullable Class scriptClass; - @Nullable - private Class scriptResultClass; + private @Nullable Class scriptResultClass; - @Nullable - private CachedResultHolder cachedResult; + private @Nullable CachedResultHolder cachedResult; private final Object scriptClassMonitor = new Object(); @@ -201,8 +195,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea * @return {@code null} always */ @Override - @Nullable - public Class[] getScriptInterfaces() { + public Class @Nullable [] getScriptInterfaces() { return null; } @@ -221,8 +214,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea * @see groovy.lang.GroovyClassLoader */ @Override - @Nullable - public Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... actualInterfaces) + public @Nullable Object getScriptedObject(ScriptSource scriptSource, Class @Nullable ... actualInterfaces) throws IOException, ScriptCompilationException { synchronized (this.scriptClassMonitor) { @@ -265,8 +257,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea } @Override - @Nullable - public Class getScriptedObjectType(ScriptSource scriptSource) + public @Nullable Class getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException { synchronized (this.scriptClassMonitor) { @@ -314,8 +305,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea * or the result of running the script instance) * @throws ScriptCompilationException in case of instantiation failure */ - @Nullable - protected Object executeScript(ScriptSource scriptSource, Class scriptClass) throws ScriptCompilationException { + protected @Nullable Object executeScript(ScriptSource scriptSource, Class scriptClass) throws ScriptCompilationException { try { GroovyObject groovyObj = (GroovyObject) ReflectionUtils.accessibleConstructor(scriptClass).newInstance(); @@ -363,8 +353,7 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea */ private static class CachedResultHolder { - @Nullable - public final Object object; + public final @Nullable Object object; public CachedResultHolder(@Nullable Object object) { this.object = object; 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 3361390037..fa250edaa0 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,9 +3,7 @@ * Groovy * into Spring's scripting infrastructure. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scripting.groovy; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 53a043f760..29d2f16d78 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,9 +1,7 @@ /** * Core interfaces for Spring's scripting support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scripting; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 0cdceadfe7..94860e0aa2 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 @@ -22,10 +22,10 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -129,8 +129,7 @@ public class ResourceScriptSource implements ScriptSource { } @Override - @Nullable - public String suggestedClassName() { + public @Nullable String suggestedClassName() { String filename = getResource().getFilename(); return (filename != null ? StringUtils.stripFilenameExtension(filename) : null); } 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 ac1b678dfb..5d71cb0eba 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 @@ -21,6 +21,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.TargetSource; import org.springframework.aop.framework.AopInfrastructureBean; @@ -51,7 +52,6 @@ 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.Assert; @@ -178,11 +178,9 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo private boolean defaultProxyTargetClass = false; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private ConfigurableBeanFactory beanFactory; + private @Nullable ConfigurableBeanFactory beanFactory; private ResourceLoader resourceLoader = new DefaultResourceLoader(); @@ -248,8 +246,7 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo @Override - @Nullable - public Class predictBeanType(Class beanClass, String beanName) { + public @Nullable Class predictBeanType(Class beanClass, String beanName) { // We only apply special treatment to ScriptFactory implementations here. if (!ScriptFactory.class.isAssignableFrom(beanClass)) { return null; @@ -304,8 +301,7 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo } @Override - @Nullable - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) { + public @Nullable Object postProcessBeforeInstantiation(Class beanClass, String beanName) { // We only apply special treatment to ScriptFactory implementations here. if (!ScriptFactory.class.isAssignableFrom(beanClass)) { return null; @@ -500,7 +496,7 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo * @see org.springframework.cglib.proxy.InterfaceMaker * @see org.springframework.beans.BeanUtils#findPropertyType */ - protected Class createConfigInterface(BeanDefinition bd, @Nullable Class[] interfaces) { + protected Class createConfigInterface(BeanDefinition bd, Class @Nullable [] interfaces) { InterfaceMaker maker = new InterfaceMaker(); PropertyValue[] pvs = bd.getPropertyValues().getPropertyValues(); for (PropertyValue pv : pvs) { @@ -546,7 +542,7 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo * @see org.springframework.scripting.ScriptFactory#getScriptedObject */ protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, String scriptFactoryBeanName, - ScriptSource scriptSource, @Nullable Class[] interfaces) { + ScriptSource scriptSource, Class @Nullable [] interfaces) { GenericBeanDefinition objectBd = new GenericBeanDefinition(bd); objectBd.setFactoryBeanName(scriptFactoryBeanName); @@ -565,7 +561,7 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo * @return the generated proxy * @see RefreshableScriptTargetSource */ - protected Object createRefreshableProxy(TargetSource ts, @Nullable Class[] interfaces, boolean proxyTargetClass) { + protected Object createRefreshableProxy(TargetSource ts, Class @Nullable [] 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/StandardScriptEvaluator.java b/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptEvaluator.java index d907574ef2..4103d54695 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptEvaluator.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptEvaluator.java @@ -24,9 +24,10 @@ import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; import javax.script.ScriptException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.scripting.ScriptCompilationException; import org.springframework.scripting.ScriptEvaluator; import org.springframework.scripting.ScriptSource; @@ -44,14 +45,11 @@ import org.springframework.util.StringUtils; */ public class StandardScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware { - @Nullable - private String engineName; + private @Nullable String engineName; - @Nullable - private volatile Bindings globalBindings; + private volatile @Nullable Bindings globalBindings; - @Nullable - private volatile ScriptEngineManager scriptEngineManager; + private volatile @Nullable ScriptEngineManager scriptEngineManager; /** @@ -132,14 +130,12 @@ public class StandardScriptEvaluator implements ScriptEvaluator, BeanClassLoader @Override - @Nullable - public Object evaluate(ScriptSource script) { + public @Nullable Object evaluate(ScriptSource script) { return evaluate(script, null); } @Override - @Nullable - public Object evaluate(ScriptSource script, @Nullable Map argumentBindings) { + public @Nullable Object evaluate(ScriptSource script, @Nullable Map argumentBindings) { ScriptEngine engine = getScriptEngine(script); try { if (CollectionUtils.isEmpty(argumentBindings)) { diff --git a/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java b/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java index a2e4c4f32f..3373f26d43 100644 --- a/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java +++ b/spring-context/src/main/java/org/springframework/scripting/support/StandardScriptFactory.java @@ -23,8 +23,9 @@ import javax.script.Invocable; import javax.script.ScriptEngine; import javax.script.ScriptEngineManager; +import org.jspecify.annotations.Nullable; + 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; @@ -49,19 +50,15 @@ import org.springframework.util.StringUtils; */ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAware { - @Nullable - private final String scriptEngineName; + private final @Nullable String scriptEngineName; private final String scriptSourceLocator; - @Nullable - private final Class[] scriptInterfaces; + private final Class @Nullable [] scriptInterfaces; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); - @Nullable - private volatile ScriptEngine scriptEngine; + private volatile @Nullable ScriptEngine scriptEngine; /** @@ -105,7 +102,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar * is supposed to implement */ public StandardScriptFactory( - @Nullable String scriptEngineName, String scriptSourceLocator, @Nullable Class... scriptInterfaces) { + @Nullable String scriptEngineName, String scriptSourceLocator, Class @Nullable ... scriptInterfaces) { Assert.hasText(scriptSourceLocator, "'scriptSourceLocator' must not be empty"); this.scriptEngineName = scriptEngineName; @@ -125,8 +122,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar } @Override - @Nullable - public Class[] getScriptInterfaces() { + public Class @Nullable [] getScriptInterfaces() { return this.scriptInterfaces; } @@ -140,8 +136,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar * Load and parse the script via JSR-223's ScriptEngine. */ @Override - @Nullable - public Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... actualInterfaces) + public @Nullable Object getScriptedObject(ScriptSource scriptSource, Class @Nullable ... actualInterfaces) throws IOException, ScriptCompilationException { Object script = evaluateScript(scriptSource); @@ -202,8 +197,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar } } - @Nullable - protected ScriptEngine retrieveScriptEngine(ScriptSource scriptSource) { + protected @Nullable ScriptEngine retrieveScriptEngine(ScriptSource scriptSource) { ScriptEngineManager scriptEngineManager = new ScriptEngineManager(this.beanClassLoader); if (this.scriptEngineName != null) { @@ -226,8 +220,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar return null; } - @Nullable - protected Object adaptToInterfaces( + protected @Nullable Object adaptToInterfaces( @Nullable Object script, ScriptSource scriptSource, Class... actualInterfaces) { Class adaptedIfc; @@ -260,8 +253,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar } @Override - @Nullable - public Class getScriptedObjectType(ScriptSource scriptSource) + public @Nullable Class getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException { return null; 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 c1163e9ece..9b2fd1dc9e 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,7 +16,8 @@ package org.springframework.scripting.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scripting.ScriptSource; import org.springframework.util.Assert; @@ -36,8 +37,7 @@ public class StaticScriptSource implements ScriptSource { private boolean modified; - @Nullable - private String className; + private @Nullable String className; /** @@ -82,8 +82,7 @@ public class StaticScriptSource implements ScriptSource { } @Override - @Nullable - public String suggestedClassName() { + public @Nullable String suggestedClassName() { return this.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 dc8b765754..c006546a2f 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,9 +3,7 @@ * Provides a ScriptFactoryPostProcessor for turning ScriptFactory * definitions into scripted objects. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.scripting.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 829c45e73e..9cb0299d7d 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,9 +4,7 @@ * *

Intended for use by tools and aspects (making an ideal target for pointcuts). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.stereotype; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 25e3d4d7b0..4247bed629 100644 --- a/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/ui/ConcurrentModel.java @@ -20,8 +20,9 @@ import java.util.Collection; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.Conventions; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -66,8 +67,7 @@ public class ConcurrentModel extends ConcurrentHashMap implement @Override - @Nullable - public Object put(String key, @Nullable Object value) { + public @Nullable Object put(String key, @Nullable Object value) { if (value != null) { return super.put(key, value); } @@ -169,8 +169,7 @@ public class ConcurrentModel extends ConcurrentHashMap implement } @Override - @Nullable - public Object getAttribute(String attributeName) { + public @Nullable Object getAttribute(String attributeName) { return get(attributeName); } diff --git a/spring-context/src/main/java/org/springframework/ui/ExtendedModelMap.java b/spring-context/src/main/java/org/springframework/ui/ExtendedModelMap.java index 5ec0a109e4..356e95964a 100644 --- a/spring-context/src/main/java/org/springframework/ui/ExtendedModelMap.java +++ b/spring-context/src/main/java/org/springframework/ui/ExtendedModelMap.java @@ -19,7 +19,7 @@ package org.springframework.ui; import java.util.Collection; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Subclass of {@link ModelMap} that implements the {@link Model} interface. 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 83cd2ee8ba..e6ba37e63f 100644 --- a/spring-context/src/main/java/org/springframework/ui/Model.java +++ b/spring-context/src/main/java/org/springframework/ui/Model.java @@ -19,7 +19,7 @@ package org.springframework.ui; import java.util.Collection; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that defines a holder for model attributes. @@ -84,8 +84,7 @@ public interface Model { * @return the corresponding attribute value, or {@code null} if none * @since 5.2 */ - @Nullable - Object getAttribute(String attributeName); + @Nullable Object getAttribute(String attributeName); /** * Return the current set of model attributes as a Map. 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 48c887666f..dac97a4ccd 100644 --- a/spring-context/src/main/java/org/springframework/ui/ModelMap.java +++ b/spring-context/src/main/java/org/springframework/ui/ModelMap.java @@ -20,8 +20,9 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.Conventions; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -150,8 +151,7 @@ public class ModelMap extends LinkedHashMap { * @return the corresponding attribute value, or {@code null} if none * @since 5.2 */ - @Nullable - public Object getAttribute(String attributeName) { + public @Nullable Object getAttribute(String attributeName) { return get(attributeName); } 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 ab52272b0d..0fefadc27e 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,7 +16,7 @@ package org.springframework.ui.context; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Sub-interface of ThemeSource to be implemented by objects that @@ -41,7 +41,6 @@ public interface HierarchicalThemeSource extends ThemeSource { /** * Return the parent of this ThemeSource, or {@code null} if none. */ - @Nullable - ThemeSource getParentThemeSource(); + @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 15bf064d46..e5c9485fbe 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,7 +16,7 @@ package org.springframework.ui.context; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that can resolve {@link Theme Themes}. @@ -42,7 +42,6 @@ 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); + @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 cedb3f0bba..d8cc933f1c 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,9 +2,7 @@ * Contains classes defining the application context subinterface * for UI applications. The theme feature is added here. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.ui.context; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/ui/context/support/DelegatingThemeSource.java b/spring-context/src/main/java/org/springframework/ui/context/support/DelegatingThemeSource.java index 9e79100a53..73bac948ad 100644 --- a/spring-context/src/main/java/org/springframework/ui/context/support/DelegatingThemeSource.java +++ b/spring-context/src/main/java/org/springframework/ui/context/support/DelegatingThemeSource.java @@ -16,7 +16,8 @@ package org.springframework.ui.context.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.context.HierarchicalThemeSource; import org.springframework.ui.context.Theme; import org.springframework.ui.context.ThemeSource; @@ -36,8 +37,7 @@ import org.springframework.ui.context.ThemeSource; @Deprecated(since = "6.0") public class DelegatingThemeSource implements HierarchicalThemeSource { - @Nullable - private ThemeSource parentThemeSource; + private @Nullable ThemeSource parentThemeSource; @Override @@ -46,15 +46,13 @@ public class DelegatingThemeSource implements HierarchicalThemeSource { } @Override - @Nullable - public ThemeSource getParentThemeSource() { + public @Nullable ThemeSource getParentThemeSource() { return this.parentThemeSource; } @Override - @Nullable - public Theme getTheme(String themeName) { + public @Nullable Theme getTheme(String themeName) { if (this.parentThemeSource != null) { return this.parentThemeSource.getTheme(themeName); } diff --git a/spring-context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java b/spring-context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java index f93bdf7e4d..338ac0b9a9 100644 --- a/spring-context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java +++ b/spring-context/src/main/java/org/springframework/ui/context/support/ResourceBundleThemeSource.java @@ -21,12 +21,12 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.context.HierarchicalMessageSource; import org.springframework.context.MessageSource; import org.springframework.context.support.ResourceBundleMessageSource; -import org.springframework.lang.Nullable; import org.springframework.ui.context.HierarchicalThemeSource; import org.springframework.ui.context.Theme; import org.springframework.ui.context.ThemeSource; @@ -49,19 +49,15 @@ public class ResourceBundleThemeSource implements HierarchicalThemeSource, BeanC protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ThemeSource parentThemeSource; + private @Nullable ThemeSource parentThemeSource; private String basenamePrefix = ""; - @Nullable - private String defaultEncoding; + private @Nullable String defaultEncoding; - @Nullable - private Boolean fallbackToSystemLocale; + private @Nullable Boolean fallbackToSystemLocale; - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; /** Map from theme name to Theme instance. */ private final Map themeCache = new ConcurrentHashMap<>(); @@ -81,8 +77,7 @@ public class ResourceBundleThemeSource implements HierarchicalThemeSource, BeanC } @Override - @Nullable - public ThemeSource getParentThemeSource() { + public @Nullable ThemeSource getParentThemeSource() { return this.parentThemeSource; } @@ -138,8 +133,7 @@ public class ResourceBundleThemeSource implements HierarchicalThemeSource, BeanC * @see #createMessageSource */ @Override - @Nullable - public Theme getTheme(String themeName) { + public @Nullable Theme getTheme(String themeName) { Theme theme = this.themeCache.get(themeName); if (theme == null) { synchronized (this.themeCache) { 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 9a6e087623..e854b4e068 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,9 +2,7 @@ * Classes supporting the org.springframework.ui.context package. * Provides support classes for specialized UI contexts, for example, for web UIs. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.ui.context.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 96269d532a..18e621b220 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,9 +2,7 @@ * Generic support for UI layer concepts. *

Provides generic {@code Model} and {@code ModelMap} holders for model attributes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.ui; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java b/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java index 64b9c9b5fb..fc2d2b8fce 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractBindingResult.java @@ -27,8 +27,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyEditorRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -97,13 +98,13 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi } @Override - public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + public void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage) { addError(new ObjectError(getObjectName(), resolveMessageCodes(errorCode), errorArgs, defaultMessage)); } @Override public void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { if (!StringUtils.hasLength(getNestedPath()) && !StringUtils.hasLength(field)) { // We're at the top of the nested object hierarchy, @@ -155,8 +156,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { for (ObjectError objectError : this.errors) { if (!(objectError instanceof FieldError)) { return objectError; @@ -177,8 +177,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { for (ObjectError objectError : this.errors) { if (objectError instanceof FieldError fieldError) { return fieldError; @@ -200,8 +199,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi } @Override - @Nullable - public FieldError getFieldError(String field) { + public @Nullable FieldError getFieldError(String field) { String fixedField = fixedField(field); for (ObjectError objectError : this.errors) { if (objectError instanceof FieldError fieldError && isMatchingFieldError(fixedField, fieldError)) { @@ -212,8 +210,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi } @Override - @Nullable - public Object getFieldValue(String field) { + public @Nullable Object getFieldValue(String field) { FieldError fieldError = getFieldError(field); // Use rejected value in case of error, current field value otherwise. if (fieldError != null) { @@ -237,8 +234,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi * @see #getActualFieldValue */ @Override - @Nullable - public Class getFieldType(@Nullable String field) { + public @Nullable Class getFieldType(@Nullable String field) { if (getTarget() != null) { Object value = getActualFieldValue(fixedField(field)); if (value != null) { @@ -276,8 +272,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi } @Override - @Nullable - public Object getRawFieldValue(String field) { + public @Nullable Object getRawFieldValue(String field) { return (getTarget() != null ? getActualFieldValue(fixedField(field)) : null); } @@ -287,8 +282,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi * editor lookup facility, if available. */ @Override - @Nullable - public PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { + public @Nullable PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { PropertyEditorRegistry editorRegistry = getPropertyEditorRegistry(); if (editorRegistry != null) { Class valueTypeToUse = valueType; @@ -306,8 +300,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi * This implementation returns {@code null}. */ @Override - @Nullable - public PropertyEditorRegistry getPropertyEditorRegistry() { + public @Nullable PropertyEditorRegistry getPropertyEditorRegistry() { return null; } @@ -378,16 +371,14 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi * Return the wrapped target object. */ @Override - @Nullable - public abstract Object getTarget(); + public abstract @Nullable Object getTarget(); /** * Extract the actual field value for the given field. * @param field the field to check * @return the current value of the field */ - @Nullable - protected abstract Object getActualFieldValue(String field); + protected abstract @Nullable Object getActualFieldValue(String field); /** * Format the given value for the specified field. @@ -397,8 +388,7 @@ public abstract class AbstractBindingResult extends AbstractErrors implements Bi * other than from a binding error, or an actual field value) * @return the formatted value */ - @Nullable - protected Object formatFieldValue(String field, @Nullable Object value) { + protected @Nullable Object formatFieldValue(String field, @Nullable Object value) { return value; } diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java index 460d860f85..584d9f5162 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java @@ -24,7 +24,8 @@ import java.util.Deque; import java.util.List; import java.util.NoSuchElementException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** 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 61675d953e..d2dc5d8417 100644 --- a/spring-context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/AbstractPropertyBindingResult.java @@ -18,6 +18,8 @@ package org.springframework.validation; import java.beans.PropertyEditor; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.ConfigurablePropertyAccessor; import org.springframework.beans.PropertyAccessorUtils; @@ -25,7 +27,6 @@ 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; /** @@ -43,8 +44,7 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public abstract class AbstractPropertyBindingResult extends AbstractBindingResult { - @Nullable - private transient ConversionService conversionService; + private transient @Nullable ConversionService conversionService; /** @@ -70,8 +70,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul * @see #getPropertyAccessor() */ @Override - @Nullable - public PropertyEditorRegistry getPropertyEditorRegistry() { + public @Nullable PropertyEditorRegistry getPropertyEditorRegistry() { return (getTarget() != null ? getPropertyAccessor() : null); } @@ -89,8 +88,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul * @see #getPropertyAccessor() */ @Override - @Nullable - public Class getFieldType(@Nullable String field) { + public @Nullable Class getFieldType(@Nullable String field) { return (getTarget() != null ? getPropertyAccessor().getPropertyType(fixedField(field)) : super.getFieldType(field)); } @@ -100,8 +98,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul * @see #getPropertyAccessor() */ @Override - @Nullable - protected Object getActualFieldValue(String field) { + protected @Nullable Object getActualFieldValue(String field) { return getPropertyAccessor().getPropertyValue(field); } @@ -110,8 +107,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul * @see #getCustomEditor */ @Override - @Nullable - protected Object formatFieldValue(String field, @Nullable Object value) { + protected @Nullable Object formatFieldValue(String field, @Nullable Object value) { String fixedField = fixedField(field); // Try custom editor... PropertyEditor customEditor = getCustomEditor(fixedField); @@ -140,8 +136,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) { + protected @Nullable PropertyEditor getCustomEditor(String fixedField) { Class targetType = getPropertyAccessor().getPropertyType(fixedField); PropertyEditor editor = getPropertyAccessor().findCustomEditor(targetType, fixedField); if (editor == null) { @@ -155,8 +150,7 @@ public abstract class AbstractPropertyBindingResult extends AbstractBindingResul * if applicable. */ @Override - @Nullable - public PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { + public @Nullable PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { Class valueTypeForLookup = valueType; if (valueTypeForLookup == null) { valueTypeForLookup = getFieldType(field); diff --git a/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java b/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java index 1cc6bb8e36..54b6143b6c 100644 --- a/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/BeanPropertyBindingResult.java @@ -18,10 +18,11 @@ package org.springframework.validation; import java.io.Serializable; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanWrapper; import org.springframework.beans.ConfigurablePropertyAccessor; import org.springframework.beans.PropertyAccessorFactory; -import org.springframework.lang.Nullable; /** * Default implementation of the {@link Errors} and {@link BindingResult} @@ -43,15 +44,13 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class BeanPropertyBindingResult extends AbstractPropertyBindingResult implements Serializable { - @Nullable - private final Object target; + private final @Nullable Object target; private final boolean autoGrowNestedPaths; private final int autoGrowCollectionLimit; - @Nullable - private transient BeanWrapper beanWrapper; + private transient @Nullable BeanWrapper beanWrapper; /** @@ -81,8 +80,7 @@ public class BeanPropertyBindingResult extends AbstractPropertyBindingResult imp @Override - @Nullable - public final Object getTarget() { + public final @Nullable Object getTarget() { return this.target; } diff --git a/spring-context/src/main/java/org/springframework/validation/BindException.java b/spring-context/src/main/java/org/springframework/validation/BindException.java index b84c81081a..0e2ea2630c 100644 --- a/spring-context/src/main/java/org/springframework/validation/BindException.java +++ b/spring-context/src/main/java/org/springframework/validation/BindException.java @@ -20,8 +20,9 @@ import java.beans.PropertyEditor; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyEditorRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -113,7 +114,7 @@ public class BindException extends Exception implements BindingResult { } @Override - public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + public void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.bindingResult.reject(errorCode, errorArgs, defaultMessage); } @@ -129,7 +130,7 @@ public class BindException extends Exception implements BindingResult { @Override public void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.bindingResult.rejectValue(field, errorCode, errorArgs, defaultMessage); } @@ -171,8 +172,7 @@ public class BindException extends Exception implements BindingResult { } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return this.bindingResult.getGlobalError(); } @@ -192,8 +192,7 @@ public class BindException extends Exception implements BindingResult { } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.bindingResult.getFieldError(); } @@ -213,26 +212,22 @@ public class BindException extends Exception implements BindingResult { } @Override - @Nullable - public FieldError getFieldError(String field) { + public @Nullable FieldError getFieldError(String field) { return this.bindingResult.getFieldError(field); } @Override - @Nullable - public Object getFieldValue(String field) { + public @Nullable Object getFieldValue(String field) { return this.bindingResult.getFieldValue(field); } @Override - @Nullable - public Class getFieldType(String field) { + public @Nullable Class getFieldType(String field) { return this.bindingResult.getFieldType(field); } @Override - @Nullable - public Object getTarget() { + public @Nullable Object getTarget() { return this.bindingResult.getTarget(); } @@ -242,21 +237,18 @@ public class BindException extends Exception implements BindingResult { } @Override - @Nullable - public Object getRawFieldValue(String field) { + public @Nullable Object getRawFieldValue(String field) { return this.bindingResult.getRawFieldValue(field); } @Override @SuppressWarnings("rawtypes") - @Nullable - public PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { + public @Nullable PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { return this.bindingResult.findEditor(field, valueType); } @Override - @Nullable - public PropertyEditorRegistry getPropertyEditorRegistry() { + public @Nullable PropertyEditorRegistry getPropertyEditorRegistry() { return this.bindingResult.getPropertyEditorRegistry(); } 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 ed3e3a1d70..e0625d6316 100644 --- a/spring-context/src/main/java/org/springframework/validation/BindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/BindingResult.java @@ -19,8 +19,9 @@ package org.springframework.validation; import java.beans.PropertyEditor; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyEditorRegistry; -import org.springframework.lang.Nullable; /** * General interface that represents binding results. Extends the @@ -55,8 +56,7 @@ public interface BindingResult extends Errors { * Return the wrapped target object, which may be a bean, an object with * public fields, a Map - depending on the concrete binding strategy. */ - @Nullable - Object getTarget(); + @Nullable Object getTarget(); /** * Return a model Map for the obtained state, exposing a BindingResult @@ -84,8 +84,7 @@ public interface BindingResult extends Errors { * @param field the field to check * @return the current value of the field in its raw form, or {@code null} if not known */ - @Nullable - Object getRawFieldValue(String field); + @Nullable Object getRawFieldValue(String field); /** * Find a custom property editor for the given type and property. @@ -95,16 +94,14 @@ 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 */ - @Nullable - PropertyEditor findEditor(@Nullable String field, @Nullable 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(); + @Nullable PropertyEditorRegistry getPropertyEditorRegistry(); /** * Resolve the given error code into message codes. 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 04694d823f..b1d3c12be4 100644 --- a/spring-context/src/main/java/org/springframework/validation/BindingResultUtils.java +++ b/spring-context/src/main/java/org/springframework/validation/BindingResultUtils.java @@ -18,7 +18,8 @@ package org.springframework.validation; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -37,8 +38,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) { + public static @Nullable BindingResult getBindingResult(Map model, String name) { Assert.notNull(model, "Model map must not be null"); Assert.notNull(name, "Name must not be null"); Object attr = model.get(BindingResult.MODEL_KEY_PREFIX + name); 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 41b8ec3a58..7991072db0 100644 --- a/spring-context/src/main/java/org/springframework/validation/DataBinder.java +++ b/spring-context/src/main/java/org/springframework/validation/DataBinder.java @@ -37,6 +37,7 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; @@ -60,7 +61,6 @@ import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; 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; @@ -142,21 +142,17 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { */ protected static final Log logger = LogFactory.getLog(DataBinder.class); - @Nullable - private Object target; + private @Nullable Object target; - @Nullable - ResolvableType targetType; + @Nullable ResolvableType targetType; private final String objectName; - @Nullable - private AbstractPropertyBindingResult bindingResult; + private @Nullable AbstractPropertyBindingResult bindingResult; private boolean directFieldAccess = false; - @Nullable - private ExtendedTypeConverter typeConverter; + private @Nullable ExtendedTypeConverter typeConverter; private boolean declarativeBinding = false; @@ -168,30 +164,23 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT; - @Nullable - private String[] allowedFields; + private String @Nullable [] allowedFields; - @Nullable - private String[] disallowedFields; + private String @Nullable [] disallowedFields; - @Nullable - private String[] requiredFields; + private String @Nullable [] requiredFields; - @Nullable - private NameResolver nameResolver; + private @Nullable NameResolver nameResolver; - @Nullable - private ConversionService conversionService; + private @Nullable ConversionService conversionService; - @Nullable - private MessageCodesResolver messageCodesResolver; + private @Nullable MessageCodesResolver messageCodesResolver; private BindingErrorProcessor bindingErrorProcessor = new DefaultBindingErrorProcessor(); private final List validators = new ArrayList<>(); - @Nullable - private Predicate excludedValidators; + private @Nullable Predicate excludedValidators; /** @@ -221,8 +210,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { *

If the target object is {@code null} and {@link #getTargetType()} is set, * then {@link #construct(ValueResolver)} may be called to create the target. */ - @Nullable - public Object getTarget() { + public @Nullable Object getTarget() { return this.target; } @@ -249,8 +237,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * Return the {@link #setTargetType configured} type for the target object. * @since 6.1 */ - @Nullable - public ResolvableType getTargetType() { + public @Nullable ResolvableType getTargetType() { return this.targetType; } @@ -526,7 +513,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @see #setDisallowedFields * @see #isAllowed(String) */ - public void setAllowedFields(@Nullable String... allowedFields) { + public void setAllowedFields(String @Nullable ... allowedFields) { this.allowedFields = PropertyAccessorUtils.canonicalPropertyNames(allowedFields); } @@ -535,8 +522,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @return array of allowed field patterns * @see #setAllowedFields(String...) */ - @Nullable - public String[] getAllowedFields() { + public String @Nullable [] getAllowedFields() { return this.allowedFields; } @@ -564,7 +550,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @see #setAllowedFields * @see #isAllowed(String) */ - public void setDisallowedFields(@Nullable String... disallowedFields) { + public void setDisallowedFields(String @Nullable ... disallowedFields) { if (disallowedFields == null) { this.disallowedFields = null; } @@ -583,8 +569,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @return array of disallowed field patterns * @see #setDisallowedFields(String...) */ - @Nullable - public String[] getDisallowedFields() { + public String @Nullable [] getDisallowedFields() { return this.disallowedFields; } @@ -601,7 +586,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @see #setBindingErrorProcessor * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE */ - public void setRequiredFields(@Nullable String... requiredFields) { + public void setRequiredFields(String @Nullable ... requiredFields) { this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields); if (logger.isDebugEnabled()) { logger.debug("DataBinder requires binding of required fields [" + @@ -613,8 +598,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * Return the fields that are required for each binding process. * @return array of field names */ - @Nullable - public String[] getRequiredFields() { + public String @Nullable [] getRequiredFields() { return this.requiredFields; } @@ -635,8 +619,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * constructor parameters. * @since 6.1 */ - @Nullable - public NameResolver getNameResolver() { + public @Nullable NameResolver getNameResolver() { return this.nameResolver; } @@ -728,8 +711,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { /** * Return the primary Validator to apply after each binding step, if any. */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return (!this.validators.isEmpty() ? this.validators.get(0) : null); } @@ -773,8 +755,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { /** * Return the associated ConversionService, if any. */ - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -847,36 +828,31 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { } @Override - @Nullable - public PropertyEditor findCustomEditor(@Nullable Class requiredType, @Nullable String propertyPath) { + public @Nullable PropertyEditor findCustomEditor(@Nullable Class requiredType, @Nullable String propertyPath) { return getPropertyEditorRegistry().findCustomEditor(requiredType, propertyPath); } @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException { + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType) throws TypeMismatchException { return getTypeConverter().convertIfNecessary(value, requiredType); } @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable MethodParameter methodParam) throws TypeMismatchException { return getTypeConverter().convertIfNecessary(value, requiredType, methodParam); } @Override - @Nullable - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field) + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable Field field) throws TypeMismatchException { return getTypeConverter().convertIfNecessary(value, requiredType, field); } - @Nullable @Override - public T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, + public @Nullable T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType, @Nullable TypeDescriptor typeDescriptor) throws TypeMismatchException { return getTypeConverter().convertIfNecessary(value, requiredType, typeDescriptor); @@ -916,8 +892,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { } } - @Nullable - private Object createObject(ResolvableType objectType, String nestedPath, ValueResolver valueResolver) { + private @Nullable Object createObject(ResolvableType objectType, String nestedPath, ValueResolver valueResolver) { Class clazz = objectType.resolve(); boolean isOptional = (clazz == Optional.class); clazz = (isOptional ? objectType.resolveGeneric(0) : clazz); @@ -1049,8 +1024,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { } @SuppressWarnings("unchecked") - @Nullable - private List createList( + private @Nullable List createList( String paramPath, Class paramType, ResolvableType type, ValueResolver valueResolver) { ResolvableType elementType = type.getNested(2); @@ -1068,8 +1042,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { } @SuppressWarnings("unchecked") - @Nullable - private Map createMap( + private @Nullable Map createMap( String paramPath, Class paramType, ResolvableType type, ValueResolver valueResolver) { ResolvableType elementType = type.getNested(2); @@ -1094,8 +1067,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { } @SuppressWarnings("unchecked") - @Nullable - private V[] createArray(String paramPath, ResolvableType type, ValueResolver valueResolver) { + private V @Nullable [] createArray(String paramPath, ResolvableType type, ValueResolver valueResolver) { ResolvableType elementType = type.getNested(2); SortedSet indexes = getIndexes(paramPath, valueResolver); if (indexes == null) { @@ -1109,8 +1081,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { return array; } - @Nullable - private static SortedSet getIndexes(String paramPath, ValueResolver valueResolver) { + private static @Nullable SortedSet getIndexes(String paramPath, ValueResolver valueResolver) { SortedSet indexes = null; for (String name : valueResolver.getNames()) { if (name.startsWith(paramPath + "[")) { @@ -1387,8 +1358,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * if unresolved. For constructor parameters, the name is determined via * {@link org.springframework.core.DefaultParameterNameDiscoverer} if unresolved. */ - @Nullable - String resolveName(MethodParameter parameter); + @Nullable String resolveName(MethodParameter parameter); } @@ -1405,8 +1375,7 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter { * @param type the target type, based on the constructor parameter type * @return the resolved value, possibly {@code null} if none found */ - @Nullable - Object resolveValue(String name, Class type); + @Nullable Object resolveValue(String name, Class type); /** * Return the names of all property values. diff --git a/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java b/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java index a18554a554..63421ec83c 100644 --- a/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java +++ b/spring-context/src/main/java/org/springframework/validation/DefaultMessageCodesResolver.java @@ -24,7 +24,8 @@ import java.util.List; import java.util.Set; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** diff --git a/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java b/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java index f01232ca1f..00c6c0c1ed 100644 --- a/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/DirectFieldBindingResult.java @@ -16,9 +16,10 @@ package org.springframework.validation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.ConfigurablePropertyAccessor; import org.springframework.beans.PropertyAccessorFactory; -import org.springframework.lang.Nullable; /** * Special implementation of the Errors and BindingResult interfaces, @@ -36,13 +37,11 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class DirectFieldBindingResult extends AbstractPropertyBindingResult { - @Nullable - private final Object target; + private final @Nullable Object target; private final boolean autoGrowNestedPaths; - @Nullable - private transient ConfigurablePropertyAccessor directFieldAccessor; + private transient @Nullable ConfigurablePropertyAccessor directFieldAccessor; /** @@ -68,8 +67,7 @@ public class DirectFieldBindingResult extends AbstractPropertyBindingResult { @Override - @Nullable - public final Object getTarget() { + public final @Nullable Object getTarget() { return this.target; } 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 a7292a5af9..cb8ff224cf 100644 --- a/spring-context/src/main/java/org/springframework/validation/Errors.java +++ b/spring-context/src/main/java/org/springframework/validation/Errors.java @@ -21,8 +21,9 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyAccessor; -import org.springframework.lang.Nullable; /** * Stores and exposes information about data-binding and validation errors @@ -144,7 +145,7 @@ public interface Errors { * @param defaultMessage fallback default message * @see #rejectValue(String, String, Object[], String) */ - void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage); + void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage); /** * Register a field error for the specified field of the current object @@ -195,7 +196,7 @@ public interface Errors { * @see #reject(String, Object[], String) */ void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage); + Object @Nullable [] errorArgs, @Nullable String defaultMessage); /** * Add all errors from the given {@code Errors} instance to this @@ -285,8 +286,7 @@ public interface Errors { * @return the global error, or {@code null} * @see #getFieldError() */ - @Nullable - default ObjectError getGlobalError() { + default @Nullable ObjectError getGlobalError() { return getGlobalErrors().stream().findFirst().orElse(null); } @@ -318,8 +318,7 @@ public interface Errors { * @return the field-specific error, or {@code null} * @see #getGlobalError() */ - @Nullable - default FieldError getFieldError() { + default @Nullable FieldError getFieldError() { return getFieldErrors().stream().findFirst().orElse(null); } @@ -359,8 +358,7 @@ public interface Errors { * @return the field-specific error, or {@code null} * @see #getFieldError() */ - @Nullable - default FieldError getFieldError(String field) { + default @Nullable FieldError getFieldError(String field) { return getFieldErrors().stream().filter(error -> field.equals(error.getField())).findFirst().orElse(null); } @@ -373,8 +371,7 @@ public interface Errors { * @return the current value of the given field * @see #getFieldType(String) */ - @Nullable - Object getFieldValue(String field); + @Nullable Object getFieldValue(String field); /** * Determine the type of the given field, as far as possible. @@ -385,8 +382,7 @@ public interface Errors { * @return the type of the field, or {@code null} if not determinable * @see #getFieldValue(String) */ - @Nullable - default Class getFieldType(String field) { + default @Nullable Class getFieldType(String field) { return Optional.ofNullable(getFieldValue(field)).map(Object::getClass).orElse(null); } diff --git a/spring-context/src/main/java/org/springframework/validation/FieldError.java b/spring-context/src/main/java/org/springframework/validation/FieldError.java index bb57d556ff..cc21efb743 100644 --- a/spring-context/src/main/java/org/springframework/validation/FieldError.java +++ b/spring-context/src/main/java/org/springframework/validation/FieldError.java @@ -16,7 +16,8 @@ package org.springframework.validation; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -37,8 +38,7 @@ public class FieldError extends ObjectError { private final String field; - @Nullable - private final Object rejectedValue; + private final @Nullable Object rejectedValue; private final boolean bindingFailure; @@ -65,7 +65,7 @@ public class FieldError extends ObjectError { * @param defaultMessage the default message to be used to resolve this message */ public FieldError(String objectName, String field, @Nullable Object rejectedValue, boolean bindingFailure, - @Nullable String[] codes, @Nullable Object[] arguments, @Nullable String defaultMessage) { + String @Nullable [] codes, Object @Nullable [] arguments, @Nullable String defaultMessage) { super(objectName, codes, arguments, defaultMessage); Assert.notNull(field, "Field must not be null"); @@ -85,8 +85,7 @@ public class FieldError extends ObjectError { /** * Return the rejected field value. */ - @Nullable - public Object getRejectedValue() { + public @Nullable Object getRejectedValue() { return this.rejectedValue; } diff --git a/spring-context/src/main/java/org/springframework/validation/MapBindingResult.java b/spring-context/src/main/java/org/springframework/validation/MapBindingResult.java index 41860a4c1d..f15a1ae7b5 100644 --- a/spring-context/src/main/java/org/springframework/validation/MapBindingResult.java +++ b/spring-context/src/main/java/org/springframework/validation/MapBindingResult.java @@ -19,8 +19,9 @@ package org.springframework.validation; import java.io.Serializable; import java.util.Map; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -61,14 +62,12 @@ public class MapBindingResult extends AbstractBindingResult implements Serializa } @Override - @NonNull - public final Object getTarget() { + public final @NonNull Object getTarget() { return this.target; } @Override - @Nullable - protected Object getActualFieldValue(String field) { + protected @Nullable Object getActualFieldValue(String field) { return this.target.get(field); } diff --git a/spring-context/src/main/java/org/springframework/validation/MessageCodeFormatter.java b/spring-context/src/main/java/org/springframework/validation/MessageCodeFormatter.java index 48d918e9da..ca45259d46 100644 --- a/spring-context/src/main/java/org/springframework/validation/MessageCodeFormatter.java +++ b/spring-context/src/main/java/org/springframework/validation/MessageCodeFormatter.java @@ -16,7 +16,7 @@ package org.springframework.validation; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A strategy interface for formatting message codes. 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 2a985e6439..8518a20b5f 100644 --- a/spring-context/src/main/java/org/springframework/validation/MessageCodesResolver.java +++ b/spring-context/src/main/java/org/springframework/validation/MessageCodesResolver.java @@ -16,7 +16,7 @@ package org.springframework.validation; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for building message codes from validation error codes. diff --git a/spring-context/src/main/java/org/springframework/validation/ObjectError.java b/spring-context/src/main/java/org/springframework/validation/ObjectError.java index b8187d3473..05eca672eb 100644 --- a/spring-context/src/main/java/org/springframework/validation/ObjectError.java +++ b/spring-context/src/main/java/org/springframework/validation/ObjectError.java @@ -16,8 +16,9 @@ package org.springframework.validation; +import org.jspecify.annotations.Nullable; + import org.springframework.context.support.DefaultMessageSourceResolvable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +38,7 @@ public class ObjectError extends DefaultMessageSourceResolvable { private final String objectName; - @Nullable - private transient Object source; + private transient @Nullable Object source; /** @@ -58,7 +58,7 @@ public class ObjectError extends DefaultMessageSourceResolvable { * @param defaultMessage the default message to be used to resolve this message */ public ObjectError( - String objectName, @Nullable String[] codes, @Nullable Object[] arguments, @Nullable String defaultMessage) { + String objectName, String @Nullable [] codes, Object @Nullable [] arguments, @Nullable String defaultMessage) { super(codes, arguments, defaultMessage); Assert.notNull(objectName, "Object name must not be null"); diff --git a/spring-context/src/main/java/org/springframework/validation/SimpleErrors.java b/spring-context/src/main/java/org/springframework/validation/SimpleErrors.java index 6854f26235..edb2c3d860 100644 --- a/spring-context/src/main/java/org/springframework/validation/SimpleErrors.java +++ b/spring-context/src/main/java/org/springframework/validation/SimpleErrors.java @@ -22,8 +22,9 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -88,13 +89,13 @@ public class SimpleErrors implements Errors, Serializable { } @Override - public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + public void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.globalErrors.add(new ObjectError(getObjectName(), new String[] {errorCode}, errorArgs, defaultMessage)); } @Override public void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { if (!StringUtils.hasLength(field)) { reject(errorCode, errorArgs, defaultMessage); @@ -123,8 +124,7 @@ public class SimpleErrors implements Errors, Serializable { } @Override - @Nullable - public Object getFieldValue(String field) { + public @Nullable Object getFieldValue(String field) { FieldError fieldError = getFieldError(field); if (fieldError != null) { return fieldError.getRejectedValue(); @@ -147,8 +147,7 @@ public class SimpleErrors implements Errors, Serializable { } @Override - @Nullable - public Class getFieldType(String field) { + public @Nullable Class getFieldType(String field) { PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(this.target.getClass(), field); if (pd != null) { return pd.getPropertyType(); 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 c033a9266d..c64a62ad38 100644 --- a/spring-context/src/main/java/org/springframework/validation/SmartValidator.java +++ b/spring-context/src/main/java/org/springframework/validation/SmartValidator.java @@ -16,7 +16,7 @@ package org.springframework.validation; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Extended variant of the {@link Validator} interface, adding support for @@ -74,8 +74,7 @@ public interface SmartValidator extends Validator { * validator type does not match. * @since 6.1 */ - @Nullable - default T unwrap(@Nullable Class type) { + default @Nullable T unwrap(@Nullable Class type) { return null; } 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 042668317d..263558009c 100644 --- a/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java +++ b/spring-context/src/main/java/org/springframework/validation/ValidationUtils.java @@ -18,8 +18,8 @@ package org.springframework.validation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -68,7 +68,7 @@ public abstract class ValidationUtils { * {@link Validator#supports(Class) support} the validation of the supplied object's type */ public static void invokeValidator( - Validator validator, Object target, Errors errors, @Nullable Object... validationHints) { + Validator validator, Object target, Errors errors, Object @Nullable ... validationHints) { Assert.notNull(validator, "Validator must not be null"); Assert.notNull(target, "Target object must not be null"); @@ -166,7 +166,7 @@ public abstract class ValidationUtils { * @param defaultMessage fallback default message */ public static void rejectIfEmpty(Errors errors, String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { Assert.notNull(errors, "Errors object must not be null"); Object value = errors.getFieldValue(field); @@ -225,7 +225,7 @@ public abstract class ValidationUtils { * (can be {@code null}) */ public static void rejectIfEmptyOrWhitespace( - Errors errors, String field, String errorCode, @Nullable Object[] errorArgs) { + Errors errors, String field, String errorCode, Object @Nullable [] errorArgs) { rejectIfEmptyOrWhitespace(errors, field, errorCode, errorArgs, null); } @@ -246,7 +246,7 @@ public abstract class ValidationUtils { * @param defaultMessage fallback default message */ public static void rejectIfEmptyOrWhitespace( - Errors errors, String field, String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Errors errors, String field, String errorCode, Object @Nullable [] errorArgs, @Nullable 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/annotation/ValidationAnnotationUtils.java b/spring-context/src/main/java/org/springframework/validation/annotation/ValidationAnnotationUtils.java index 9a612eeda4..e297187587 100644 --- a/spring-context/src/main/java/org/springframework/validation/annotation/ValidationAnnotationUtils.java +++ b/spring-context/src/main/java/org/springframework/validation/annotation/ValidationAnnotationUtils.java @@ -18,8 +18,9 @@ package org.springframework.validation.annotation; import java.lang.annotation.Annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; /** * Utility class for handling validation annotations. @@ -45,8 +46,7 @@ public abstract class ValidationAnnotationUtils { * @return the validation hints to apply (possibly an empty array), * or {@code null} if this annotation does not trigger any validation */ - @Nullable - public static Object[] determineValidationHints(Annotation ann) { + public static Object @Nullable [] determineValidationHints(Annotation ann) { // Direct presence of @Validated ? if (ann instanceof Validated validated) { return validated.value(); 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 177ad9c8d9..afce17fc8a 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,9 +5,7 @@ *

Provides an extended variant of JSR-303's {@code @Valid}, * supporting the specification of validation groups. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.validation.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessor.java index 50d66dcf49..c81ec72182 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessor.java @@ -36,6 +36,7 @@ import jakarta.validation.metadata.ParameterDescriptor; import jakarta.validation.metadata.PropertyDescriptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.MemberCategory; @@ -46,7 +47,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.KotlinDetector; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -68,8 +68,7 @@ class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotP @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { if (beanValidationPresent) { return BeanValidationDelegate.processAheadOfTime(registeredBean); } @@ -82,11 +81,9 @@ class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotP */ private static class BeanValidationDelegate { - @Nullable - private static final Validator validator = getValidatorIfAvailable(); + private static final @Nullable Validator validator = getValidatorIfAvailable(); - @Nullable - private static Validator getValidatorIfAvailable() { + private static @Nullable Validator getValidatorIfAvailable() { try (ValidatorFactory validator = Validation.buildDefaultValidatorFactory()) { return validator.getValidator(); } @@ -96,8 +93,7 @@ class BeanValidationBeanRegistrationAotProcessor implements BeanRegistrationAotP } } - @Nullable - public static BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public static @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { if (validator == null) { return null; } diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessor.java index 77c7966a0e..d912eef2b5 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/BeanValidationPostProcessor.java @@ -23,13 +23,13 @@ import jakarta.validation.ConstraintViolation; import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopProxyUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,8 +42,7 @@ import org.springframework.util.Assert; */ public class BeanValidationPostProcessor implements BeanPostProcessor, InitializingBean { - @Nullable - private Validator validator; + private @Nullable Validator validator; private boolean afterInitialization = false; diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/CustomValidatorBean.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/CustomValidatorBean.java index 37800c7df5..50f14273cd 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/CustomValidatorBean.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/CustomValidatorBean.java @@ -22,9 +22,9 @@ import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorContext; import jakarta.validation.ValidatorFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * Configurable bean class that exposes a specific JSR-303 Validator @@ -36,14 +36,11 @@ import org.springframework.lang.Nullable; */ public class CustomValidatorBean extends SpringValidatorAdapter implements Validator, InitializingBean { - @Nullable - private ValidatorFactory validatorFactory; + private @Nullable ValidatorFactory validatorFactory; - @Nullable - private MessageInterpolator messageInterpolator; + private @Nullable MessageInterpolator messageInterpolator; - @Nullable - private TraversableResolver traversableResolver; + private @Nullable TraversableResolver traversableResolver; /** diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java index 6a0f939c4f..00e7af3ee2 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.java @@ -43,6 +43,7 @@ import jakarta.validation.ValidatorFactory; import jakarta.validation.bootstrap.GenericBootstrap; import jakarta.validation.bootstrap.ProviderSpecificBootstrap; import org.hibernate.validator.messageinterpolation.ResourceBundleMessageInterpolator; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; @@ -51,7 +52,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.MessageSource; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; @@ -84,37 +84,27 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter implements ValidatorFactory, ApplicationContextAware, InitializingBean, DisposableBean { @SuppressWarnings("rawtypes") - @Nullable - private Class providerClass; + private @Nullable Class providerClass; - @Nullable - private ValidationProviderResolver validationProviderResolver; + private @Nullable ValidationProviderResolver validationProviderResolver; - @Nullable - private MessageInterpolator messageInterpolator; + private @Nullable MessageInterpolator messageInterpolator; - @Nullable - private TraversableResolver traversableResolver; + private @Nullable TraversableResolver traversableResolver; - @Nullable - private ConstraintValidatorFactory constraintValidatorFactory; + private @Nullable ConstraintValidatorFactory constraintValidatorFactory; - @Nullable - private ParameterNameDiscoverer parameterNameDiscoverer; + private @Nullable ParameterNameDiscoverer parameterNameDiscoverer; - @Nullable - private Resource[] mappingLocations; + private Resource @Nullable [] mappingLocations; private final Map validationPropertyMap = new HashMap<>(); - @Nullable - private Consumer> configurationInitializer; + private @Nullable Consumer> configurationInitializer; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private ValidatorFactory validatorFactory; + private @Nullable ValidatorFactory validatorFactory; /** @@ -252,7 +242,7 @@ public class LocalValidatorFactoryBean extends SpringValidatorAdapter @Override - @SuppressWarnings({"rawtypes", "unchecked"}) + @SuppressWarnings({"rawtypes", "unchecked", "NullAway"}) // TODO NullAway bug? public void afterPropertiesSet() { Configuration configuration; if (this.providerClass != null) { diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationAdapter.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationAdapter.java index f65fb56b7f..d9829014eb 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationAdapter.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationAdapter.java @@ -38,6 +38,7 @@ import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; import jakarta.validation.executable.ExecutableValidator; import jakarta.validation.metadata.ConstraintDescriptor; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopProxyUtils; import org.springframework.aop.support.AopUtils; @@ -50,7 +51,6 @@ import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.function.SingletonSupplier; import org.springframework.validation.BeanPropertyBindingResult; @@ -235,7 +235,7 @@ public class MethodValidationAdapter implements MethodValidator { @Override public final MethodValidationResult validateArguments( - Object target, Method method, @Nullable MethodParameter[] parameters, + Object target, Method method, MethodParameter @Nullable [] parameters, Object[] arguments, Class[] groups) { Set> violations = @@ -461,17 +461,13 @@ public class MethodValidationAdapter implements MethodValidator { private final MethodParameter parameter; - @Nullable - private final Object value; + private final @Nullable Object value; - @Nullable - private final Object container; + private final @Nullable Object container; - @Nullable - private final Integer containerIndex; + private final @Nullable Integer containerIndex; - @Nullable - private final Object containerKey; + private final @Nullable Object containerKey; private final List resolvableErrors = new ArrayList<>(); @@ -511,17 +507,13 @@ public class MethodValidationAdapter implements MethodValidator { private final MethodParameter parameter; - @Nullable - private final Object bean; + private final @Nullable Object bean; - @Nullable - private final Object container; + private final @Nullable Object container; - @Nullable - private final Integer containerIndex; + private final @Nullable Integer containerIndex; - @Nullable - private final Object containerKey; + private final @Nullable Object containerKey; private final Errors errors; diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java index ce39c9aa08..3d1f6aa110 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationInterceptor.java @@ -30,6 +30,7 @@ import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -40,7 +41,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.validation.BeanPropertyBindingResult; @@ -141,8 +141,7 @@ public class MethodValidationInterceptor implements MethodInterceptor { @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { // Avoid Validator invocation on FactoryBean.getObjectType/isSingleton if (isFactoryBeanMetadataMethod(invocation.getMethod())) { return invocation.proceed(); @@ -268,8 +267,7 @@ public class MethodValidationInterceptor implements MethodInterceptor { return arguments; } - @Nullable - private static Class[] determineValidationGroups(Parameter parameter) { + private static Class @Nullable [] determineValidationGroups(Parameter parameter) { Validated validated = AnnotationUtils.findAnnotation(parameter, Validated.class); if (validated != null) { return validated.value(); diff --git a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java index 8e518bbc14..6b97534466 100644 --- a/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java +++ b/spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java @@ -31,12 +31,12 @@ import jakarta.validation.ValidationException; import jakarta.validation.executable.ExecutableValidator; import jakarta.validation.metadata.BeanDescriptor; import jakarta.validation.metadata.ConstraintDescriptor; +import org.jspecify.annotations.Nullable; import org.springframework.beans.InvalidPropertyException; import org.springframework.beans.NotReadablePropertyException; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.support.DefaultMessageSourceResolvable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -69,8 +69,7 @@ public class SpringValidatorAdapter implements SmartValidator, jakarta.validatio private static final Set internalAnnotationAttributes = Set.of("message", "groups", "payload"); - @Nullable - private jakarta.validation.Validator targetValidator; + private jakarta.validation.@Nullable Validator targetValidator; /** @@ -305,8 +304,7 @@ public class SpringValidatorAdapter implements SmartValidator, jakarta.validatio * @see jakarta.validation.ConstraintViolation#getInvalidValue() * @see org.springframework.validation.FieldError#getRejectedValue() */ - @Nullable - protected Object getRejectedValue(String field, ConstraintViolation violation, BindingResult bindingResult) { + protected @Nullable Object getRejectedValue(String field, ConstraintViolation violation, BindingResult bindingResult) { Object invalidValue = violation.getInvalidValue(); if (!field.isEmpty() && !field.contains("[]") && (invalidValue == violation.getLeafBean() || field.contains("[") || field.contains("."))) { @@ -423,8 +421,7 @@ public class SpringValidatorAdapter implements SmartValidator, jakarta.validatio } @Override - @Nullable - public Object[] getArguments() { + public Object @Nullable [] getArguments() { return null; } @@ -446,11 +443,9 @@ public class SpringValidatorAdapter implements SmartValidator, jakarta.validatio @SuppressWarnings("serial") private static class ViolationObjectError extends ObjectError implements Serializable { - @Nullable - private transient SpringValidatorAdapter adapter; + private @Nullable transient SpringValidatorAdapter adapter; - @Nullable - private transient ConstraintViolation violation; + private @Nullable transient ConstraintViolation violation; public ViolationObjectError(String objectName, String[] codes, Object[] arguments, ConstraintViolation violation, SpringValidatorAdapter adapter) { @@ -476,11 +471,9 @@ public class SpringValidatorAdapter implements SmartValidator, jakarta.validatio @SuppressWarnings("serial") private static class ViolationFieldError extends FieldError implements Serializable { - @Nullable - private transient SpringValidatorAdapter adapter; + private @Nullable transient SpringValidatorAdapter adapter; - @Nullable - private transient ConstraintViolation violation; + private @Nullable transient ConstraintViolation violation; public ViolationFieldError(String objectName, String field, @Nullable Object rejectedValue, String[] codes, Object[] arguments, ConstraintViolation violation, SpringValidatorAdapter adapter) { 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 c367d4b455..9f6498812e 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,9 +8,7 @@ * which defines a shared ValidatorFactory/Validator setup for availability * to other Spring components. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.validation.beanvalidation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/validation/method/MethodValidator.java b/spring-context/src/main/java/org/springframework/validation/method/MethodValidator.java index 3a937edd4b..2b97be8e42 100644 --- a/spring-context/src/main/java/org/springframework/validation/method/MethodValidator.java +++ b/spring-context/src/main/java/org/springframework/validation/method/MethodValidator.java @@ -18,8 +18,9 @@ package org.springframework.validation.method; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * Contract to apply method validation and handle the results. @@ -51,7 +52,7 @@ public interface MethodValidator { * @return the result of validation */ MethodValidationResult validateArguments( - Object target, Method method, @Nullable MethodParameter[] parameters, + Object target, Method method, MethodParameter @Nullable [] parameters, Object[] arguments, Class[] groups); /** @@ -62,7 +63,7 @@ public interface MethodValidator { * @throws MethodValidationException in case of unhandled errors. */ default void applyArgumentValidation( - Object target, Method method, @Nullable MethodParameter[] parameters, + Object target, Method method, MethodParameter @Nullable [] parameters, Object[] arguments, Class[] groups) { MethodValidationResult result = validateArguments(target, method, parameters, arguments, groups); diff --git a/spring-context/src/main/java/org/springframework/validation/method/ParameterErrors.java b/spring-context/src/main/java/org/springframework/validation/method/ParameterErrors.java index ad3bba6b74..81ee123592 100644 --- a/spring-context/src/main/java/org/springframework/validation/method/ParameterErrors.java +++ b/spring-context/src/main/java/org/springframework/validation/method/ParameterErrors.java @@ -18,8 +18,9 @@ package org.springframework.validation.method; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.validation.Errors; import org.springframework.validation.FieldError; import org.springframework.validation.ObjectError; @@ -92,7 +93,7 @@ public class ParameterErrors extends ParameterValidationResult implements Errors } @Override - public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + public void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.errors.reject(errorCode, errorArgs, defaultMessage); } @@ -108,7 +109,7 @@ public class ParameterErrors extends ParameterValidationResult implements Errors @Override public void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.errors.rejectValue(field, errorCode, errorArgs, defaultMessage); } @@ -149,8 +150,7 @@ public class ParameterErrors extends ParameterValidationResult implements Errors } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return this.errors.getGlobalError(); } @@ -170,8 +170,7 @@ public class ParameterErrors extends ParameterValidationResult implements Errors } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.errors.getFieldError(); } @@ -191,20 +190,17 @@ public class ParameterErrors extends ParameterValidationResult implements Errors } @Override - @Nullable - public FieldError getFieldError(String field) { + public @Nullable FieldError getFieldError(String field) { return this.errors.getFieldError(field); } @Override - @Nullable - public Object getFieldValue(String field) { + public @Nullable Object getFieldValue(String field) { return this.errors.getFieldError(field); } @Override - @Nullable - public Class getFieldType(String field) { + public @Nullable Class getFieldType(String field) { return this.errors.getFieldType(field); } diff --git a/spring-context/src/main/java/org/springframework/validation/method/ParameterValidationResult.java b/spring-context/src/main/java/org/springframework/validation/method/ParameterValidationResult.java index 740796976d..e3a753c9b4 100644 --- a/spring-context/src/main/java/org/springframework/validation/method/ParameterValidationResult.java +++ b/spring-context/src/main/java/org/springframework/validation/method/ParameterValidationResult.java @@ -20,9 +20,10 @@ import java.util.Collection; import java.util.List; import java.util.function.BiFunction; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSourceResolvable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -49,19 +50,15 @@ public class ParameterValidationResult { private final MethodParameter methodParameter; - @Nullable - private final Object argument; + private final @Nullable Object argument; private final List resolvableErrors; - @Nullable - private final Object container; + private final @Nullable Object container; - @Nullable - private final Integer containerIndex; + private final @Nullable Integer containerIndex; - @Nullable - private final Object containerKey; + private final @Nullable Object containerKey; private final BiFunction, Object> sourceLookup; @@ -96,8 +93,7 @@ public class ParameterValidationResult { /** * The method argument value that was validated. */ - @Nullable - public Object getArgument() { + public @Nullable Object getArgument() { return this.argument; } @@ -132,8 +128,7 @@ public class ParameterValidationResult { * {@link #getContainerIndex()} and {@link #getContainerKey()} provide * information about the index or key if applicable. */ - @Nullable - public Object getContainer() { + public @Nullable Object getContainer() { return this.container; } @@ -142,8 +137,7 @@ public class ParameterValidationResult { * {@link List} or array, this method returns the index of the validated * {@link #getArgument() argument}. */ - @Nullable - public Integer getContainerIndex() { + public @Nullable Integer getContainerIndex() { return this.containerIndex; } @@ -152,8 +146,7 @@ public class ParameterValidationResult { * key such as {@link java.util.Map}, this method returns the key of the * validated {@link #getArgument() argument}. */ - @Nullable - public Object getContainerKey() { + public @Nullable Object getContainerKey() { return this.containerKey; } diff --git a/spring-context/src/main/java/org/springframework/validation/method/package-info.java b/spring-context/src/main/java/org/springframework/validation/method/package-info.java index 001ea1b69c..04f41ca92a 100644 --- a/spring-context/src/main/java/org/springframework/validation/method/package-info.java +++ b/spring-context/src/main/java/org/springframework/validation/method/package-info.java @@ -13,9 +13,7 @@ * */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.validation.method; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 cc26d2bb67..2af4394c82 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,9 +2,7 @@ * Provides data binding and validation functionality, * for usage in business and/or UI layers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.validation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java index 3411f9a909..bca828e8dd 100644 --- a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java +++ b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareConcurrentModel.java @@ -18,7 +18,8 @@ package org.springframework.validation.support; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.ConcurrentModel; import org.springframework.validation.BindingResult; @@ -43,8 +44,7 @@ import org.springframework.validation.BindingResult; public class BindingAwareConcurrentModel extends ConcurrentModel { @Override - @Nullable - public Object put(String key, @Nullable Object value) { + public @Nullable Object put(String key, @Nullable Object value) { removeBindingResultIfNecessary(key, value); return super.put(key, value); } diff --git a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java index c37eca8a7a..573c382627 100644 --- a/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java +++ b/spring-context/src/main/java/org/springframework/validation/support/BindingAwareModelMap.java @@ -18,7 +18,8 @@ package org.springframework.validation.support; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.ExtendedModelMap; import org.springframework.validation.BindingResult; 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 355c476679..e7197c303b 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,9 +1,7 @@ /** * Support classes for handling validation results. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.validation.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java index c7f56212bc..98ac18bee3 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/AspectAndAdvicePrecedenceTests.java @@ -19,6 +19,7 @@ package org.springframework.aop.aspectj; import java.lang.reflect.Method; import org.aspectj.lang.ProceedingJoinPoint; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; /** * @author Adrian Colyer diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java index ed740ab88c..1c7b674046 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/BeanNamePointcutTests.java @@ -19,6 +19,7 @@ package org.springframework.aop.aspectj; import java.lang.reflect.Method; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -27,7 +28,6 @@ import org.springframework.aop.framework.Advised; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java index bc6f45bfc4..34e6bc313b 100644 --- a/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java +++ b/spring-context/src/test/java/org/springframework/aop/aspectj/autoproxy/AspectJAutoProxyCreatorTests.java @@ -29,6 +29,7 @@ import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -66,7 +67,6 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.DecoratingProxy; import org.springframework.core.NestedRuntimeException; import org.springframework.core.annotation.Order; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java index 49e142044f..b99c0c13cc 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java @@ -30,6 +30,7 @@ import java.util.Map; import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -70,7 +71,6 @@ import org.springframework.beans.testfixture.beans.SerializablePerson; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.testfixture.TimeStamped; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; diff --git a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java index 343633881f..245bc5ed48 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java @@ -20,6 +20,8 @@ import java.io.Serializable; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.ClassFilter; @@ -35,8 +37,6 @@ import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.context.ApplicationContextException; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java index f2fb4eea74..811a5550d5 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java @@ -18,6 +18,7 @@ package org.springframework.aop.framework; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.interceptor.ExposeInvocationInterceptor; @@ -25,7 +26,6 @@ import org.springframework.aop.support.AopUtils; import org.springframework.beans.testfixture.beans.IOther; import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.beans.testfixture.beans.TestBean; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; diff --git a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java index 481fe6e591..273ff8978b 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/ProxyFactoryBeanTests.java @@ -25,6 +25,7 @@ import java.util.List; import org.aopalliance.aop.Advice; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -58,7 +59,6 @@ import org.springframework.context.testfixture.beans.TestApplicationListener; import org.springframework.core.io.ClassPathResource; import org.springframework.core.testfixture.TimeStamped; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatException; diff --git a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java index 90731091f3..3b1615338f 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/AutoProxyCreatorTests.java @@ -21,6 +21,7 @@ import java.lang.reflect.Proxy; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.TargetSource; @@ -45,7 +46,6 @@ import org.springframework.context.ApplicationContextAware; import org.springframework.context.MessageSource; import org.springframework.context.support.StaticApplicationContext; import org.springframework.context.support.StaticMessageSource; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -414,8 +414,7 @@ class AutoProxyCreatorTests { } @Override - @Nullable - protected Object[] getAdvicesAndAdvisorsForBean(Class beanClass, String name, @Nullable TargetSource customTargetSource) { + protected Object @Nullable [] getAdvicesAndAdvisorsForBean(Class beanClass, String name, @Nullable TargetSource customTargetSource) { if (StaticMessageSource.class.equals(beanClass)) { return DO_NOT_PROXY; } diff --git a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorInitTests.java b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorInitTests.java index 799cbf11e0..350e7e4138 100644 --- a/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorInitTests.java +++ b/spring-context/src/test/java/org/springframework/aop/framework/autoproxy/BeanNameAutoProxyCreatorInitTests.java @@ -18,12 +18,12 @@ package org.springframework.aop.framework.autoproxy; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.MethodBeforeAdvice; import org.springframework.beans.testfixture.beans.Pet; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; diff --git a/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java b/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java index 9d358b81cd..3d524830c9 100644 --- a/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java +++ b/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.CompletableFuture; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.mockito.Mockito; import reactor.core.publisher.Flux; @@ -43,7 +44,6 @@ import org.springframework.cache.support.SimpleCacheManager; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalStateException; @@ -531,8 +531,7 @@ class CacheReproTests { } @Override - @Nullable - protected Collection getCacheNames(CacheOperationInvocationContext context) { + protected @Nullable Collection getCacheNames(CacheOperationInvocationContext context) { String cacheName = (String) context.getArgs()[0]; if (cacheName != null) { return Collections.singleton(cacheName); diff --git a/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java b/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java index c43df31de4..e065cde9d1 100644 --- a/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java +++ b/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java @@ -21,6 +21,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; import java.util.concurrent.atomic.AtomicLong; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -37,7 +38,6 @@ import org.springframework.cache.interceptor.LoggingCacheErrorHandler; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.catchThrowable; diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluatorTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluatorTests.java index 3b826775a5..75ff994160 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluatorTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheOperationExpressionEvaluatorTests.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Iterator; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; @@ -36,7 +37,6 @@ import org.springframework.context.support.StaticApplicationContext; import org.springframework.expression.EvaluationContext; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java index 4e5cafd54b..39fad9892b 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java @@ -21,6 +21,7 @@ import java.util.Collection; import java.util.Collections; import java.util.concurrent.atomic.AtomicLong; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,7 +38,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.testfixture.cache.CacheTestUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -260,8 +260,7 @@ class CacheResolverCustomizationTests { } @Override - @Nullable - protected Collection getCacheNames(CacheOperationInvocationContext context) { + protected @Nullable Collection getCacheNames(CacheOperationInvocationContext context) { String cacheName = (String) context.getArgs()[1]; return Collections.singleton(cacheName); } @@ -275,8 +274,7 @@ class CacheResolverCustomizationTests { } @Override - @Nullable - protected Collection getCacheNames(CacheOperationInvocationContext context) { + protected @Nullable Collection getCacheNames(CacheOperationInvocationContext context) { return null; } } diff --git a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java index c7ccf72758..2d96f0d343 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java @@ -20,6 +20,7 @@ import java.util.Map; import java.util.Objects; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.hint.MemberCategory; @@ -38,7 +39,6 @@ import org.springframework.context.annotation6.Jsr330NamedForScanning; import org.springframework.context.testfixture.context.annotation.CglibConfiguration; import org.springframework.context.testfixture.context.annotation.LambdaBeanConfiguration; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import static java.lang.String.format; diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java index 9b7777cbf9..7d238cb6a2 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ConfigurationClassPostProcessorAotContributionTests.java @@ -25,6 +25,7 @@ import java.util.function.Predicate; import javax.lang.model.element.Modifier; import org.assertj.core.api.InstanceOfAssertFactories; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -61,7 +62,6 @@ import org.springframework.core.type.AnnotationMetadata; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.ParameterizedTypeName; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import static org.assertj.core.api.Assertions.assertThat; @@ -223,9 +223,8 @@ class ConfigurationClassPostProcessorAotContributionTests { this.metadata = importMetadata; } - @Nullable @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + public @Nullable Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (beanName.equals("testProcessing")) { return this.metadata; } @@ -441,8 +440,7 @@ class ConfigurationClassPostProcessorAotContributionTests { } - @Nullable - private BeanFactoryInitializationAotContribution getContribution(Class... types) { + private @Nullable BeanFactoryInitializationAotContribution getContribution(Class... types) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); for (Class type : types) { beanFactory.registerBeanDefinition(type.getName(), new RootBeanDefinition(type)); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java index 5f2fb5f9dc..2014c12000 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/ImportSelectorTests.java @@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Predicate; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -46,7 +47,6 @@ import org.springframework.core.annotation.Order; import org.springframework.core.env.Environment; import org.springframework.core.io.ResourceLoader; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -403,8 +403,7 @@ public class ImportSelectorTests { } @Override - @Nullable - public Predicate getExclusionFilter() { + public @Nullable Predicate getExclusionFilter() { return className -> className.endsWith("ImportedSelector1"); } } @@ -440,18 +439,16 @@ public class ImportSelectorTests { public static class GroupedDeferredImportSelector1 extends DeferredImportSelector1 { - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } } public static class GroupedDeferredImportSelector2 extends DeferredImportSelector2 { - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } } @@ -471,9 +468,8 @@ public class ImportSelectorTests { return new String[] { DeferredImportSelector1.class.getName(), ChildConfiguration1.class.getName() }; } - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } @@ -492,9 +488,8 @@ public class ImportSelectorTests { return new String[] { DeferredImportSelector2.class.getName(), ChildConfiguration2.class.getName() }; } - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } @@ -515,9 +510,8 @@ public class ImportSelectorTests { return new String[] { DeferredImportedSelector3.class.getName() }; } - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } @@ -537,9 +531,8 @@ public class ImportSelectorTests { return new String[] { DeferredImportSelector2.class.getName() }; } - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } diff --git a/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilderTests.java b/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilderTests.java index 5e08fafbf6..2e2dc67b2b 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilderTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/ReflectiveProcessorAotContributionBuilderTests.java @@ -20,6 +20,7 @@ import java.util.List; import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.api.ObjectArrayAssert; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.aot.BeanFactoryInitializationAotContribution; @@ -35,7 +36,6 @@ import org.springframework.context.testfixture.context.aot.scan.reflective.Refle import org.springframework.context.testfixture.context.aot.scan.reflective2.Reflective2OnType; import org.springframework.context.testfixture.context.aot.scan.reflective2.reflective21.Reflective21OnType; import org.springframework.context.testfixture.context.aot.scan.reflective2.reflective22.Reflective22OnType; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java b/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java index bb4aa59ff8..ecf4d6f22a 100644 --- a/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/aot/RuntimeHintsBeanFactoryInitializationAotProcessorTests.java @@ -22,6 +22,7 @@ import java.util.Enumeration; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,7 +39,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportRuntimeHints; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-context/src/test/java/org/springframework/context/event/test/AbstractIdentifiable.java b/spring-context/src/test/java/org/springframework/context/event/test/AbstractIdentifiable.java index 80add57c4d..4b3773c7ca 100644 --- a/spring-context/src/test/java/org/springframework/context/event/test/AbstractIdentifiable.java +++ b/spring-context/src/test/java/org/springframework/context/event/test/AbstractIdentifiable.java @@ -18,7 +18,7 @@ package org.springframework.context.event.test; import java.util.UUID; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Stephane Nicoll diff --git a/spring-context/src/test/java/org/springframework/context/event/test/GenericEventPojo.java b/spring-context/src/test/java/org/springframework/context/event/test/GenericEventPojo.java index 51f06ee24f..bbff12e686 100644 --- a/spring-context/src/test/java/org/springframework/context/event/test/GenericEventPojo.java +++ b/spring-context/src/test/java/org/springframework/context/event/test/GenericEventPojo.java @@ -16,9 +16,10 @@ package org.springframework.context.event.test; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableTypeProvider; -import org.springframework.lang.Nullable; /** * A simple POJO that implements {@link ResolvableTypeProvider}. diff --git a/spring-context/src/test/java/org/springframework/context/event/test/IdentifiableApplicationEvent.java b/spring-context/src/test/java/org/springframework/context/event/test/IdentifiableApplicationEvent.java index b4e5d98ffb..7df44c5923 100644 --- a/spring-context/src/test/java/org/springframework/context/event/test/IdentifiableApplicationEvent.java +++ b/spring-context/src/test/java/org/springframework/context/event/test/IdentifiableApplicationEvent.java @@ -18,8 +18,9 @@ package org.springframework.context.event.test; import java.util.UUID; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; -import org.springframework.lang.Nullable; /** * A basic test event that can be uniquely identified easily. diff --git a/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java index 90e3ccba60..c42422d2a7 100644 --- a/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java @@ -21,6 +21,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.context.ConfigurableApplicationContext; @@ -31,7 +32,6 @@ import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; -import org.springframework.lang.Nullable; import org.springframework.tests.sample.beans.ResourceTestBean; import static org.assertj.core.api.Assertions.assertThat; @@ -82,8 +82,7 @@ class ConversionServiceFactoryBeanTests { return Collections.singleton(new ConvertiblePair(String.class, Baz.class)); } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return new Baz(); } }); diff --git a/spring-context/src/test/java/org/springframework/context/support/StaticApplicationContextMulticasterTests.java b/spring-context/src/test/java/org/springframework/context/support/StaticApplicationContextMulticasterTests.java index 62535c0d27..2f1d47fc2c 100644 --- a/spring-context/src/test/java/org/springframework/context/support/StaticApplicationContextMulticasterTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/StaticApplicationContextMulticasterTests.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.MutablePropertyValues; @@ -34,7 +35,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.EncodedResource; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-context/src/test/java/org/springframework/jmx/export/TestDynamicMBean.java b/spring-context/src/test/java/org/springframework/jmx/export/TestDynamicMBean.java index 819dc5af86..1878c0aee7 100644 --- a/spring-context/src/test/java/org/springframework/jmx/export/TestDynamicMBean.java +++ b/spring-context/src/test/java/org/springframework/jmx/export/TestDynamicMBean.java @@ -25,7 +25,7 @@ import javax.management.MBeanInfo; import javax.management.MBeanNotificationInfo; import javax.management.MBeanOperationInfo; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Rob Harrop diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java index 17c3f20883..ebe8931ae0 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/EnableAsyncTests.java @@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.awaitility.Awaitility; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.Advisor; @@ -49,7 +50,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Lazy; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; @@ -630,9 +630,8 @@ class EnableAsyncTests { public static class ExecutorPostProcessor implements BeanPostProcessor { - @Nullable @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + public @Nullable Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { if (bean instanceof ThreadPoolTaskExecutor) { ((ThreadPoolTaskExecutor) bean).setThreadNamePrefix("Post-"); } diff --git a/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java b/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java index 4e7fc7c470..e1d2488483 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/concurrent/AbstractSchedulingTaskExecutorTests.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; import org.awaitility.Awaitility; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,7 +37,6 @@ import org.junit.jupiter.api.TestInfo; import org.springframework.beans.factory.DisposableBean; import org.springframework.core.task.AsyncTaskExecutor; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-context/src/test/java/org/springframework/scheduling/support/PeriodicTriggerTests.java b/spring-context/src/test/java/org/springframework/scheduling/support/PeriodicTriggerTests.java index ad1f6222d3..c51cf92192 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/support/PeriodicTriggerTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/support/PeriodicTriggerTests.java @@ -20,9 +20,9 @@ import java.time.Duration; import java.time.Instant; import java.time.temporal.ChronoUnit; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.scheduling.TriggerContext; import org.springframework.util.NumberUtils; @@ -227,8 +227,7 @@ class PeriodicTriggerTests { return new TestTriggerContext(toInstant(scheduled), toInstant(actual), toInstant(completion)); } - @Nullable - private static Instant toInstant(@Nullable Object o) { + private static @Nullable Instant toInstant(@Nullable Object o) { if (o == null) { return null; } @@ -249,14 +248,11 @@ class PeriodicTriggerTests { private static class TestTriggerContext implements TriggerContext { - @Nullable - private final Instant scheduled; + private final @Nullable Instant scheduled; - @Nullable - private final Instant actual; + private final @Nullable Instant actual; - @Nullable - private final Instant completion; + private final @Nullable Instant completion; TestTriggerContext(@Nullable Instant scheduled, @Nullable Instant actual, @Nullable Instant completion) { diff --git a/spring-context/src/test/java/org/springframework/scripting/groovy/LogUserAdvice.java b/spring-context/src/test/java/org/springframework/scripting/groovy/LogUserAdvice.java index 8bcc9ffde8..4f219bb84f 100644 --- a/spring-context/src/test/java/org/springframework/scripting/groovy/LogUserAdvice.java +++ b/spring-context/src/test/java/org/springframework/scripting/groovy/LogUserAdvice.java @@ -18,9 +18,10 @@ package org.springframework.scripting.groovy; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.MethodBeforeAdvice; import org.springframework.aop.ThrowsAdvice; -import org.springframework.lang.Nullable; public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice { diff --git a/spring-context/src/test/java/org/springframework/ui/ModelMapTests.java b/spring-context/src/test/java/org/springframework/ui/ModelMapTests.java index 5c36f02ce4..4b2f9ceb48 100644 --- a/spring-context/src/test/java/org/springframework/ui/ModelMapTests.java +++ b/spring-context/src/test/java/org/springframework/ui/ModelMapTests.java @@ -25,11 +25,11 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.testfixture.beans.TestBean; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; diff --git a/spring-context/src/test/java/org/springframework/validation/DataBinderConstructTests.java b/spring-context/src/test/java/org/springframework/validation/DataBinderConstructTests.java index 819c72227a..e375b2832a 100644 --- a/spring-context/src/test/java/org/springframework/validation/DataBinderConstructTests.java +++ b/spring-context/src/test/java/org/springframework/validation/DataBinderConstructTests.java @@ -23,11 +23,11 @@ import java.util.Optional; import java.util.Set; import jakarta.validation.constraints.NotNull; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.ResolvableType; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import static org.assertj.core.api.Assertions.assertThat; @@ -211,8 +211,7 @@ class DataBinderConstructTests { private final String param1; - @Nullable - private final DataClass nestedParam2; + private final @Nullable DataClass nestedParam2; public NestedDataClass(String param1, @Nullable DataClass nestedParam2) { this.param1 = param1; @@ -223,8 +222,7 @@ class DataBinderConstructTests { return this.param1; } - @Nullable - public DataClass nestedParam2() { + public @Nullable DataClass nestedParam2() { return this.nestedParam2; } } diff --git a/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java b/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java index 81ee18a8a4..77549a8177 100644 --- a/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java +++ b/spring-context/src/test/java/org/springframework/validation/DataBinderTests.java @@ -36,6 +36,7 @@ import java.util.Optional; import java.util.Set; import java.util.TreeSet; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.BeanWrapper; @@ -62,7 +63,6 @@ import org.springframework.format.Formatter; import org.springframework.format.number.NumberStyleFormatter; import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.format.support.FormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.tests.sample.beans.BeanWithObjectProperty; import org.springframework.util.StringUtils; diff --git a/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessorTests.java b/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessorTests.java index 3147fd8555..9197c706b1 100644 --- a/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/validation/beanvalidation/BeanValidationBeanRegistrationAotProcessorTests.java @@ -32,6 +32,7 @@ import jakarta.validation.Payload; import jakarta.validation.Valid; import jakarta.validation.constraints.Pattern; import org.hibernate.validator.internal.constraintvalidators.bv.PatternValidator; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -45,7 +46,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.OverridingClassLoader; -import org.springframework.lang.Nullable; import static java.lang.annotation.ElementType.ANNOTATION_TYPE; import static java.lang.annotation.ElementType.CONSTRUCTOR; @@ -150,8 +150,7 @@ class BeanValidationBeanRegistrationAotProcessorTests { } } - @Nullable - private BeanRegistrationAotContribution createContribution(Class beanClass) { + private @Nullable BeanRegistrationAotContribution createContribution(Class beanClass) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass)); return this.processor.processAheadOfTime(RegisteredBean.of(beanFactory, beanClass.getName())); diff --git a/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterPropertyPathTests.java b/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterPropertyPathTests.java index 76a3caae13..b5437b7e9c 100644 --- a/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterPropertyPathTests.java +++ b/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterPropertyPathTests.java @@ -25,10 +25,10 @@ import java.util.Optional; import jakarta.validation.Valid; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.validation.FieldError; import org.springframework.validation.method.MethodValidationResult; diff --git a/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterTests.java b/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterTests.java index 8326a5c238..6eac0de1ac 100644 --- a/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterTests.java +++ b/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationAdapterTests.java @@ -37,12 +37,12 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import jakarta.validation.constraintvalidation.SupportedValidationTarget; import jakarta.validation.constraintvalidation.ValidationTarget; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.context.MessageSourceResolvable; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.validation.FieldError; import org.springframework.validation.method.MethodValidationResult; diff --git a/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationProxyTests.java b/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationProxyTests.java index a058f2c241..cc16e59096 100644 --- a/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationProxyTests.java +++ b/spring-context/src/test/java/org/springframework/validation/beanvalidation/MethodValidationProxyTests.java @@ -28,6 +28,7 @@ import jakarta.validation.constraints.NotNull; import jakarta.validation.groups.Default; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -42,7 +43,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.BridgeMethodResolver; -import org.springframework.lang.Nullable; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.AsyncAnnotationAdvisor; import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor; @@ -223,9 +223,8 @@ class MethodValidationProxyTests { private final MyValidBean myValidBean = new MyValidBean(); - @Nullable @Override - public Object invoke(MethodInvocation invocation) { + public @Nullable Object invoke(MethodInvocation invocation) { Method method; try { method = ClassUtils.getMethod(MyValidBean.class, invocation.getMethod().getName(), (Class[]) null); diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/cache/beans/TestEntity.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/cache/beans/TestEntity.java index 4fd7e9c045..899662bdc6 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/cache/beans/TestEntity.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/cache/beans/TestEntity.java @@ -18,7 +18,8 @@ package org.springframework.context.testfixture.cache.beans; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/index/CandidateComponentsTestClassLoader.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/index/CandidateComponentsTestClassLoader.java index d86dafb553..36d7f40a47 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/index/CandidateComponentsTestClassLoader.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/index/CandidateComponentsTestClassLoader.java @@ -22,8 +22,9 @@ import java.util.Collections; import java.util.Enumeration; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * A test {@link ClassLoader} that can be used in a testing context to control the @@ -66,11 +67,9 @@ public class CandidateComponentsTestClassLoader extends ClassLoader { } - @Nullable - private final Enumeration resourceUrls; + private final @Nullable Enumeration resourceUrls; - @Nullable - private final IOException cause; + private final @Nullable IOException cause; public CandidateComponentsTestClassLoader(ClassLoader classLoader, Enumeration resourceUrls) { super(classLoader); diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java index 92b0e3fc4b..cd1d0dee9e 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContext.java @@ -33,8 +33,8 @@ import javax.naming.OperationNotSupportedException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -213,8 +213,7 @@ public class SimpleNamingContext implements Context { } @Override - @Nullable - public Object addToEnvironment(String propName, Object propVal) { + public @Nullable Object addToEnvironment(String propName, Object propVal) { return this.environment.put(propName, propVal); } diff --git a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContextBuilder.java b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContextBuilder.java index fa253ada98..19ca64a667 100644 --- a/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContextBuilder.java +++ b/spring-context/src/testFixtures/java/org/springframework/context/testfixture/jndi/SimpleNamingContextBuilder.java @@ -26,8 +26,8 @@ import javax.naming.spi.NamingManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -88,8 +88,7 @@ import org.springframework.util.ReflectionUtils; public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder { /** An instance of this class bound to JNDI. */ - @Nullable - private static volatile SimpleNamingContextBuilder activated; + private static volatile @Nullable SimpleNamingContextBuilder activated; private static boolean initialized = false; @@ -101,8 +100,7 @@ public class SimpleNamingContextBuilder implements InitialContextFactoryBuilder * @return the current SimpleNamingContextBuilder instance, * or {@code null} if none */ - @Nullable - public static SimpleNamingContextBuilder getCurrentContextBuilder() { + public static @Nullable SimpleNamingContextBuilder getCurrentContextBuilder() { return activated; } diff --git a/spring-core-test/src/main/java/org/springframework/aot/agent/InstrumentedBridgeMethods.java b/spring-core-test/src/main/java/org/springframework/aot/agent/InstrumentedBridgeMethods.java index 35610a9222..22ec0e45a3 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/agent/InstrumentedBridgeMethods.java +++ b/spring-core-test/src/main/java/org/springframework/aot/agent/InstrumentedBridgeMethods.java @@ -31,7 +31,7 @@ import java.util.Locale; import java.util.ResourceBundle; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Instrumented version of JDK methods to be used by bytecode rewritten by the {@link RuntimeHintsAgent}. @@ -232,8 +232,7 @@ public abstract class InstrumentedBridgeMethods { return result; } - @Nullable - public static URL classgetResource(Class clazz, String name) { + public static @Nullable URL classgetResource(Class clazz, String name) { URL result = clazz.getResource(name); RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETRESOURCE) .onInstance(clazz).withArgument(name).returnValue(result).build(); @@ -241,8 +240,7 @@ public abstract class InstrumentedBridgeMethods { return result; } - @Nullable - public static InputStream classgetResourceAsStream(Class clazz, String name) { + public static @Nullable InputStream classgetResourceAsStream(Class clazz, String name) { InputStream result = clazz.getResourceAsStream(name); RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASS_GETRESOURCEASSTREAM) .onInstance(clazz).withArgument(name).returnValue(result).build(); @@ -267,8 +265,7 @@ public abstract class InstrumentedBridgeMethods { return result; } - @Nullable - public static URL classloadergetResource(ClassLoader classLoader, String name) { + public static @Nullable URL classloadergetResource(ClassLoader classLoader, String name) { URL result = classLoader.getResource(name); RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASSLOADER_GETRESOURCE) .onInstance(classLoader).withArgument(name).returnValue(result).build(); @@ -276,8 +273,7 @@ public abstract class InstrumentedBridgeMethods { return result; } - @Nullable - public static InputStream classloadergetResourceAsStream(ClassLoader classLoader, String name) { + public static @Nullable InputStream classloadergetResourceAsStream(ClassLoader classLoader, String name) { InputStream result = classLoader.getResourceAsStream(name); RecordedInvocation invocation = RecordedInvocation.of(InstrumentedMethod.CLASSLOADER_GETRESOURCEASSTREAM) .onInstance(classLoader).withArgument(name).returnValue(result).build(); diff --git a/spring-core-test/src/main/java/org/springframework/aot/agent/InvocationsRecorderClassTransformer.java b/spring-core-test/src/main/java/org/springframework/aot/agent/InvocationsRecorderClassTransformer.java index f9cc6abd17..f3babf532a 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/agent/InvocationsRecorderClassTransformer.java +++ b/spring-core-test/src/main/java/org/springframework/aot/agent/InvocationsRecorderClassTransformer.java @@ -21,8 +21,9 @@ import java.lang.instrument.IllegalClassFormatException; import java.security.ProtectionDomain; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.ClassReader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-core-test/src/main/java/org/springframework/aot/agent/MethodReference.java b/spring-core-test/src/main/java/org/springframework/aot/agent/MethodReference.java index 4a2f119445..0ab3fa387e 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/agent/MethodReference.java +++ b/spring-core-test/src/main/java/org/springframework/aot/agent/MethodReference.java @@ -18,7 +18,7 @@ package org.springframework.aot.agent; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Reference to a Java method, identified by its owner class and the method name. diff --git a/spring-core-test/src/main/java/org/springframework/aot/agent/RecordedInvocation.java b/spring-core-test/src/main/java/org/springframework/aot/agent/RecordedInvocation.java index 7572fcebdd..20e411e7ee 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/agent/RecordedInvocation.java +++ b/spring-core-test/src/main/java/org/springframework/aot/agent/RecordedInvocation.java @@ -20,9 +20,10 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -36,15 +37,13 @@ import org.springframework.util.Assert; */ public final class RecordedInvocation { - @Nullable - private final Object instance; + private final @Nullable Object instance; private final InstrumentedMethod instrumentedMethod; private final Object[] arguments; - @Nullable - private final Object returnValue; + private final @Nullable Object returnValue; private final List stackFrames; @@ -160,8 +159,7 @@ public final class RecordedInvocation { * @return the value returned by the invocation */ @SuppressWarnings("unchecked") - @Nullable - public T getReturnValue() { + public @Nullable T getReturnValue() { return (T) this.returnValue; } @@ -192,15 +190,13 @@ public final class RecordedInvocation { */ public static class Builder { - @Nullable - private Object instance; + private @Nullable Object instance; private final InstrumentedMethod instrumentedMethod; private Object[] arguments = new Object[0]; - @Nullable - private Object returnValue; + private @Nullable Object returnValue; Builder(InstrumentedMethod instrumentedMethod) { @@ -234,7 +230,7 @@ public final class RecordedInvocation { * @param arguments the invocation arguments * @return {@code this}, to facilitate method chaining */ - public Builder withArguments(@Nullable Object... arguments) { + public Builder withArguments(Object @Nullable ... arguments) { if (arguments != null) { this.arguments = arguments; } diff --git a/spring-core-test/src/main/java/org/springframework/aot/agent/RuntimeHintsAgent.java b/spring-core-test/src/main/java/org/springframework/aot/agent/RuntimeHintsAgent.java index e03f71de77..1d1cf826a1 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/agent/RuntimeHintsAgent.java +++ b/spring-core-test/src/main/java/org/springframework/aot/agent/RuntimeHintsAgent.java @@ -20,8 +20,9 @@ import java.lang.instrument.Instrumentation; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** diff --git a/spring-core-test/src/main/java/org/springframework/aot/agent/package-info.java b/spring-core-test/src/main/java/org/springframework/aot/agent/package-info.java index 1ea09811ae..e19fa356b9 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/agent/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/aot/agent/package-info.java @@ -1,9 +1,7 @@ /** * Support for recording method invocations relevant to {@link org.springframework.aot.hint.RuntimeHints} metadata. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.agent; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/agent/package-info.java b/spring-core-test/src/main/java/org/springframework/aot/test/agent/package-info.java index dc7ecdddfd..ff84188ae0 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/agent/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/agent/package-info.java @@ -1,9 +1,7 @@ /** * Testing support for the {@link org.springframework.aot.agent.RuntimeHintsAgent}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.test.agent; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java b/spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java index 9235cf21d5..7f00527d61 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generate/package-info.java @@ -1,9 +1,7 @@ /** * Test support for core AOT classes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.test.generate; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core-test/src/main/java/org/springframework/core/test/io/support/MockSpringFactoriesLoader.java b/spring-core-test/src/main/java/org/springframework/core/test/io/support/MockSpringFactoriesLoader.java index 70a6067a6a..135ffbf986 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/io/support/MockSpringFactoriesLoader.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/io/support/MockSpringFactoriesLoader.java @@ -24,8 +24,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.support.SpringFactoriesLoader; -import org.springframework.lang.Nullable; /** * Simple mock {@link SpringFactoriesLoader} implementation that can be used for testing @@ -67,9 +68,8 @@ public class MockSpringFactoriesLoader extends SpringFactoriesLoader { @Override - @Nullable @SuppressWarnings("unchecked") - protected T instantiateFactory(String implementationName, Class type, + protected @Nullable T instantiateFactory(String implementationName, Class type, @Nullable ArgumentResolver argumentResolver, FailureHandler failureHandler) { if (implementationName.startsWith("!")) { Object implementation = this.implementations.get(implementationName); diff --git a/spring-core-test/src/main/java/org/springframework/core/test/io/support/package-info.java b/spring-core-test/src/main/java/org/springframework/core/test/io/support/package-info.java index 99ef464171..d87f5a2b56 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/io/support/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/io/support/package-info.java @@ -1,9 +1,7 @@ /** * Test support classes for Spring's I/O support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.test.io.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java index 595c920a3a..711ed5d2e4 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/ClassFiles.java @@ -23,7 +23,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An immutable collection of {@link ClassFile} instances. @@ -112,8 +112,7 @@ public final class ClassFiles implements Iterable { * @param name the fully qualified name to find * @return a {@link ClassFile} instance or {@code null} */ - @Nullable - public ClassFile get(String name) { + public @Nullable ClassFile get(String name) { return this.files.get(name); } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/CompileWithForkedClassLoaderClassLoader.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/CompileWithForkedClassLoaderClassLoader.java index fe728b22ac..8d626d6823 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/CompileWithForkedClassLoaderClassLoader.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/CompileWithForkedClassLoaderClassLoader.java @@ -22,7 +22,7 @@ import java.net.URL; import java.util.Enumeration; import java.util.function.Function; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link ClassLoader} implementation to support @@ -73,8 +73,7 @@ final class CompileWithForkedClassLoaderClassLoader extends ClassLoader { return (bytes != null ? defineClass(name, bytes, 0, bytes.length, null) : super.findClass(name)); } - @Nullable - private byte[] findClassBytes(String name) { + private byte @Nullable [] findClassBytes(String name) { byte[] bytes = this.classResourceLookup.apply(name); if (bytes != null) { return bytes; @@ -98,8 +97,7 @@ final class CompileWithForkedClassLoaderClassLoader extends ClassLoader { } @Override - @Nullable - protected URL findResource(String name) { + protected @Nullable URL findResource(String name) { return this.testClassLoader.getResource(name); } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/Compiled.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/Compiled.java index 1ef3175e45..4125df1c41 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/Compiled.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/Compiled.java @@ -21,7 +21,8 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -38,8 +39,7 @@ public class Compiled { private final ResourceFiles resourceFiles; - @Nullable - private List> compiledClasses; + private @Nullable List> compiledClasses; Compiled(ClassLoader classLoader, SourceFiles sourceFiles, ResourceFiles resourceFiles) { diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassFileObject.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassFileObject.java index cd395d4a46..de8ee3360f 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassFileObject.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassFileObject.java @@ -26,7 +26,7 @@ import java.net.URI; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * In-memory {@link JavaFileObject} used to hold class bytecode. @@ -38,8 +38,7 @@ class DynamicClassFileObject extends SimpleJavaFileObject { private final String className; - @Nullable - private volatile byte[] bytes; + private volatile byte @Nullable [] bytes; DynamicClassFileObject(String className) { @@ -80,8 +79,7 @@ class DynamicClassFileObject extends SimpleJavaFileObject { return this.className; } - @Nullable - byte[] getBytes() { + byte @Nullable [] getBytes() { return this.bytes; } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java index c55d664011..3a95b7e53f 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicClassLoader.java @@ -29,7 +29,8 @@ import java.util.Map; import java.util.function.Function; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -52,8 +53,7 @@ public class DynamicClassLoader extends ClassLoader { private final Map dynamicResourceFiles; - @Nullable - private final Method defineClassMethod; + private final @Nullable Method defineClassMethod; public DynamicClassLoader(ClassLoader parent, ClassFiles classFiles, ResourceFiles resourceFiles, @@ -89,8 +89,7 @@ public class DynamicClassLoader extends ClassLoader { return (clazz != null ? clazz : super.findClass(name)); } - @Nullable - private Class defineClass(String name, @Nullable byte[] bytes) { + private @Nullable Class defineClass(String name, byte @Nullable [] bytes) { if (bytes == null) { return null; } @@ -111,8 +110,7 @@ public class DynamicClassLoader extends ClassLoader { } @Override - @Nullable - protected URL findResource(String name) { + protected @Nullable URL findResource(String name) { if (name.endsWith(ClassUtils.CLASS_FILE_SUFFIX)) { String className = ClassUtils.convertResourcePathToClassName(name.substring(0, name.length() - ClassUtils.CLASS_FILE_SUFFIX.length())); @@ -132,8 +130,7 @@ public class DynamicClassLoader extends ClassLoader { return super.findResource(name); } - @Nullable - private byte[] findClassBytes(String name) { + private byte @Nullable [] findClassBytes(String name) { ClassFile classFile = this.classFiles.get(name); if (classFile != null) { return classFile.getContent(); @@ -162,8 +159,7 @@ public class DynamicClassLoader extends ClassLoader { private static class SingletonEnumeration implements Enumeration { - @Nullable - private E element; + private @Nullable E element; SingletonEnumeration(@Nullable E element) { @@ -177,8 +173,7 @@ public class DynamicClassLoader extends ClassLoader { } @Override - @Nullable - public E nextElement() { + public @Nullable E nextElement() { E next = this.element; this.element = null; return next; diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java index bbc81923a7..f17d7b048f 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFile.java @@ -19,7 +19,8 @@ package org.springframework.core.test.tools; import java.io.IOException; import java.nio.charset.StandardCharsets; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFileAssert.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFileAssert.java index f59f33fb73..dbbf3f79a1 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFileAssert.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFileAssert.java @@ -17,8 +17,7 @@ package org.springframework.core.test.tools; import org.assertj.core.api.AbstractAssert; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java index 23b2d47ccd..29c0f2e971 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicFiles.java @@ -25,7 +25,7 @@ import java.util.Map; import java.util.function.Predicate; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Internal class used by {@link SourceFiles} and {@link ResourceFiles} to @@ -83,8 +83,7 @@ final class DynamicFiles implements Iterable { return this.files.isEmpty(); } - @Nullable - F get(String path) { + @Nullable F get(String path) { return this.files.get(path); } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicResourceFileObject.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicResourceFileObject.java index 5e09f46e54..43a4bae342 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicResourceFileObject.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/DynamicResourceFileObject.java @@ -26,7 +26,7 @@ import java.net.URI; import javax.tools.JavaFileObject; import javax.tools.SimpleJavaFileObject; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * In-memory {@link JavaFileObject} used to hold generated resource file contents. @@ -37,8 +37,7 @@ import org.springframework.lang.Nullable; */ class DynamicResourceFileObject extends SimpleJavaFileObject { - @Nullable - private volatile byte[] bytes; + private volatile byte @Nullable [] bytes; DynamicResourceFileObject(String fileName) { @@ -73,8 +72,7 @@ class DynamicResourceFileObject extends SimpleJavaFileObject { this.bytes = bytes; } - @Nullable - byte[] getBytes() { + byte @Nullable [] getBytes() { return this.bytes; } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java index 1a53e92277..870713cf5b 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/ResourceFiles.java @@ -19,7 +19,7 @@ package org.springframework.core.test.tools; import java.util.Iterator; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An immutable collection of {@link ResourceFile} instances. @@ -115,8 +115,7 @@ public final class ResourceFiles implements Iterable { * @param path the path to find * @return a {@link ResourceFile} instance or {@code null} */ - @Nullable - public ResourceFile get(String path) { + public @Nullable ResourceFile get(String path) { return this.files.get(path); } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFile.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFile.java index 8db946050b..02918a4bc6 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFile.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFile.java @@ -29,9 +29,9 @@ import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaSource; import org.assertj.core.api.AssertProvider; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.InputStreamSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.FileCopyUtils; diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java index ad8bab385a..1505a5412d 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/SourceFiles.java @@ -20,7 +20,8 @@ import java.util.Iterator; import java.util.regex.Pattern; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -117,8 +118,7 @@ public final class SourceFiles implements Iterable { * @param path the path to find * @return a {@link SourceFile} instance or {@code null} */ - @Nullable - public SourceFile get(String path) { + public @Nullable SourceFile get(String path) { return this.files.get(path); } diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/TestCompiler.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/TestCompiler.java index bb77051b9e..14027e6a5c 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/TestCompiler.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/TestCompiler.java @@ -35,7 +35,7 @@ import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; import javax.tools.ToolProvider; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Utility that can be used to dynamically compile and test Java source code. @@ -48,8 +48,7 @@ import org.springframework.lang.Nullable; */ public final class TestCompiler { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final JavaCompiler compiler; diff --git a/spring-core-test/src/main/java/org/springframework/core/test/tools/package-info.java b/spring-core-test/src/main/java/org/springframework/core/test/tools/package-info.java index a541c066c4..750eb47a71 100644 --- a/spring-core-test/src/main/java/org/springframework/core/test/tools/package-info.java +++ b/spring-core-test/src/main/java/org/springframework/core/test/tools/package-info.java @@ -1,9 +1,7 @@ /** * Support classes for compiling and testing generated code. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.test.tools; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/spring-core.gradle b/spring-core/spring-core.gradle index 71a30eba42..76d7e4016c 100644 --- a/spring-core/spring-core.gradle +++ b/spring-core/spring-core.gradle @@ -71,6 +71,7 @@ dependencies { api(files(javapoetRepackJar)) api(files(objenesisRepackJar)) api("commons-logging:commons-logging") + api("org.jspecify:jspecify") compileOnly("io.projectreactor.tools:blockhound") compileOnly("org.graalvm.sdk:graal-sdk") optional("io.micrometer:context-propagation") diff --git a/spring-core/src/main/java/org/springframework/aot/generate/ClassNameGenerator.java b/spring-core/src/main/java/org/springframework/aot/generate/ClassNameGenerator.java index 48c88041e4..dc617405ec 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/ClassNameGenerator.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/ClassNameGenerator.java @@ -20,8 +20,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.ClassName; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; diff --git a/spring-core/src/main/java/org/springframework/aot/generate/DefaultMethodReference.java b/spring-core/src/main/java/org/springframework/aot/generate/DefaultMethodReference.java index 3018c6407c..77c860ffe2 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/DefaultMethodReference.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/DefaultMethodReference.java @@ -21,11 +21,12 @@ import java.util.List; import javax.lang.model.element.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.TypeName; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,8 +40,7 @@ public class DefaultMethodReference implements MethodReference { private final MethodSpec method; - @Nullable - private final ClassName declaringClass; + private final @Nullable ClassName declaringClass; public DefaultMethodReference(MethodSpec method, @Nullable ClassName declaringClass) { diff --git a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClass.java b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClass.java index 2b1caa6d13..23c7a81920 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClass.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClass.java @@ -21,10 +21,11 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.ClassName; import org.springframework.javapoet.JavaFile; import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +38,7 @@ import org.springframework.util.Assert; */ public final class GeneratedClass { - @Nullable - private final GeneratedClass enclosingClass; + private final @Nullable GeneratedClass enclosingClass; private final ClassName name; @@ -98,8 +98,7 @@ public final class GeneratedClass { * instance represents a top-level class. * @return the enclosing generated class, if any */ - @Nullable - public GeneratedClass getEnclosingClass() { + public @Nullable GeneratedClass getEnclosingClass() { return this.enclosingClass; } diff --git a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClasses.java b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClasses.java index 5e057001bb..e6aad3d286 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClasses.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedClasses.java @@ -23,9 +23,10 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.ClassName; import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java index 98979191a8..2b98963b14 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedFiles.java @@ -18,9 +18,10 @@ package org.springframework.aot.generate; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.InputStreamSource; import org.springframework.javapoet.JavaFile; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -264,8 +265,7 @@ public interface GeneratedFiles { * Return an {@link InputStreamSource} for the content of the file or * {@code null} if the file does not exist. */ - @Nullable - public InputStreamSource getContent() { + public @Nullable InputStreamSource getContent() { return (exists() ? this.existingContent.get() : null); } diff --git a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedTypeReference.java b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedTypeReference.java index 9e2ec90886..54bb19bcbb 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/GeneratedTypeReference.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/GeneratedTypeReference.java @@ -16,10 +16,11 @@ package org.springframework.aot.generate; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.AbstractTypeReference; import org.springframework.aot.hint.TypeReference; import org.springframework.javapoet.ClassName; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +38,7 @@ public final class GeneratedTypeReference extends AbstractTypeReference { this.className = className; } - @Nullable - private static GeneratedTypeReference safeCreate(@Nullable ClassName className) { + private static @Nullable GeneratedTypeReference safeCreate(@Nullable ClassName className) { return (className != null ? new GeneratedTypeReference(className) : null); } diff --git a/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java b/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java index b79a0b3318..7e82efa15c 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/InMemoryGeneratedFiles.java @@ -23,8 +23,9 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.InputStreamSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.function.ThrowingConsumer; @@ -64,8 +65,7 @@ public class InMemoryGeneratedFiles implements GeneratedFiles { * @return the file content or {@code null} if no file could be found * @throws IOException on read error */ - @Nullable - public String getGeneratedFileContent(Kind kind, String path) throws IOException { + public @Nullable String getGeneratedFileContent(Kind kind, String path) throws IOException { InputStreamSource source = getGeneratedFile(kind, path); if (source != null) { return new String(source.getInputStream().readAllBytes(), StandardCharsets.UTF_8); @@ -79,8 +79,7 @@ public class InMemoryGeneratedFiles implements GeneratedFiles { * @param path the path of the file * @return the file source or {@code null} if no file could be found */ - @Nullable - public InputStreamSource getGeneratedFile(Kind kind, String path) { + public @Nullable InputStreamSource getGeneratedFile(Kind kind, String path) { Assert.notNull(kind, "'kind' must not be null"); Assert.hasLength(path, "'path' must not be empty"); Map paths = this.files.get(kind); diff --git a/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java b/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java index 6a4ff72f6f..7630055f17 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/MethodName.java @@ -19,7 +19,8 @@ package org.springframework.aot.generate; import java.util.Arrays; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-core/src/main/java/org/springframework/aot/generate/MethodReference.java b/spring-core/src/main/java/org/springframework/aot/generate/MethodReference.java index a33573d74f..42ff4169aa 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/MethodReference.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/MethodReference.java @@ -18,10 +18,11 @@ package org.springframework.aot.generate; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.ClassName; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.TypeName; -import org.springframework.lang.Nullable; /** * A reference to a method with convenient code generation for @@ -74,8 +75,7 @@ public interface MethodReference { * @param argumentType the argument type * @return the code for this argument, or {@code null} */ - @Nullable - CodeBlock generateCode(TypeName argumentType); + @Nullable CodeBlock generateCode(TypeName argumentType); /** * Factory method that returns an {@link ArgumentCodeGenerator} that diff --git a/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerationException.java b/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerationException.java index dead0694e4..2faba073c1 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerationException.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerationException.java @@ -16,7 +16,7 @@ package org.springframework.aot.generate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Thrown when value code generation fails. @@ -27,8 +27,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ValueCodeGenerationException extends RuntimeException { - @Nullable - private final Object value; + private final @Nullable Object value; protected ValueCodeGenerationException(String message, @Nullable Object value, @Nullable Throwable cause) { @@ -54,8 +53,7 @@ public class ValueCodeGenerationException extends RuntimeException { /** * Return the value that failed to be generated. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } diff --git a/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerator.java b/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerator.java index b30b1acff1..4699261f16 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerator.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGenerator.java @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.javapoet.CodeBlock; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -41,8 +42,7 @@ public final class ValueCodeGenerator { private final List delegates; - @Nullable - private final GeneratedMethods generatedMethods; + private final @Nullable GeneratedMethods generatedMethods; private ValueCodeGenerator(List delegates, @Nullable GeneratedMethods generatedMethods) { @@ -128,8 +128,7 @@ public final class ValueCodeGenerator { * {@code null} if no specific scope is set. * @return the generated methods to use for code generation */ - @Nullable - public GeneratedMethods getGeneratedMethods() { + public @Nullable GeneratedMethods getGeneratedMethods() { return this.generatedMethods; } @@ -149,8 +148,7 @@ public final class ValueCodeGenerator { * @return the code that represents the specified value or {@code null} if * the specified value is not supported. */ - @Nullable - CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value); + @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value); } } diff --git a/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGeneratorDelegates.java b/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGeneratorDelegates.java index 86904a0c30..bccc9986f5 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGeneratorDelegates.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/ValueCodeGeneratorDelegates.java @@ -30,11 +30,12 @@ import java.util.TreeMap; import java.util.TreeSet; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.ValueCodeGenerator.Delegate; import org.springframework.core.ResolvableType; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.CodeBlock.Builder; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -94,8 +95,7 @@ public abstract class ValueCodeGeneratorDelegates { @Override @SuppressWarnings("unchecked") - @Nullable - public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { if (this.collectionType.isInstance(value)) { T collection = (T) value; if (collection.isEmpty()) { @@ -136,8 +136,7 @@ public abstract class ValueCodeGeneratorDelegates { private static final CodeBlock EMPTY_RESULT = CodeBlock.of("$T.emptyMap()", Collections.class); @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object value) { if (value instanceof Map map) { if (map.isEmpty()) { return EMPTY_RESULT; @@ -154,8 +153,7 @@ public abstract class ValueCodeGeneratorDelegates { * @return the code that represents the specified map or {@code null} if * the specified map is not supported. */ - @Nullable - protected CodeBlock generateMapCode(ValueCodeGenerator valueCodeGenerator, Map map) { + protected @Nullable CodeBlock generateMapCode(ValueCodeGenerator valueCodeGenerator, Map map) { map = orderForCodeConsistency(map); boolean useOfEntries = map.size() > 10; CodeBlock.Builder code = CodeBlock.builder(); @@ -209,8 +207,7 @@ public abstract class ValueCodeGeneratorDelegates { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value instanceof Boolean || value instanceof Integer) { return CodeBlock.of("$L", value); } @@ -252,8 +249,7 @@ public abstract class ValueCodeGeneratorDelegates { private static class StringDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value instanceof String) { return CodeBlock.of("$S", value); } @@ -268,8 +264,7 @@ public abstract class ValueCodeGeneratorDelegates { private static class CharsetDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value instanceof Charset charset) { return CodeBlock.of("$T.forName($S)", Charset.class, charset.name()); } @@ -284,8 +279,7 @@ public abstract class ValueCodeGeneratorDelegates { private static class EnumDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value instanceof Enum enumValue) { return CodeBlock.of("$T.$L", enumValue.getDeclaringClass(), enumValue.name()); @@ -301,8 +295,7 @@ public abstract class ValueCodeGeneratorDelegates { private static class ClassDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value instanceof Class clazz) { return CodeBlock.of("$T.class", ClassUtils.getUserClass(clazz)); } @@ -317,8 +310,7 @@ public abstract class ValueCodeGeneratorDelegates { private static class ResolvableTypeDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value instanceof ResolvableType resolvableType) { return generateCode(resolvableType, false); } @@ -360,8 +352,7 @@ public abstract class ValueCodeGeneratorDelegates { private static class ArrayDelegate implements Delegate { @Override - @Nullable - public CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { + public @Nullable CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { if (value.getClass().isArray()) { Stream elements = Arrays.stream(ObjectUtils.toObjectArray(value)) .map(codeGenerator::generateCode); diff --git a/spring-core/src/main/java/org/springframework/aot/generate/package-info.java b/spring-core/src/main/java/org/springframework/aot/generate/package-info.java index c6c380a8e2..b85a083bf3 100644 --- a/spring-core/src/main/java/org/springframework/aot/generate/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/generate/package-info.java @@ -2,9 +2,7 @@ * Support classes for components that contribute generated code equivalent to a * runtime behavior. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.generate; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/AbstractTypeReference.java b/spring-core/src/main/java/org/springframework/aot/hint/AbstractTypeReference.java index 77c7834167..a70ecfcd6c 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/AbstractTypeReference.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/AbstractTypeReference.java @@ -18,7 +18,7 @@ package org.springframework.aot.hint; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Base {@link TypeReference} implementation that ensures consistent behaviour @@ -34,8 +34,7 @@ public abstract class AbstractTypeReference implements TypeReference { private final String simpleName; - @Nullable - private final TypeReference enclosingType; + private final @Nullable TypeReference enclosingType; protected AbstractTypeReference(String packageName, String simpleName, @Nullable TypeReference enclosingType) { @@ -63,9 +62,8 @@ public abstract class AbstractTypeReference implements TypeReference { return this.simpleName; } - @Nullable @Override - public TypeReference getEnclosingType() { + public @Nullable TypeReference getEnclosingType() { return this.enclosingType; } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java index 00d258cc23..3f60d79bc5 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/BindingReflectionHintsRegistrar.java @@ -29,13 +29,13 @@ import java.util.function.Consumer; import kotlin.jvm.JvmClassMappingKt; import kotlin.reflect.KClass; +import org.jspecify.annotations.Nullable; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ConditionalHint.java b/spring-core/src/main/java/org/springframework/aot/hint/ConditionalHint.java index c9784ef592..a19bc26bf6 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ConditionalHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ConditionalHint.java @@ -16,7 +16,8 @@ package org.springframework.aot.hint; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -33,8 +34,7 @@ public interface ConditionalHint { * {@code null} if this hint should always been applied. * @return the reachable type, if any */ - @Nullable - TypeReference getReachableType(); + @Nullable TypeReference getReachableType(); /** * Whether the condition described for this hint is met. If it is not, diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java b/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java index 5d0c3a4d26..2653774976 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ExecutableHint.java @@ -24,7 +24,8 @@ import java.util.List; import java.util.function.Consumer; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -113,8 +114,7 @@ public final class ExecutableHint extends MemberHint implements Comparable parameterTypes; - @Nullable - private ExecutableMode mode; + private @Nullable ExecutableMode mode; Builder(String name, List parameterTypes) { diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ExecutableMode.java b/spring-core/src/main/java/org/springframework/aot/hint/ExecutableMode.java index 2de9e84c44..c4e0a03de0 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ExecutableMode.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ExecutableMode.java @@ -18,7 +18,7 @@ package org.springframework.aot.hint; import java.lang.reflect.Executable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represent the need of reflection for a given {@link Executable}. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/JavaSerializationHint.java b/spring-core/src/main/java/org/springframework/aot/hint/JavaSerializationHint.java index 8f41d18f51..46bdf6c091 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/JavaSerializationHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/JavaSerializationHint.java @@ -20,7 +20,7 @@ package org.springframework.aot.hint; import java.io.Serializable; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A hint that describes the need for Java serialization at runtime. @@ -32,8 +32,7 @@ public final class JavaSerializationHint implements ConditionalHint { private final TypeReference type; - @Nullable - private final TypeReference reachableType; + private final @Nullable TypeReference reachableType; JavaSerializationHint(Builder builder) { @@ -51,8 +50,7 @@ public final class JavaSerializationHint implements ConditionalHint { } @Override - @Nullable - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -75,8 +73,7 @@ public final class JavaSerializationHint implements ConditionalHint { private final TypeReference type; - @Nullable - private TypeReference reachableType; + private @Nullable TypeReference reachableType; Builder(TypeReference type) { this.type = type; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/JdkProxyHint.java b/spring-core/src/main/java/org/springframework/aot/hint/JdkProxyHint.java index 4310ab5a4f..b9ddfec425 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/JdkProxyHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/JdkProxyHint.java @@ -22,7 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A hint that describes the need for a JDK interface-based {@link Proxy}. @@ -35,8 +35,7 @@ public final class JdkProxyHint implements ConditionalHint { private final List proxiedInterfaces; - @Nullable - private final TypeReference reachableType; + private final @Nullable TypeReference reachableType; private JdkProxyHint(Builder builder) { @@ -71,9 +70,8 @@ public final class JdkProxyHint implements ConditionalHint { return this.proxiedInterfaces; } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -97,8 +95,7 @@ public final class JdkProxyHint implements ConditionalHint { private final LinkedList proxiedInterfaces; - @Nullable - private TypeReference reachableType; + private @Nullable TypeReference reachableType; Builder() { this.proxiedInterfaces = new LinkedList<>(); diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java index d16778dac9..e66aaec411 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionHints.java @@ -26,8 +26,9 @@ import java.util.Map; import java.util.function.Consumer; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.TypeHint.Builder; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -59,8 +60,7 @@ public class ReflectionHints { * @param type the type to inspect * @return the reflection hints for this type, or {@code null} */ - @Nullable - public TypeHint getTypeHint(TypeReference type) { + public @Nullable TypeHint getTypeHint(TypeReference type) { Builder typeHintBuilder = this.types.get(type); return (typeHintBuilder != null ? typeHintBuilder.build() : null); } @@ -70,8 +70,7 @@ public class ReflectionHints { * @param type the type to inspect * @return the reflection hints for this type, or {@code null} */ - @Nullable - public TypeHint getTypeHint(Class type) { + public @Nullable TypeHint getTypeHint(Class type) { return getTypeHint(TypeReference.of(type)); } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java index 3e4a26557a..1e55f338b8 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ReflectionTypeReference.java @@ -16,7 +16,8 @@ package org.springframework.aot.hint; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -35,8 +36,7 @@ final class ReflectionTypeReference extends AbstractTypeReference { this.type = type; } - @Nullable - private static TypeReference getEnclosingClass(Class type) { + private static @Nullable TypeReference getEnclosingClass(Class type) { Class candidate = (type.isArray() ? type.componentType().getEnclosingClass() : type.getEnclosingClass()); return (candidate != null ? new ReflectionTypeReference(candidate) : null); diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ResourceBundleHint.java b/spring-core/src/main/java/org/springframework/aot/hint/ResourceBundleHint.java index c6a652260d..e14c9f3cc9 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ResourceBundleHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ResourceBundleHint.java @@ -19,7 +19,7 @@ package org.springframework.aot.hint; import java.util.Objects; import java.util.ResourceBundle; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A hint that describes the need to access a {@link ResourceBundle}. @@ -32,8 +32,7 @@ public final class ResourceBundleHint implements ConditionalHint { private final String baseName; - @Nullable - private final TypeReference reachableType; + private final @Nullable TypeReference reachableType; ResourceBundleHint(Builder builder) { @@ -49,9 +48,8 @@ public final class ResourceBundleHint implements ConditionalHint { return this.baseName; } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -74,8 +72,7 @@ public final class ResourceBundleHint implements ConditionalHint { private String baseName; - @Nullable - private TypeReference reachableType; + private @Nullable TypeReference reachableType; Builder(String baseName) { this.baseName = baseName; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ResourceHints.java b/spring-core/src/main/java/org/springframework/aot/hint/ResourceHints.java index 490dd257f4..021bf7fe20 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ResourceHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ResourceHints.java @@ -24,9 +24,10 @@ import java.util.Set; import java.util.function.Consumer; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Gather the need for resources available at runtime. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHint.java b/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHint.java index b403e7d4df..5dda53db96 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHint.java @@ -18,7 +18,8 @@ package org.springframework.aot.hint; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; @@ -58,8 +59,7 @@ public final class ResourcePatternHint implements ConditionalHint { private final String pattern; - @Nullable - private final TypeReference reachableType; + private final @Nullable TypeReference reachableType; ResourcePatternHint(String pattern, @Nullable TypeReference reachableType) { @@ -86,9 +86,8 @@ public final class ResourcePatternHint implements ConditionalHint { return PATH_MATCHER.match(this.pattern, path); } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java b/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java index 952c441392..d9b2c8bcd3 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/ResourcePatternHints.java @@ -22,7 +22,7 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A collection of {@link ResourcePatternHint} describing whether resources should diff --git a/spring-core/src/main/java/org/springframework/aot/hint/RuntimeHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/RuntimeHintsRegistrar.java index 742be48a41..c84f6410cb 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/RuntimeHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/RuntimeHintsRegistrar.java @@ -16,7 +16,7 @@ package org.springframework.aot.hint; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Contract for registering {@link RuntimeHints} based on the {@link ClassLoader} diff --git a/spring-core/src/main/java/org/springframework/aot/hint/SerializationHints.java b/spring-core/src/main/java/org/springframework/aot/hint/SerializationHints.java index 70b9df4284..bca351b449 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/SerializationHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/SerializationHints.java @@ -22,7 +22,7 @@ import java.util.Set; import java.util.function.Consumer; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Gather the need for Java serialization at runtime. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/SimpleTypeReference.java b/spring-core/src/main/java/org/springframework/aot/hint/SimpleTypeReference.java index 62a3ff9978..98d7d03e34 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/SimpleTypeReference.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/SimpleTypeReference.java @@ -20,7 +20,8 @@ import java.util.List; import javax.lang.model.SourceVersion; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -34,8 +35,7 @@ final class SimpleTypeReference extends AbstractTypeReference { private static final List PRIMITIVE_NAMES = List.of("boolean", "byte", "short", "int", "long", "char", "float", "double", "void"); - @Nullable - private String canonicalName; + private @Nullable String canonicalName; SimpleTypeReference(String packageName, String simpleName, @Nullable TypeReference enclosingType) { super(packageName, simpleName, enclosingType); diff --git a/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java b/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java index 70b7b7ea0e..4502e502f5 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/TypeHint.java @@ -27,7 +27,8 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -42,8 +43,7 @@ public final class TypeHint implements ConditionalHint { private final TypeReference type; - @Nullable - private final TypeReference reachableType; + private final @Nullable TypeReference reachableType; private final Set fields; @@ -83,9 +83,8 @@ public final class TypeHint implements ConditionalHint { return this.type; } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -144,8 +143,7 @@ public final class TypeHint implements ConditionalHint { private final TypeReference type; - @Nullable - private TypeReference reachableType; + private @Nullable TypeReference reachableType; private final Set fields = new HashSet<>(); diff --git a/spring-core/src/main/java/org/springframework/aot/hint/TypeReference.java b/spring-core/src/main/java/org/springframework/aot/hint/TypeReference.java index 6bc2c8cf28..809b2970dd 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/TypeReference.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/TypeReference.java @@ -19,7 +19,7 @@ package org.springframework.aot.hint; import java.util.Arrays; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Type abstraction that can be used to refer to types that are not available as @@ -62,8 +62,7 @@ public interface TypeReference extends Comparable { * does not have an enclosing type. * @return the enclosing type, if any */ - @Nullable - TypeReference getEnclosingType(); + @Nullable TypeReference getEnclosingType(); /** * Create an instance based on the specified type. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionReflectiveProcessor.java b/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionReflectiveProcessor.java index 129744a1c5..e3983f5112 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionReflectiveProcessor.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/annotation/RegisterReflectionReflectiveProcessor.java @@ -24,11 +24,11 @@ import java.util.Objects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -80,8 +80,7 @@ public class RegisterReflectionReflectiveProcessor implements ReflectiveProcesso hints.registerType(target, type -> type.withMembers(memberCategories)); } - @Nullable - private Class loadClass(String className) { + private @Nullable Class loadClass(String className) { try { return ClassUtils.forName(className, getClass().getClassLoader()); } diff --git a/spring-core/src/main/java/org/springframework/aot/hint/annotation/package-info.java b/spring-core/src/main/java/org/springframework/aot/hint/annotation/package-info.java index fac7035752..263ff633eb 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/annotation/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/annotation/package-info.java @@ -1,9 +1,7 @@ /** * Annotation support for runtime hints. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.hint.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/package-info.java b/spring-core/src/main/java/org/springframework/aot/hint/package-info.java index 19bccf9a7f..d8448d481a 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/package-info.java @@ -2,9 +2,7 @@ * Support for registering the need for reflection, resources, java * serialization and proxies at runtime. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.hint; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/predicate/ReflectionHintsPredicates.java b/spring-core/src/main/java/org/springframework/aot/hint/predicate/ReflectionHintsPredicates.java index 69ba572e35..47dc61429f 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/predicate/ReflectionHintsPredicates.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/predicate/ReflectionHintsPredicates.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Set; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableHint; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.MemberCategory; @@ -34,7 +36,6 @@ import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeReference; import org.springframework.core.MethodIntrospector; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -203,8 +204,7 @@ public class ReflectionHintsPredicates { this.type = type; } - @Nullable - private TypeHint getTypeHint(RuntimeHints hints) { + private @Nullable TypeHint getTypeHint(RuntimeHints hints) { return hints.reflection().getTypeHint(this.type); } @@ -373,8 +373,7 @@ public class ReflectionHintsPredicates { private final Field field; - @Nullable - private ExecutableMode executableMode; + private @Nullable ExecutableMode executableMode; FieldHintPredicate(Field field) { this.field = field; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/predicate/package-info.java b/spring-core/src/main/java/org/springframework/aot/hint/predicate/package-info.java index 8d6d410e07..5bb1f8bf6c 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/predicate/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/predicate/package-info.java @@ -1,9 +1,7 @@ /** * Predicate support for runtime hints. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.hint.predicate; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/FilePatternResourceHintsRegistrar.java b/spring-core/src/main/java/org/springframework/aot/hint/support/FilePatternResourceHintsRegistrar.java index 22119ee762..a7f9bfc99d 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/FilePatternResourceHintsRegistrar.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/FilePatternResourceHintsRegistrar.java @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ResourceHints; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java index ed820c4a15..2f3137155a 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/KotlinDetectorRuntimeHints.java @@ -16,10 +16,11 @@ package org.springframework.aot.hint.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for {@link org.springframework.core.KotlinDetector}. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java index c086c2c7ec..b477cbce80 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/ObjectToObjectConverterRuntimeHints.java @@ -20,13 +20,14 @@ import java.time.LocalDate; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for popular conventions in diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java index 371812e06c..60f1203c7c 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/PathMatchingResourcePatternResolverRuntimeHints.java @@ -16,11 +16,12 @@ package org.springframework.aot.hint.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} for {@link PathMatchingResourcePatternResolver}. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java index 8081223c52..d43cff56ae 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringFactoriesLoaderRuntimeHints.java @@ -21,13 +21,13 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.core.log.LogMessage; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -90,8 +90,7 @@ class SpringFactoriesLoaderRuntimeHints implements RuntimeHintsRegistrar { } } - @Nullable - private Class resolveClassName(ClassLoader classLoader, String factoryClassName) { + private @Nullable Class resolveClassName(ClassLoader classLoader, String factoryClassName) { try { Class clazz = ClassUtils.resolveClassName(factoryClassName, classLoader); // Force resolution of all constructors to cache diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringPropertiesRuntimeHints.java b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringPropertiesRuntimeHints.java index 50e61caa4d..e6cd63d476 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/SpringPropertiesRuntimeHints.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/SpringPropertiesRuntimeHints.java @@ -16,9 +16,10 @@ package org.springframework.aot.hint.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for {@link org.springframework.core.SpringProperties}. diff --git a/spring-core/src/main/java/org/springframework/aot/hint/support/package-info.java b/spring-core/src/main/java/org/springframework/aot/hint/support/package-info.java index 87ce610cfe..02331601b1 100644 --- a/spring-core/src/main/java/org/springframework/aot/hint/support/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/hint/support/package-info.java @@ -1,9 +1,7 @@ /** * Convenience classes for using runtime hints. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.hint.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/FileNativeConfigurationWriter.java b/spring-core/src/main/java/org/springframework/aot/nativex/FileNativeConfigurationWriter.java index 22a0cd5c9d..2ddc0dc7a3 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/FileNativeConfigurationWriter.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/FileNativeConfigurationWriter.java @@ -23,7 +23,7 @@ import java.io.Writer; import java.nio.file.Path; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A {@link NativeConfigurationWriter} implementation that writes the @@ -38,11 +38,9 @@ public class FileNativeConfigurationWriter extends NativeConfigurationWriter { private final Path basePath; - @Nullable - private final String groupId; + private final @Nullable String groupId; - @Nullable - private final String artifactId; + private final @Nullable String artifactId; public FileNativeConfigurationWriter(Path basePath) { this(basePath, null, null); diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/ReflectionHintsAttributes.java b/spring-core/src/main/java/org/springframework/aot/nativex/ReflectionHintsAttributes.java index 468a9d51fb..db246f0a2d 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/ReflectionHintsAttributes.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/ReflectionHintsAttributes.java @@ -26,6 +26,8 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ConditionalHint; import org.springframework.aot.hint.ExecutableHint; import org.springframework.aot.hint.ExecutableMode; @@ -36,7 +38,6 @@ import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * Collect {@link ReflectionHints} as map attributes ready for JSON serialization for the GraalVM diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/feature/package-info.java b/spring-core/src/main/java/org/springframework/aot/nativex/feature/package-info.java index db71c8c1a6..87aa20315f 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/feature/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/feature/package-info.java @@ -1,9 +1,7 @@ /** * GraalVM native image features, not part of Spring Framework public API. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.nativex.feature; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/package-info.java b/spring-core/src/main/java/org/springframework/aot/nativex/package-info.java index 4cbc506572..056c804af7 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/package-info.java @@ -1,9 +1,7 @@ /** * Support for generating GraalVM native configuration from runtime hints. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.nativex; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/nativex/substitution/package-info.java b/spring-core/src/main/java/org/springframework/aot/nativex/substitution/package-info.java index dca0e7c560..d11c6ea3bf 100644 --- a/spring-core/src/main/java/org/springframework/aot/nativex/substitution/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/nativex/substitution/package-info.java @@ -1,9 +1,7 @@ /** * GraalVM native image substitutions, not part of Spring Framework public API. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot.nativex.substitution; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/aot/package-info.java b/spring-core/src/main/java/org/springframework/aot/package-info.java index 36bce0751c..4ca9a01ba1 100644 --- a/spring-core/src/main/java/org/springframework/aot/package-info.java +++ b/spring-core/src/main/java/org/springframework/aot/package-info.java @@ -1,9 +1,7 @@ /** * Core package for Spring AOT infrastructure. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.aot; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 3347e4a4e3..721ce6d610 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessor.java @@ -18,7 +18,8 @@ package org.springframework.core; import java.util.function.Function; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -48,8 +49,7 @@ public interface AttributeAccessor { * @param name the unique attribute key * @return the current value of the attribute, if any */ - @Nullable - Object getAttribute(String name); + @Nullable Object getAttribute(String name); /** * Compute a new value for the attribute identified by {@code name} if @@ -89,8 +89,7 @@ public interface AttributeAccessor { * @param name the unique attribute key * @return the last value of the attribute, if any */ - @Nullable - Object removeAttribute(String name); + @Nullable Object removeAttribute(String name); /** * Return {@code true} if the attribute identified by {@code name} exists. diff --git a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java index 87e1975a82..c1645140b7 100644 --- a/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java +++ b/spring-core/src/main/java/org/springframework/core/AttributeAccessorSupport.java @@ -21,7 +21,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Function; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -55,8 +56,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { Assert.notNull(name, "Name must not be null"); return this.attributes.get(name); } @@ -73,8 +73,7 @@ public abstract class AttributeAccessorSupport implements AttributeAccessor, Ser } @Override - @Nullable - public Object removeAttribute(String name) { + public @Nullable Object removeAttribute(String name) { Assert.notNull(name, "Name must not be null"); return this.attributes.remove(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 a5c6662025..934f040e19 100644 --- a/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java +++ b/spring-core/src/main/java/org/springframework/core/BridgeMethodResolver.java @@ -24,7 +24,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -148,8 +149,7 @@ public final class BridgeMethodResolver { * @param bridgeMethod the bridge method * @return the bridged method, or {@code null} if none found */ - @Nullable - private static Method searchCandidates(List candidateMethods, Method bridgeMethod) { + private static @Nullable Method searchCandidates(List candidateMethods, Method bridgeMethod) { if (candidateMethods.isEmpty()) { return null; } @@ -215,8 +215,7 @@ public final 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) { + private static @Nullable Method findGenericDeclaration(Method bridgeMethod) { if (!bridgeMethod.isBridge()) { return bridgeMethod; } @@ -235,8 +234,7 @@ public final class BridgeMethodResolver { return searchInterfaces(interfaces, bridgeMethod); } - @Nullable - private static Method searchInterfaces(Class[] interfaces, Method bridgeMethod) { + private static @Nullable Method searchInterfaces(Class[] interfaces, Method bridgeMethod) { for (Class ifc : interfaces) { Method method = searchForMatch(ifc, bridgeMethod); if (method != null && !method.isBridge()) { @@ -257,8 +255,7 @@ public final 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) { + private static @Nullable Method searchForMatch(Class type, Method bridgeMethod) { try { return type.getDeclaredMethod(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 83af2d54dd..ebdc5b7cd2 100644 --- a/spring-core/src/main/java/org/springframework/core/CollectionFactory.java +++ b/spring-core/src/main/java/org/springframework/core/CollectionFactory.java @@ -36,7 +36,8 @@ import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -349,8 +350,7 @@ public final class CollectionFactory { public static Properties createStringAdaptingProperties() { return new SortedProperties(false) { @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { Object value = get(key); return (value != null ? value.toString() : null); } 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 eb845e4797..60425774d5 100644 --- a/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java +++ b/spring-core/src/main/java/org/springframework/core/ConfigurableObjectInputStream.java @@ -22,7 +22,8 @@ import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectStreamClass; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -35,8 +36,7 @@ import org.springframework.util.ClassUtils; */ public class ConfigurableObjectInputStream extends ObjectInputStream { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final boolean acceptProxyClasses; @@ -144,8 +144,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 { + protected @Nullable 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 7e794fe4d2..e7456bef79 100644 --- a/spring-core/src/main/java/org/springframework/core/Constants.java +++ b/spring-core/src/main/java/org/springframework/core/Constants.java @@ -23,7 +23,8 @@ import java.util.Locale; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; 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 eae2f796fb..88aeba5f02 100644 --- a/spring-core/src/main/java/org/springframework/core/Conventions.java +++ b/spring-core/src/main/java/org/springframework/core/Conventions.java @@ -21,7 +21,8 @@ import java.lang.reflect.Proxy; import java.util.Collection; import java.util.Iterator; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; diff --git a/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java b/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java index 48efd73d74..c336fe30ed 100644 --- a/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java +++ b/spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java @@ -41,11 +41,11 @@ import kotlinx.coroutines.GlobalScope; import kotlinx.coroutines.flow.Flow; import kotlinx.coroutines.reactor.MonoKt; import kotlinx.coroutines.reactor.ReactorFlowKt; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; diff --git a/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java b/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java index 787c1e14e3..24a1f60034 100644 --- a/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java +++ b/spring-core/src/main/java/org/springframework/core/DecoratingClassLoader.java @@ -19,7 +19,8 @@ package org.springframework.core; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 a5e0d74c65..e849a594ea 100644 --- a/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java +++ b/spring-core/src/main/java/org/springframework/core/GenericTypeResolver.java @@ -25,7 +25,8 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -90,8 +91,7 @@ public final 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 genericType) { + public static @Nullable Class resolveReturnTypeArgument(Method method, Class genericType) { Assert.notNull(method, "Method must not be null"); ResolvableType resolvableType = ResolvableType.forMethodReturnType(method).as(genericType); if (!resolvableType.hasGenerics() || resolvableType.getType() instanceof WildcardType) { @@ -108,8 +108,7 @@ public final class GenericTypeResolver { * @param genericType 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 genericType) { + public static @Nullable Class resolveTypeArgument(Class clazz, Class genericType) { ResolvableType resolvableType = ResolvableType.forClass(clazz).as(genericType); if (!resolvableType.hasGenerics()) { return null; @@ -117,8 +116,7 @@ public final class GenericTypeResolver { return getSingleGeneric(resolvableType); } - @Nullable - private static Class getSingleGeneric(ResolvableType resolvableType) { + private static @Nullable Class getSingleGeneric(ResolvableType resolvableType) { Assert.isTrue(resolvableType.getGenerics().length == 1, () -> "Expected 1 type argument on generic interface [" + resolvableType + "] but found " + resolvableType.getGenerics().length); @@ -135,8 +133,7 @@ public final 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 genericType) { + public static Class @Nullable [] resolveTypeArguments(Class clazz, Class genericType) { ResolvableType type = ResolvableType.forClass(clazz).as(genericType); if (!type.hasGenerics() || !type.hasResolvableGenerics()) { return null; @@ -295,8 +292,7 @@ public final class GenericTypeResolver { } @Override - @Nullable - public ResolvableType resolveVariable(TypeVariable variable) { + public @Nullable ResolvableType resolveVariable(TypeVariable variable) { Type type = this.typeVariableMap.get(variable); return (type != null ? ResolvableType.forType(type) : null); } diff --git a/spring-core/src/main/java/org/springframework/core/KotlinDetector.java b/spring-core/src/main/java/org/springframework/core/KotlinDetector.java index 696ee372b0..ad9976ce93 100644 --- a/spring-core/src/main/java/org/springframework/core/KotlinDetector.java +++ b/spring-core/src/main/java/org/springframework/core/KotlinDetector.java @@ -19,7 +19,8 @@ package org.springframework.core; import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -32,11 +33,9 @@ import org.springframework.util.ClassUtils; @SuppressWarnings("unchecked") public abstract class KotlinDetector { - @Nullable - private static final Class kotlinMetadata; + private static final @Nullable Class kotlinMetadata; - @Nullable - private static final Class kotlinJvmInline; + private static final @Nullable Class kotlinJvmInline; // For ConstantFieldFeature compliance, otherwise could be deduced from kotlinMetadata private static final boolean kotlinPresent; diff --git a/spring-core/src/main/java/org/springframework/core/KotlinReflectionParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/KotlinReflectionParameterNameDiscoverer.java index 485e289444..fe7faca797 100644 --- a/spring-core/src/main/java/org/springframework/core/KotlinReflectionParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/KotlinReflectionParameterNameDiscoverer.java @@ -23,8 +23,7 @@ import java.util.List; import kotlin.reflect.KFunction; import kotlin.reflect.KParameter; import kotlin.reflect.jvm.ReflectJvmMapping; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link ParameterNameDiscoverer} implementation which uses Kotlin's reflection facilities @@ -41,8 +40,7 @@ import org.springframework.lang.Nullable; public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDiscoverer { @Override - @Nullable - public String[] getParameterNames(Method method) { + public @Nullable String @Nullable [] getParameterNames(Method method) { if (!KotlinDetector.isKotlinType(method.getDeclaringClass())) { return null; } @@ -57,8 +55,7 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis } @Override - @Nullable - public String[] getParameterNames(Constructor ctor) { + public @Nullable String @Nullable [] getParameterNames(Constructor ctor) { if (ctor.getDeclaringClass().isEnum() || !KotlinDetector.isKotlinType(ctor.getDeclaringClass())) { return null; } @@ -72,8 +69,7 @@ public class KotlinReflectionParameterNameDiscoverer implements ParameterNameDis } } - @Nullable - private String[] getParameterNames(List parameters) { + private @Nullable String @Nullable [] getParameterNames(List parameters) { String[] parameterNames = parameters.stream() // Extension receivers of extension methods must be included as they appear as normal method parameters in Java .filter(p -> KParameter.Kind.VALUE.equals(p.getKind()) || KParameter.Kind.EXTENSION_RECEIVER.equals(p.getKind())) 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 b7a450e49e..b7efe2ab2d 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodClassKey.java +++ b/spring-core/src/main/java/org/springframework/core/MethodClassKey.java @@ -18,7 +18,8 @@ package org.springframework.core; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -33,8 +34,7 @@ public final class MethodClassKey implements Comparable { private final Method method; - @Nullable - private final Class targetClass; + private final @Nullable Class 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 f1ceac4a7c..91f9e45347 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java +++ b/spring-core/src/main/java/org/springframework/core/MethodIntrospector.java @@ -23,7 +23,8 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -155,8 +156,7 @@ public final 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); + @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 fd2d666fe1..61860d73e8 100644 --- a/spring-core/src/main/java/org/springframework/core/MethodParameter.java +++ b/spring-core/src/main/java/org/springframework/core/MethodParameter.java @@ -38,8 +38,8 @@ import kotlin.Unit; import kotlin.reflect.KFunction; import kotlin.reflect.KParameter; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -71,36 +71,27 @@ public class MethodParameter { private final int parameterIndex; - @Nullable - private volatile Parameter parameter; + private volatile @Nullable Parameter parameter; private int nestingLevel; /** Map from Integer level to Integer type index. */ - @Nullable - Map typeIndexesPerLevel; + @Nullable Map typeIndexesPerLevel; /** The containing class. Could also be supplied by overriding {@link #getContainingClass()} */ - @Nullable - private volatile Class containingClass; + private volatile @Nullable Class containingClass; - @Nullable - private volatile Class parameterType; + private volatile @Nullable Class parameterType; - @Nullable - private volatile Type genericParameterType; + private volatile @Nullable Type genericParameterType; - @Nullable - private volatile Annotation[] parameterAnnotations; + private volatile Annotation @Nullable [] parameterAnnotations; - @Nullable - private volatile ParameterNameDiscoverer parameterNameDiscoverer; + private volatile @Nullable ParameterNameDiscoverer parameterNameDiscoverer; - @Nullable - volatile String parameterName; + volatile @Nullable String parameterName; - @Nullable - private volatile MethodParameter nestedMethodParameter; + private volatile @Nullable MethodParameter nestedMethodParameter; /** @@ -197,8 +188,7 @@ public class MethodParameter { *

Note: Either Method or Constructor is available. * @return the Method, or {@code null} if none */ - @Nullable - public Method getMethod() { + public @Nullable Method getMethod() { return (this.executable instanceof Method method ? method : null); } @@ -207,8 +197,7 @@ public class MethodParameter { *

Note: Either Method or Constructor is available. * @return the Constructor, or {@code null} if none */ - @Nullable - public Constructor getConstructor() { + public @Nullable Constructor getConstructor() { return (this.executable instanceof Constructor constructor ? constructor : null); } @@ -331,8 +320,7 @@ public class MethodParameter { * if none specified (indicating the default type index) * @see #getNestingLevel() */ - @Nullable - public Integer getTypeIndexForCurrentLevel() { + public @Nullable Integer getTypeIndexForCurrentLevel() { return getTypeIndexForLevel(this.nestingLevel); } @@ -342,8 +330,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) { + public @Nullable Integer getTypeIndexForLevel(int nestingLevel) { return getTypeIndexesPerLevel().get(nestingLevel); } @@ -616,8 +603,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) { + public @Nullable A getMethodAnnotation(Class annotationType) { A annotation = getAnnotatedElement().getAnnotation(annotationType); return (annotation != null ? adaptAnnotation(annotation) : null); } @@ -669,8 +655,7 @@ public class MethodParameter { * @return the annotation object, or {@code null} if not found */ @SuppressWarnings("unchecked") - @Nullable - public A getParameterAnnotation(Class annotationType) { + public @Nullable A getParameterAnnotation(Class annotationType) { Annotation[] anns = getParameterAnnotations(); for (Annotation ann : anns) { if (annotationType.isInstance(ann)) { @@ -706,8 +691,7 @@ public class MethodParameter { * {@link #initParameterNameDiscovery ParameterNameDiscoverer} * has been set to begin with) */ - @Nullable - public String getParameterName() { + public @Nullable String getParameterName() { if (this.parameterIndex < 0) { return null; } @@ -882,8 +866,7 @@ public class MethodParameter { */ private static class FieldAwareConstructorParameter extends MethodParameter { - @Nullable - private volatile Annotation[] combinedAnnotations; + private volatile Annotation @Nullable [] combinedAnnotations; public FieldAwareConstructorParameter(Constructor constructor, int parameterIndex, String fieldName) { super(constructor, parameterIndex); diff --git a/spring-core/src/main/java/org/springframework/core/NativeDetector.java b/spring-core/src/main/java/org/springframework/core/NativeDetector.java index 46d72b7bdd..87f2f83c0f 100644 --- a/spring-core/src/main/java/org/springframework/core/NativeDetector.java +++ b/spring-core/src/main/java/org/springframework/core/NativeDetector.java @@ -16,7 +16,7 @@ package org.springframework.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A common delegate for detecting a GraalVM native image environment. @@ -27,8 +27,7 @@ import org.springframework.lang.Nullable; public abstract class NativeDetector { // See https://github.com/oracle/graal/blob/master/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/ImageInfo.java - @Nullable - private static final String imageCode = System.getProperty("org.graalvm.nativeimage.imagecode"); + private static final @Nullable String imageCode = System.getProperty("org.graalvm.nativeimage.imagecode"); private static final boolean inNativeImage = (imageCode != 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 dcf25b5f5c..1195c04f09 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedCheckedException.java +++ b/spring-core/src/main/java/org/springframework/core/NestedCheckedException.java @@ -16,7 +16,7 @@ package org.springframework.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Handy class for wrapping checked {@code Exceptions} with a root cause. @@ -60,8 +60,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() { + public @Nullable 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 a2a596eacf..eba2740602 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java +++ b/spring-core/src/main/java/org/springframework/core/NestedExceptionUtils.java @@ -16,7 +16,7 @@ package org.springframework.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Helper class for implementing exception classes which are capable of @@ -41,8 +41,7 @@ public abstract class NestedExceptionUtils { * with selective inclusion of cause messages */ @Deprecated(since = "6.0") - @Nullable - public static String buildMessage(@Nullable String message, @Nullable Throwable cause) { + public static @Nullable String buildMessage(@Nullable String message, @Nullable Throwable cause) { if (cause == null) { return message; } @@ -60,8 +59,7 @@ public abstract class NestedExceptionUtils { * @return the innermost exception, or {@code null} if none * @since 4.3.9 */ - @Nullable - public static Throwable getRootCause(@Nullable Throwable original) { + public static @Nullable Throwable getRootCause(@Nullable 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 bd6afe4d14..0a50f34b2a 100644 --- a/spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java +++ b/spring-core/src/main/java/org/springframework/core/NestedRuntimeException.java @@ -16,7 +16,7 @@ package org.springframework.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Handy class for wrapping runtime {@code Exceptions} with a root cause. @@ -61,8 +61,7 @@ public abstract class NestedRuntimeException extends RuntimeException { * @return the innermost exception, or {@code null} if none * @since 2.0 */ - @Nullable - public Throwable getRootCause() { + public @Nullable 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 2724a414cf..43b8409e8e 100644 --- a/spring-core/src/main/java/org/springframework/core/OrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/OrderComparator.java @@ -20,7 +20,8 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -140,8 +141,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) { + protected @Nullable Integer findOrder(Object obj) { return (obj instanceof Ordered ordered ? ordered.getOrder() : null); } @@ -156,8 +156,7 @@ public class OrderComparator implements Comparator { * @return the priority value, or {@code null} if none * @since 4.1 */ - @Nullable - public Integer getPriority(Object obj) { + public @Nullable Integer getPriority(Object obj) { return null; } @@ -222,8 +221,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); + @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 63aeab629a..15c8c7cca9 100644 --- a/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java +++ b/spring-core/src/main/java/org/springframework/core/OverridingClassLoader.java @@ -19,7 +19,8 @@ package org.springframework.core; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.FileCopyUtils; /** @@ -47,8 +48,7 @@ public class OverridingClassLoader extends DecoratingClassLoader { } - @Nullable - private final ClassLoader overrideDelegate; + private final @Nullable ClassLoader overrideDelegate; /** @@ -115,8 +115,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 { + protected @Nullable Class loadClassForOverriding(String name) throws ClassNotFoundException { Class result = findLoadedClass(name); if (result == null) { byte[] bytes = loadBytesForClass(name); @@ -137,8 +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 { + protected byte @Nullable [] loadBytesForClass(String name) throws ClassNotFoundException { InputStream is = openStreamForClass(name); if (is == null) { return null; @@ -161,8 +159,7 @@ public class OverridingClassLoader extends DecoratingClassLoader { * @param name the name of the class * @return the InputStream containing the byte code for the specified class */ - @Nullable - protected InputStream openStreamForClass(String name) { + protected @Nullable InputStream openStreamForClass(String name) { String internalName = name.replace('.', '/') + CLASS_FILE_SUFFIX; return getParent().getResourceAsStream(internalName); } 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 f60d28b637..460327fd1f 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterNameDiscoverer.java @@ -19,7 +19,7 @@ package org.springframework.core; import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to discover parameter names for methods and constructors. @@ -45,8 +45,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); + @Nullable String @Nullable [] getParameterNames(Method method); /** * Return parameter names for a constructor, or {@code null} if they cannot be determined. @@ -57,7 +56,6 @@ 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); + @Nullable String @Nullable [] getParameterNames(Constructor ctor); } diff --git a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java index d9c1361d48..5bd2683e36 100644 --- a/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java +++ b/spring-core/src/main/java/org/springframework/core/ParameterizedTypeReference.java @@ -19,7 +19,8 @@ package org.springframework.core; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java index bb69327833..02eea42306 100644 --- a/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/PrioritizedParameterNameDiscoverer.java @@ -21,7 +21,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link ParameterNameDiscoverer} implementation that tries several discoverer @@ -49,10 +49,9 @@ public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscover @Override - @Nullable - public String[] getParameterNames(Method method) { + public @Nullable String @Nullable [] getParameterNames(Method method) { for (ParameterNameDiscoverer pnd : this.parameterNameDiscoverers) { - String[] result = pnd.getParameterNames(method); + @Nullable String[] result = pnd.getParameterNames(method); if (result != null) { return result; } @@ -61,10 +60,9 @@ public class PrioritizedParameterNameDiscoverer implements ParameterNameDiscover } @Override - @Nullable - public String[] getParameterNames(Constructor ctor) { + public @Nullable String @Nullable [] getParameterNames(Constructor ctor) { for (ParameterNameDiscoverer pnd : this.parameterNameDiscoverers) { - String[] result = pnd.getParameterNames(ctor); + @Nullable String[] result = pnd.getParameterNames(ctor); if (result != null) { return result; } diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java b/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java index 0356f47f59..ee06e4e57b 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapter.java @@ -18,9 +18,9 @@ package org.springframework.core; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 01ffdb9e20..9deb894890 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveAdapterRegistry.java @@ -25,6 +25,7 @@ import java.util.concurrent.CompletionStage; import java.util.concurrent.Flow; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.FlowAdapters; import org.reactivestreams.Publisher; import reactor.adapter.JdkFlowAdapter; @@ -33,7 +34,6 @@ import reactor.blockhound.integration.BlockHoundIntegration; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -56,8 +56,7 @@ import org.springframework.util.ReflectionUtils; */ public class ReactiveAdapterRegistry { - @Nullable - private static volatile ReactiveAdapterRegistry sharedInstance; + private static volatile @Nullable ReactiveAdapterRegistry sharedInstance; private static final boolean reactiveStreamsPresent; @@ -174,8 +173,7 @@ public class ReactiveAdapterRegistry { * Get the adapter for the given reactive type. * @return the corresponding adapter, or {@code null} if none available */ - @Nullable - public ReactiveAdapter getAdapter(Class reactiveType) { + public @Nullable ReactiveAdapter getAdapter(Class reactiveType) { return getAdapter(reactiveType, null); } @@ -188,8 +186,7 @@ public class ReactiveAdapterRegistry { * (i.e. to adapt from; may be {@code null} if the reactive type is specified) * @return the corresponding adapter, or {@code null} if none available */ - @Nullable - public ReactiveAdapter getAdapter(@Nullable Class reactiveType, @Nullable Object source) { + public @Nullable ReactiveAdapter getAdapter(@Nullable Class reactiveType, @Nullable Object source) { if (this.adapters.isEmpty()) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java b/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java index 9d53e023bd..518ef64250 100644 --- a/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/ReactiveTypeDescriptor.java @@ -18,7 +18,8 @@ package org.springframework.core; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -36,8 +37,7 @@ public final class ReactiveTypeDescriptor { private final boolean noValue; - @Nullable - private final Supplier emptySupplier; + private final @Nullable Supplier emptySupplier; private final boolean deferred; 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 d8d4ac98e7..b6428acab8 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableType.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableType.java @@ -34,10 +34,11 @@ import java.util.Map; import java.util.Set; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + 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; @@ -106,38 +107,29 @@ public class ResolvableType implements Serializable { /** * The component type for an array or {@code null} if the type should be deduced. */ - @Nullable - private final ResolvableType componentType; + private final @Nullable ResolvableType componentType; /** * Optional provider for the type. */ - @Nullable - private final TypeProvider typeProvider; + private final @Nullable TypeProvider typeProvider; /** * The {@code VariableResolver} to use or {@code null} if no resolver is available. */ - @Nullable - private final VariableResolver variableResolver; + private final @Nullable VariableResolver variableResolver; - @Nullable - private final Integer hash; + private final @Nullable Integer hash; - @Nullable - private Class resolved; + private @Nullable Class resolved; - @Nullable - private volatile ResolvableType superType; + private volatile @Nullable ResolvableType superType; - @Nullable - private volatile ResolvableType[] interfaces; + private volatile ResolvableType @Nullable [] interfaces; - @Nullable - private volatile ResolvableType[] generics; + private volatile ResolvableType @Nullable [] generics; - @Nullable - private volatile Boolean unresolvableGenerics; + private volatile @Nullable Boolean unresolvableGenerics; /** @@ -212,8 +204,7 @@ public class ResolvableType implements Serializable { * Return the underlying Java {@link Class} being managed, if available; * otherwise {@code null}. */ - @Nullable - public Class getRawClass() { + public @Nullable Class getRawClass() { if (this.type == this.resolved) { return this.resolved; } @@ -759,7 +750,7 @@ public class ResolvableType implements Serializable { * @see #resolveGeneric(int...) * @see #resolveGenerics() */ - public ResolvableType getGeneric(@Nullable int... indexes) { + public ResolvableType getGeneric(int @Nullable ... indexes) { ResolvableType[] generics = getGenerics(); if (indexes == null || indexes.length == 0) { return (generics.length == 0 ? NONE : generics[0]); @@ -870,8 +861,7 @@ public class ResolvableType implements Serializable { * @see #getGeneric(int...) * @see #resolve() */ - @Nullable - public Class resolveGeneric(int... indexes) { + public @Nullable Class resolveGeneric(int... indexes) { return getGeneric(indexes).resolve(); } @@ -888,8 +878,7 @@ public class ResolvableType implements Serializable { * @see #resolveGeneric(int...) * @see #resolveGenerics() */ - @Nullable - public Class resolve() { + public @Nullable Class resolve() { return this.resolved; } @@ -908,8 +897,7 @@ public class ResolvableType implements Serializable { return (this.resolved != null ? this.resolved : fallback); } - @Nullable - private Class resolveClass() { + private @Nullable Class resolveClass() { if (this.type == EmptyType.INSTANCE) { return null; } @@ -953,16 +941,14 @@ public class ResolvableType implements Serializable { return NONE; } - @Nullable - private Type resolveBounds(Type[] bounds) { + private @Nullable Type resolveBounds(Type[] bounds) { if (bounds.length == 0 || bounds[0] == Object.class) { return null; } return bounds[0]; } - @Nullable - private ResolvableType resolveVariable(TypeVariable variable) { + private @Nullable ResolvableType resolveVariable(TypeVariable variable) { if (this.type instanceof TypeVariable) { return resolveType().resolveVariable(variable); } @@ -1062,8 +1048,7 @@ public class ResolvableType implements Serializable { /** * Adapts this {@code ResolvableType} to a {@link VariableResolver}. */ - @Nullable - VariableResolver asVariableResolver() { + @Nullable VariableResolver asVariableResolver() { if (this == NONE) { return null; } @@ -1190,7 +1175,7 @@ public class ResolvableType implements Serializable { * @return a {@code ResolvableType} for the specific class and generics * @see #forClassWithGenerics(Class, Class...) */ - public static ResolvableType forClassWithGenerics(Class clazz, @Nullable ResolvableType... generics) { + public static ResolvableType forClassWithGenerics(Class clazz, @Nullable ResolvableType @Nullable ... generics) { Assert.notNull(clazz, "Class must not be null"); TypeVariable[] variables = clazz.getTypeParameters(); if (generics != null) { @@ -1578,8 +1563,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); + @Nullable ResolvableType resolveVariable(TypeVariable variable); } @@ -1593,8 +1577,7 @@ public class ResolvableType implements Serializable { } @Override - @Nullable - public ResolvableType resolveVariable(TypeVariable variable) { + public @Nullable ResolvableType resolveVariable(TypeVariable variable) { return this.source.resolveVariable(variable); } @@ -1610,16 +1593,15 @@ public class ResolvableType implements Serializable { private final TypeVariable[] variables; - private final ResolvableType[] generics; + private final @Nullable ResolvableType[] generics; - public TypeVariablesVariableResolver(TypeVariable[] variables, ResolvableType[] generics) { + public TypeVariablesVariableResolver(TypeVariable[] variables, @Nullable ResolvableType[] generics) { this.variables = variables; this.generics = generics; } @Override - @Nullable - public ResolvableType resolveVariable(TypeVariable variable) { + public @Nullable ResolvableType resolveVariable(TypeVariable variable) { TypeVariable variableToCompare = SerializableTypeWrapper.unwrap(variable); for (int i = 0; i < this.variables.length; i++) { TypeVariable resolvedVariable = SerializableTypeWrapper.unwrap(this.variables[i]); @@ -1662,8 +1644,7 @@ public class ResolvableType implements Serializable { } @Override - @Nullable - public Type getOwnerType() { + public @Nullable Type getOwnerType() { return null; } @@ -1787,8 +1768,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) { + public static @Nullable WildcardBounds get(ResolvableType type) { ResolvableType candidate = type; while (!(candidate.getType() instanceof WildcardType || candidate.isUnresolvableTypeVariable())) { if (candidate == NONE) { 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 0f5b6b585a..037bf3d8cc 100644 --- a/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java +++ b/spring-core/src/main/java/org/springframework/core/ResolvableTypeProvider.java @@ -16,7 +16,7 @@ package org.springframework.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Any object can implement this interface to provide its actual {@link ResolvableType}. @@ -37,7 +37,6 @@ 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(); + @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 ba7bc2a60f..9a568e07a5 100644 --- a/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java +++ b/spring-core/src/main/java/org/springframework/core/SerializableTypeWrapper.java @@ -29,7 +29,8 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -68,8 +69,7 @@ final class SerializableTypeWrapper { /** * Return a {@link Serializable} variant of {@link Field#getGenericType()}. */ - @Nullable - public static Type forField(Field field) { + public static @Nullable Type forField(Field field) { return forTypeProvider(new FieldTypeProvider(field)); } @@ -77,8 +77,7 @@ final class SerializableTypeWrapper { * Return a {@link Serializable} variant of * {@link MethodParameter#getGenericParameterType()}. */ - @Nullable - public static Type forMethodParameter(MethodParameter methodParameter) { + public static @Nullable Type forMethodParameter(MethodParameter methodParameter) { return forTypeProvider(new MethodParameterTypeProvider(methodParameter)); } @@ -101,8 +100,7 @@ final class SerializableTypeWrapper { *

If type artifacts are generally not serializable in the current runtime * environment, this delegate will simply return the original {@code Type} as-is. */ - @Nullable - static Type forTypeProvider(TypeProvider provider) { + static @Nullable Type forTypeProvider(TypeProvider provider) { Type providedType = provider.getType(); if (providedType == null || providedType instanceof Serializable) { // No serializable type wrapping necessary (for example, for java.lang.Class) @@ -154,15 +152,13 @@ final class SerializableTypeWrapper { /** * Return the (possibly non {@link Serializable}) {@link Type}. */ - @Nullable - Type getType(); + @Nullable Type getType(); /** * Return the source of the type, or {@code null} if not known. *

The default implementation returns {@code null}. */ - @Nullable - default Object getSource() { + default @Nullable Object getSource() { return null; } } @@ -183,8 +179,7 @@ final class SerializableTypeWrapper { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { switch (method.getName()) { case "equals" -> { Object other = args[0]; @@ -273,8 +268,7 @@ final class SerializableTypeWrapper { @SuppressWarnings("serial") static class MethodParameterTypeProvider implements TypeProvider { - @Nullable - private final String methodName; + private final @Nullable String methodName; private final Class[] parameterTypes; @@ -337,8 +331,7 @@ final class SerializableTypeWrapper { private transient Method method; - @Nullable - private transient volatile Object result; + private transient volatile @Nullable Object result; public MethodInvokeTypeProvider(TypeProvider provider, Method method, int index) { this.provider = provider; @@ -349,8 +342,7 @@ final class SerializableTypeWrapper { } @Override - @Nullable - public Type getType() { + public @Nullable Type getType() { Object result = this.result; if (result == null) { // Lazy invocation of the target method on the provided type @@ -362,8 +354,7 @@ final class SerializableTypeWrapper { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/SmartClassLoader.java b/spring-core/src/main/java/org/springframework/core/SmartClassLoader.java index 695d09c68e..1a8162d277 100644 --- a/spring-core/src/main/java/org/springframework/core/SmartClassLoader.java +++ b/spring-core/src/main/java/org/springframework/core/SmartClassLoader.java @@ -18,7 +18,7 @@ package org.springframework.core; import java.security.ProtectionDomain; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by a reloading-aware ClassLoader diff --git a/spring-core/src/main/java/org/springframework/core/SortedProperties.java b/spring-core/src/main/java/org/springframework/core/SortedProperties.java index cb3e7a93e2..6ec7dc775f 100644 --- a/spring-core/src/main/java/org/springframework/core/SortedProperties.java +++ b/spring-core/src/main/java/org/springframework/core/SortedProperties.java @@ -30,7 +30,7 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Specialization of {@link Properties} that sorts properties alphanumerically 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 e82c371a19..54f0d079f0 100644 --- a/spring-core/src/main/java/org/springframework/core/SpringProperties.java +++ b/spring-core/src/main/java/org/springframework/core/SpringProperties.java @@ -21,7 +21,7 @@ import java.io.InputStream; import java.net.URL; import java.util.Properties; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Static holder for local Spring properties, i.e. defined at the Spring library level. @@ -97,8 +97,7 @@ public final 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) { + public static @Nullable String getProperty(String key) { String value = localProperties.getProperty(key); if (value == null) { try { 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 7d03c21607..8d6bf55340 100644 --- a/spring-core/src/main/java/org/springframework/core/SpringVersion.java +++ b/spring-core/src/main/java/org/springframework/core/SpringVersion.java @@ -16,7 +16,7 @@ package org.springframework.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Class that exposes the Spring version. Fetches the @@ -42,8 +42,7 @@ public final class SpringVersion { * or {@code null} if it cannot be determined. * @see Package#getImplementationVersion() */ - @Nullable - public static String getVersion() { + public static @Nullable String getVersion() { Package pkg = SpringVersion.class.getPackage(); return (pkg != null ? pkg.getImplementationVersion() : null); } diff --git a/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java b/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java index 9bce47f435..6a8cbdf649 100644 --- a/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java +++ b/spring-core/src/main/java/org/springframework/core/StandardReflectionParameterNameDiscoverer.java @@ -20,7 +20,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link ParameterNameDiscoverer} implementation which uses JDK 8's reflection facilities @@ -39,19 +39,16 @@ import org.springframework.lang.Nullable; public class StandardReflectionParameterNameDiscoverer implements ParameterNameDiscoverer { @Override - @Nullable - public String[] getParameterNames(Method method) { + public @Nullable String @Nullable [] getParameterNames(Method method) { return getParameterNames(method.getParameters()); } @Override - @Nullable - public String[] getParameterNames(Constructor ctor) { + public @Nullable String @Nullable [] getParameterNames(Constructor ctor) { return getParameterNames(ctor.getParameters()); } - @Nullable - private String[] getParameterNames(Parameter[] parameters) { + private String @Nullable [] getParameterNames(Parameter[] parameters) { String[] parameterNames = new String[parameters.length]; for (int i = 0; i < parameters.length; i++) { Parameter param = parameters[i]; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java index 978e9684c2..0c80f267f6 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AbstractMergedAnnotation.java @@ -21,7 +21,8 @@ import java.util.NoSuchElementException; import java.util.Optional; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -34,8 +35,7 @@ import org.springframework.util.Assert; */ abstract class AbstractMergedAnnotation implements MergedAnnotation { - @Nullable - private volatile A synthesizedAnnotation; + private volatile @Nullable A synthesizedAnnotation; @Override @@ -230,8 +230,7 @@ abstract class AbstractMergedAnnotation implements MergedA * @throws IllegalArgumentException if the source type is not compatible * @throws NoSuchElementException if the value is required but not found */ - @Nullable - protected abstract T getAttributeValue(String attributeName, Class type); + protected abstract @Nullable T getAttributeValue(String attributeName, Class type); /** * Factory method used to create the synthesized annotation. 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 1ac4f84a5e..83d22e58bc 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 @@ -24,10 +24,11 @@ import java.util.LinkedHashSet; import java.util.Set; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.core.BridgeMethodResolver; import org.springframework.core.annotation.MergedAnnotation.Adapt; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -243,8 +244,7 @@ public abstract class AnnotatedElementUtils { * @see #getMergedAnnotation(AnnotatedElement, Class) * @see #findMergedAnnotation(AnnotatedElement, Class) */ - @Nullable - public static AnnotationAttributes getMergedAnnotationAttributes( + public static @Nullable AnnotationAttributes getMergedAnnotationAttributes( AnnotatedElement element, Class annotationType) { MergedAnnotation mergedAnnotation = getAnnotations(element) @@ -270,8 +270,7 @@ public abstract class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getAllAnnotationAttributes(AnnotatedElement, String) */ - @Nullable - public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, + public static @Nullable AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName) { return getMergedAnnotationAttributes(element, annotationName, false, false); @@ -303,8 +302,7 @@ public abstract class AnnotatedElementUtils { * @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ - @Nullable - public static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, + public static @Nullable AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { MergedAnnotation mergedAnnotation = getAnnotations(element) @@ -326,8 +324,7 @@ public abstract class AnnotatedElementUtils { * @since 4.2 * @see #findMergedAnnotation(AnnotatedElement, Class) */ - @Nullable - public static A getMergedAnnotation(AnnotatedElement element, Class annotationType) { + public static @Nullable A getMergedAnnotation(AnnotatedElement element, Class annotationType) { // Shortcut: directly present on the element, with no merging needed? if (AnnotationFilter.PLAIN.matches(annotationType) || AnnotationsScanner.hasPlainJavaAnnotationsOnly(element)) { @@ -481,8 +478,7 @@ public abstract class AnnotatedElementUtils { * attributes from all annotations found, or {@code null} if not found * @see #getAllAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ - @Nullable - public static MultiValueMap getAllAnnotationAttributes( + public static @Nullable MultiValueMap getAllAnnotationAttributes( AnnotatedElement element, String annotationName) { return getAllAnnotationAttributes(element, annotationName, false, false); @@ -506,8 +502,7 @@ public abstract 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, + public static @Nullable MultiValueMap getAllAnnotationAttributes(AnnotatedElement element, String annotationName, final boolean classValuesAsString, final boolean nestedAnnotationsAsMap) { Adapt[] adaptations = Adapt.values(classValuesAsString, nestedAnnotationsAsMap); @@ -568,8 +563,7 @@ public abstract class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ - @Nullable - public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, + public static @Nullable AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, Class annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { MergedAnnotation mergedAnnotation = findAnnotations(element) @@ -604,8 +598,7 @@ public abstract class AnnotatedElementUtils { * @see #findMergedAnnotation(AnnotatedElement, Class) * @see #getMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) */ - @Nullable - public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, + public static @Nullable AnnotationAttributes findMergedAnnotationAttributes(AnnotatedElement element, String annotationName, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { MergedAnnotation mergedAnnotation = findAnnotations(element) @@ -631,8 +624,7 @@ public abstract class AnnotatedElementUtils { * @see #findMergedAnnotationAttributes(AnnotatedElement, String, boolean, boolean) * @see #getMergedAnnotationAttributes(AnnotatedElement, Class) */ - @Nullable - public static A findMergedAnnotation(AnnotatedElement element, Class annotationType) { + public static @Nullable A findMergedAnnotation(AnnotatedElement element, Class annotationType) { // Shortcut: directly present on the element, with no merging needed? if (AnnotationFilter.PLAIN.matches(annotationType) || AnnotationsScanner.hasPlainJavaAnnotationsOnly(element)) { @@ -823,8 +815,7 @@ public abstract class AnnotatedElementUtils { return MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY, repeatableContainers); } - @Nullable - private static MultiValueMap nullIfEmpty(MultiValueMap map) { + private static @Nullable MultiValueMap nullIfEmpty(MultiValueMap map) { return (map.isEmpty() ? null : map); } @@ -832,8 +823,7 @@ public abstract class AnnotatedElementUtils { return Comparator.> comparingInt(MergedAnnotation::getAggregateIndex).reversed(); } - @Nullable - private static AnnotationAttributes getAnnotationAttributes(MergedAnnotation annotation, + private static @Nullable AnnotationAttributes getAnnotationAttributes(MergedAnnotation annotation, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { if (!annotation.isPresent()) { @@ -856,8 +846,7 @@ public abstract class AnnotatedElementUtils { @Override @SuppressWarnings("unchecked") - @Nullable - public T getAnnotation(Class annotationClass) { + public @Nullable T getAnnotation(Class annotationClass) { for (Annotation annotation : this.annotations) { if (annotation.annotationType() == annotationClass) { return (T) annotation; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedMethod.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedMethod.java index e50e79bf90..a7e24d5c11 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedMethod.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotatedMethod.java @@ -22,11 +22,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -52,8 +53,7 @@ public class AnnotatedMethod { private final MethodParameter[] parameters; - @Nullable - private volatile List inheritedParameterAnnotations; + private volatile @Nullable List inheritedParameterAnnotations; /** @@ -148,8 +148,7 @@ public class AnnotatedMethod { * @return the annotation, or {@code null} if none found * @see AnnotatedElementUtils#findMergedAnnotation */ - @Nullable - public A getMethodAnnotation(Class annotationType) { + public @Nullable A getMethodAnnotation(Class annotationType) { return AnnotatedElementUtils.findMergedAnnotation(this.method, annotationType); } @@ -231,8 +230,7 @@ public class AnnotatedMethod { // Support methods for use in subclass variants - @Nullable - protected static Object findProvidedArgument(MethodParameter parameter, @Nullable Object... providedArgs) { + protected static @Nullable Object findProvidedArgument(MethodParameter parameter, @Nullable Object... providedArgs) { if (!ObjectUtils.isEmpty(providedArgs)) { for (Object providedArg : providedArgs) { if (parameter.getParameterType().isInstance(providedArg)) { @@ -254,8 +252,7 @@ public class AnnotatedMethod { */ protected class AnnotatedMethodParameter extends SynthesizingMethodParameter { - @Nullable - private volatile Annotation[] combinedAnnotations; + private volatile Annotation @Nullable [] combinedAnnotations; public AnnotatedMethodParameter(int index) { super(AnnotatedMethod.this.getBridgedMethod(), index); @@ -267,8 +264,7 @@ public class AnnotatedMethod { } @Override - @NonNull - public Method getMethod() { + public @NonNull Method getMethod() { return AnnotatedMethod.this.getBridgedMethod(); } @@ -278,8 +274,7 @@ public class AnnotatedMethod { } @Override - @Nullable - public T getMethodAnnotation(Class annotationType) { + public @Nullable T getMethodAnnotation(Class annotationType) { return AnnotatedMethod.this.getMethodAnnotation(annotationType); } @@ -335,8 +330,7 @@ public class AnnotatedMethod { */ private class ReturnValueMethodParameter extends AnnotatedMethodParameter { - @Nullable - private final Class returnValueType; + private final @Nullable Class returnValueType; public ReturnValueMethodParameter(@Nullable Object returnValue) { super(-1); 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 7732e00806..30f43f90b8 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,7 +22,8 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -48,8 +49,7 @@ public class AnnotationAttributes extends LinkedHashMap { private static final String UNKNOWN = "unknown"; - @Nullable - private final Class annotationType; + private final @Nullable Class annotationType; final String displayName; @@ -147,8 +147,7 @@ public class AnnotationAttributes extends LinkedHashMap { } @SuppressWarnings("unchecked") - @Nullable - private static Class getAnnotationType(String annotationType, @Nullable ClassLoader classLoader) { + private static @Nullable Class getAnnotationType(String annotationType, @Nullable ClassLoader classLoader) { if (classLoader != null) { try { return (Class) classLoader.loadClass(annotationType); @@ -166,8 +165,7 @@ public class AnnotationAttributes extends LinkedHashMap { * @return the annotation type, or {@code null} if unknown * @since 4.2 */ - @Nullable - public Class annotationType() { + public @Nullable Class annotationType() { return this.annotationType; } @@ -412,8 +410,7 @@ public class AnnotationAttributes extends LinkedHashMap { * to the {@link #AnnotationAttributes(Map)} constructor. * @param map original source of annotation attribute key-value pairs */ - @Nullable - public static AnnotationAttributes fromMap(@Nullable Map map) { + public static @Nullable AnnotationAttributes fromMap(@Nullable Map map) { if (map == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java index 3ac17cd27e..ac1b86f2a4 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationAwareOrderComparator.java @@ -20,10 +20,11 @@ import java.lang.reflect.AnnotatedElement; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.DecoratingProxy; import org.springframework.core.OrderComparator; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; /** * {@code AnnotationAwareOrderComparator} is an extension of @@ -59,8 +60,7 @@ public class AnnotationAwareOrderComparator extends OrderComparator { * check in the superclass. */ @Override - @Nullable - protected Integer findOrder(Object obj) { + protected @Nullable Integer findOrder(Object obj) { Integer order = super.findOrder(obj); if (order != null) { return order; @@ -68,8 +68,7 @@ public class AnnotationAwareOrderComparator extends OrderComparator { return findOrderFromAnnotation(obj); } - @Nullable - private Integer findOrderFromAnnotation(Object obj) { + private @Nullable Integer findOrderFromAnnotation(Object obj) { AnnotatedElement element = (obj instanceof AnnotatedElement ae ? ae : obj.getClass()); MergedAnnotations annotations = MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY); Integer order = OrderUtils.getOrderFromAnnotations(element, annotations); @@ -86,8 +85,7 @@ public class AnnotationAwareOrderComparator extends OrderComparator { * multiple matches but only one object to be returned. */ @Override - @Nullable - public Integer getPriority(Object obj) { + public @Nullable Integer getPriority(Object obj) { if (obj instanceof Class clazz) { return OrderUtils.getPriority(clazz); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java index 5bda87e8da..f5e1a4ceaf 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMapping.java @@ -33,9 +33,9 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.MirrorSet; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -72,8 +72,7 @@ final class AnnotationTypeMapping { private static final int[] EMPTY_INT_ARRAY = new int[0]; - @Nullable - private final AnnotationTypeMapping source; + private final @Nullable AnnotationTypeMapping source; private final AnnotationTypeMapping root; @@ -83,8 +82,7 @@ final class AnnotationTypeMapping { private final List> metaTypes; - @Nullable - private final Annotation annotation; + private final @Nullable Annotation annotation; private final AttributeMethods attributes; @@ -481,8 +479,7 @@ final class AnnotationTypeMapping { * Get the source of the mapping or {@code null}. * @return the source of the mapping */ - @Nullable - AnnotationTypeMapping getSource() { + @Nullable AnnotationTypeMapping getSource() { return this.source; } @@ -511,8 +508,7 @@ final class AnnotationTypeMapping { * meta-annotation, or {@code null} if this is the root mapping. * @return the source annotation of the mapping */ - @Nullable - Annotation getAnnotation() { + @Nullable Annotation getAnnotation() { return this.annotation; } @@ -560,8 +556,7 @@ final class AnnotationTypeMapping { * also be considered. * @return the mapped annotation value, or {@code null} */ - @Nullable - Object getMappedAnnotationValue(int attributeIndex, boolean metaAnnotationsOnly) { + @Nullable Object getMappedAnnotationValue(int attributeIndex, boolean metaAnnotationsOnly) { int mappedIndex = this.annotationValueMappings[attributeIndex]; if (mappedIndex == -1) { return null; @@ -727,8 +722,7 @@ final class AnnotationTypeMapping { return this.mirrorSets[index]; } - @Nullable - MirrorSet getAssigned(int attributeIndex) { + @Nullable MirrorSet getAssigned(int attributeIndex) { return this.assigned[attributeIndex]; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java index e8e07ec311..e26201476d 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationTypeMappings.java @@ -25,7 +25,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ConcurrentReferenceHashMap; /** 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 b46bd281ec..8a6b393366 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 @@ -30,11 +30,12 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.BridgeMethodResolver; import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.MirrorSet; import org.springframework.core.annotation.MergedAnnotation.Adapt; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -187,8 +188,7 @@ public abstract class AnnotationUtils { * @since 4.0 */ @SuppressWarnings("unchecked") - @Nullable - public static A getAnnotation(Annotation annotation, Class annotationType) { + public static @Nullable A getAnnotation(Annotation annotation, Class annotationType) { // Shortcut: directly present on the element, with no merging needed? if (annotationType.isInstance(annotation)) { return synthesizeAnnotation((A) annotation, annotationType); @@ -215,8 +215,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) { + public static @Nullable A getAnnotation(AnnotatedElement annotatedElement, Class annotationType) { // Shortcut: directly present on the element, with no merging needed? if (AnnotationFilter.PLAIN.matches(annotationType) || AnnotationsScanner.hasPlainJavaAnnotationsOnly(annotatedElement)) { @@ -247,8 +246,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) { + public static @Nullable A getAnnotation(Method method, Class annotationType) { Method resolvedMethod = BridgeMethodResolver.findBridgedMethod(method); return getAnnotation((AnnotatedElement) resolvedMethod, annotationType); } @@ -266,8 +264,7 @@ public abstract class AnnotationUtils { * @deprecated as of 5.2 since it is superseded by the {@link MergedAnnotations} API */ @Deprecated - @Nullable - public static Annotation[] getAnnotations(AnnotatedElement annotatedElement) { + public static Annotation @Nullable [] getAnnotations(AnnotatedElement annotatedElement) { try { return synthesizeAnnotationArray(annotatedElement.getAnnotations(), annotatedElement); } @@ -291,8 +288,7 @@ public abstract class AnnotationUtils { * @deprecated as of 5.2 since it is superseded by the {@link MergedAnnotations} API */ @Deprecated - @Nullable - public static Annotation[] getAnnotations(Method method) { + public static Annotation @Nullable [] getAnnotations(Method method) { try { return synthesizeAnnotationArray(BridgeMethodResolver.findBridgedMethod(method).getAnnotations(), method); } @@ -480,8 +476,7 @@ public abstract class AnnotationUtils { * @return the first matching annotation, or {@code null} if not found * @since 4.2 */ - @Nullable - public static A findAnnotation( + public static @Nullable A findAnnotation( AnnotatedElement annotatedElement, @Nullable Class annotationType) { if (annotationType == null) { @@ -515,8 +510,7 @@ public abstract class AnnotationUtils { * @return the first matching annotation, or {@code null} if not found * @see #getAnnotation(Method, Class) */ - @Nullable - public static A findAnnotation(Method method, @Nullable Class annotationType) { + public static @Nullable A findAnnotation(Method method, @Nullable Class annotationType) { if (annotationType == null) { return null; } @@ -555,8 +549,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, @Nullable Class annotationType) { + public static @Nullable A findAnnotation(Class clazz, @Nullable Class annotationType) { if (annotationType == null) { return null; } @@ -605,8 +598,7 @@ public abstract class AnnotationUtils { * @deprecated as of 5.2 since it is superseded by the {@link MergedAnnotations} API */ @Deprecated - @Nullable - public static Class findAnnotationDeclaringClass( + public static @Nullable Class findAnnotationDeclaringClass( Class annotationType, @Nullable Class clazz) { if (clazz == null) { @@ -642,8 +634,7 @@ public abstract class AnnotationUtils { * @deprecated as of 5.2 since it is superseded by the {@link MergedAnnotations} API */ @Deprecated - @Nullable - public static Class findAnnotationDeclaringClassForTypes( + public static @Nullable Class findAnnotationDeclaringClassForTypes( List> annotationTypes, @Nullable Class clazz) { if (clazz == null) { @@ -984,8 +975,7 @@ public abstract class AnnotationUtils { } } - @Nullable - private static Object getAttributeValueForMirrorResolution(Method attribute, @Nullable Object attributes) { + private static @Nullable Object getAttributeValueForMirrorResolution(Method attribute, @Nullable Object attributes) { if (!(attributes instanceof AnnotationAttributes annotationAttributes)) { return null; } @@ -993,8 +983,7 @@ public abstract class AnnotationUtils { return (result instanceof DefaultValueHolder defaultValueHolder ? defaultValueHolder.defaultValue : result); } - @Nullable - private static Object adaptValue( + private static @Nullable Object adaptValue( @Nullable Object annotatedElement, @Nullable Object value, boolean classValuesAsString) { if (classValuesAsString) { @@ -1032,8 +1021,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) { + public static @Nullable Object getValue(Annotation annotation) { return getValue(annotation, VALUE); } @@ -1046,8 +1034,7 @@ public abstract class AnnotationUtils { * in which case such an exception will be rethrown * @see #getValue(Annotation) */ - @Nullable - public static Object getValue(@Nullable Annotation annotation, @Nullable String attributeName) { + public static @Nullable Object getValue(@Nullable Annotation annotation, @Nullable String attributeName) { if (annotation == null || !StringUtils.hasText(attributeName)) { return null; } @@ -1075,8 +1062,7 @@ public abstract class AnnotationUtils { * @return the value returned from the method invocation * @since 5.3.24 */ - @Nullable - static Object invokeAnnotationMethod(Method method, @Nullable Object annotation) { + static @Nullable Object invokeAnnotationMethod(Method method, @Nullable Object annotation) { if (annotation == null) { return null; } @@ -1156,8 +1142,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) { + public static @Nullable Object getDefaultValue(Annotation annotation) { return getDefaultValue(annotation, VALUE); } @@ -1168,8 +1153,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(@Nullable Annotation annotation, @Nullable String attributeName) { + public static @Nullable Object getDefaultValue(@Nullable Annotation annotation, @Nullable String attributeName) { return (annotation != null ? getDefaultValue(annotation.annotationType(), attributeName) : null); } @@ -1180,8 +1164,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) { + public static @Nullable Object getDefaultValue(Class annotationType) { return getDefaultValue(annotationType, VALUE); } @@ -1193,8 +1176,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( + public static @Nullable Object getDefaultValue( @Nullable Class annotationType, @Nullable String attributeName) { if (annotationType == null || !StringUtils.hasText(attributeName)) { diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsProcessor.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsProcessor.java index f7a3d16f2d..8c1c81824e 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsProcessor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsProcessor.java @@ -18,7 +18,7 @@ package org.springframework.core.annotation; import java.lang.annotation.Annotation; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Callback interface used to process annotations. @@ -40,8 +40,7 @@ interface AnnotationsProcessor { * @param aggregateIndex the aggregate index about to be processed * @return a {@code non-null} result if no further processing is required */ - @Nullable - default R doWithAggregate(C context, int aggregateIndex) { + default @Nullable R doWithAggregate(C context, int aggregateIndex) { return null; } @@ -55,8 +54,7 @@ interface AnnotationsProcessor { * {@code null} elements) * @return a {@code non-null} result if no further processing is required */ - @Nullable - R doWithAnnotations(C context, int aggregateIndex, @Nullable Object source, Annotation[] annotations); + @Nullable R doWithAnnotations(C context, int aggregateIndex, @Nullable Object source, Annotation[] annotations); /** * Get the final result to be returned. By default this method returns @@ -64,8 +62,7 @@ interface AnnotationsProcessor { * @param result the last early exit result, or {@code null} if none * @return the final result to be returned to the caller */ - @Nullable - default R finish(@Nullable R result) { + default @Nullable R finish(@Nullable R result) { return result; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java index a3d08f369b..8b09b1d5ce 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationsScanner.java @@ -25,12 +25,13 @@ import java.util.Arrays; import java.util.Map; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.BridgeMethodResolver; import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.MergedAnnotations.Search; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -75,16 +76,14 @@ abstract class AnnotationsScanner { * @param processor the processor that receives the annotations * @return the result of {@link AnnotationsProcessor#finish(Object)} */ - @Nullable - static R scan(C context, AnnotatedElement source, SearchStrategy searchStrategy, + static @Nullable R scan(C context, AnnotatedElement source, SearchStrategy searchStrategy, Predicate> searchEnclosingClass, AnnotationsProcessor processor) { R result = process(context, source, searchStrategy, searchEnclosingClass, processor); return processor.finish(result); } - @Nullable - private static R process(C context, AnnotatedElement source, + private static @Nullable R process(C context, AnnotatedElement source, SearchStrategy searchStrategy, Predicate> searchEnclosingClass, AnnotationsProcessor processor) { @@ -97,8 +96,7 @@ abstract class AnnotationsScanner { return processElement(context, source, processor); } - @Nullable - private static R processClass(C context, Class source, SearchStrategy searchStrategy, + private static @Nullable R processClass(C context, Class source, SearchStrategy searchStrategy, Predicate> searchEnclosingClass, AnnotationsProcessor processor) { return switch (searchStrategy) { @@ -109,8 +107,7 @@ abstract class AnnotationsScanner { }; } - @Nullable - private static R processClassInheritedAnnotations(C context, Class source, + private static @Nullable R processClassInheritedAnnotations(C context, Class source, AnnotationsProcessor processor) { try { @@ -164,8 +161,7 @@ abstract class AnnotationsScanner { return null; } - @Nullable - private static R processClassHierarchy(C context, Class source, + private static @Nullable R processClassHierarchy(C context, Class source, AnnotationsProcessor processor, boolean includeInterfaces, Predicate> searchEnclosingClass) { @@ -173,8 +169,7 @@ abstract class AnnotationsScanner { includeInterfaces, searchEnclosingClass); } - @Nullable - private static R processClassHierarchy(C context, int[] aggregateIndex, Class source, + private static @Nullable R processClassHierarchy(C context, int[] aggregateIndex, Class source, AnnotationsProcessor processor, boolean includeInterfaces, Predicate> searchEnclosingClass) { @@ -236,8 +231,7 @@ abstract class AnnotationsScanner { return null; } - @Nullable - private static R processMethod(C context, Method source, + private static @Nullable R processMethod(C context, Method source, SearchStrategy searchStrategy, AnnotationsProcessor processor) { return switch (searchStrategy) { @@ -249,8 +243,7 @@ abstract class AnnotationsScanner { }; } - @Nullable - private static R processMethodInheritedAnnotations(C context, Method source, + private static @Nullable R processMethodInheritedAnnotations(C context, Method source, AnnotationsProcessor processor) { try { @@ -264,8 +257,7 @@ abstract class AnnotationsScanner { return null; } - @Nullable - private static R processMethodHierarchy(C context, int[] aggregateIndex, + private static @Nullable R processMethodHierarchy(C context, int[] aggregateIndex, Class sourceClass, AnnotationsProcessor processor, Method rootMethod, boolean includeInterfaces) { @@ -390,8 +382,7 @@ abstract class AnnotationsScanner { return true; } - @Nullable - private static R processMethodAnnotations(C context, int aggregateIndex, Method source, + private static @Nullable R processMethodAnnotations(C context, int aggregateIndex, Method source, AnnotationsProcessor processor) { Annotation[] annotations = getDeclaredAnnotations(source, false); @@ -412,8 +403,7 @@ abstract class AnnotationsScanner { return null; } - @Nullable - private static R processElement(C context, AnnotatedElement source, + private static @Nullable R processElement(C context, AnnotatedElement source, AnnotationsProcessor processor) { try { @@ -428,8 +418,7 @@ abstract class AnnotationsScanner { } @SuppressWarnings("unchecked") - @Nullable - static A getDeclaredAnnotation(AnnotatedElement source, Class annotationType) { + static @Nullable A getDeclaredAnnotation(AnnotatedElement source, Class annotationType) { Annotation[] annotations = getDeclaredAnnotations(source, false); for (Annotation annotation : annotations) { if (annotation != null && annotationType == annotation.annotationType()) { diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java b/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java index fb8c2bda38..c524f355eb 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AttributeMethods.java @@ -22,7 +22,8 @@ import java.util.Arrays; import java.util.Comparator; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -49,8 +50,7 @@ final class AttributeMethods { }; - @Nullable - private final Class annotationType; + private final @Nullable Class annotationType; private final Method[] attributeMethods; @@ -155,8 +155,7 @@ final class AttributeMethods { * @param name the attribute name to find * @return the attribute method or {@code null} */ - @Nullable - Method get(String name) { + @Nullable Method get(String name) { int index = indexOf(name); return (index != -1 ? this.attributeMethods[index] : null); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java b/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java index 23178ce385..5bcdfbae37 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/IntrospectionFailureLogger.java @@ -18,8 +18,7 @@ package org.springframework.core.annotation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Log facade used to handle annotation introspection failures (in particular @@ -55,8 +54,7 @@ enum IntrospectionFailureLogger { }; - @Nullable - private static Log logger; + private static @Nullable Log logger; void log(String message, @Nullable Object source, Exception ex) { diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java index 6d9c1bcf5d..f67befc9d3 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotation.java @@ -28,8 +28,9 @@ import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; /** * A single merged annotation returned from a {@link MergedAnnotations} @@ -133,8 +134,7 @@ public interface MergedAnnotation { * {@link #getRoot() root}. * @return the source, or {@code null} */ - @Nullable - Object getSource(); + @Nullable Object getSource(); /** * Get the source of the meta-annotation, or {@code null} if the @@ -144,8 +144,7 @@ public interface MergedAnnotation { * @return the meta-annotation source or {@code null} * @see #getRoot() */ - @Nullable - MergedAnnotation getMetaSource(); + @Nullable MergedAnnotation getMetaSource(); /** * Get the root annotation, i.e. the {@link #getDistance() distance} {@code 0} diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java index 95c2bd6a52..dc0e1612bd 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationPredicates.java @@ -23,7 +23,8 @@ import java.util.Set; import java.util.function.Function; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -125,8 +126,7 @@ public abstract class MergedAnnotationPredicates { private boolean hasLastValue; - @Nullable - private Object lastValue; + private @Nullable Object lastValue; FirstRunOfPredicate(Function, ?> valueExtractor) { Assert.notNull(valueExtractor, "Value extractor must not be null"); diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java index 7d054454a1..8f4733e885 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotations.java @@ -24,7 +24,8 @@ import java.util.Collection; import java.util.function.Predicate; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationsCollection.java b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationsCollection.java index 01c0bafd1b..6908fa1956 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationsCollection.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MergedAnnotationsCollection.java @@ -26,7 +26,8 @@ import java.util.function.Predicate; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -155,8 +156,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations { } @SuppressWarnings("unchecked") - @Nullable - private MergedAnnotation find(Object requiredType, + private @Nullable MergedAnnotation find(Object requiredType, @Nullable Predicate> predicate, @Nullable MergedAnnotationSelector selector) { @@ -222,8 +222,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations { private class AnnotationsSpliterator implements Spliterator> { - @Nullable - private final Object requiredType; + private final @Nullable Object requiredType; private final int[] mappingCursors; @@ -259,8 +258,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations { return false; } - @Nullable - private AnnotationTypeMapping getNextSuitableMapping(int annotationIndex) { + private @Nullable AnnotationTypeMapping getNextSuitableMapping(int annotationIndex) { AnnotationTypeMapping mapping; do { mapping = getMapping(annotationIndex, this.mappingCursors[annotationIndex]); @@ -273,15 +271,13 @@ final class MergedAnnotationsCollection implements MergedAnnotations { return null; } - @Nullable - private AnnotationTypeMapping getMapping(int annotationIndex, int mappingIndex) { + private @Nullable AnnotationTypeMapping getMapping(int annotationIndex, int mappingIndex) { AnnotationTypeMappings mappings = MergedAnnotationsCollection.this.mappings[annotationIndex]; return (mappingIndex < mappings.size() ? mappings.get(mappingIndex) : null); } - @Nullable @SuppressWarnings("unchecked") - private MergedAnnotation createMergedAnnotationIfPossible(int annotationIndex, int mappingIndex) { + private @Nullable MergedAnnotation createMergedAnnotationIfPossible(int annotationIndex, int mappingIndex) { MergedAnnotation root = annotations[annotationIndex]; if (mappingIndex == 0) { return (MergedAnnotation) root; @@ -293,8 +289,7 @@ final class MergedAnnotationsCollection implements MergedAnnotations { } @Override - @Nullable - public Spliterator> trySplit() { + public @Nullable Spliterator> trySplit() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java index 0c7c9abad6..1b8840bf88 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/MissingMergedAnnotation.java @@ -25,7 +25,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An {@link AbstractMergedAnnotation} used as the implementation of @@ -56,14 +56,12 @@ final class MissingMergedAnnotation extends AbstractMerged } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return null; } @Override - @Nullable - public MergedAnnotation getMetaSource() { + public @Nullable MergedAnnotation getMetaSource() { return null; } 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 41db68d95c..f3f3031f81 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 @@ -19,8 +19,9 @@ package org.springframework.core.annotation; import java.lang.reflect.AnnotatedElement; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; import org.springframework.util.ConcurrentReferenceHashMap; /** @@ -66,8 +67,7 @@ public abstract class OrderUtils { * @return the priority value, or the specified default order if none can be found * @see #getPriority(Class) */ - @Nullable - public static Integer getOrder(Class type, @Nullable Integer defaultOrder) { + public static @Nullable Integer getOrder(Class type, @Nullable Integer defaultOrder) { Integer order = getOrder(type); return (order != null ? order : defaultOrder); } @@ -79,8 +79,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) { + public static @Nullable Integer getOrder(Class type) { return getOrder((AnnotatedElement) type); } @@ -91,8 +90,7 @@ public abstract class OrderUtils { * @return the order value, or {@code null} if none can be found * @since 5.3 */ - @Nullable - public static Integer getOrder(AnnotatedElement element) { + public static @Nullable Integer getOrder(AnnotatedElement element) { return getOrderFromAnnotations(element, MergedAnnotations.from(element, SearchStrategy.TYPE_HIERARCHY)); } @@ -104,8 +102,7 @@ public abstract class OrderUtils { * @param annotations the annotation to consider * @return the order value, or {@code null} if none can be found */ - @Nullable - static Integer getOrderFromAnnotations(AnnotatedElement element, MergedAnnotations annotations) { + static @Nullable Integer getOrderFromAnnotations(AnnotatedElement element, MergedAnnotations annotations) { if (!(element instanceof Class)) { return findOrder(annotations); } @@ -118,8 +115,7 @@ public abstract class OrderUtils { return result; } - @Nullable - private static Integer findOrder(MergedAnnotations annotations) { + private static @Nullable Integer findOrder(MergedAnnotations annotations) { MergedAnnotation orderAnnotation = annotations.get(Order.class); if (orderAnnotation.isPresent()) { return orderAnnotation.getInt(MergedAnnotation.VALUE); @@ -137,8 +133,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) { + public static @Nullable Integer getPriority(Class type) { return MergedAnnotations.from(type, SearchStrategy.TYPE_HIERARCHY).get(JAKARTA_PRIORITY_ANNOTATION) .getValue(MergedAnnotation.VALUE, Integer.class).orElse(null); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java b/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java index c050a695f4..2e82f189dc 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/PackagesAnnotationFilter.java @@ -18,7 +18,8 @@ package org.springframework.core.annotation; import java.util.Arrays; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java b/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java index 9f7bf61ad2..cc53a6ce22 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/RepeatableContainers.java @@ -22,8 +22,9 @@ import java.lang.reflect.Method; import java.util.Map; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.ObjectUtils; @@ -47,8 +48,7 @@ public abstract class RepeatableContainers { static final Map, Object> cache = new ConcurrentReferenceHashMap<>(); - @Nullable - private final RepeatableContainers parent; + private final @Nullable RepeatableContainers parent; private RepeatableContainers(@Nullable RepeatableContainers parent) { @@ -71,8 +71,7 @@ public abstract class RepeatableContainers { return new ExplicitRepeatableContainer(this, repeatable, container); } - @Nullable - Annotation[] findRepeatedAnnotations(Annotation annotation) { + Annotation @Nullable [] findRepeatedAnnotations(Annotation annotation) { if (this.parent == null) { return null; } @@ -155,8 +154,7 @@ public abstract class RepeatableContainers { } @Override - @Nullable - Annotation[] findRepeatedAnnotations(Annotation annotation) { + Annotation @Nullable [] findRepeatedAnnotations(Annotation annotation) { Method method = getRepeatedAnnotationsMethod(annotation.annotationType()); if (method != null) { return (Annotation[]) AnnotationUtils.invokeAnnotationMethod(method, annotation); @@ -164,8 +162,7 @@ public abstract class RepeatableContainers { return super.findRepeatedAnnotations(annotation); } - @Nullable - private static Method getRepeatedAnnotationsMethod(Class annotationType) { + private static @Nullable Method getRepeatedAnnotationsMethod(Class annotationType) { Object result = cache.computeIfAbsent(annotationType, StandardRepeatableContainers::computeRepeatedAnnotationsMethod); return (result != NONE ? (Method) result : null); @@ -241,8 +238,7 @@ public abstract class RepeatableContainers { } @Override - @Nullable - Annotation[] findRepeatedAnnotations(Annotation annotation) { + Annotation @Nullable [] findRepeatedAnnotations(Annotation annotation) { if (this.container.isAssignableFrom(annotation.annotationType())) { return (Annotation[]) AnnotationUtils.invokeAnnotationMethod(this.valueMethod, annotation); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java index 2319be3b6d..560b74a844 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/SynthesizedMergedAnnotationInvocationHandler.java @@ -26,7 +26,8 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -54,11 +55,9 @@ final class SynthesizedMergedAnnotationInvocationHandler i private final Map valueCache = new ConcurrentHashMap<>(8); - @Nullable - private volatile Integer hashCode; + private volatile @Nullable Integer hashCode; - @Nullable - private volatile String string; + private volatile @Nullable String string; private SynthesizedMergedAnnotationInvocationHandler(MergedAnnotation annotation, Class type) { diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java index 1d0d093aa2..c28fa9336d 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotation.java @@ -29,7 +29,8 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -82,14 +83,11 @@ final class TypeMappedAnnotation extends AbstractMergedAnn private final AnnotationTypeMapping mapping; - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; - @Nullable - private final Object source; + private final @Nullable Object source; - @Nullable - private final Object rootAttributes; + private final @Nullable Object rootAttributes; private final ValueExtractor valueExtractor; @@ -97,8 +95,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn private final boolean useMergedValues; - @Nullable - private final Predicate attributeFilter; + private final @Nullable Predicate attributeFilter; private final int[] resolvedRootMirrors; @@ -114,7 +111,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn private TypeMappedAnnotation(AnnotationTypeMapping mapping, @Nullable ClassLoader classLoader, @Nullable Object source, @Nullable Object rootAttributes, ValueExtractor valueExtractor, - int aggregateIndex, @Nullable int[] resolvedRootMirrors) { + int aggregateIndex, int @Nullable [] resolvedRootMirrors) { this.mapping = mapping; this.classLoader = classLoader; @@ -175,14 +172,12 @@ final class TypeMappedAnnotation extends AbstractMergedAnn } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @Override - @Nullable - public MergedAnnotation getMetaSource() { + public @Nullable MergedAnnotation getMetaSource() { AnnotationTypeMapping metaSourceMapping = this.mapping.getSource(); if (metaSourceMapping == null) { return null; @@ -366,8 +361,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn } @Override - @Nullable - protected T getAttributeValue(String attributeName, Class type) { + protected @Nullable T getAttributeValue(String attributeName, Class type) { int attributeIndex = getAttributeIndex(attributeName, false); return (attributeIndex != -1 ? getValue(attributeIndex, type) : null); } @@ -381,8 +375,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return value; } - @Nullable - private T getValue(int attributeIndex, Class type) { + private @Nullable T getValue(int attributeIndex, Class type) { Method attribute = this.mapping.getAttributes().get(attributeIndex); Object value = getValue(attributeIndex, true, false); if (value == null) { @@ -391,8 +384,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return adapt(attribute, value, type); } - @Nullable - private Object getValue(int attributeIndex, boolean useConventionMapping, boolean forMirrorResolution) { + private @Nullable Object getValue(int attributeIndex, boolean useConventionMapping, boolean forMirrorResolution) { AnnotationTypeMapping mapping = this.mapping; if (this.useMergedValues) { int mappedIndex = this.mapping.getAliasMapping(attributeIndex); @@ -419,8 +411,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return getValueFromMetaAnnotation(attributeIndex, forMirrorResolution); } - @Nullable - private Object getValueFromMetaAnnotation(int attributeIndex, boolean forMirrorResolution) { + private @Nullable Object getValueFromMetaAnnotation(int attributeIndex, boolean forMirrorResolution) { Object value = null; if (this.useMergedValues || forMirrorResolution) { value = this.mapping.getMappedAnnotationValue(attributeIndex, forMirrorResolution); @@ -432,16 +423,14 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return value; } - @Nullable - private Object getValueForMirrorResolution(Method attribute, @Nullable Object annotation) { + private @Nullable Object getValueForMirrorResolution(Method attribute, @Nullable Object annotation) { int attributeIndex = this.mapping.getAttributes().indexOf(attribute); boolean valueAttribute = VALUE.equals(attribute.getName()); return getValue(attributeIndex, !valueAttribute, true); } @SuppressWarnings("unchecked") - @Nullable - private T adapt(Method attribute, @Nullable Object value, Class type) { + private @Nullable T adapt(Method attribute, @Nullable Object value, Class type) { if (value == null) { return null; } @@ -585,8 +574,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn return false; } - @Nullable - private ClassLoader getClassLoader() { + private @Nullable ClassLoader getClassLoader() { if (this.classLoader != null) { return this.classLoader; } @@ -619,8 +607,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn mappings.get(0), classLoader, source, attributes, TypeMappedAnnotation::extractFromMap, 0); } - @Nullable - static TypeMappedAnnotation createIfPossible( + static @Nullable TypeMappedAnnotation createIfPossible( AnnotationTypeMapping mapping, MergedAnnotation annotation, IntrospectionFailureLogger logger) { if (annotation instanceof TypeMappedAnnotation typeMappedAnnotation) { @@ -633,8 +620,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn annotation.getAggregateIndex(), logger); } - @Nullable - static TypeMappedAnnotation createIfPossible( + static @Nullable TypeMappedAnnotation createIfPossible( AnnotationTypeMapping mapping, @Nullable Object source, Annotation annotation, int aggregateIndex, IntrospectionFailureLogger logger) { @@ -642,8 +628,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn AnnotationUtils::invokeAnnotationMethod, aggregateIndex, logger); } - @Nullable - private static TypeMappedAnnotation createIfPossible( + private static @Nullable TypeMappedAnnotation createIfPossible( AnnotationTypeMapping mapping, @Nullable Object source, @Nullable Object rootAttribute, ValueExtractor valueExtractor, int aggregateIndex, IntrospectionFailureLogger logger) { @@ -664,8 +649,7 @@ final class TypeMappedAnnotation extends AbstractMergedAnn } @SuppressWarnings("unchecked") - @Nullable - static Object extractFromMap(Method attribute, @Nullable Object map) { + static @Nullable Object extractFromMap(Method attribute, @Nullable Object map) { return (map != null ? ((Map) map).get(attribute.getName()) : null); } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java index 7187cceb42..c83b332823 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/TypeMappedAnnotations.java @@ -29,7 +29,7 @@ import java.util.function.Predicate; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link MergedAnnotations} implementation that searches for and adapts @@ -48,26 +48,21 @@ final class TypeMappedAnnotations implements MergedAnnotations { null, new Annotation[0], RepeatableContainers.none(), AnnotationFilter.ALL); - @Nullable - private final Object source; + private final @Nullable Object source; - @Nullable - private final AnnotatedElement element; + private final @Nullable AnnotatedElement element; - @Nullable - private final SearchStrategy searchStrategy; + private final @Nullable SearchStrategy searchStrategy; private final Predicate> searchEnclosingClass; - @Nullable - private final Annotation[] annotations; + private final Annotation @Nullable [] annotations; private final RepeatableContainers repeatableContainers; private final AnnotationFilter annotationFilter; - @Nullable - private volatile List aggregates; + private volatile @Nullable List aggregates; private TypeMappedAnnotations(AnnotatedElement element, SearchStrategy searchStrategy, @@ -238,8 +233,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { return aggregates; } - @Nullable - private R scan(C criteria, AnnotationsProcessor processor) { + private @Nullable R scan(C criteria, AnnotationsProcessor processor) { if (this.annotations != null) { R result = processor.doWithAnnotations(criteria, 0, this.source, this.annotations); return processor.finish(result); @@ -314,8 +308,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { } @Override - @Nullable - public Boolean doWithAnnotations(Object requiredType, int aggregateIndex, + public @Nullable Boolean doWithAnnotations(Object requiredType, int aggregateIndex, @Nullable Object source, Annotation[] annotations) { for (Annotation annotation : annotations) { @@ -374,13 +367,11 @@ final class TypeMappedAnnotations implements MergedAnnotations { private final Object requiredType; - @Nullable - private final Predicate> predicate; + private final @Nullable Predicate> predicate; private final MergedAnnotationSelector selector; - @Nullable - private MergedAnnotation result; + private @Nullable MergedAnnotation result; MergedAnnotationFinder(Object requiredType, @Nullable Predicate> predicate, @Nullable MergedAnnotationSelector selector) { @@ -391,14 +382,12 @@ final class TypeMappedAnnotations implements MergedAnnotations { } @Override - @Nullable - public MergedAnnotation doWithAggregate(Object context, int aggregateIndex) { + public @Nullable MergedAnnotation doWithAggregate(Object context, int aggregateIndex) { return this.result; } @Override - @Nullable - public MergedAnnotation doWithAnnotations(Object type, int aggregateIndex, + public @Nullable MergedAnnotation doWithAnnotations(Object type, int aggregateIndex, @Nullable Object source, Annotation[] annotations) { for (Annotation annotation : annotations) { @@ -412,8 +401,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { return null; } - @Nullable - private MergedAnnotation process( + private @Nullable MergedAnnotation process( Object type, int aggregateIndex, @Nullable Object source, Annotation annotation) { Annotation[] repeatedAnnotations = repeatableContainers.findRepeatedAnnotations(annotation); @@ -447,8 +435,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { } @Override - @Nullable - public MergedAnnotation finish(@Nullable MergedAnnotation result) { + public @Nullable MergedAnnotation finish(@Nullable MergedAnnotation result) { return (result != null ? result : this.result); } } @@ -462,8 +449,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { private final List aggregates = new ArrayList<>(); @Override - @Nullable - public List doWithAnnotations(Object criteria, int aggregateIndex, + public @Nullable List doWithAnnotations(Object criteria, int aggregateIndex, @Nullable Object source, Annotation[] annotations) { this.aggregates.add(createAggregate(aggregateIndex, source, annotations)); @@ -506,8 +492,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { private final int aggregateIndex; - @Nullable - private final Object source; + private final @Nullable Object source; private final List annotations; @@ -527,8 +512,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { return this.annotations.size(); } - @Nullable - AnnotationTypeMapping getMapping(int annotationIndex, int mappingIndex) { + @Nullable AnnotationTypeMapping getMapping(int annotationIndex, int mappingIndex) { AnnotationTypeMappings mappings = getMappings(annotationIndex); return (mappingIndex < mappings.size() ? mappings.get(mappingIndex) : null); } @@ -537,8 +521,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { return this.mappings[annotationIndex]; } - @Nullable - MergedAnnotation createMergedAnnotationIfPossible( + @Nullable MergedAnnotation createMergedAnnotationIfPossible( int annotationIndex, int mappingIndex, IntrospectionFailureLogger logger) { return TypeMappedAnnotation.createIfPossible( @@ -554,15 +537,13 @@ final class TypeMappedAnnotations implements MergedAnnotations { */ private class AggregatesSpliterator implements Spliterator> { - @Nullable - private final Object requiredType; + private final @Nullable Object requiredType; private final List aggregates; private int aggregateCursor; - @Nullable - private int[] mappingCursors; + private int @Nullable [] mappingCursors; AggregatesSpliterator(@Nullable Object requiredType, List aggregates) { this.requiredType = requiredType; @@ -613,8 +594,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { return false; } - @Nullable - private AnnotationTypeMapping getNextSuitableMapping(Aggregate aggregate, int annotationIndex) { + private @Nullable AnnotationTypeMapping getNextSuitableMapping(Aggregate aggregate, int annotationIndex) { int[] cursors = this.mappingCursors; if (cursors != null) { AnnotationTypeMapping mapping; @@ -631,8 +611,7 @@ final class TypeMappedAnnotations implements MergedAnnotations { } @Override - @Nullable - public Spliterator> trySplit() { + public @Nullable Spliterator> trySplit() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/ValueExtractor.java b/spring-core/src/main/java/org/springframework/core/annotation/ValueExtractor.java index 5f1b214639..e3cc58c27f 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/ValueExtractor.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/ValueExtractor.java @@ -20,7 +20,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy API for extracting a value for an annotation attribute from a given @@ -37,7 +37,6 @@ interface ValueExtractor { * Extract the annotation attribute represented by the supplied {@link Method} * from the supplied source {@link Object}. */ - @Nullable - Object extract(Method attribute, @Nullable Object object); + @Nullable Object extract(Method attribute, @Nullable Object object); } 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 af9d8e10ab..27602936c7 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,9 +2,7 @@ * Core support package for annotations, meta-annotations, and merged * annotations with attribute overrides. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractCharSequenceDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractCharSequenceDecoder.java index 340792259b..7df7afe64a 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractCharSequenceDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractCharSequenceDecoder.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,7 +36,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.LimitedDataBufferList; import org.springframework.core.log.LogFormatUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractDataBufferDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractDataBufferDecoder.java index 655b53e411..7db7d427eb 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractDataBufferDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractDataBufferDecoder.java @@ -18,6 +18,7 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -25,7 +26,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** @@ -101,8 +101,7 @@ public abstract class AbstractDataBufferDecoder extends AbstractDecoder { * {@link #decode(DataBuffer, ResolvableType, MimeType, Map)} instead */ @Deprecated - @Nullable - protected T decodeDataBuffer(DataBuffer buffer, ResolvableType elementType, + protected @Nullable T decodeDataBuffer(DataBuffer buffer, ResolvableType elementType, @Nullable MimeType mimeType, @Nullable Map hints) { return decode(buffer, elementType, mimeType, hints); diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java index 7810d20681..ddf3dbcf9c 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractDecoder.java @@ -22,12 +22,12 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; 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; /** diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java index 49915e02a7..160be4b1f2 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractEncoder.java @@ -21,9 +21,9 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java index 719b6f2773..74da390216 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/AbstractSingleValueEncoder.java @@ -18,6 +18,7 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -25,7 +26,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-core/src/main/java/org/springframework/core/codec/ByteArrayDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/ByteArrayDecoder.java index 65f8222d17..74aa335134 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ByteArrayDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ByteArrayDecoder.java @@ -18,10 +18,11 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/ByteArrayEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/ByteArrayEncoder.java index 6eef1a1f77..94329d6eef 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ByteArrayEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ByteArrayEncoder.java @@ -18,13 +18,13 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; 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; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java index 0da03706e5..3f2659e46b 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferDecoder.java @@ -19,10 +19,11 @@ package org.springframework.core.codec; import java.nio.ByteBuffer; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java index 8d60066152..c86371db6b 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ByteBufferEncoder.java @@ -19,13 +19,13 @@ package org.springframework.core.codec; import java.nio.ByteBuffer; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; 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; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/CharBufferDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/CharBufferDecoder.java index 6745a2e00c..0ce75215bb 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/CharBufferDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/CharBufferDecoder.java @@ -21,9 +21,10 @@ import java.nio.CharBuffer; import java.nio.charset.Charset; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java index 4103a1cec2..b7e239cfed 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/CharSequenceEncoder.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -31,7 +32,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.log.LogFormatUtils; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; 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 f621858783..a519d9d723 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 @@ -16,8 +16,9 @@ package org.springframework.core.codec; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * General error that indicates a problem while encoding and decoding to and diff --git a/spring-core/src/main/java/org/springframework/core/codec/DataBufferDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/DataBufferDecoder.java index 788eafdb0e..c03508858f 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/DataBufferDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/DataBufferDecoder.java @@ -18,12 +18,12 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/DataBufferEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/DataBufferEncoder.java index 88e8f1cc2a..4f7af8db22 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/DataBufferEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/DataBufferEncoder.java @@ -18,13 +18,13 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; 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; import org.springframework.util.MimeTypeUtils; 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 f49063f101..285b46998b 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 @@ -22,13 +22,13 @@ import java.util.Map; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; 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.Assert; import org.springframework.util.MimeType; @@ -90,8 +90,7 @@ public interface Decoder { * @return the decoded value, possibly {@code null} * @since 5.2 */ - @Nullable - default T decode(DataBuffer buffer, ResolvableType targetType, + default @Nullable T decode(DataBuffer buffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map hints) throws DecodingException { CompletableFuture future = decodeToMono(Mono.just(buffer), targetType, mimeType, hints).toFuture(); 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 873996dbcb..d87a0aac10 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 @@ -16,7 +16,7 @@ package org.springframework.core.codec; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Indicates an issue with decoding the input stream with a focus on content 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 8cbcfcfbc9..551c6dd9d1 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 @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -27,7 +28,6 @@ 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; /** 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 7d9f7a1a1b..5c5b83f229 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 @@ -16,7 +16,7 @@ package org.springframework.core.codec; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Indicates an issue with encoding the input Object stream with a focus on diff --git a/spring-core/src/main/java/org/springframework/core/codec/Hints.java b/spring-core/src/main/java/org/springframework/core/codec/Hints.java index 21ad5dd204..91b44b3625 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Hints.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Hints.java @@ -20,10 +20,10 @@ import java.util.Collections; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferDecoder.java index 150db2b893..9b81fa5095 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferDecoder.java @@ -20,12 +20,12 @@ import java.util.Map; import io.netty5.buffer.Buffer; import io.netty5.buffer.DefaultBufferAllocators; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.Netty5DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferEncoder.java index 588367132d..63a0a5f21a 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/Netty5BufferEncoder.java @@ -19,6 +19,7 @@ package org.springframework.core.codec; import java.util.Map; import io.netty5.buffer.Buffer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -26,7 +27,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.Netty5DataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufDecoder.java index 569a5cc832..7f185e6fc1 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufDecoder.java @@ -20,12 +20,12 @@ import java.util.Map; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.NettyDataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufEncoder.java index da07d638aa..ea177f3863 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/NettyByteBufEncoder.java @@ -19,6 +19,7 @@ package org.springframework.core.codec; import java.util.Map; import io.netty.buffer.ByteBuf; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -26,7 +27,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.NettyDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java index b62964ef36..ab0ca020a4 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ResourceDecoder.java @@ -19,6 +19,7 @@ package org.springframework.core.codec; import java.io.ByteArrayInputStream; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -28,7 +29,6 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; @@ -80,8 +80,7 @@ public class ResourceDecoder extends AbstractDataBufferDecoder { if (clazz == InputStreamResource.class) { return new InputStreamResource(new ByteArrayInputStream(bytes)) { @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return filename; } @Override @@ -93,8 +92,7 @@ public class ResourceDecoder extends AbstractDataBufferDecoder { else if (Resource.class.isAssignableFrom(clazz)) { return new ByteArrayResource(bytes) { @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return filename; } }; diff --git a/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java index 58b0a094fb..1c6c29a9f7 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ResourceEncoder.java @@ -18,6 +18,7 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; @@ -25,7 +26,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/ResourceRegionEncoder.java b/spring-core/src/main/java/org/springframework/core/codec/ResourceRegionEncoder.java index 3330ac6e15..9e11097441 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/ResourceRegionEncoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/ResourceRegionEncoder.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.util.Map; import java.util.OptionalLong; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.support.ResourceRegion; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java b/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java index d68abc2a33..2612e5b598 100644 --- a/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java +++ b/spring-core/src/main/java/org/springframework/core/codec/StringDecoder.java @@ -19,9 +19,10 @@ package org.springframework.core.codec; import java.nio.charset.Charset; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; 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 acf70ed8f9..4fcd5b047a 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,9 +3,7 @@ * {@link org.springframework.core.codec.Decoder} abstractions to convert * between a reactive stream of bytes and Java objects. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.codec; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConversionFailedException.java b/spring-core/src/main/java/org/springframework/core/convert/ConversionFailedException.java index 9f47c83175..7fb395086b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConversionFailedException.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConversionFailedException.java @@ -16,7 +16,8 @@ package org.springframework.core.convert; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -29,13 +30,11 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") public class ConversionFailedException extends ConversionException { - @Nullable - private final TypeDescriptor sourceType; + private final @Nullable TypeDescriptor sourceType; private final TypeDescriptor targetType; - @Nullable - private final Object value; + private final @Nullable Object value; /** @@ -59,8 +58,7 @@ public class ConversionFailedException extends ConversionException { /** * Return the source type we tried to convert the value from. */ - @Nullable - public TypeDescriptor getSourceType() { + public @Nullable TypeDescriptor getSourceType() { return this.sourceType; } @@ -74,8 +72,7 @@ public class ConversionFailedException extends ConversionException { /** * Return the offending value. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } 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 9c02d51cbc..3ce51475b1 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,7 +16,7 @@ package org.springframework.core.convert; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A service interface for type conversion. This is the entry point into the convert system. @@ -72,8 +72,7 @@ public interface ConversionService { * @throws ConversionException if a conversion exception occurred * @throws IllegalArgumentException if targetType is {@code null} */ - @Nullable - T convert(@Nullable Object source, Class targetType); + @Nullable T convert(@Nullable Object source, Class targetType); /** * Convert the given {@code source} to the specified {@code targetType}. @@ -87,8 +86,7 @@ public interface ConversionService { * @throws IllegalArgumentException if targetType is {@code null} * @since 6.1 */ - @Nullable - default Object convert(@Nullable Object source, TypeDescriptor targetType) { + default @Nullable Object convert(@Nullable Object source, TypeDescriptor targetType) { return convert(source, TypeDescriptor.forObject(source), targetType); } @@ -105,7 +103,6 @@ public interface ConversionService { * @throws IllegalArgumentException if targetType is {@code null}, * or {@code sourceType} is {@code null} but source is not {@code null} */ - @Nullable - Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType); + @Nullable Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java b/spring-core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java index e4dd3c51a0..3b7f64ebf4 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java +++ b/spring-core/src/main/java/org/springframework/core/convert/ConverterNotFoundException.java @@ -16,7 +16,7 @@ package org.springframework.core.convert; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception to be thrown when a suitable converter could not be found @@ -29,8 +29,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ConverterNotFoundException extends ConversionException { - @Nullable - private final TypeDescriptor sourceType; + private final @Nullable TypeDescriptor sourceType; private final TypeDescriptor targetType; @@ -50,8 +49,7 @@ public class ConverterNotFoundException extends ConversionException { /** * Return the source type that was requested to convert from. */ - @Nullable - public TypeDescriptor getSourceType() { + public @Nullable TypeDescriptor getSourceType() { return this.sourceType; } 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 f222515150..2d1eed9252 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 @@ -24,8 +24,9 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; +import org.jspecify.annotations.Nullable; + 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; @@ -52,18 +53,15 @@ public final class Property { private final Class objectType; - @Nullable - private final Method readMethod; + private final @Nullable Method readMethod; - @Nullable - private final Method writeMethod; + private final @Nullable Method writeMethod; private final String name; private final MethodParameter methodParameter; - @Nullable - private Annotation[] annotations; + private Annotation @Nullable [] annotations; public Property(Class objectType, @Nullable Method readMethod, @Nullable Method writeMethod) { @@ -105,16 +103,14 @@ public final class Property { /** * The property getter method: for example, {@code getFoo()}. */ - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } /** * The property setter method: for example, {@code setFoo(String)}. */ - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { return this.writeMethod; } @@ -185,16 +181,14 @@ public final class Property { return write; } - @Nullable - private MethodParameter resolveReadMethodParameter() { + private @Nullable MethodParameter resolveReadMethodParameter() { if (getReadMethod() == null) { return null; } return new MethodParameter(getReadMethod(), -1).withContainingClass(getObjectType()); } - @Nullable - private MethodParameter resolveWriteMethodParameter() { + private @Nullable MethodParameter resolveWriteMethodParameter() { if (getWriteMethod() == null) { return null; } @@ -224,8 +218,7 @@ public final class Property { } } - @Nullable - private Field getField() { + private @Nullable Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { return null; @@ -245,8 +238,7 @@ public final class Property { return field; } - @Nullable - private Class declaringClass() { + private @Nullable Class declaringClass() { if (getReadMethod() != null) { return getReadMethod().getDeclaringClass(); } 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 a29ae07516..48aefd8daa 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 @@ -27,11 +27,12 @@ import java.util.HashMap; import java.util.Map; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -120,7 +121,7 @@ public class TypeDescriptor implements Serializable { * @param annotations the type annotations * @since 4.0 */ - public TypeDescriptor(ResolvableType resolvableType, @Nullable Class type, @Nullable Annotation[] annotations) { + public TypeDescriptor(ResolvableType resolvableType, @Nullable Class type, Annotation @Nullable [] annotations) { this.resolvableType = resolvableType; this.type = (type != null ? type : resolvableType.toClass()); this.annotatedElement = AnnotatedElementAdapter.from(annotations); @@ -177,8 +178,7 @@ public class TypeDescriptor implements Serializable { * {@code null} if it could not be obtained * @since 6.1 */ - @Nullable - public TypeDescriptor nested(int nestingLevel) { + public @Nullable TypeDescriptor nested(int nestingLevel) { ResolvableType nested = this.resolvableType; for (int i = 0; i < nestingLevel; i++) { if (Object.class == nested.getType()) { @@ -227,8 +227,7 @@ public class TypeDescriptor implements Serializable { * @throws IllegalArgumentException if this type is not assignable to the super-type * @since 3.2 */ - @Nullable - public TypeDescriptor upcast(@Nullable Class superType) { + public @Nullable TypeDescriptor upcast(@Nullable Class superType) { if (superType == null) { return null; } @@ -280,8 +279,7 @@ public class TypeDescriptor implements Serializable { * @param annotationType the annotation type * @return the annotation, or {@code null} if no such annotation exists on this type descriptor */ - @Nullable - public T getAnnotation(Class annotationType) { + public @Nullable T getAnnotation(Class annotationType) { if (this.annotatedElement.isEmpty()) { // Shortcut: AnnotatedElementUtils would have to expect AnnotatedElement.getAnnotations() // to return a copy of the array, whereas we can do it more efficiently here. @@ -354,8 +352,7 @@ public class TypeDescriptor implements Serializable { * an array type or a {@code java.util.Collection} or if its element type is not parameterized * @see #elementTypeDescriptor(Object) */ - @Nullable - public TypeDescriptor getElementTypeDescriptor() { + public @Nullable TypeDescriptor getElementTypeDescriptor() { if (getResolvableType().isArray()) { return new TypeDescriptor(getResolvableType().getComponentType(), null, getAnnotations()); } @@ -382,8 +379,7 @@ public class TypeDescriptor implements Serializable { * @see #getElementTypeDescriptor() * @see #narrow(Object) */ - @Nullable - public TypeDescriptor elementTypeDescriptor(Object element) { + public @Nullable TypeDescriptor elementTypeDescriptor(Object element) { return narrow(element, getElementTypeDescriptor()); } @@ -402,8 +398,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() { + public @Nullable TypeDescriptor getMapKeyTypeDescriptor() { Assert.state(isMap(), "Not a [java.util.Map]"); return getRelatedIfResolvable(getResolvableType().asMap().getGeneric(0)); } @@ -425,8 +420,7 @@ public class TypeDescriptor implements Serializable { * @throws IllegalStateException if this type is not a {@code java.util.Map} * @see #narrow(Object) */ - @Nullable - public TypeDescriptor getMapKeyTypeDescriptor(Object mapKey) { + public @Nullable TypeDescriptor getMapKeyTypeDescriptor(Object mapKey) { return narrow(mapKey, getMapKeyTypeDescriptor()); } @@ -439,8 +433,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() { + public @Nullable TypeDescriptor getMapValueTypeDescriptor() { Assert.state(isMap(), "Not a [java.util.Map]"); return getRelatedIfResolvable(getResolvableType().asMap().getGeneric(1)); } @@ -462,21 +455,18 @@ public class TypeDescriptor implements Serializable { * @throws IllegalStateException if this type is not a {@code java.util.Map} * @see #narrow(Object) */ - @Nullable - public TypeDescriptor getMapValueTypeDescriptor(@Nullable Object mapValue) { + public @Nullable TypeDescriptor getMapValueTypeDescriptor(@Nullable Object mapValue) { return narrow(mapValue, getMapValueTypeDescriptor()); } - @Nullable - private TypeDescriptor getRelatedIfResolvable(ResolvableType type) { + private @Nullable TypeDescriptor getRelatedIfResolvable(ResolvableType type) { if (type.resolve() == null) { return null; } return new TypeDescriptor(type, null, getAnnotations()); } - @Nullable - private TypeDescriptor narrow(@Nullable Object value, @Nullable TypeDescriptor typeDescriptor) { + private @Nullable TypeDescriptor narrow(@Nullable Object value, @Nullable TypeDescriptor typeDescriptor) { if (typeDescriptor != null) { return typeDescriptor.narrow(value); } @@ -552,9 +542,8 @@ public class TypeDescriptor implements Serializable { * @param source the source object * @return the type descriptor */ - @Nullable @Contract("!null -> !null; null -> null") - public static TypeDescriptor forObject(@Nullable Object source) { + public static @Nullable TypeDescriptor forObject(@Nullable Object source) { return (source != null ? valueOf(source.getClass()) : null); } @@ -633,9 +622,8 @@ public class TypeDescriptor implements Serializable { * @return an array {@link TypeDescriptor} or {@code null} if {@code elementTypeDescriptor} is {@code null} * @since 3.2.1 */ - @Nullable @Contract("!null -> !null; null -> null") - public static TypeDescriptor array(@Nullable TypeDescriptor elementTypeDescriptor) { + public static @Nullable TypeDescriptor array(@Nullable TypeDescriptor elementTypeDescriptor) { if (elementTypeDescriptor == null) { return null; } @@ -665,8 +653,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) { + public static @Nullable TypeDescriptor nested(MethodParameter methodParameter, int nestingLevel) { if (methodParameter.getNestingLevel() != 1) { throw new IllegalArgumentException("MethodParameter nesting level must be 1: " + "use the nestingLevel parameter to specify the desired nestingLevel for nested type traversal"); @@ -695,8 +682,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) { + public static @Nullable TypeDescriptor nested(Field field, int nestingLevel) { return new TypeDescriptor(field).nested(nestingLevel); } @@ -721,8 +707,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(Property property, int nestingLevel) { + public static @Nullable TypeDescriptor nested(Property property, int nestingLevel) { return new TypeDescriptor(property).nested(nestingLevel); } @@ -748,7 +733,7 @@ public class TypeDescriptor implements Serializable { this.annotations = annotations; } - private static AnnotatedElementAdapter from(@Nullable Annotation[] annotations) { + private static AnnotatedElementAdapter from(Annotation @Nullable [] annotations) { if (annotations == null || annotations.length == 0) { return EMPTY; } @@ -766,9 +751,8 @@ public class TypeDescriptor implements Serializable { } @Override - @Nullable @SuppressWarnings("unchecked") - public T getAnnotation(Class annotationClass) { + public @Nullable T getAnnotation(Class annotationClass) { for (Annotation annotation : this.annotations) { if (annotation.annotationType() == annotationClass) { return (T) annotation; 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 b603fdc28b..5f3b59b37e 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,7 +16,8 @@ package org.springframework.core.convert.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -41,8 +42,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); + @Nullable T convert(S source); /** * Construct a composed {@link Converter} that first applies this {@link Converter} diff --git a/spring-core/src/main/java/org/springframework/core/convert/converter/ConvertingComparator.java b/spring-core/src/main/java/org/springframework/core/convert/converter/ConvertingComparator.java index a313a7938a..63b122550b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/converter/ConvertingComparator.java +++ b/spring-core/src/main/java/org/springframework/core/convert/converter/ConvertingComparator.java @@ -19,8 +19,9 @@ package org.springframework.core.convert.converter; import java.util.Comparator; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.comparator.Comparators; @@ -120,8 +121,7 @@ public class ConvertingComparator implements Comparator { } @Override - @Nullable - public T convert(S source) { + public @Nullable T convert(S source) { return this.conversionService.convert(source, this.targetType); } } 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 2460ed12ae..769dd48aa8 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 @@ -18,8 +18,9 @@ package org.springframework.core.convert.converter; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -53,8 +54,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(); + @Nullable Set getConvertibleTypes(); /** * Convert the source object to the targetType described by the {@code TypeDescriptor}. @@ -63,8 +63,7 @@ public interface GenericConverter { * @param targetType the type descriptor of the field we are converting to * @return the converted object */ - @Nullable - Object convert(@Nullable 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 c7a057daab..9438b49ce7 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,9 +1,7 @@ /** * SPI to implement Converters for the type conversion system. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.convert.converter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 7cef7265ea..2c0dbc6cb3 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,9 +1,7 @@ /** * Type conversion system API. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.convert; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java index 1030774522..0326aaab2f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToArrayConverter.java @@ -21,10 +21,11 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.ObjectUtils; /** @@ -61,8 +62,7 @@ final class ArrayToArrayConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (this.conversionService instanceof GenericConversionService genericConversionService) { TypeDescriptor targetElement = targetType.getElementTypeDescriptor(); if (targetElement != null && targetType.getType().isInstance(source) && diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java index 7a9c76239d..01f9e0626e 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToCollectionConverter.java @@ -22,11 +22,12 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts an array to a Collection. @@ -62,8 +63,7 @@ final class ArrayToCollectionConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java index 4547d18734..40e58ca3ff 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToObjectConverter.java @@ -20,10 +20,11 @@ import java.lang.reflect.Array; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts an array to an Object by returning the first array element @@ -53,8 +54,7 @@ final class ArrayToObjectConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java index fad85e5133..5f5e484564 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ArrayToStringConverter.java @@ -20,10 +20,11 @@ import java.util.Arrays; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.ObjectUtils; /** @@ -55,8 +56,7 @@ final class ArrayToStringConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return this.helperConverter.convert(Arrays.asList(ObjectUtils.toObjectArray(source)), sourceType, targetType); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java index 3023eb6781..55c7791f12 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ByteBufferConverter.java @@ -19,10 +19,11 @@ package org.springframework.core.convert.support; import java.nio.ByteBuffer; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts a {@link ByteBuffer} directly to and from {@code byte[] ByteBuffer} directly to and from {@code byte[]s} and indirectly @@ -77,8 +78,7 @@ final class ByteBufferConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { boolean byteBufferTarget = targetType.isAssignableTo(BYTE_BUFFER_TYPE); if (source instanceof ByteBuffer buffer) { return (byteBufferTarget ? buffer.duplicate() : convertFromByteBuffer(buffer, targetType)); @@ -90,8 +90,7 @@ final class ByteBufferConverter implements ConditionalGenericConverter { throw new IllegalStateException("Unexpected source/target types"); } - @Nullable - private Object convertFromByteBuffer(ByteBuffer source, TypeDescriptor targetType) { + private @Nullable Object convertFromByteBuffer(ByteBuffer source, TypeDescriptor targetType) { byte[] bytes = new byte[source.remaining()]; source.get(bytes); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java index 026587a03d..83fd24e260 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToArrayConverter.java @@ -21,10 +21,11 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.Assert; /** @@ -61,8 +62,7 @@ final class CollectionToArrayConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java index f20c950d61..3447c8a728 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToCollectionConverter.java @@ -20,11 +20,12 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts from a Collection to another Collection. @@ -60,8 +61,7 @@ final class CollectionToCollectionConverter implements ConditionalGenericConvert } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java index 81b4a41adc..23433009be 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToObjectConverter.java @@ -20,10 +20,11 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts a Collection to an Object by returning the first collection element after converting it to the desired targetType. @@ -50,8 +51,7 @@ final class CollectionToObjectConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java index e007ee279d..e1d7313c1b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/CollectionToStringConverter.java @@ -21,10 +21,11 @@ import java.util.Collections; import java.util.Set; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts a Collection to a comma-delimited String. @@ -56,8 +57,7 @@ final class CollectionToStringConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (!(source instanceof Collection sourceCollection)) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ConversionServiceFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/ConversionServiceFactory.java index 7275d31241..901fb2215f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ConversionServiceFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ConversionServiceFactory.java @@ -18,11 +18,12 @@ package org.springframework.core.convert.support; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.ConverterRegistry; import org.springframework.core.convert.converter.GenericConverter; -import org.springframework.lang.Nullable; /** * A factory for common {@link org.springframework.core.convert.ConversionService} diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java b/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java index f2f400da32..aad0e4d13b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ConversionUtils.java @@ -16,11 +16,12 @@ package org.springframework.core.convert.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.GenericConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -33,8 +34,7 @@ import org.springframework.util.ClassUtils; */ abstract class ConversionUtils { - @Nullable - public static Object invokeConverter(GenericConverter converter, @Nullable Object source, + public static @Nullable Object invokeConverter(GenericConverter converter, @Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { try { diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ConvertingPropertyEditorAdapter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ConvertingPropertyEditorAdapter.java index dcf4c8bb8b..c3787dc281 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ConvertingPropertyEditorAdapter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ConvertingPropertyEditorAdapter.java @@ -18,9 +18,10 @@ package org.springframework.core.convert.support; import java.beans.PropertyEditorSupport; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -61,8 +62,7 @@ public class ConvertingPropertyEditorAdapter extends PropertyEditorSupport { } @Override - @Nullable - public String getAsText() { + public @Nullable String getAsText() { if (this.canConvertToString) { return (String) this.conversionService.convert(getValue(), this.targetDescriptor, TypeDescriptor.valueOf(String.class)); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java b/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java index 7e5acd9d18..9f48679653 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/DefaultConversionService.java @@ -22,10 +22,11 @@ import java.util.Locale; import java.util.UUID; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.core.KotlinDetector; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.converter.ConverterRegistry; -import org.springframework.lang.Nullable; /** * A specialization of {@link GenericConversionService} configured by default @@ -42,8 +43,7 @@ import org.springframework.lang.Nullable; */ public class DefaultConversionService extends GenericConversionService { - @Nullable - private static volatile DefaultConversionService sharedInstance; + private static volatile @Nullable DefaultConversionService sharedInstance; /** diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java index 63313d3ae6..7f783a32f7 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/FallbackObjectToStringConverter.java @@ -20,9 +20,10 @@ import java.io.StringWriter; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Simply calls {@link Object#toString()} to convert any supported object @@ -61,8 +62,7 @@ final class FallbackObjectToStringConverter implements ConditionalGenericConvert } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return (source != null ? source.toString() : null); } 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 a662918b64..edff9b0163 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 @@ -28,6 +28,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.CopyOnWriteArraySet; +import org.jspecify.annotations.Nullable; + import org.springframework.core.DecoratingProxy; import org.springframework.core.ResolvableType; import org.springframework.core.convert.ConversionFailedException; @@ -41,7 +43,6 @@ 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; @@ -159,15 +160,13 @@ public class GenericConversionService implements ConfigurableConversionService { @SuppressWarnings("unchecked") @Override - @Nullable - public T convert(@Nullable Object source, Class targetType) { + public @Nullable T convert(@Nullable Object source, Class targetType) { Assert.notNull(targetType, "Target type to convert to cannot be null"); return (T) convert(source, TypeDescriptor.forObject(source), TypeDescriptor.valueOf(targetType)); } @Override - @Nullable - public Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { Assert.notNull(targetType, "Target type to convert to cannot be null"); if (sourceType == null) { Assert.isTrue(source == null, "Source must be [null] if source type == [null]"); @@ -203,8 +202,7 @@ public class GenericConversionService implements ConfigurableConversionService { * @param targetType the target type to convert to * @return the converted null object */ - @Nullable - protected Object convertNullSource(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { + protected @Nullable Object convertNullSource(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { if (targetType.getObjectType() == Optional.class) { return Optional.empty(); } @@ -222,8 +220,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) { + protected @Nullable GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { ConverterCacheKey key = new ConverterCacheKey(sourceType, targetType); GenericConverter converter = this.converterCache.get(key); if (converter != null) { @@ -252,16 +249,14 @@ 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) { + protected @Nullable GenericConverter getDefaultConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { return (sourceType.isAssignableTo(targetType) ? NO_OP_CONVERTER : null); } // Internal helpers - @Nullable - private ResolvableType[] getRequiredTypeInfo(Class converterClass, Class genericIfc) { + private ResolvableType @Nullable [] getRequiredTypeInfo(Class converterClass, Class genericIfc) { ResolvableType resolvableType = ResolvableType.forClass(converterClass).as(genericIfc); ResolvableType[] generics = resolvableType.getGenerics(); if (generics.length < 2) { @@ -279,8 +274,7 @@ public class GenericConversionService implements ConfigurableConversionService { this.converterCache.clear(); } - @Nullable - private Object handleConverterNotFound( + private @Nullable Object handleConverterNotFound( @Nullable Object source, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { @@ -294,8 +288,7 @@ public class GenericConversionService implements ConfigurableConversionService { throw new ConverterNotFoundException(sourceType, targetType); } - @Nullable - private Object handleResult(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType, @Nullable Object result) { + private @Nullable Object handleResult(@Nullable TypeDescriptor sourceType, TypeDescriptor targetType, @Nullable Object result) { if (result == null) { assertNotPrimitiveTargetType(sourceType, targetType); } @@ -350,8 +343,7 @@ public class GenericConversionService implements ConfigurableConversionService { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return convertNullSource(sourceType, targetType); } @@ -401,8 +393,7 @@ public class GenericConversionService implements ConfigurableConversionService { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return convertNullSource(sourceType, targetType); } @@ -499,8 +490,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) { + public @Nullable GenericConverter find(TypeDescriptor sourceType, TypeDescriptor targetType) { // Search the full type hierarchy List> sourceCandidates = getClassHierarchy(sourceType.getType()); List> targetCandidates = getClassHierarchy(targetType.getType()); @@ -516,8 +506,7 @@ public class GenericConversionService implements ConfigurableConversionService { return null; } - @Nullable - private GenericConverter getRegisteredConverter(TypeDescriptor sourceType, + private @Nullable GenericConverter getRegisteredConverter(TypeDescriptor sourceType, TypeDescriptor targetType, ConvertiblePair convertiblePair) { // Check specifically registered converters @@ -621,8 +610,7 @@ public class GenericConversionService implements ConfigurableConversionService { this.converters.addFirst(converter); } - @Nullable - public GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable GenericConverter getConverter(TypeDescriptor sourceType, TypeDescriptor targetType) { for (GenericConverter converter : this.converters) { if (!(converter instanceof ConditionalGenericConverter genericConverter) || genericConverter.matches(sourceType, targetType)) { @@ -651,14 +639,12 @@ public class GenericConversionService implements ConfigurableConversionService { } @Override - @Nullable - public Set getConvertibleTypes() { + public @Nullable Set getConvertibleTypes() { return null; } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return source; } 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 c3984fb039..7908ed6e57 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 @@ -21,10 +21,11 @@ import java.lang.reflect.Modifier; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -63,8 +64,7 @@ final class IdToEntityConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } @@ -75,8 +75,7 @@ final class IdToEntityConverter implements ConditionalGenericConverter { return ReflectionUtils.invokeMethod(finder, source, id); } - @Nullable - private Method getFinder(Class entityClass) { + private @Nullable Method getFinder(Class entityClass) { String finderMethod = "find" + getEntityName(entityClass); Method[] methods; boolean localOnlyFiltered; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java index 3247e5bf3d..7f6fb0351e 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/MapToMapConverter.java @@ -22,11 +22,12 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts a Map to another Map. @@ -61,8 +62,7 @@ final class MapToMapConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } @@ -114,16 +114,14 @@ final class MapToMapConverter implements ConditionalGenericConverter { targetType.getMapValueTypeDescriptor(), this.conversionService); } - @Nullable - private Object convertKey(Object sourceKey, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) { + private @Nullable Object convertKey(Object sourceKey, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) { if (targetType == null) { return sourceKey; } return this.conversionService.convert(sourceKey, sourceType.getMapKeyTypeDescriptor(sourceKey), targetType); } - @Nullable - private Object convertValue(Object sourceValue, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) { + private @Nullable Object convertValue(Object sourceValue, TypeDescriptor sourceType, @Nullable TypeDescriptor targetType) { if (targetType == null) { return sourceValue; } @@ -133,11 +131,9 @@ final class MapToMapConverter implements ConditionalGenericConverter { private static class MapEntry { - @Nullable - private final Object key; + private final @Nullable Object key; - @Nullable - private final Object value; + private final @Nullable Object value; public MapEntry(@Nullable Object key, @Nullable Object value) { this.key = key; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java index e57a7b8153..21041df784 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToArrayConverter.java @@ -20,10 +20,11 @@ import java.lang.reflect.Array; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.Assert; /** @@ -56,8 +57,7 @@ final class ObjectToArrayConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java index 28cf07c2b4..8d0e49f9ea 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToCollectionConverter.java @@ -20,11 +20,12 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.CollectionFactory; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts an Object to a single-element Collection containing the Object. @@ -55,8 +56,7 @@ final class ObjectToCollectionConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java index b65f11f24f..6d948c6927 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java @@ -25,10 +25,11 @@ import java.util.Collections; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionFailedException; 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.ConcurrentReferenceHashMap; import org.springframework.util.ReflectionUtils; @@ -89,8 +90,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } @@ -133,8 +133,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { return (getValidatedExecutable(targetClass, sourceClass) != null); } - @Nullable - private static Executable getValidatedExecutable(Class targetClass, Class sourceClass) { + private static @Nullable Executable getValidatedExecutable(Class targetClass, Class sourceClass) { Executable executable = conversionExecutableCache.get(targetClass); if (executable != null && isApplicable(executable, sourceClass)) { return executable; @@ -169,8 +168,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { } } - @Nullable - private static Method determineToMethod(Class targetClass, Class sourceClass) { + private static @Nullable Method determineToMethod(Class targetClass, Class sourceClass) { if (String.class == targetClass || String.class == sourceClass) { // Do not accept a toString() method or any to methods on String itself return null; @@ -181,8 +179,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { ClassUtils.isAssignable(targetClass, method.getReturnType()) ? method : null); } - @Nullable - private static Method determineFactoryMethod(Class targetClass, Class sourceClass) { + private static @Nullable Method determineFactoryMethod(Class targetClass, Class sourceClass) { if (String.class == targetClass) { // Do not accept the String.valueOf(Object) method return null; @@ -209,8 +206,7 @@ final class ObjectToObjectConverter implements ConditionalGenericConverter { return (ClassUtils.isAssignable(type1, type2) || ClassUtils.isAssignable(type2, type1)); } - @Nullable - private static Constructor determineFactoryConstructor(Class targetClass, Class sourceClass) { + private static @Nullable Constructor determineFactoryConstructor(Class targetClass, Class sourceClass) { return ClassUtils.getConstructorIfAvailable(targetClass, sourceClass); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java index 2993326c4c..49b3df34c0 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/ObjectToOptionalConverter.java @@ -21,10 +21,11 @@ import java.util.Collection; import java.util.Optional; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.CollectionUtils; /** diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java index 438d58c6f5..d1840e357e 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StreamConverter.java @@ -24,10 +24,11 @@ import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.converter.ConditionalGenericConverter; -import org.springframework.lang.Nullable; /** * Converts a {@link Stream} to and from a collection or array, converting the @@ -89,8 +90,7 @@ class StreamConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (sourceType.isAssignableTo(STREAM_TYPE)) { return convertFromStream((Stream) source, sourceType, targetType); } @@ -101,8 +101,7 @@ class StreamConverter implements ConditionalGenericConverter { throw new IllegalStateException("Unexpected source/target types"); } - @Nullable - private Object convertFromStream(@Nullable Stream source, TypeDescriptor streamType, TypeDescriptor targetType) { + private @Nullable Object convertFromStream(@Nullable Stream source, TypeDescriptor streamType, TypeDescriptor targetType) { List content = (source != null ? source.collect(Collectors.toList()) : Collections.emptyList()); TypeDescriptor listType = TypeDescriptor.collection(List.class, streamType.getElementTypeDescriptor()); return this.conversionService.convert(content, listType, targetType); diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java index 7cece80cf8..7c6508c39b 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToArrayConverter.java @@ -20,10 +20,11 @@ import java.lang.reflect.Array; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.Assert; import org.springframework.util.StringUtils; @@ -57,8 +58,7 @@ final class StringToArrayConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java index 694e85b876..3f26518665 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToBooleanConverter.java @@ -19,8 +19,9 @@ package org.springframework.core.convert.support; import java.util.Locale; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.Nullable; /** * Converts a String to a Boolean. @@ -38,8 +39,7 @@ final class StringToBooleanConverter implements Converter { @Override - @Nullable - public Boolean convert(String source) { + public @Nullable Boolean convert(String source) { String value = source.trim(); if (value.isEmpty()) { return null; diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java index 97374fbba7..92d987d7f7 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCharacterConverter.java @@ -16,8 +16,9 @@ package org.springframework.core.convert.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.Nullable; /** * Converts a String to a Character. @@ -28,8 +29,7 @@ import org.springframework.lang.Nullable; final class StringToCharacterConverter implements Converter { @Override - @Nullable - public Character convert(String source) { + public @Nullable Character convert(String source) { if (source.isEmpty()) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java index df565b4ed1..4a7276e67f 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToCollectionConverter.java @@ -20,11 +20,12 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.CollectionFactory; 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.StringUtils; /** @@ -58,8 +59,7 @@ final class StringToCollectionConverter implements ConditionalGenericConverter { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java index 887690be59..78427e4ca8 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToEnumConverterFactory.java @@ -16,9 +16,10 @@ package org.springframework.core.convert.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; -import org.springframework.lang.Nullable; /** * Converts from a String to a {@link java.lang.Enum} by calling {@link Enum#valueOf(Class, String)}. @@ -45,8 +46,7 @@ final class StringToEnumConverterFactory implements ConverterFactory { @Override - @Nullable - public Locale convert(String source) { + public @Nullable Locale convert(String source) { return StringUtils.parseLocale(source); } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToNumberConverterFactory.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToNumberConverterFactory.java index 082d4c972a..508741d5e7 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToNumberConverterFactory.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToNumberConverterFactory.java @@ -16,9 +16,10 @@ package org.springframework.core.convert.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.ConverterFactory; -import org.springframework.lang.Nullable; import org.springframework.util.NumberUtils; /** @@ -56,8 +57,7 @@ final class StringToNumberConverterFactory implements ConverterFactory { @Override - @Nullable - public Pattern convert(String source) { + public @Nullable Pattern convert(String source) { if (source.isEmpty()) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java index 10a1b93d19..35c75d23cc 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToRegexConverter.java @@ -17,9 +17,9 @@ package org.springframework.core.convert.support; import kotlin.text.Regex; +import org.jspecify.annotations.Nullable; import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.Nullable; /** * Converts from a String to a Kotlin {@link Regex}. @@ -31,8 +31,7 @@ import org.springframework.lang.Nullable; final class StringToRegexConverter implements Converter { @Override - @Nullable - public Regex convert(String source) { + public @Nullable Regex convert(String source) { if (source.isEmpty()) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java index cb63290f4e..ea189065fb 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToUUIDConverter.java @@ -18,8 +18,9 @@ package org.springframework.core.convert.support; import java.util.UUID; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -32,8 +33,7 @@ import org.springframework.util.StringUtils; final class StringToUUIDConverter implements Converter { @Override - @Nullable - public UUID convert(String source) { + public @Nullable UUID convert(String source) { return (StringUtils.hasText(source) ? UUID.fromString(source.trim()) : null); } 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 c516a7e37f..6ca951f898 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,9 +1,7 @@ /** * Default implementation of the type conversion system. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.convert.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index de1e84c535..fa3fa1907b 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -24,10 +24,10 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.SpringProperties; import org.springframework.core.convert.support.ConfigurableConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -288,8 +288,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { * @since 5.3.4 * @see #ACTIVE_PROFILES_PROPERTY_NAME */ - @Nullable - protected String doGetActiveProfilesProperty() { + protected @Nullable String doGetActiveProfilesProperty() { return getProperty(ACTIVE_PROFILES_PROPERTY_NAME); } @@ -355,8 +354,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { * @since 5.3.4 * @see #DEFAULT_PROFILES_PROPERTY_NAME */ - @Nullable - protected String doGetDefaultProfilesProperty() { + protected @Nullable String doGetDefaultProfilesProperty() { return getProperty(DEFAULT_PROFILES_PROPERTY_NAME); } @@ -552,8 +550,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return this.propertyResolver.getProperty(key); } @@ -563,8 +560,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } @Override - @Nullable - public T getProperty(String key, Class targetType) { + public @Nullable T getProperty(String key, Class targetType) { return this.propertyResolver.getProperty(key, targetType); } 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 151c482b7e..fdea0e0ce2 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 @@ -22,11 +22,11 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -43,14 +43,11 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private volatile ConfigurableConversionService conversionService; + private volatile @Nullable ConfigurableConversionService conversionService; - @Nullable - private PropertyPlaceholderHelper nonStrictHelper; + private @Nullable PropertyPlaceholderHelper nonStrictHelper; - @Nullable - private PropertyPlaceholderHelper strictHelper; + private @Nullable PropertyPlaceholderHelper strictHelper; private boolean ignoreUnresolvableNestedPlaceholders = false; @@ -58,11 +55,9 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe private String placeholderSuffix = SystemPropertyUtils.PLACEHOLDER_SUFFIX; - @Nullable - private String valueSeparator = SystemPropertyUtils.VALUE_SEPARATOR; + private @Nullable String valueSeparator = SystemPropertyUtils.VALUE_SEPARATOR; - @Nullable - private Character escapeCharacter = SystemPropertyUtils.ESCAPE_CHARACTER; + private @Nullable Character escapeCharacter = SystemPropertyUtils.ESCAPE_CHARACTER; private final Set requiredProperties = new LinkedHashSet<>(); @@ -175,8 +170,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe } @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return getProperty(key, String.class); } @@ -264,8 +258,7 @@ public abstract class AbstractPropertyResolver implements ConfigurablePropertyRe * @since 4.3.5 */ @SuppressWarnings("unchecked") - @Nullable - protected T convertValueIfNecessary(Object value, @Nullable Class targetType) { + protected @Nullable T convertValueIfNecessary(Object value, @Nullable Class targetType) { if (targetType == null) { return (T) value; } @@ -288,7 +281,6 @@ 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); + protected abstract @Nullable 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 d221596667..aa3a5f15c8 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,7 +23,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A simple representation of command line arguments, broken into @@ -73,8 +73,7 @@ class CommandLineArgs { *

{@code null} signifies that the option was not present on the command * line. An empty list signifies that no values were associated with this option. */ - @Nullable - public List getOptionValues(String optionName) { + public @Nullable 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 a49d3e93d8..3e941d53cb 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,7 +19,8 @@ package org.springframework.core.env; import java.util.Collection; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -265,8 +266,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou * #getOptionValues(String)} method. */ @Override - @Nullable - public final String getProperty(String name) { + public final @Nullable String getProperty(String name) { if (this.nonOptionArgsPropertyName.equals(name)) { Collection nonOptionArguments = getNonOptionArgs(); if (nonOptionArguments.isEmpty()) { @@ -306,8 +306,7 @@ public abstract class CommandLinePropertySource extends EnumerablePropertySou *

  • if the option is not present, return {@code null}
  • * */ - @Nullable - protected abstract List getOptionValues(String name); + protected abstract @Nullable List getOptionValues(String name); /** * Return the collection of non-option arguments parsed from the command line. diff --git a/spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java index 5fe8115842..c3c0ba4aae 100644 --- a/spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/CompositePropertySource.java @@ -23,7 +23,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -56,8 +57,7 @@ public class CompositePropertySource extends EnumerablePropertySource { @Override - @Nullable - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { for (PropertySource propertySource : this.propertySources) { Object candidate = propertySource.getProperty(name); if (candidate != null) { 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 01f47dae1f..f4113d144c 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 @@ -16,8 +16,9 @@ package org.springframework.core.env; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.support.ConfigurableConversionService; -import org.springframework.lang.Nullable; /** * Configuration interface to be implemented by most if not all {@link PropertyResolver} diff --git a/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java index 679bca5b14..6a90eed009 100644 --- a/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/JOptCommandLinePropertySource.java @@ -22,8 +22,8 @@ import java.util.List; import joptsimple.OptionSet; import joptsimple.OptionSpec; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -104,8 +104,7 @@ public class JOptCommandLinePropertySource extends CommandLinePropertySource getOptionValues(String name) { + public @Nullable List getOptionValues(String name) { List argValues = this.source.valuesOf(name); List stringArgValues = new ArrayList<>(); for (Object argValue : argValues) { diff --git a/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java b/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java index 36597a5b24..975c086b3d 100644 --- a/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/MapPropertySource.java @@ -18,7 +18,8 @@ package org.springframework.core.env; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -45,8 +46,7 @@ public class MapPropertySource extends EnumerablePropertySource get(String name) { + public @Nullable PropertySource get(String name) { for (PropertySource propertySource : this.propertySourceList) { if (propertySource.getName().equals(name)) { return propertySource; @@ -155,8 +154,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) { + public @Nullable PropertySource remove(String name) { synchronized (this.propertySourceList) { int index = this.propertySourceList.indexOf(PropertySource.named(name)); return (index != -1 ? this.propertySourceList.remove(index) : null); diff --git a/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java b/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java index dcc9474e5d..b4398dc6c1 100644 --- a/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java +++ b/spring-core/src/main/java/org/springframework/core/env/ProfilesParser.java @@ -26,7 +26,8 @@ import java.util.StringTokenizer; import java.util.function.Predicate; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 173a1a3378..e346e53041 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,7 +16,7 @@ package org.springframework.core.env; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface for resolving properties against any underlying source. @@ -43,8 +43,7 @@ public interface PropertyResolver { * @see #getProperty(String, Class) * @see #getRequiredProperty(String) */ - @Nullable - String getProperty(String key); + @Nullable String getProperty(String key); /** * Return the property value associated with the given key, or @@ -63,8 +62,7 @@ public interface PropertyResolver { * @param targetType the expected type of the property value * @see #getRequiredProperty(String, Class) */ - @Nullable - T getProperty(String key, Class targetType); + @Nullable T getProperty(String key, Class targetType); /** * Return the property value associated with the given key, 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 3135f07220..98e9174576 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 @@ -20,8 +20,8 @@ import java.util.Objects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -125,8 +125,7 @@ public abstract class PropertySource { * @param name the property to find * @see PropertyResolver#getRequiredProperty(String) */ - @Nullable - public abstract Object getProperty(String name); + public abstract @Nullable Object getProperty(String name); /** @@ -218,8 +217,7 @@ public abstract class PropertySource { * Always returns {@code null}. */ @Override - @Nullable - public String getProperty(String name) { + public @Nullable String getProperty(String name) { return null; } } @@ -251,8 +249,7 @@ public abstract class PropertySource { } @Override - @Nullable - public String getProperty(String name) { + public @Nullable String getProperty(String name) { throw new UnsupportedOperationException(USAGE_ERROR); } } 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 0296ea1a27..d6e6ab80fa 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 @@ -19,7 +19,7 @@ package org.springframework.core.env; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Holder containing one or more {@link PropertySource} objects. @@ -49,7 +49,6 @@ 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); + @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 3558d0fa77..9b35cc2d68 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,7 +16,7 @@ package org.springframework.core.env; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link PropertyResolver} implementation that resolves property values against @@ -31,8 +31,7 @@ import org.springframework.lang.Nullable; */ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver { - @Nullable - private final PropertySources propertySources; + private final @Nullable PropertySources propertySources; /** @@ -57,25 +56,21 @@ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver { } @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return getProperty(key, String.class, true); } @Override - @Nullable - public T getProperty(String key, Class targetValueType) { + public @Nullable T getProperty(String key, Class targetValueType) { return getProperty(key, targetValueType, true); } @Override - @Nullable - protected String getPropertyAsRawString(String key) { + protected @Nullable String getPropertyAsRawString(String key) { return getProperty(key, String.class, false); } - @Nullable - protected T getProperty(String key, Class targetValueType, boolean resolveNestedPlaceholders) { + protected @Nullable T getProperty(String key, Class targetValueType, boolean resolveNestedPlaceholders) { if (this.propertySources != null) { for (PropertySource propertySource : this.propertySources) { if (logger.isTraceEnabled()) { diff --git a/spring-core/src/main/java/org/springframework/core/env/SimpleCommandLinePropertySource.java b/spring-core/src/main/java/org/springframework/core/env/SimpleCommandLinePropertySource.java index 767d9b6211..64dd05cd4f 100644 --- a/spring-core/src/main/java/org/springframework/core/env/SimpleCommandLinePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/env/SimpleCommandLinePropertySource.java @@ -18,7 +18,8 @@ package org.springframework.core.env; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -126,8 +127,7 @@ public class SimpleCommandLinePropertySource extends CommandLinePropertySource getOptionValues(String name) { + protected @Nullable List getOptionValues(String name) { return this.source.getOptionValues(name); } 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 ebea271253..33e088597d 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 @@ -19,7 +19,8 @@ package org.springframework.core.env; import java.util.Locale; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -89,8 +90,7 @@ public class SystemEnvironmentPropertySource extends MapPropertySource { * any underscore/uppercase variant thereof exists in this property source. */ @Override - @Nullable - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { String actualName = resolvePropertyName(name); if (logger.isDebugEnabled() && !name.equals(actualName)) { logger.debug("PropertySource '" + getName() + "' does not contain property '" + name + @@ -120,8 +120,7 @@ public class SystemEnvironmentPropertySource extends MapPropertySource { return name; } - @Nullable - private String checkPropertyName(String name) { + private @Nullable String checkPropertyName(String name) { // Check name as-is if (this.source.containsKey(name)) { return 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 a0784c4c8d..d2253a9b04 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,9 +2,7 @@ * Spring's environment abstraction consisting of bean definition * profile and hierarchical property source support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.env; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index 4e70092fb7..87b98ed8ce 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -29,8 +29,8 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ResourceUtils; /** @@ -215,8 +215,7 @@ public abstract class AbstractResource implements Resource { * assuming that this resource type does not have a filename. */ @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java index b0f84a9460..03af0cbc92 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java @@ -22,7 +22,8 @@ import java.io.InputStream; import java.nio.charset.Charset; import java.util.Arrays; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 1454b92f80..72e8c532dd 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,7 +21,8 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -53,11 +54,9 @@ public class ClassPathResource extends AbstractFileResolvingResource { private final String absolutePath; - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; - @Nullable - private final Class clazz; + private final @Nullable Class clazz; /** @@ -140,8 +139,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { /** * Return the {@link ClassLoader} that this resource will be obtained from. */ - @Nullable - public final ClassLoader getClassLoader() { + public final @Nullable ClassLoader getClassLoader() { return (this.clazz != null ? this.clazz.getClassLoader() : this.classLoader); } @@ -172,8 +170,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { * Resolves a {@link URL} for the underlying class path resource. * @return the resolved URL, or {@code null} if not resolvable */ - @Nullable - protected URL resolveURL() { + protected @Nullable URL resolveURL() { try { if (this.clazz != null) { return this.clazz.getResource(this.path); @@ -250,8 +247,7 @@ public class ClassPathResource extends AbstractFileResolvingResource { * @see StringUtils#getFilename(String) */ @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return StringUtils.getFilename(this.absolutePath); } 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 c7a7403a74..eac1fd4646 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,7 +24,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ResourceUtils; @@ -48,8 +49,7 @@ import org.springframework.util.StringUtils; */ public class DefaultResourceLoader implements ResourceLoader { - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; private final Set protocolResolvers = new LinkedHashSet<>(4); @@ -93,8 +93,7 @@ public class DefaultResourceLoader implements ResourceLoader { * @see ClassPathResource */ @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return (this.classLoader != null ? this.classLoader : ClassUtils.getDefaultClassLoader()); } diff --git a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java index 49d9d854a9..1c600f5bb0 100644 --- a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java @@ -20,7 +20,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple {@link Resource} implementation that holds a resource description diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index fcae1575c6..acd8c98abd 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java @@ -34,7 +34,8 @@ import java.nio.file.NoSuchFileException; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -63,8 +64,7 @@ public class FileSystemResource extends AbstractResource implements WritableReso private final String path; - @Nullable - private final File file; + private final @Nullable File file; private final Path filePath; diff --git a/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java b/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java index b910bbc916..7bb38ad93d 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileUrlResource.java @@ -26,7 +26,8 @@ import java.nio.channels.WritableByteChannel; import java.nio.file.Files; import java.nio.file.StandardOpenOption; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ResourceUtils; /** @@ -45,8 +46,7 @@ import org.springframework.util.ResourceUtils; */ public class FileUrlResource extends UrlResource implements WritableResource { - @Nullable - private volatile File file; + private volatile @Nullable File file; /** diff --git a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java index 906eb233a6..1666d1e939 100644 --- a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java @@ -19,7 +19,8 @@ package org.springframework.core.io; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java b/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java index 225a6042a3..0413f83667 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ModuleResource.java @@ -20,7 +20,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -93,8 +94,7 @@ public class ModuleResource extends AbstractResource { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return StringUtils.getFilename(this.path); } diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index 729f080230..fb6ba958a1 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -33,7 +33,8 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 53cc9301eb..cf0def7ca8 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,7 +16,7 @@ package org.springframework.core.io; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A resolution strategy for protocol-specific resource handles. @@ -40,7 +40,6 @@ 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); + @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 91458934fe..44975e1fdc 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 @@ -26,7 +26,8 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.charset.Charset; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.FileCopyUtils; /** @@ -193,8 +194,7 @@ public interface Resource extends InputStreamSource { * have a filename. *

    Implementations are encouraged to return the filename unencoded. */ - @Nullable - String getFilename(); + @Nullable String getFilename(); /** * Return a description for this resource, 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 0eec6fd6a3..1cb67aa898 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 @@ -19,9 +19,10 @@ package org.springframework.core.io; import java.beans.PropertyEditorSupport; import java.io.IOException; +import org.jspecify.annotations.Nullable; + 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; @@ -51,8 +52,7 @@ public class ResourceEditor extends PropertyEditorSupport { private final ResourceLoader resourceLoader; - @Nullable - private PropertyResolver propertyResolver; + private @Nullable PropertyResolver propertyResolver; private final boolean ignoreUnresolvablePlaceholders; @@ -122,8 +122,7 @@ public class ResourceEditor extends PropertyEditorSupport { @Override - @Nullable - public String getAsText() { + public @Nullable String getAsText() { Resource value = (Resource) getValue(); try { // Try to determine URL for resource. 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 2c58f931d1..cc44f95cfc 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,7 +16,8 @@ package org.springframework.core.io; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ResourceUtils; /** @@ -76,7 +77,6 @@ public interface ResourceLoader { * @see org.springframework.util.ClassUtils#getDefaultClassLoader() * @see org.springframework.util.ClassUtils#forName(String, ClassLoader) */ - @Nullable - ClassLoader getClassLoader(); + @Nullable ClassLoader getClassLoader(); } diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index 4c5c3e0226..a85ddbf8a5 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -30,7 +30,8 @@ import java.net.URLDecoder; import java.nio.charset.StandardCharsets; import java.util.Base64; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -53,8 +54,7 @@ public class UrlResource extends AbstractFileResolvingResource { /** * Original URI, if available; used for URI and File access. */ - @Nullable - private final URI uri; + private final @Nullable URI uri; /** * Original URL, used for actual access. @@ -64,8 +64,7 @@ public class UrlResource extends AbstractFileResolvingResource { /** * Cleaned URL String (with normalized path), used for comparisons. */ - @Nullable - private volatile String cleanedUrl; + private volatile @Nullable String cleanedUrl; /** @@ -331,8 +330,7 @@ public class UrlResource extends AbstractFileResolvingResource { * @see java.net.URLDecoder#decode(String, java.nio.charset.Charset) */ @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { if (this.uri != null) { String path = this.uri.getPath(); if (path != null) { diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java index 00203ed3b9..16f2a7757e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java @@ -22,7 +22,8 @@ import java.io.InputStream; import java.net.URI; import java.net.URL; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java b/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java index 781712a224..6ecdbf2c3b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsUtils.java @@ -25,7 +25,8 @@ import java.lang.reflect.Method; import java.net.URI; import java.net.URL; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ReflectionUtils; /** @@ -184,13 +185,11 @@ public abstract class VfsUtils { return invokeVfsMethod(VFS_METHOD_GET_ROOT_URL, null, url); } - @Nullable - protected static Object doGetVisitorAttributes() { + protected static @Nullable Object doGetVisitorAttributes() { return ReflectionUtils.getField(VISITOR_ATTRIBUTES_FIELD_RECURSE, null); } - @Nullable - protected static String doGetPath(Object resource) { + protected static @Nullable String doGetPath(Object resource) { return (String) ReflectionUtils.invokeMethod(VIRTUAL_FILE_METHOD_GET_PATH_NAME, resource); } diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java index e8de69083d..87aef781cc 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java @@ -41,6 +41,7 @@ import java.util.function.Consumer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -52,7 +53,6 @@ import reactor.core.publisher.SynchronousSink; import reactor.util.context.Context; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java index d9d43da4ee..fa05dd6ae1 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/DefaultDataBuffer.java @@ -22,7 +22,8 @@ import java.util.Arrays; import java.util.NoSuchElementException; import java.util.function.IntPredicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/JettyDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/JettyDataBuffer.java index 5d211bfc31..3ce726369b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/JettyDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/JettyDataBuffer.java @@ -22,8 +22,8 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.IntPredicate; import org.eclipse.jetty.io.Content; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,8 +39,7 @@ public final class JettyDataBuffer implements PooledDataBuffer { private final DefaultDataBuffer delegate; - @Nullable - private final Content.Chunk chunk; + private final Content.@Nullable Chunk chunk; private final JettyDataBufferFactory bufferFactory; diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java index 70a544cd4f..418938eaa5 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/Netty5DataBuffer.java @@ -24,8 +24,8 @@ import java.util.function.IntPredicate; import io.netty5.buffer.Buffer; import io.netty5.buffer.BufferComponent; import io.netty5.buffer.ComponentIterator; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -359,8 +359,7 @@ public final class Netty5DataBuffer implements CloseableDataBuffer, TouchableDat private final boolean readable; - @Nullable - private T next; + private @Nullable T next; public BufferComponentIterator(ComponentIterator delegate, boolean readable) { Assert.notNull(delegate, "Delegate must not be null"); diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java index ddcc6c6f9b..9c7d22e15b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/NettyDataBuffer.java @@ -24,8 +24,8 @@ import java.util.function.IntPredicate; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java b/spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java index dc6cad9101..4dadbd6163 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/OutputStreamPublisher.java @@ -25,11 +25,11 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -139,8 +139,7 @@ final class OutputStreamPublisher implements Publisher { private final AtomicReference parkedThread = new AtomicReference<>(); - @Nullable - private volatile Throwable error; + private volatile @Nullable Throwable error; private long produced; diff --git a/spring-core/src/main/java/org/springframework/core/io/buffer/SubscriberInputStream.java b/spring-core/src/main/java/org/springframework/core/io/buffer/SubscriberInputStream.java index 4fc6d0eae7..505260af86 100644 --- a/spring-core/src/main/java/org/springframework/core/io/buffer/SubscriberInputStream.java +++ b/spring-core/src/main/java/org/springframework/core/io/buffer/SubscriberInputStream.java @@ -28,11 +28,11 @@ import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; import java.util.concurrent.locks.ReentrantLock; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.Exceptions; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -80,16 +80,13 @@ final class SubscriberInputStream extends InputStream implements Subscriber isNotSystemModule = resolvedModule -> !systemModuleNames.contains(resolvedModule.name()); - @Nullable - private static Method equinoxResolveMethod; + private static @Nullable Method equinoxResolveMethod; static { try { @@ -260,8 +259,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol private final Map> jarEntriesCache = new ConcurrentHashMap<>(); - @Nullable - private volatile Set manifestEntriesCache; + private volatile @Nullable Set manifestEntriesCache; /** @@ -307,8 +305,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return getResourceLoader().getClassLoader(); } @@ -1075,8 +1072,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol return result; } - @Nullable - private Resource findResource(ModuleReader moduleReader, String name) { + private @Nullable Resource findResource(ModuleReader moduleReader, String name) { try { return moduleReader.find(name) .map(this::convertModuleSystemURI) @@ -1142,8 +1138,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (Object.class == method.getDeclaringClass()) { switch (methodName) { @@ -1174,8 +1169,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol } } - @Nullable - public Object getAttributes() { + public @Nullable Object getAttributes() { return VfsPatternUtils.getVisitorAttributes(); } @@ -1224,8 +1218,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol * @param path the file path (with or without a leading slash) * @return the alternative form or {@code null} */ - @Nullable - private static Resource createAlternative(String path) { + private static @Nullable Resource createAlternative(String path) { try { String alternativePath = path.startsWith("/") ? path.substring(1) : "/" + path; return asJarFileResource(alternativePath); diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java index 85d53d4047..3a6955bd03 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertiesLoaderSupport.java @@ -24,9 +24,9 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.DefaultPropertiesPersister; import org.springframework.util.PropertiesPersister; @@ -44,18 +44,15 @@ public abstract class PropertiesLoaderSupport { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - protected Properties[] localProperties; + protected Properties @Nullable [] localProperties; protected boolean localOverride = false; - @Nullable - private Resource[] locations; + private Resource @Nullable [] locations; private boolean ignoreResourceNotFound = false; - @Nullable - private String fileEncoding; + private @Nullable String fileEncoding; private PropertiesPersister propertiesPersister = DefaultPropertiesPersister.INSTANCE; 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 af5d58e8ec..241f1ee552 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 @@ -24,8 +24,9 @@ import java.net.URLConnection; import java.util.Enumeration; import java.util.Properties; +import org.jspecify.annotations.Nullable; + 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; diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceDescriptor.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceDescriptor.java index 6c3059b527..7b55af24dc 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceDescriptor.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceDescriptor.java @@ -19,7 +19,7 @@ package org.springframework.core.io.support; import java.util.Arrays; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Descriptor for a {@link org.springframework.core.env.PropertySource PropertySource}. diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceFactory.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceFactory.java index 3de69fca7c..3ee58ad9ee 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceFactory.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceFactory.java @@ -18,8 +18,9 @@ package org.springframework.core.io.support; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.env.PropertySource; -import org.springframework.lang.Nullable; /** * Strategy interface for creating resource-based {@link PropertySource} wrappers. diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java index 02f0370b22..33174276ec 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PropertySourceProcessor.java @@ -26,6 +26,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.env.CompositePropertySource; import org.springframework.core.env.ConfigurableEnvironment; @@ -34,7 +35,6 @@ import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.PlaceholderResolutionException; import org.springframework.util.ReflectionUtils; diff --git a/spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java b/spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java index 0a16606c9c..cb30e846c1 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/ResourceArrayPropertyEditor.java @@ -26,12 +26,12 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.env.Environment; import org.springframework.core.env.PropertyResolver; import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -64,8 +64,7 @@ public class ResourceArrayPropertyEditor extends PropertyEditorSupport { private final ResourcePatternResolver resourcePatternResolver; - @Nullable - private PropertyResolver propertyResolver; + private @Nullable PropertyResolver propertyResolver; private final boolean ignoreUnresolvablePlaceholders; 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 c6c778430b..a3e4e3b013 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 @@ -16,8 +16,9 @@ package org.springframework.core.io.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.util.ResourceUtils; /** diff --git a/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertySource.java b/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertySource.java index ad9e57aa4b..342588ec7b 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertySource.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/ResourcePropertySource.java @@ -20,10 +20,11 @@ import java.io.IOException; import java.util.Map; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.core.env.PropertiesPropertySource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -45,8 +46,7 @@ import org.springframework.util.StringUtils; public class ResourcePropertySource extends PropertiesPropertySource { /** The original resource name, if different from the given name. */ - @Nullable - private final String resourceName; + private final @Nullable String resourceName; /** 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 2bfefa1c40..c2dc31a2c3 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 @@ -41,12 +41,12 @@ import kotlin.reflect.jvm.KCallablesJvm; import kotlin.reflect.jvm.ReflectJvmMapping; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.KotlinDetector; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.io.UrlResource; import org.springframework.core.log.LogMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -104,8 +104,7 @@ public class SpringFactoriesLoader { static final Map> cache = new ConcurrentReferenceHashMap<>(); - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final Map> factories; @@ -216,8 +215,7 @@ public class SpringFactoriesLoader { return this.factories.getOrDefault(factoryType.getName(), Collections.emptyList()); } - @Nullable - protected T instantiateFactory(String implementationName, Class type, + protected @Nullable T instantiateFactory(String implementationName, Class type, @Nullable ArgumentResolver argumentResolver, FailureHandler failureHandler) { try { @@ -397,8 +395,7 @@ public class SpringFactoriesLoader { return new FactoryInstantiator<>((Constructor) constructor); } - @Nullable - private static Constructor findConstructor(Class factoryImplementationClass) { + private static @Nullable Constructor findConstructor(Class factoryImplementationClass) { // Same algorithm as BeanUtils.getResolvableConstructor Constructor constructor = findPrimaryKotlinConstructor(factoryImplementationClass); constructor = (constructor != null ? constructor : @@ -410,8 +407,7 @@ public class SpringFactoriesLoader { return constructor; } - @Nullable - private static Constructor findPrimaryKotlinConstructor(Class factoryImplementationClass) { + private static @Nullable Constructor findPrimaryKotlinConstructor(Class factoryImplementationClass) { return (isKotlinType(factoryImplementationClass) ? KotlinDelegate.findPrimaryConstructor(factoryImplementationClass) : null); } @@ -420,13 +416,11 @@ public class SpringFactoriesLoader { return KotlinDetector.isKotlinReflectPresent() && KotlinDetector.isKotlinType(factoryImplementationClass); } - @Nullable - private static Constructor findSingleConstructor(Constructor[] constructors) { + private static @Nullable Constructor findSingleConstructor(Constructor[] constructors) { return (constructors.length == 1 ? constructors[0] : null); } - @Nullable - private static Constructor findDeclaredConstructor(Class factoryImplementationClass) { + private static @Nullable Constructor findDeclaredConstructor(Class factoryImplementationClass) { try { return factoryImplementationClass.getDeclaredConstructor(); } @@ -443,8 +437,7 @@ public class SpringFactoriesLoader { */ private static class KotlinDelegate { - @Nullable - static Constructor findPrimaryConstructor(Class clazz) { + static @Nullable Constructor findPrimaryConstructor(Class clazz) { try { KFunction primaryConstructor = KClasses.getPrimaryConstructor(JvmClassMappingKt.getKotlinClass(clazz)); if (primaryConstructor != null) { @@ -512,8 +505,7 @@ public class SpringFactoriesLoader { * @param type the argument type * @return the resolved argument value or {@code null} */ - @Nullable - T resolve(Class type); + @Nullable T resolve(Class type); /** * Create a new composed {@link ArgumentResolver} by combining this resolver diff --git a/spring-core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java b/spring-core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java index 5fcaf8af34..767ed07967 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/VfsPatternUtils.java @@ -21,8 +21,9 @@ import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; import java.net.URL; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.VfsUtils; -import org.springframework.lang.Nullable; /** * Artificial class used for accessing the {@link VfsUtils} methods @@ -33,8 +34,7 @@ import org.springframework.lang.Nullable; */ abstract class VfsPatternUtils extends VfsUtils { - @Nullable - static Object getVisitorAttributes() { + static @Nullable Object getVisitorAttributes() { return doGetVisitorAttributes(); } 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 2b1395fbb2..36169e1f51 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,9 +2,7 @@ * Support classes for Spring's resource abstraction. * Includes a ResourcePatternResolver mechanism. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.io.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java b/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java index 52cf86663e..6ddce2c76d 100644 --- a/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java +++ b/spring-core/src/main/java/org/springframework/core/log/LogFormatUtils.java @@ -20,8 +20,8 @@ import java.util.function.Function; import java.util.regex.Pattern; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; diff --git a/spring-core/src/main/java/org/springframework/core/log/LogMessage.java b/spring-core/src/main/java/org/springframework/core/log/LogMessage.java index e1206d5c35..12669dc7ef 100644 --- a/spring-core/src/main/java/org/springframework/core/log/LogMessage.java +++ b/spring-core/src/main/java/org/springframework/core/log/LogMessage.java @@ -18,7 +18,8 @@ package org.springframework.core.log; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -42,8 +43,7 @@ import org.springframework.util.Assert; */ public abstract class LogMessage implements CharSequence { - @Nullable - private String result; + private @Nullable String result; @Override @@ -176,8 +176,7 @@ public abstract class LogMessage implements CharSequence { private static final class FormatMessage1 extends FormatMessage { - @Nullable - private final Object arg1; + private final @Nullable Object arg1; FormatMessage1(String format, @Nullable Object arg1) { super(format); @@ -193,11 +192,9 @@ public abstract class LogMessage implements CharSequence { private static final class FormatMessage2 extends FormatMessage { - @Nullable - private final Object arg1; + private final @Nullable Object arg1; - @Nullable - private final Object arg2; + private final @Nullable Object arg2; FormatMessage2(String format, @Nullable Object arg1, @Nullable Object arg2) { super(format); @@ -214,14 +211,11 @@ public abstract class LogMessage implements CharSequence { private static final class FormatMessage3 extends FormatMessage { - @Nullable - private final Object arg1; + private final @Nullable Object arg1; - @Nullable - private final Object arg2; + private final @Nullable Object arg2; - @Nullable - private final Object arg3; + private final @Nullable Object arg3; FormatMessage3(String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3) { super(format); @@ -239,17 +233,13 @@ public abstract class LogMessage implements CharSequence { private static final class FormatMessage4 extends FormatMessage { - @Nullable - private final Object arg1; + private final @Nullable Object arg1; - @Nullable - private final Object arg2; + private final @Nullable Object arg2; - @Nullable - private final Object arg3; + private final @Nullable Object arg3; - @Nullable - private final Object arg4; + private final @Nullable Object arg4; FormatMessage4(String format, @Nullable Object arg1, @Nullable Object arg2, @Nullable Object arg3, @Nullable Object arg4) { @@ -269,8 +259,7 @@ public abstract class LogMessage implements CharSequence { private static final class FormatMessageX extends FormatMessage { - @Nullable - private final Object[] args; + private final @Nullable Object[] args; FormatMessageX(String format, @Nullable Object... args) { super(format); diff --git a/spring-core/src/main/java/org/springframework/core/log/package-info.java b/spring-core/src/main/java/org/springframework/core/log/package-info.java index b14fac177c..eb628ffa88 100644 --- a/spring-core/src/main/java/org/springframework/core/log/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/log/package-info.java @@ -1,9 +1,7 @@ /** * Useful delegates for Spring's logging conventions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.log; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java b/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java index 9a497d3eb9..b32263a01b 100644 --- a/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java +++ b/spring-core/src/main/java/org/springframework/core/metrics/DefaultApplicationStartup.java @@ -20,7 +20,7 @@ import java.util.Collections; import java.util.Iterator; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Default "no op" {@code ApplicationStartup} implementation. @@ -54,8 +54,7 @@ class DefaultApplicationStartup implements ApplicationStartup { } @Override - @Nullable - public Long getParentId() { + public @Nullable Long getParentId() { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/metrics/StartupStep.java b/spring-core/src/main/java/org/springframework/core/metrics/StartupStep.java index e9061cb423..2f35beefdc 100644 --- a/spring-core/src/main/java/org/springframework/core/metrics/StartupStep.java +++ b/spring-core/src/main/java/org/springframework/core/metrics/StartupStep.java @@ -18,7 +18,7 @@ package org.springframework.core.metrics; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Step recording metrics about a particular phase or action happening during the {@link ApplicationStartup}. @@ -56,8 +56,7 @@ public interface StartupStep { *

    The parent step is the step that was started the most recently * when the current step was created. */ - @Nullable - Long getParentId(); + @Nullable Long getParentId(); /** * Add a {@link Tag} to the step. diff --git a/spring-core/src/main/java/org/springframework/core/metrics/jfr/package-info.java b/spring-core/src/main/java/org/springframework/core/metrics/jfr/package-info.java index 54b7c8db11..b005cb230b 100644 --- a/spring-core/src/main/java/org/springframework/core/metrics/jfr/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/metrics/jfr/package-info.java @@ -1,9 +1,7 @@ /** * Support package for recording startup metrics using Java Flight Recorder. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.metrics.jfr; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/metrics/package-info.java b/spring-core/src/main/java/org/springframework/core/metrics/package-info.java index 8774a4bd11..c4deb39d6a 100644 --- a/spring-core/src/main/java/org/springframework/core/metrics/package-info.java +++ b/spring-core/src/main/java/org/springframework/core/metrics/package-info.java @@ -1,9 +1,7 @@ /** * Support package for recording metrics during application startup. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.metrics; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 703f29b4b2..b347e187ed 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.core; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java b/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java index 3096daf961..9a642fe4c8 100644 --- a/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java +++ b/spring-core/src/main/java/org/springframework/core/serializer/DefaultDeserializer.java @@ -20,8 +20,9 @@ import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ConfigurableObjectInputStream; -import org.springframework.lang.Nullable; /** * A default {@link Deserializer} implementation that reads an input stream @@ -35,8 +36,7 @@ import org.springframework.lang.Nullable; */ public class DefaultDeserializer implements Deserializer { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; /** 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 88f4d3ba4a..f3d5b17802 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,9 +3,7 @@ * Provides an abstraction over various serialization techniques. * Includes exceptions for serialization and deserialization failures. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.serializer; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/serializer/support/DeserializingConverter.java b/spring-core/src/main/java/org/springframework/core/serializer/support/DeserializingConverter.java index 782ddc901b..c8accc6e38 100644 --- a/spring-core/src/main/java/org/springframework/core/serializer/support/DeserializingConverter.java +++ b/spring-core/src/main/java/org/springframework/core/serializer/support/DeserializingConverter.java @@ -18,10 +18,11 @@ package org.springframework.core.serializer.support; import java.io.ByteArrayInputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; import org.springframework.core.serializer.DefaultDeserializer; import org.springframework.core.serializer.Deserializer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 4e46ea8a59..499d6224ab 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,9 +2,7 @@ * Support classes for Spring's serializer abstraction. * Includes adapters to the Converter SPI. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.serializer.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/core/style/DefaultToStringStyler.java b/spring-core/src/main/java/org/springframework/core/style/DefaultToStringStyler.java index 9eb0d37205..5ad1e93a59 100644 --- a/spring-core/src/main/java/org/springframework/core/style/DefaultToStringStyler.java +++ b/spring-core/src/main/java/org/springframework/core/style/DefaultToStringStyler.java @@ -16,7 +16,8 @@ package org.springframework.core.style; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; diff --git a/spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.java b/spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.java index 3dd8891646..50548a6d17 100644 --- a/spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.java +++ b/spring-core/src/main/java/org/springframework/core/style/DefaultValueStyler.java @@ -23,7 +23,8 @@ import java.util.Map; import java.util.Set; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; diff --git a/spring-core/src/main/java/org/springframework/core/style/ToStringCreator.java b/spring-core/src/main/java/org/springframework/core/style/ToStringCreator.java index fbb5cc96bd..d857f85982 100644 --- a/spring-core/src/main/java/org/springframework/core/style/ToStringCreator.java +++ b/spring-core/src/main/java/org/springframework/core/style/ToStringCreator.java @@ -16,7 +16,8 @@ package org.springframework.core.style; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-core/src/main/java/org/springframework/core/style/ToStringStyler.java b/spring-core/src/main/java/org/springframework/core/style/ToStringStyler.java index 3e20e72d94..06d3793e9d 100644 --- a/spring-core/src/main/java/org/springframework/core/style/ToStringStyler.java +++ b/spring-core/src/main/java/org/springframework/core/style/ToStringStyler.java @@ -16,7 +16,7 @@ package org.springframework.core.style; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A strategy interface for pretty-printing {@code toString()} methods. 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 974a72d551..a2e21f5a95 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,7 +16,7 @@ package org.springframework.core.style; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy that encapsulates value String styling algorithms 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 c3fe9bfa48..7bd028d63c 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,9 +1,7 @@ /** * Support for styling values as Strings, with ToStringCreator as central class. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.style; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 413a80367d..1d7e821a70 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 @@ -24,7 +24,8 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.ThreadFactory; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ConcurrencyThrottleSupport; import org.springframework.util.CustomizableThreadCreator; @@ -76,19 +77,15 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator /** Internal concurrency throttle used by this executor. */ private final ConcurrencyThrottleAdapter concurrencyThrottle = new ConcurrencyThrottleAdapter(); - @Nullable - private VirtualThreadDelegate virtualThreadDelegate; + private @Nullable VirtualThreadDelegate virtualThreadDelegate; - @Nullable - private ThreadFactory threadFactory; + private @Nullable ThreadFactory threadFactory; - @Nullable - private TaskDecorator taskDecorator; + private @Nullable TaskDecorator taskDecorator; private long taskTerminationTimeout; - @Nullable - private Set activeThreads; + private @Nullable Set activeThreads; private volatile boolean active = true; @@ -142,8 +139,7 @@ public class SimpleAsyncTaskExecutor extends CustomizableThreadCreator /** * Return the external factory to use for creating new Threads, if any. */ - @Nullable - public final ThreadFactory getThreadFactory() { + public final @Nullable 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 099867d9c6..367345a717 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,9 +2,7 @@ * This package defines Spring's core TaskExecutor abstraction, * and provides SyncTaskExecutor and SimpleAsyncTaskExecutor implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.task; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a9878aab2e..fd9788e35c 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 @@ -23,10 +23,11 @@ import java.util.concurrent.Future; import java.util.concurrent.FutureTask; import java.util.concurrent.RejectedExecutionException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.task.TaskDecorator; import org.springframework.core.task.TaskRejectedException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -46,8 +47,7 @@ public class TaskExecutorAdapter implements AsyncTaskExecutor { private final Executor concurrentExecutor; - @Nullable - private TaskDecorator taskDecorator; + private @Nullable TaskDecorator taskDecorator; /** 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 e9dfcd9dc4..9eb9c52937 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,9 +2,7 @@ * Support classes for Spring's TaskExecutor abstraction. * Includes an adapter for the standard ExecutorService interface. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.task.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f5608ffc34..5fab2a3b19 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 @@ -25,6 +25,8 @@ import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotation.Adapt; @@ -32,7 +34,6 @@ import org.springframework.core.annotation.MergedAnnotationCollectors; import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.MergedAnnotationSelectors; import org.springframework.core.annotation.MergedAnnotations; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -86,8 +87,7 @@ public interface AnnotatedTypeMetadata { * as map key (for example, "location") and the attribute's value as map value; or * {@code null} if no matching annotation is found */ - @Nullable - default Map getAnnotationAttributes(String annotationName) { + default @Nullable Map getAnnotationAttributes(String annotationName) { return getAnnotationAttributes(annotationName, false); } @@ -106,8 +106,7 @@ public interface AnnotatedTypeMetadata { * as map key (for example, "location") and the attribute's value as map value; or * {@code null} if no matching annotation is found */ - @Nullable - default Map getAnnotationAttributes(String annotationName, + default @Nullable Map getAnnotationAttributes(String annotationName, boolean classValuesAsString) { MergedAnnotation annotation = getAnnotations().get(annotationName, @@ -130,8 +129,7 @@ public interface AnnotatedTypeMetadata { * map value; or {@code null} if no matching annotation is found * @see #getAllAnnotationAttributes(String, boolean) */ - @Nullable - default MultiValueMap getAllAnnotationAttributes(String annotationName) { + default @Nullable MultiValueMap getAllAnnotationAttributes(String annotationName) { return getAllAnnotationAttributes(annotationName, false); } @@ -150,8 +148,7 @@ public interface AnnotatedTypeMetadata { * map value; or {@code null} if no matching annotation is found * @see #getAllAnnotationAttributes(String) */ - @Nullable - default MultiValueMap getAllAnnotationAttributes( + default @Nullable MultiValueMap getAllAnnotationAttributes( String annotationName, boolean classValuesAsString) { Adapt[] adaptations = Adapt.values(classValuesAsString, true); 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 cbb5ab4168..96ab62f022 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,7 +16,7 @@ package org.springframework.core.type; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that defines abstract metadata of a specific class, @@ -86,8 +86,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(); + @Nullable String getEnclosingClassName(); /** * Return whether the underlying class has a superclass. @@ -100,8 +99,7 @@ public interface ClassMetadata { * Return the name of the superclass of the underlying class, * or {@code null} if there is no superclass defined. */ - @Nullable - String getSuperClassName(); + @Nullable String getSuperClassName(); /** * Return the names of all interfaces that the underlying class diff --git a/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java b/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java index bc34ed937a..33356252e5 100644 --- a/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/StandardAnnotationMetadata.java @@ -23,13 +23,14 @@ import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.RepeatableContainers; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.util.ReflectionUtils; @@ -50,8 +51,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements private final boolean nestedAnnotationsAsMap; - @Nullable - private Set annotationTypes; + private @Nullable Set annotationTypes; /** @@ -105,8 +105,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements } @Override - @Nullable - public Map getAnnotationAttributes(String annotationName, boolean classValuesAsString) { + public @Nullable Map getAnnotationAttributes(String annotationName, boolean classValuesAsString) { if (this.nestedAnnotationsAsMap) { return AnnotationMetadata.super.getAnnotationAttributes(annotationName, classValuesAsString); } @@ -115,8 +114,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements } @Override - @Nullable - public MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { + public @Nullable MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { if (this.nestedAnnotationsAsMap) { return AnnotationMetadata.super.getAllAnnotationAttributes(annotationName, classValuesAsString); } diff --git a/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java b/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java index 702b5c1b77..6e57d49c45 100644 --- a/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/StandardClassMetadata.java @@ -19,7 +19,8 @@ package org.springframework.core.type; import java.lang.reflect.Modifier; import java.util.LinkedHashSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -88,15 +89,13 @@ public class StandardClassMetadata implements ClassMetadata { } @Override - @Nullable - public String getEnclosingClassName() { + public @Nullable String getEnclosingClassName() { Class enclosingClass = this.introspectedClass.getEnclosingClass(); return (enclosingClass != null ? enclosingClass.getName() : null); } @Override - @Nullable - public String getSuperClassName() { + public @Nullable String getSuperClassName() { Class superClass = this.introspectedClass.getSuperclass(); return (superClass != null ? superClass.getName() : null); } diff --git a/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java b/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java index 40943a223f..7d300dd3b7 100644 --- a/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/StandardMethodMetadata.java @@ -20,11 +20,12 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.RepeatableContainers; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -130,8 +131,7 @@ public class StandardMethodMetadata implements MethodMetadata { } @Override - @Nullable - public Map getAnnotationAttributes(String annotationName, boolean classValuesAsString) { + public @Nullable Map getAnnotationAttributes(String annotationName, boolean classValuesAsString) { if (this.nestedAnnotationsAsMap) { return MethodMetadata.super.getAnnotationAttributes(annotationName, classValuesAsString); } @@ -140,8 +140,7 @@ public class StandardMethodMetadata implements MethodMetadata { } @Override - @Nullable - public MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { + public @Nullable MultiValueMap getAllAnnotationAttributes(String annotationName, boolean classValuesAsString) { if (this.nestedAnnotationsAsMap) { return MethodMetadata.super.getAllAnnotationAttributes(annotationName, classValuesAsString); } diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java b/spring-core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java index 9d9956fcf2..6c8241a5d6 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/CachingMetadataReaderFactory.java @@ -21,10 +21,11 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ConcurrentMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; /** * Caching implementation of the {@link MetadataReaderFactory} interface, @@ -41,8 +42,7 @@ public class CachingMetadataReaderFactory extends SimpleMetadataReaderFactory { public static final int DEFAULT_CACHE_LIMIT = 256; /** MetadataReader cache: either local or shared at the ResourceLoader level. */ - @Nullable - private Map metadataReaderCache; + private @Nullable Map metadataReaderCache; /** diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/MergedAnnotationReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/MergedAnnotationReadingVisitor.java index 1a2bfe899d..e37379a190 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/MergedAnnotationReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/MergedAnnotationReadingVisitor.java @@ -25,12 +25,13 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.AnnotationVisitor; import org.springframework.asm.SpringAsmInfo; import org.springframework.asm.Type; import org.springframework.core.annotation.AnnotationFilter; import org.springframework.core.annotation.MergedAnnotation; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -43,11 +44,9 @@ import org.springframework.util.ClassUtils; */ class MergedAnnotationReadingVisitor extends AnnotationVisitor { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; - @Nullable - private final Object source; + private final @Nullable Object source; private final Class annotationType; @@ -81,8 +80,7 @@ class MergedAnnotationReadingVisitor extends AnnotationVis } @Override - @Nullable - public AnnotationVisitor visitAnnotation(String name, String descriptor) { + public @Nullable AnnotationVisitor visitAnnotation(String name, String descriptor) { return visitAnnotation(descriptor, annotation -> this.attributes.put(name, annotation)); } @@ -108,8 +106,7 @@ class MergedAnnotationReadingVisitor extends AnnotationVis } @SuppressWarnings("unchecked") - @Nullable - private AnnotationVisitor visitAnnotation( + private @Nullable AnnotationVisitor visitAnnotation( String descriptor, Consumer> consumer) { String className = Type.getType(descriptor).getClassName(); @@ -121,8 +118,7 @@ class MergedAnnotationReadingVisitor extends AnnotationVis } @SuppressWarnings("unchecked") - @Nullable - static AnnotationVisitor get(@Nullable ClassLoader classLoader, + static @Nullable AnnotationVisitor get(@Nullable ClassLoader classLoader, @Nullable Object source, String descriptor, boolean visible, Consumer> consumer) { @@ -173,8 +169,7 @@ class MergedAnnotationReadingVisitor extends AnnotationVis } @Override - @Nullable - public AnnotationVisitor visitAnnotation(String name, String descriptor) { + public @Nullable AnnotationVisitor visitAnnotation(String name, String descriptor) { return MergedAnnotationReadingVisitor.this.visitAnnotation(descriptor, this.elements::add); } diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java index ba4c84f1c2..ceb3bb698c 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadata.java @@ -20,11 +20,12 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Opcodes; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.MethodMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -42,11 +43,9 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata { private final int access; - @Nullable - private final String enclosingClassName; + private final @Nullable String enclosingClassName; - @Nullable - private final String superClassName; + private final @Nullable String superClassName; private final boolean independentInnerClass; @@ -58,8 +57,7 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata { private final MergedAnnotations mergedAnnotations; - @Nullable - private Set annotationTypes; + private @Nullable Set annotationTypes; SimpleAnnotationMetadata(String className, int access, @Nullable String enclosingClassName, @@ -108,14 +106,12 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata { } @Override - @Nullable - public String getEnclosingClassName() { + public @Nullable String getEnclosingClassName() { return this.enclosingClassName; } @Override - @Nullable - public String getSuperClassName() { + public @Nullable String getSuperClassName() { return this.superClassName; } diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java index a4e1128e62..d3b72faed0 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleAnnotationMetadataReadingVisitor.java @@ -19,6 +19,8 @@ package org.springframework.core.type.classreading; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.AnnotationVisitor; import org.springframework.asm.ClassVisitor; import org.springframework.asm.MethodVisitor; @@ -27,7 +29,6 @@ import org.springframework.asm.SpringAsmInfo; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.type.MethodMetadata; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -40,18 +41,15 @@ import org.springframework.util.ClassUtils; */ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private String className = ""; private int access; - @Nullable - private String superClassName; + private @Nullable String superClassName; - @Nullable - private String enclosingClassName; + private @Nullable String enclosingClassName; private boolean independentInnerClass; @@ -63,11 +61,9 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor { private final Set declaredMethods = new LinkedHashSet<>(4); - @Nullable - private SimpleAnnotationMetadata metadata; + private @Nullable SimpleAnnotationMetadata metadata; - @Nullable - private Source source; + private @Nullable Source source; SimpleAnnotationMetadataReadingVisitor(@Nullable ClassLoader classLoader) { @@ -111,15 +107,13 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor { } @Override - @Nullable - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + public @Nullable AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { return MergedAnnotationReadingVisitor.get(this.classLoader, getSource(), descriptor, visible, this.annotations::add); } @Override - @Nullable - public MethodVisitor visitMethod( + public @Nullable MethodVisitor visitMethod( int access, String name, String descriptor, String signature, String[] exceptions) { // Skip bridge methods and constructors - we're only interested in original user methods. diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java index 08150a51a4..fece634b13 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReader.java @@ -19,12 +19,12 @@ package org.springframework.core.type.classreading; import java.io.IOException; import java.io.InputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.ClassReader; import org.springframework.core.io.Resource; import org.springframework.core.type.AnnotationMetadata; import org.springframework.core.type.ClassMetadata; -import org.springframework.lang.Nullable; - /** * {@link MetadataReader} implementation based on an ASM * {@link org.springframework.asm.ClassReader}. diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReaderFactory.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReaderFactory.java index 46aa8f4771..58a834a309 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReaderFactory.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMetadataReaderFactory.java @@ -19,10 +19,11 @@ package org.springframework.core.type.classreading; import java.io.FileNotFoundException; import java.io.IOException; +import org.jspecify.annotations.Nullable; + 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.ClassUtils; /** diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java index 4b4a0ac5e5..c7016ff854 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadata.java @@ -16,10 +16,11 @@ package org.springframework.core.type.classreading; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Opcodes; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.type.MethodMetadata; -import org.springframework.lang.Nullable; /** * {@link MethodMetadata} created from a {@link SimpleMethodMetadataReadingVisitor}. diff --git a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadataReadingVisitor.java b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadataReadingVisitor.java index 895887263e..0e1c686230 100644 --- a/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadataReadingVisitor.java +++ b/spring-core/src/main/java/org/springframework/core/type/classreading/SimpleMethodMetadataReadingVisitor.java @@ -20,13 +20,14 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.AnnotationVisitor; import org.springframework.asm.MethodVisitor; import org.springframework.asm.SpringAsmInfo; import org.springframework.asm.Type; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; -import org.springframework.lang.Nullable; /** * ASM method visitor that creates {@link SimpleMethodMetadata}. @@ -38,8 +39,7 @@ import org.springframework.lang.Nullable; */ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final String declaringClassName; @@ -53,8 +53,7 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor { private final Consumer consumer; - @Nullable - private Source source; + private @Nullable Source source; SimpleMethodMetadataReadingVisitor(@Nullable ClassLoader classLoader, String declaringClassName, @@ -71,8 +70,7 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor { @Override - @Nullable - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { + public @Nullable AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { return MergedAnnotationReadingVisitor.get(this.classLoader, getSource(), descriptor, visible, this.annotations::add); } @@ -107,8 +105,7 @@ final class SimpleMethodMetadataReadingVisitor extends MethodVisitor { private final String descriptor; - @Nullable - private String toStringValue; + private @Nullable String toStringValue; Source(String declaringClassName, String methodName, String descriptor) { this.declaringClassName = declaringClassName; 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 37a94af610..2adda85520 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,9 +1,7 @@ /** * Support classes for reading annotation and class-level metadata. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.type.classreading; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ee7d6d5046..119ba4fb01 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 @@ -20,11 +20,11 @@ import java.io.IOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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. @@ -146,16 +146,14 @@ public abstract class AbstractTypeHierarchyTraversingFilter implements TypeFilte /** * Override this to match on supertype name. */ - @Nullable - protected Boolean matchSuperClass(String superClassName) { + protected @Nullable Boolean matchSuperClass(String superClassName) { return null; } /** * Override this to match on interface type name. */ - @Nullable - protected Boolean matchInterface(String interfaceName) { + protected @Nullable 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 5584edcb68..114adc96d0 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 @@ -19,10 +19,11 @@ package org.springframework.core.type.filter; import java.lang.annotation.Annotation; import java.lang.annotation.Inherited; +import org.jspecify.annotations.Nullable; + 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,19 +103,16 @@ public class AnnotationTypeFilter extends AbstractTypeHierarchyTraversingFilter } @Override - @Nullable - protected Boolean matchSuperClass(String superClassName) { + protected @Nullable Boolean matchSuperClass(String superClassName) { return hasAnnotation(superClassName); } @Override - @Nullable - protected Boolean matchInterface(String interfaceName) { + protected @Nullable Boolean matchInterface(String interfaceName) { return hasAnnotation(interfaceName); } - @Nullable - protected Boolean hasAnnotation(String typeName) { + protected @Nullable 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/AspectJTypeFilter.java b/spring-core/src/main/java/org/springframework/core/type/filter/AspectJTypeFilter.java index 86fbde4363..c78cb7eb8b 100644 --- a/spring-core/src/main/java/org/springframework/core/type/filter/AspectJTypeFilter.java +++ b/spring-core/src/main/java/org/springframework/core/type/filter/AspectJTypeFilter.java @@ -28,10 +28,10 @@ import org.aspectj.weaver.patterns.IScope; import org.aspectj.weaver.patterns.PatternParser; import org.aspectj.weaver.patterns.SimpleScope; import org.aspectj.weaver.patterns.TypePattern; +import org.jspecify.annotations.Nullable; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.lang.Nullable; /** * Type filter that uses AspectJ type pattern for matching. 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 53566f60a7..7293eb2973 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,7 +16,8 @@ package org.springframework.core.type.filter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -55,19 +56,16 @@ public class AssignableTypeFilter extends AbstractTypeHierarchyTraversingFilter } @Override - @Nullable - protected Boolean matchSuperClass(String superClassName) { + protected @Nullable Boolean matchSuperClass(String superClassName) { return matchTargetType(superClassName); } @Override - @Nullable - protected Boolean matchInterface(String interfaceName) { + protected @Nullable Boolean matchInterface(String interfaceName) { return matchTargetType(interfaceName); } - @Nullable - protected Boolean matchTargetType(String typeName) { + protected @Nullable 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 dacedaf28a..6589c371cb 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,9 +1,7 @@ /** * Core support package for type filtering (for example, for classpath scanning). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.type.filter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f63ddb1be3..6b0d6a987b 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,9 +1,7 @@ /** * Core support package for type introspection. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.core.type; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f06fca0539..e159afd488 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 @@ -7,4 +7,7 @@ * (for example, FindBugs or Animal Sniffer), alternative JVM languages (for example, Kotlin), as well as IDEs * (for example, IntelliJ IDEA or Eclipse with corresponding project setup). */ +@NullMarked package org.springframework.lang; + +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java index 9afaf25323..267e1f9eb1 100644 --- a/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/AntPathMatcher.java @@ -25,7 +25,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link PathMatcher} implementation for Ant-style path patterns. @@ -91,8 +91,7 @@ public class AntPathMatcher implements PathMatcher { private boolean trimTokens = false; - @Nullable - private volatile Boolean cachePatterns; + private volatile @Nullable Boolean cachePatterns; private final Map tokenizedPatternCache = new ConcurrentHashMap<>(256); @@ -654,8 +653,7 @@ public class AntPathMatcher implements PathMatcher { private final boolean exactMatch; - @Nullable - private final Pattern pattern; + private final @Nullable Pattern pattern; private final List variableNames = new ArrayList<>(); @@ -856,8 +854,8 @@ public class AntPathMatcher implements PathMatcher { */ private static class PatternInfo { - @Nullable - private final String pattern; + + private final @Nullable String pattern; private int uriVars; @@ -869,8 +867,7 @@ public class AntPathMatcher implements PathMatcher { private boolean prefixPattern; - @Nullable - private Integer length; + private @Nullable Integer length; PatternInfo(@Nullable String pattern, String pathSeparator) { this.pattern = pattern; 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 71db455505..31dea19027 100644 --- a/spring-core/src/main/java/org/springframework/util/Assert.java +++ b/spring-core/src/main/java/org/springframework/util/Assert.java @@ -20,8 +20,9 @@ import java.util.Collection; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Assertion utility class that assists in validating arguments. @@ -318,7 +319,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the object array is {@code null} or contains no elements */ @Contract("null, _ -> fail") - public static void notEmpty(@Nullable Object[] array, String message) { + public static void notEmpty(Object @Nullable [] array, String message) { if (ObjectUtils.isEmpty(array)) { throw new IllegalArgumentException(message); } @@ -337,7 +338,7 @@ public abstract class Assert { * @since 5.0 */ @Contract("null, _ -> fail") - public static void notEmpty(@Nullable Object[] array, Supplier messageSupplier) { + public static void notEmpty(Object @Nullable [] array, Supplier messageSupplier) { if (ObjectUtils.isEmpty(array)) { throw new IllegalArgumentException(nullSafeGet(messageSupplier)); } @@ -351,7 +352,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(@Nullable Object[] array, String message) { + public static void noNullElements(Object @Nullable [] array, String message) { if (array != null) { for (Object element : array) { if (element == null) { @@ -373,7 +374,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the object array contains a {@code null} element * @since 5.0 */ - public static void noNullElements(@Nullable Object[] array, Supplier messageSupplier) { + public static void noNullElements(Object @Nullable [] array, Supplier messageSupplier) { if (array != null) { for (Object element : array) { if (element == null) { @@ -644,8 +645,7 @@ public abstract class Assert { return msg + (msg.endsWith(" ") ? "" : ": ") + typeName; } - @Nullable - private static String nullSafeGet(@Nullable Supplier messageSupplier) { + private static @Nullable String nullSafeGet(@Nullable Supplier messageSupplier) { return (messageSupplier != null ? messageSupplier.get() : null); } diff --git a/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java b/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java index 4a01bd5021..45dcae3225 100644 --- a/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java +++ b/spring-core/src/main/java/org/springframework/util/AutoPopulatingList.java @@ -25,7 +25,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple {@link List} wrapper class that allows for elements to be 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 91df05d573..5a66d209d5 100644 --- a/spring-core/src/main/java/org/springframework/util/ClassUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ClassUtils.java @@ -52,7 +52,7 @@ import java.util.TimeZone; import java.util.UUID; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Miscellaneous {@code java.lang.Class} utility methods. @@ -221,8 +221,7 @@ public abstract class ClassUtils { * @see Thread#getContextClassLoader() * @see ClassLoader#getSystemClassLoader() */ - @Nullable - public static ClassLoader getDefaultClassLoader() { + public static @Nullable ClassLoader getDefaultClassLoader() { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); @@ -253,8 +252,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(@Nullable ClassLoader classLoaderToUse) { + public static @Nullable ClassLoader overrideThreadContextClassLoader(@Nullable ClassLoader classLoaderToUse) { Thread currentThread = Thread.currentThread(); ClassLoader threadContextClassLoader = currentThread.getContextClassLoader(); if (classLoaderToUse != null && !classLoaderToUse.equals(threadContextClassLoader)) { @@ -495,8 +493,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(@Nullable String name) { + public static @Nullable Class resolvePrimitiveClassName(@Nullable String name) { Class result = null; // Most class names will be quite long, considering that they // SHOULD sit in a package, so a length check is worthwhile. @@ -883,8 +880,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(@Nullable Class clazz1, @Nullable Class clazz2) { + public static @Nullable Class determineCommonAncestor(@Nullable Class clazz1, @Nullable Class clazz2) { if (clazz1 == null) { return clazz2; } @@ -1030,8 +1026,7 @@ public abstract class ClassUtils { * @param value the value to introspect * @return the qualified name of the class */ - @Nullable - public static String getDescriptiveType(@Nullable Object value) { + public static @Nullable String getDescriptiveType(@Nullable Object value) { if (value == null) { return null; } @@ -1194,8 +1189,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) { + public static @Nullable Constructor getConstructorIfAvailable(Class clazz, Class... paramTypes) { Assert.notNull(clazz, "Class must not be null"); try { return clazz.getConstructor(paramTypes); @@ -1288,8 +1282,7 @@ public abstract class ClassUtils { * @return the method, or {@code null} if not found * @see Class#getMethod */ - @Nullable - public static Method getMethodIfAvailable(Class clazz, String methodName, @Nullable Class... paramTypes) { + public static @Nullable Method getMethodIfAvailable(Class clazz, String methodName, @Nullable Class @Nullable ... paramTypes) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(methodName, "Method name must not be null"); if (paramTypes != null) { @@ -1460,8 +1453,7 @@ public abstract class ClassUtils { return (result != null ? result : method); } - @Nullable - private static Method findInterfaceMethodIfPossible(String methodName, Class[] parameterTypes, + private static @Nullable Method findInterfaceMethodIfPossible(String methodName, Class[] parameterTypes, Class startClass, Class endClass, boolean requirePublicInterface) { Class current = startClass; @@ -1526,8 +1518,7 @@ public abstract class ClassUtils { return (result != null ? result : method); } - @Nullable - private static Method findPubliclyAccessibleMethodIfPossible( + private static @Nullable Method findPubliclyAccessibleMethodIfPossible( String methodName, Class[] parameterTypes, Class declaringClass) { Class current = declaringClass.getSuperclass(); @@ -1589,8 +1580,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) { + public static @Nullable 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"); try { @@ -1603,8 +1593,7 @@ public abstract class ClassUtils { } - @Nullable - private static Method getMethodOrNull(Class clazz, String methodName, Class[] paramTypes) { + private static @Nullable Method getMethodOrNull(Class clazz, String methodName, @Nullable Class @Nullable [] paramTypes) { try { return clazz.getMethod(methodName, paramTypes); } 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 65ff2debd9..aaa9d7a788 100644 --- a/spring-core/src/main/java/org/springframework/util/CollectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/CollectionUtils.java @@ -34,8 +34,9 @@ import java.util.SortedSet; import java.util.function.BiFunction; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Miscellaneous collection utility methods. @@ -268,8 +269,7 @@ public abstract class CollectionUtils { * @param candidates the candidates to search for * @return the first present object, or {@code null} if not found */ - @Nullable - public static E findFirstMatch(Collection source, Collection candidates) { + public static @Nullable E findFirstMatch(Collection source, Collection candidates) { if (isEmpty(source) || isEmpty(candidates)) { return null; } @@ -289,8 +289,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, @Nullable Class type) { + public static @Nullable T findValueOfType(Collection collection, @Nullable Class type) { if (isEmpty(collection)) { return null; } @@ -316,8 +315,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) { + public static @Nullable Object findValueOfType(Collection collection, Class[] types) { if (isEmpty(collection) || ObjectUtils.isEmpty(types)) { return null; } @@ -360,8 +358,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) { + public static @Nullable Class findCommonElementType(Collection collection) { if (isEmpty(collection)) { return null; } @@ -389,8 +386,7 @@ public abstract class CollectionUtils { * @see LinkedHashMap#keySet() * @see java.util.LinkedHashSet */ - @Nullable - public static T firstElement(@Nullable Set set) { + public static @Nullable T firstElement(@Nullable Set set) { if (isEmpty(set)) { return null; } @@ -412,8 +408,7 @@ public abstract class CollectionUtils { * @return the first element, or {@code null} if none * @since 5.2.3 */ - @Nullable - public static T firstElement(@Nullable List list) { + public static @Nullable T firstElement(@Nullable List list) { if (isEmpty(list)) { return null; } @@ -430,8 +425,7 @@ public abstract class CollectionUtils { * @see LinkedHashMap#keySet() * @see java.util.LinkedHashSet */ - @Nullable - public static T lastElement(@Nullable Set set) { + public static @Nullable T lastElement(@Nullable Set set) { if (isEmpty(set)) { return null; } @@ -454,8 +448,7 @@ public abstract class CollectionUtils { * @return the last element, or {@code null} if none * @since 5.0.3 */ - @Nullable - public static T lastElement(@Nullable List list) { + public static @Nullable T lastElement(@Nullable List list) { if (isEmpty(list)) { return null; } diff --git a/spring-core/src/main/java/org/springframework/util/CompositeMap.java b/spring-core/src/main/java/org/springframework/util/CompositeMap.java index 6678806df4..8902a3ea08 100644 --- a/spring-core/src/main/java/org/springframework/util/CompositeMap.java +++ b/spring-core/src/main/java/org/springframework/util/CompositeMap.java @@ -23,7 +23,7 @@ import java.util.Set; import java.util.function.BiFunction; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Composite map that combines two other maps. @@ -42,11 +42,9 @@ final class CompositeMap implements Map { private final Map second; - @Nullable - private final BiFunction putFunction; + private final @Nullable BiFunction putFunction; - @Nullable - private final Consumer> putAllFunction; + private final @Nullable Consumer> putAllFunction; CompositeMap(Map first, Map second) { @@ -97,8 +95,7 @@ final class CompositeMap implements Map { } @Override - @Nullable - public V get(Object key) { + public @Nullable V get(Object key) { V firstResult = this.first.get(key); if (firstResult != null) { return firstResult; @@ -109,8 +106,7 @@ final class CompositeMap implements Map { } @Override - @Nullable - public V put(K key, V value) { + public @Nullable V put(K key, V value) { if (this.putFunction == null) { throw new UnsupportedOperationException(); } @@ -120,8 +116,7 @@ final class CompositeMap implements Map { } @Override - @Nullable - public V remove(Object key) { + public @Nullable V remove(Object key) { V firstResult = this.first.remove(key); V secondResult = this.second.remove(key); if (firstResult != null) { diff --git a/spring-core/src/main/java/org/springframework/util/CompositeSet.java b/spring-core/src/main/java/org/springframework/util/CompositeSet.java index 4bc8603140..fb30d3b32e 100644 --- a/spring-core/src/main/java/org/springframework/util/CompositeSet.java +++ b/spring-core/src/main/java/org/springframework/util/CompositeSet.java @@ -18,7 +18,7 @@ package org.springframework.util; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Composite set that combines two other sets. This type is only exposed through diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java b/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java index 926bb671ce..d783b8b171 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentLruCache.java @@ -28,7 +28,7 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Function; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple LRU (Least Recently Used) cache, bounded by a specified cache capacity. @@ -223,7 +223,6 @@ public final class ConcurrentLruCache { * @return {@code true} if the key was present before, * {@code false} if there was no matching key */ - @Nullable public boolean remove(K key) { final Node node = this.cache.remove(key); if (node == null) { @@ -486,19 +485,16 @@ public final class ConcurrentLruCache { private static final class Node extends AtomicReference> { final K key; - @Nullable - Node prev; + @Nullable Node prev; - @Nullable - Node next; + @Nullable Node next; Node(K key, CacheEntry cacheEntry) { super(cacheEntry); this.key = key; } - @Nullable - public Node getPrevious() { + public @Nullable Node getPrevious() { return this.prev; } @@ -506,8 +502,7 @@ public final class ConcurrentLruCache { this.prev = prev; } - @Nullable - public Node getNext() { + public @Nullable Node getNext() { return this.next; } @@ -523,15 +518,12 @@ public final class ConcurrentLruCache { private static final class EvictionQueue { - @Nullable - Node first; + @Nullable Node first; - @Nullable - Node last; + @Nullable Node last; - @Nullable - Node poll() { + @Nullable Node poll() { if (this.first == null) { 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 090622e019..9213241de1 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -34,7 +34,7 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.ReentrantLock; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A {@link ConcurrentHashMap} that uses {@link ReferenceType#SOFT soft} or @@ -99,8 +99,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Late binding entry set. */ - @Nullable - private volatile Set> entrySet; + private volatile @Nullable Set> entrySet; /** @@ -231,16 +230,14 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - @Nullable - public V get(@Nullable Object key) { + public @Nullable V get(@Nullable Object key) { Reference ref = getReference(key, Restructure.WHEN_NECESSARY); Entry entry = (ref != null ? ref.get() : null); return (entry != null ? entry.getValue() : null); } @Override - @Nullable - public V getOrDefault(@Nullable Object key, @Nullable V defaultValue) { + public @Nullable V getOrDefault(@Nullable Object key, @Nullable V defaultValue) { Reference ref = getReference(key, Restructure.WHEN_NECESSARY); Entry entry = (ref != null ? ref.get() : null); return (entry != null ? entry.getValue() : defaultValue); @@ -260,30 +257,25 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param restructure types of restructure allowed during this call * @return the reference, or {@code null} if not found */ - @Nullable - protected final Reference getReference(@Nullable Object key, Restructure restructure) { + protected final @Nullable Reference getReference(@Nullable Object key, Restructure restructure) { int hash = getHash(key); return getSegmentForHash(hash).getReference(key, hash, restructure); } @Override - @Nullable - public V put(@Nullable K key, @Nullable V value) { + public @Nullable V put(@Nullable K key, @Nullable V value) { return put(key, value, true); } @Override - @Nullable - public V putIfAbsent(@Nullable K key, @Nullable V value) { + public @Nullable V putIfAbsent(@Nullable K key, @Nullable V value) { return put(key, value, false); } - @Nullable - private V put(@Nullable final K key, @Nullable final V value, final boolean overwriteExisting) { + private @Nullable V put(final @Nullable K key, final @Nullable V value, final boolean overwriteExisting) { return doTask(key, new Task(TaskOption.RESTRUCTURE_BEFORE, TaskOption.RESIZE) { @Override - @Nullable - protected V execute(@Nullable Reference ref, @Nullable Entry entry, @Nullable Entries entries) { + protected @Nullable V execute(@Nullable Reference ref, @Nullable Entry entry, @Nullable Entries entries) { if (entry != null) { V oldValue = entry.getValue(); if (overwriteExisting) { @@ -299,12 +291,10 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - @Nullable - public V remove(@Nullable Object key) { + public @Nullable V remove(@Nullable Object key) { return doTask(key, new Task(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) { @Override - @Nullable - protected V execute(@Nullable Reference ref, @Nullable Entry entry) { + protected @Nullable V execute(@Nullable Reference ref, @Nullable Entry entry) { if (entry != null) { if (ref != null) { ref.release(); @@ -317,7 +307,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - public boolean remove(@Nullable Object key, @Nullable final Object value) { + public boolean remove(@Nullable Object key, final @Nullable Object value) { Boolean result = doTask(key, new Task(TaskOption.RESTRUCTURE_AFTER, TaskOption.SKIP_IF_EMPTY) { @Override protected Boolean execute(@Nullable Reference ref, @Nullable Entry entry) { @@ -334,7 +324,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - public boolean replace(@Nullable K key, @Nullable final V oldValue, @Nullable final V newValue) { + public boolean replace(@Nullable K key, final @Nullable V oldValue, final @Nullable V newValue) { Boolean result = doTask(key, new Task(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) { @Override protected Boolean execute(@Nullable Reference ref, @Nullable Entry entry) { @@ -349,12 +339,10 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - @Nullable - public V replace(@Nullable K key, @Nullable final V value) { + public @Nullable V replace(@Nullable K key, final @Nullable V value) { return doTask(key, new Task(TaskOption.RESTRUCTURE_BEFORE, TaskOption.SKIP_IF_EMPTY) { @Override - @Nullable - protected V execute(@Nullable Reference ref, @Nullable Entry entry) { + protected @Nullable V execute(@Nullable Reference ref, @Nullable Entry entry) { if (entry != null) { V oldValue = entry.getValue(); entry.setValue(value); @@ -414,8 +402,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen return entrySet; } - @Nullable - private T doTask(@Nullable Object key, Task task) { + private @Nullable T doTask(@Nullable Object key, Task task) { int hash = getHash(key); return getSegmentForHash(hash).doTask(hash, key, task); } @@ -490,8 +477,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen this.resizeThreshold = resizeThreshold; } - @Nullable - public Reference getReference(@Nullable Object key, int hash, Restructure restructure) { + public @Nullable Reference getReference(@Nullable Object key, int hash, Restructure restructure) { if (restructure == Restructure.WHEN_NECESSARY) { restructureIfNecessary(false); } @@ -513,8 +499,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @param task the update operation * @return the result of the operation */ - @Nullable - public T doTask(final int hash, @Nullable final Object key, final Task task) { + public @Nullable T doTask(final int hash, final @Nullable Object key, final Task task) { boolean resize = task.hasOption(TaskOption.RESIZE); if (task.hasOption(TaskOption.RESTRUCTURE_BEFORE)) { restructureIfNecessary(resize); @@ -656,8 +641,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } } - @Nullable - private Reference findInChain(Reference ref, @Nullable Object key, int hash) { + private @Nullable Reference findInChain(Reference ref, @Nullable Object key, int hash) { Reference currRef = ref; while (currRef != null) { if (currRef.getHash() == hash) { @@ -710,8 +694,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Return the referenced entry, or {@code null} if the entry is no longer available. */ - @Nullable - Entry get(); + @Nullable Entry get(); /** * Return the hash for the reference. @@ -721,8 +704,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * Return the next reference in the chain, or {@code null} if none. */ - @Nullable - Reference getNext(); + @Nullable Reference getNext(); /** * Release this entry and ensure that it will be returned from @@ -739,11 +721,9 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen */ protected static final class Entry implements Map.Entry { - @Nullable - private final K key; + private final @Nullable K key; - @Nullable - private volatile V value; + private volatile @Nullable V value; public Entry(@Nullable K key, @Nullable V value) { this.key = key; @@ -751,20 +731,17 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - @Nullable - public K getKey() { + public @Nullable K getKey() { return this.key; } @Override - @Nullable - public V getValue() { + public @Nullable V getValue() { return this.value; } @Override - @Nullable - public V setValue(@Nullable V value) { + public @Nullable V setValue(@Nullable V value) { V previous = this.value; this.value = value; return previous; @@ -812,8 +789,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return the result of the task * @see #execute(Reference, Entry) */ - @Nullable - protected T execute(@Nullable Reference ref, @Nullable Entry entry, @Nullable Entries entries) { + protected @Nullable T execute(@Nullable Reference ref, @Nullable Entry entry, @Nullable Entries entries) { return execute(ref, entry); } @@ -824,8 +800,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return the result of the task * @see #execute(Reference, Entry, Entries) */ - @Nullable - protected T execute(@Nullable Reference ref, @Nullable Entry entry) { + protected @Nullable T execute(@Nullable Reference ref, @Nullable Entry entry) { return null; } } @@ -904,17 +879,13 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen private int referenceIndex; - @Nullable - private Reference[] references; + private Reference @Nullable [] references; - @Nullable - private Reference reference; + private @Nullable Reference reference; - @Nullable - private Entry next; + private @Nullable Entry next; - @Nullable - private Entry last; + private @Nullable Entry last; public EntryIterator() { moveToNextSegment(); @@ -1020,8 +991,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen * @return a reference to purge or {@code null} */ @SuppressWarnings("unchecked") - @Nullable - public Reference pollForPurge() { + public @Nullable Reference pollForPurge() { return (Reference) this.queue.poll(); } } @@ -1034,8 +1004,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen private final int hash; - @Nullable - private final Reference nextReference; + private final @Nullable Reference nextReference; public SoftEntryReference(Entry entry, int hash, @Nullable Reference next, ReferenceQueue> queue) { @@ -1051,8 +1020,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - @Nullable - public Reference getNext() { + public @Nullable Reference getNext() { return this.nextReference; } @@ -1070,8 +1038,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen private final int hash; - @Nullable - private final Reference nextReference; + private final @Nullable Reference nextReference; public WeakEntryReference(Entry entry, int hash, @Nullable Reference next, ReferenceQueue> queue) { @@ -1087,8 +1054,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } @Override - @Nullable - public Reference getNext() { + public @Nullable Reference getNext() { return this.nextReference; } 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 dd4fc28e7f..fbb775c6f6 100644 --- a/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java +++ b/spring-core/src/main/java/org/springframework/util/CustomizableThreadCreator.java @@ -19,7 +19,7 @@ package org.springframework.util; import java.io.Serializable; import java.util.concurrent.atomic.AtomicInteger; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple customizable helper class for creating new {@link Thread} instances. @@ -41,8 +41,7 @@ public class CustomizableThreadCreator implements Serializable { private boolean daemon = false; - @Nullable - private ThreadGroup threadGroup; + private @Nullable ThreadGroup threadGroup; private final AtomicInteger threadCount = new AtomicInteger(); @@ -136,8 +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() { + public @Nullable ThreadGroup getThreadGroup() { return this.threadGroup; } diff --git a/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java b/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java index e91eda5699..02599754ad 100644 --- a/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java +++ b/spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java @@ -25,7 +25,7 @@ import java.util.ArrayDeque; import java.util.Deque; import java.util.Iterator; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A speedy alternative to {@link java.io.ByteArrayOutputStream}. Note that @@ -349,8 +349,7 @@ public class FastByteArrayOutputStream extends OutputStream { private final Iterator buffersIterator; - @Nullable - private byte[] currentBuffer; + private byte @Nullable [] currentBuffer; private int currentBufferLength = 0; 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 f68a895246..388ab5e341 100644 --- a/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java +++ b/spring-core/src/main/java/org/springframework/util/FileCopyUtils.java @@ -27,7 +27,7 @@ import java.io.StringWriter; import java.io.Writer; import java.nio.file.Files; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple utility methods for file and stream copying. All copy methods use a block size diff --git a/spring-core/src/main/java/org/springframework/util/FileSystemUtils.java b/spring-core/src/main/java/org/springframework/util/FileSystemUtils.java index d060c1c118..c857588d18 100644 --- a/spring-core/src/main/java/org/springframework/util/FileSystemUtils.java +++ b/spring-core/src/main/java/org/springframework/util/FileSystemUtils.java @@ -26,7 +26,7 @@ import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; import java.util.EnumSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; import static java.nio.file.FileVisitOption.FOLLOW_LINKS; diff --git a/spring-core/src/main/java/org/springframework/util/FilteredIterator.java b/spring-core/src/main/java/org/springframework/util/FilteredIterator.java index ab2c59a592..3205721522 100644 --- a/spring-core/src/main/java/org/springframework/util/FilteredIterator.java +++ b/spring-core/src/main/java/org/springframework/util/FilteredIterator.java @@ -20,7 +20,7 @@ import java.util.Iterator; import java.util.NoSuchElementException; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link Iterator} that filters out values that do not match a predicate. @@ -37,8 +37,7 @@ final class FilteredIterator implements Iterator { private final Predicate filter; - @Nullable - private E next; + private @Nullable E next; private boolean hasNext; diff --git a/spring-core/src/main/java/org/springframework/util/FilteredMap.java b/spring-core/src/main/java/org/springframework/util/FilteredMap.java index e4bb17d862..d577fd4e21 100644 --- a/spring-core/src/main/java/org/springframework/util/FilteredMap.java +++ b/spring-core/src/main/java/org/springframework/util/FilteredMap.java @@ -21,7 +21,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Map that filters out values that do not match a predicate. @@ -76,8 +76,7 @@ final class FilteredMap extends AbstractMap { @Override @SuppressWarnings("unchecked") - @Nullable - public V get(Object key) { + public @Nullable V get(Object key) { V value = this.delegate.get(key); if (value != null && this.filter.test((K) key)) { return value; @@ -88,8 +87,7 @@ final class FilteredMap extends AbstractMap { } @Override - @Nullable - public V put(K key, V value) { + public @Nullable V put(K key, V value) { V oldValue = this.delegate.put(key, value); if (oldValue != null && this.filter.test(key)) { return oldValue; @@ -101,8 +99,7 @@ final class FilteredMap extends AbstractMap { @Override @SuppressWarnings("unchecked") - @Nullable - public V remove(Object key) { + public @Nullable V remove(Object key) { V oldValue = this.delegate.remove(key); if (oldValue != null && this.filter.test((K) key)) { return oldValue; diff --git a/spring-core/src/main/java/org/springframework/util/FilteredSet.java b/spring-core/src/main/java/org/springframework/util/FilteredSet.java index 21d6ac6e17..acf03d0c3b 100644 --- a/spring-core/src/main/java/org/springframework/util/FilteredSet.java +++ b/spring-core/src/main/java/org/springframework/util/FilteredSet.java @@ -19,7 +19,7 @@ package org.springframework.util; import java.util.Set; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Set that filters out values that do not match a predicate. 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 08e2000f1a..7e2005a286 100644 --- a/spring-core/src/main/java/org/springframework/util/InstanceFilter.java +++ b/spring-core/src/main/java/org/springframework/util/InstanceFilter.java @@ -19,7 +19,7 @@ package org.springframework.util; import java.util.Collection; import java.util.Collections; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A simple instance filter that checks if a given instance match based on 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 3a1f9f1029..6fbc5fa1be 100644 --- a/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java +++ b/spring-core/src/main/java/org/springframework/util/LinkedCaseInsensitiveMap.java @@ -31,7 +31,7 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import java.util.function.Function; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link LinkedHashMap} variant that stores String keys in a case-insensitive @@ -56,14 +56,11 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable private final Locale locale; - @Nullable - private transient volatile Set keySet; + private transient volatile @Nullable Set keySet; - @Nullable - private transient volatile Collection values; + private transient volatile @Nullable Collection values; - @Nullable - private transient volatile Set> entrySet; + private transient volatile @Nullable Set> entrySet; /** @@ -164,8 +161,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - @Nullable - public V get(Object key) { + public @Nullable V get(Object key) { if (key instanceof String string) { String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey(string)); if (caseInsensitiveKey != null) { @@ -176,8 +172,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - @Nullable - public V getOrDefault(Object key, V defaultValue) { + public @Nullable V getOrDefault(Object key, V defaultValue) { if (key instanceof String string) { String caseInsensitiveKey = this.caseInsensitiveKeys.get(convertKey(string)); if (caseInsensitiveKey != null) { @@ -188,8 +183,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - @Nullable - public V put(String key, @Nullable V value) { + public @Nullable V put(String key, @Nullable V value) { String oldKey = this.caseInsensitiveKeys.put(convertKey(key), key); V oldKeyValue = null; if (oldKey != null && !oldKey.equals(key)) { @@ -208,8 +202,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - @Nullable - public V putIfAbsent(String key, @Nullable V value) { + public @Nullable V putIfAbsent(String key, @Nullable V value) { String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key); if (oldKey != null) { V oldKeyValue = this.targetMap.get(oldKey); @@ -224,8 +217,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - @Nullable - public V computeIfAbsent(String key, Function mappingFunction) { + public @Nullable V computeIfAbsent(String key, Function mappingFunction) { String oldKey = this.caseInsensitiveKeys.putIfAbsent(convertKey(key), key); if (oldKey != null) { V oldKeyValue = this.targetMap.get(oldKey); @@ -240,8 +232,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable } @Override - @Nullable - public V remove(Object key) { + public @Nullable V remove(Object key) { if (key instanceof String string) { String caseInsensitiveKey = removeCaseInsensitiveKey(string); if (caseInsensitiveKey != null) { @@ -348,8 +339,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable return false; } - @Nullable - private String removeCaseInsensitiveKey(String key) { + private @Nullable String removeCaseInsensitiveKey(String key) { return this.caseInsensitiveKeys.remove(convertKey(key)); } @@ -494,8 +484,7 @@ public class LinkedCaseInsensitiveMap implements Map, Serializable private final Iterator> delegate; - @Nullable - private Entry last; + private @Nullable Entry last; public EntryIterator() { this.delegate = targetMap.entrySet().iterator(); 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 73171aec1d..f17b0aca39 100644 --- a/spring-core/src/main/java/org/springframework/util/MethodInvoker.java +++ b/spring-core/src/main/java/org/springframework/util/MethodInvoker.java @@ -20,7 +20,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Helper class that allows for specifying a method to invoke in a declarative @@ -41,24 +41,18 @@ public class MethodInvoker { private static final Object[] EMPTY_ARGUMENTS = new Object[0]; - @Nullable - protected Class targetClass; + protected @Nullable Class targetClass; - @Nullable - private Object targetObject; + private @Nullable Object targetObject; - @Nullable - private String targetMethod; + private @Nullable String targetMethod; - @Nullable - private String staticMethod; + private @Nullable String staticMethod; - @Nullable - private Object[] arguments; + private Object @Nullable [] arguments; /** The method we will call. */ - @Nullable - private Method methodObject; + private @Nullable Method methodObject; /** @@ -75,8 +69,7 @@ public class MethodInvoker { /** * Return the target class on which to call the target method. */ - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { return this.targetClass; } @@ -97,8 +90,7 @@ public class MethodInvoker { /** * Return the target object on which to call the target method. */ - @Nullable - public Object getTargetObject() { + public @Nullable Object getTargetObject() { return this.targetObject; } @@ -116,8 +108,7 @@ public class MethodInvoker { /** * Return the name of the method to be invoked. */ - @Nullable - public String getTargetMethod() { + public @Nullable String getTargetMethod() { return this.targetMethod; } @@ -136,7 +127,7 @@ public class MethodInvoker { * Set arguments for the method invocation. If this property is not set, * or the Object array is of length 0, a method with no arguments is assumed. */ - public void setArguments(@Nullable Object... arguments) { + public void setArguments(Object @Nullable ... arguments) { this.arguments = arguments; } @@ -213,8 +204,7 @@ public class MethodInvoker { * @see #getTargetMethod() * @see #getArguments() */ - @Nullable - protected Method findMatchingMethod() { + protected @Nullable Method findMatchingMethod() { String targetMethod = getTargetMethod(); Object[] arguments = getArguments(); int argCount = arguments.length; @@ -271,8 +261,7 @@ public class MethodInvoker { * @throws IllegalAccessException if the target method couldn't be accessed * @see #prepare */ - @Nullable - public Object invoke() throws InvocationTargetException, IllegalAccessException { + public @Nullable Object invoke() throws InvocationTargetException, IllegalAccessException { // In the static case, target will simply be {@code null}. Object targetObject = getTargetObject(); Method preparedMethod = getPreparedMethod(); @@ -304,7 +293,7 @@ public class MethodInvoker { * @param args the arguments to match * @return the accumulated weight for all arguments */ - public static int getTypeDifferenceWeight(Class[] paramTypes, Object[] args) { + public static int getTypeDifferenceWeight(Class[] paramTypes, @Nullable Object[] args) { int result = 0; for (int i = 0; i < paramTypes.length; i++) { if (!ClassUtils.isAssignableValue(paramTypes[i], args[i])) { 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 5a32846842..4ced66b010 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeType.java +++ b/spring-core/src/main/java/org/springframework/util/MimeType.java @@ -29,7 +29,7 @@ import java.util.Locale; import java.util.Map; import java.util.TreeSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represents a MIME Type, as originally defined in RFC 2046 and subsequently @@ -103,11 +103,9 @@ public class MimeType implements Comparable, Serializable { private final Map parameters; - @Nullable - private transient Charset resolvedCharset; + private transient @Nullable Charset resolvedCharset; - @Nullable - private volatile String toStringValue; + private volatile @Nullable String toStringValue; /** @@ -295,8 +293,7 @@ public class MimeType implements Comparable, Serializable { * Return the subtype suffix as defined in RFC 6839. * @since 5.3 */ - @Nullable - public String getSubtypeSuffix() { + public @Nullable String getSubtypeSuffix() { int suffixIndex = this.subtype.lastIndexOf('+'); if (suffixIndex != -1 && this.subtype.length() > suffixIndex) { return this.subtype.substring(suffixIndex + 1); @@ -309,8 +306,7 @@ public class MimeType implements Comparable, Serializable { * @return the character set, or {@code null} if not available * @since 4.3 */ - @Nullable - public Charset getCharset() { + public @Nullable Charset getCharset() { return this.resolvedCharset; } @@ -319,8 +315,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) { + public @Nullable String getParameter(String name) { return this.parameters.get(name); } diff --git a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java index f3a9f2b688..06dbca09b3 100644 --- a/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/MimeTypeUtils.java @@ -30,7 +30,7 @@ import java.util.Random; import java.util.function.BiPredicate; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Miscellaneous {@link MimeType} utility methods. @@ -167,8 +167,7 @@ public abstract class MimeTypeUtils { private static final ConcurrentLruCache cachedMimeTypes = new ConcurrentLruCache<>(64, MimeTypeUtils::parseMimeTypeInternal); - @Nullable - private static volatile Random random; + private static volatile @Nullable Random random; static { // Not using "parseMimeType" to avoid static init cost diff --git a/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java index 959a69b843..e7e80a8643 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiToSingleValueMapAdapter.java @@ -28,7 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Adapts a given {@link MultiValueMap} to the {@link Map} contract. The @@ -46,11 +46,9 @@ final class MultiToSingleValueMapAdapter implements Map, Serializabl private final MultiValueMap targetMap; - @Nullable - private transient Collection values; + private transient @Nullable Collection values; - @Nullable - private transient Set> entries; + private transient @Nullable Set> entries; /** @@ -101,20 +99,17 @@ final class MultiToSingleValueMapAdapter implements Map, Serializabl } @Override - @Nullable - public V get(Object key) { + public @Nullable V get(Object key) { return adaptValue(this.targetMap.get(key)); } - @Nullable @Override - public V put(K key, @Nullable V value) { + public @Nullable V put(K key, @Nullable V value) { return adaptValue(this.targetMap.put(key, adaptValue(value))); } @Override - @Nullable - public V remove(Object key) { + public @Nullable V remove(Object key) { return adaptValue(this.targetMap.remove(key)); } @@ -205,8 +200,7 @@ final class MultiToSingleValueMapAdapter implements Map, Serializabl this.targetMap.forEach((k, vs) -> action.accept(k, vs.get(0))); } - @Nullable - private V adaptValue(@Nullable List values) { + private @Nullable V adaptValue(@Nullable List values) { if (!CollectionUtils.isEmpty(values)) { return values.get(0); } @@ -215,8 +209,7 @@ final class MultiToSingleValueMapAdapter implements Map, Serializabl } } - @Nullable - private List adaptValue(@Nullable V value) { + private @Nullable List adaptValue(@Nullable V value) { if (value != null) { return Collections.singletonList(value); } 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 262601a5a4..195db529d0 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMap.java @@ -19,7 +19,7 @@ package org.springframework.util; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Extension of the {@code Map} interface that stores multiple values. @@ -36,8 +36,7 @@ public interface MultiValueMap extends Map> { * @param key the key * @return the first value for the specified key, or {@code null} if none */ - @Nullable - V getFirst(K key); + @Nullable V getFirst(K key); /** * Add the given single value to the current list of values for the given key. diff --git a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java index 4c7c2f1d13..97207b8f00 100644 --- a/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/MultiValueMapAdapter.java @@ -24,7 +24,7 @@ import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Adapts a given {@link Map} to the {@link MultiValueMap} contract. @@ -56,8 +56,7 @@ public class MultiValueMapAdapter implements MultiValueMap, Serializ // MultiValueMap implementation @Override - @Nullable - public V getFirst(K key) { + public @Nullable V getFirst(K key) { List values = this.targetMap.get(key); return (!CollectionUtils.isEmpty(values) ? values.get(0) : null); } @@ -126,26 +125,22 @@ public class MultiValueMapAdapter implements MultiValueMap, Serializ } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { return this.targetMap.get(key); } @Override - @Nullable - public List put(K key, List value) { + public @Nullable List put(K key, List value) { return this.targetMap.put(key, value); } @Override - @Nullable - public List putIfAbsent(K key, List value) { + public @Nullable List putIfAbsent(K key, List value) { return this.targetMap.putIfAbsent(key, value); } @Override - @Nullable - public List remove(Object key) { + public @Nullable List remove(Object key) { return this.targetMap.remove(key); } diff --git a/spring-core/src/main/java/org/springframework/util/NumberUtils.java b/spring-core/src/main/java/org/springframework/util/NumberUtils.java index 27bb5db53b..8ac49b9396 100644 --- a/spring-core/src/main/java/org/springframework/util/NumberUtils.java +++ b/spring-core/src/main/java/org/springframework/util/NumberUtils.java @@ -23,7 +23,7 @@ import java.text.NumberFormat; import java.text.ParseException; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Miscellaneous utility methods for number conversion and parsing. 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 07e338a7da..ad22311e99 100644 --- a/spring-core/src/main/java/org/springframework/util/ObjectUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ObjectUtils.java @@ -27,8 +27,9 @@ import java.util.Optional; import java.util.StringJoiner; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Miscellaneous object utility methods. @@ -82,7 +83,7 @@ public abstract class ObjectUtils { * @param declaredExceptions the exception types declared in the throws clause * @return whether the given exception is compatible */ - public static boolean isCompatibleWithThrowsClause(Throwable ex, @Nullable Class... declaredExceptions) { + public static boolean isCompatibleWithThrowsClause(Throwable ex, Class @Nullable ... declaredExceptions) { if (!isCheckedException(ex)) { return true; } @@ -113,7 +114,7 @@ public abstract class ObjectUtils { * @see #isEmpty(Object) */ @Contract("null -> true") - public static boolean isEmpty(@Nullable Object[] array) { + public static boolean isEmpty(@Nullable Object @Nullable [] array) { return (array == null || array.length == 0); } @@ -171,8 +172,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(@Nullable Object obj) { + public static @Nullable Object unwrapOptional(@Nullable Object obj) { if (obj instanceof Optional optional) { Object result = optional.orElse(null); Assert.isTrue(!(result instanceof Optional), "Multi-level Optional usage not supported"); @@ -188,7 +188,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(@Nullable Object[] array, Object element) { + public static boolean containsElement(Object @Nullable [] array, Object element) { if (array == null) { return false; } @@ -253,7 +253,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(@Nullable A[] array, @Nullable O obj) { + public static A[] addObjectToArray(A @Nullable [] array, @Nullable O obj) { return addObjectToArray(array, obj, (array != null ? array.length : 0)); } @@ -266,7 +266,7 @@ public abstract class ObjectUtils { * @return the new array (of the same component type; never {@code null}) * @since 6.0 */ - public static A[] addObjectToArray(@Nullable A[] array, @Nullable O obj, int position) { + public static A[] addObjectToArray(A @Nullable [] array, @Nullable O obj, int position) { Class componentType = Object.class; if (array != null) { componentType = array.getClass().componentType(); @@ -398,7 +398,7 @@ public abstract class ObjectUtils { * @return a hash value of the elements * @since 6.1 */ - public static int nullSafeHash(@Nullable Object... elements) { + public static int nullSafeHash(@Nullable Object @Nullable ... elements) { if (elements == null) { return 0; } @@ -459,7 +459,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(Object[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable Object[] array) { + public static int nullSafeHashCode(Object @Nullable [] array) { return Arrays.hashCode(array); } @@ -469,7 +469,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(boolean[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable boolean[] array) { + public static int nullSafeHashCode(boolean @Nullable [] array) { return Arrays.hashCode(array); } @@ -479,7 +479,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(byte[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable byte[] array) { + public static int nullSafeHashCode(byte @Nullable [] array) { return Arrays.hashCode(array); } @@ -489,7 +489,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(char[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable char[] array) { + public static int nullSafeHashCode(char @Nullable [] array) { return Arrays.hashCode(array); } @@ -499,7 +499,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(double[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable double[] array) { + public static int nullSafeHashCode(double @Nullable [] array) { return Arrays.hashCode(array); } @@ -509,7 +509,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(float[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable float[] array) { + public static int nullSafeHashCode(float @Nullable [] array) { return Arrays.hashCode(array); } @@ -519,7 +519,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(int[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable int[] array) { + public static int nullSafeHashCode(int @Nullable [] array) { return Arrays.hashCode(array); } @@ -529,7 +529,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(long[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable long[] array) { + public static int nullSafeHashCode(long @Nullable [] array) { return Arrays.hashCode(array); } @@ -539,7 +539,7 @@ public abstract class ObjectUtils { * @deprecated as of 6.1 in favor of {@link Arrays#hashCode(short[])} */ @Deprecated(since = "6.1") - public static int nullSafeHashCode(@Nullable short[] array) { + public static int nullSafeHashCode(short @Nullable [] array) { return Arrays.hashCode(array); } @@ -651,7 +651,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(@Nullable Object[] array) { + public static String nullSafeToString(Object @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -675,7 +675,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(@Nullable boolean[] array) { + public static String nullSafeToString(boolean @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -699,7 +699,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(@Nullable byte[] array) { + public static String nullSafeToString(byte @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -722,7 +722,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(@Nullable char[] array) { + public static String nullSafeToString(char @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -745,7 +745,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(@Nullable double[] array) { + public static String nullSafeToString(double @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -768,7 +768,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(@Nullable float[] array) { + public static String nullSafeToString(float @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -791,7 +791,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(@Nullable int[] array) { + public static String nullSafeToString(int @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -814,7 +814,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(@Nullable long[] array) { + public static String nullSafeToString(long @Nullable [] array) { if (array == null) { return NULL_STRING; } @@ -838,7 +838,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(@Nullable short[] array) { + public static String nullSafeToString(short @Nullable [] array) { if (array == null) { return NULL_STRING; } diff --git a/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java b/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java index 9f050351f0..dc4afcb6d3 100644 --- a/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java +++ b/spring-core/src/main/java/org/springframework/util/PatternMatchUtils.java @@ -16,7 +16,7 @@ package org.springframework.util; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Utility methods for simple pattern matching, in particular for Spring's typical @@ -83,7 +83,7 @@ public abstract class PatternMatchUtils { * @param str the String to match * @return whether the String matches any of the given patterns */ - public static boolean simpleMatch(@Nullable String[] patterns, @Nullable String str) { + public static boolean simpleMatch(String @Nullable [] patterns, @Nullable String str) { if (patterns != null) { for (String pattern : patterns) { if (simpleMatch(pattern, str)) { diff --git a/spring-core/src/main/java/org/springframework/util/PlaceholderParser.java b/spring-core/src/main/java/org/springframework/util/PlaceholderParser.java index 22aa50e602..751b29f741 100644 --- a/spring-core/src/main/java/org/springframework/util/PlaceholderParser.java +++ b/spring-core/src/main/java/org/springframework/util/PlaceholderParser.java @@ -26,8 +26,8 @@ import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; /** @@ -76,13 +76,11 @@ final class PlaceholderParser { private final String simplePrefix; - @Nullable - private final String separator; + private final @Nullable String separator; private final boolean ignoreUnresolvablePlaceholders; - @Nullable - private final Character escape; + private final @Nullable Character escape; /** @@ -211,8 +209,7 @@ final class PlaceholderParser { return new NestedPlaceholderPart(text, parts, null); } - @Nullable - private String[] splitKeyAndDefault(String value) { + private String @Nullable [] splitKeyAndDefault(String value) { if (this.separator == null || !value.contains(this.separator)) { return null; } @@ -309,8 +306,7 @@ final class PlaceholderParser { private final PlaceholderResolver resolver; - @Nullable - private Set visitedPlaceholders; + private @Nullable Set visitedPlaceholders; PartResolutionContext(PlaceholderResolver resolver, String prefix, String suffix, @@ -323,8 +319,7 @@ final class PlaceholderParser { } @Override - @Nullable - public String resolvePlaceholder(String placeholderName) { + public @Nullable String resolvePlaceholder(String placeholderName) { String value = this.resolver.resolvePlaceholder(placeholderName); if (value != null && logger.isTraceEnabled()) { logger.trace("Resolved placeholder '" + placeholderName + "'"); @@ -444,8 +439,7 @@ final class PlaceholderParser { * @return the full resolution of the given {@code key} or {@code null} if * the placeholder has no value to begin with */ - @Nullable - protected String resolveRecursively(PartResolutionContext resolutionContext, String key) { + protected @Nullable String resolveRecursively(PartResolutionContext resolutionContext, String key) { String resolvedValue = resolutionContext.resolvePlaceholder(key); if (resolvedValue != null) { resolutionContext.flagPlaceholderAsVisited(key); @@ -502,8 +496,7 @@ final class PlaceholderParser { private final String key; - @Nullable - private final String fallback; + private final @Nullable String fallback; /** * Create a new instance. @@ -539,8 +532,7 @@ final class PlaceholderParser { private final List keyParts; - @Nullable - private final List defaultParts; + private final @Nullable List defaultParts; /** * Create a new instance. diff --git a/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java b/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java index 8054677301..1a28a371ae 100644 --- a/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java +++ b/spring-core/src/main/java/org/springframework/util/PlaceholderResolutionException.java @@ -21,7 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Thrown when the resolution of placeholder failed. This exception provides 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 8e1d6094c6..ae73ab2973 100644 --- a/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java +++ b/spring-core/src/main/java/org/springframework/util/PropertyPlaceholderHelper.java @@ -18,7 +18,7 @@ package org.springframework.util; import java.util.Properties; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Utility class for working with Strings that have placeholder values in them. @@ -112,8 +112,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); + @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 4d1af9d217..ec29a41f6b 100644 --- a/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ReflectionUtils.java @@ -27,7 +27,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple utility class for working with the reflection API and handling @@ -213,8 +213,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) { + public static @Nullable Method findMethod(Class clazz, String name) { return findMethod(clazz, name, EMPTY_CLASS_ARRAY); } @@ -228,8 +227,7 @@ public abstract class ReflectionUtils { * (may be {@code null} to indicate any signature) * @return the Method object, or {@code null} if none found */ - @Nullable - public static Method findMethod(Class clazz, String name, @Nullable Class... paramTypes) { + public static @Nullable Method findMethod(Class clazz, String name, Class @Nullable ... paramTypes) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(name, "Method name must not be null"); Class searchType = clazz; @@ -260,8 +258,7 @@ public abstract class ReflectionUtils { * @return the invocation result, if any * @see #invokeMethod(java.lang.reflect.Method, Object, Object[]) */ - @Nullable - public static Object invokeMethod(Method method, @Nullable Object target) { + public static @Nullable Object invokeMethod(Method method, @Nullable Object target) { return invokeMethod(method, target, EMPTY_OBJECT_ARRAY); } @@ -275,8 +272,7 @@ public abstract class ReflectionUtils { * @param args the invocation arguments (may be {@code null}) * @return the invocation result, if any */ - @Nullable - public static Object invokeMethod(Method method, @Nullable Object target, @Nullable Object... args) { + public static @Nullable Object invokeMethod(Method method, @Nullable Object target, @Nullable Object... args) { try { return method.invoke(target, args); } @@ -486,8 +482,7 @@ public abstract class ReflectionUtils { return (result.length == 0 || !defensive) ? result : result.clone(); } - @Nullable - private static List findDefaultMethodsOnInterfaces(Class clazz) { + private static @Nullable List findDefaultMethodsOnInterfaces(Class clazz) { List result = null; for (Class ifc : clazz.getInterfaces()) { for (Method method : ifc.getMethods()) { @@ -577,8 +572,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) { + public static @Nullable Field findField(Class clazz, String name) { return findField(clazz, name, null); } @@ -591,8 +585,7 @@ 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 */ - @Nullable - public static Field findField(Class clazz, @Nullable String name, @Nullable Class type) { + public static @Nullable 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; @@ -617,8 +610,7 @@ public abstract class ReflectionUtils { * @return the corresponding Field object, or {@code null} if not found * @since 6.1 */ - @Nullable - public static Field findFieldIgnoreCase(Class clazz, String name) { + public static @Nullable Field findFieldIgnoreCase(Class clazz, String name) { Assert.notNull(clazz, "Class must not be null"); Assert.notNull(name, "Name must not be null"); Class searchType = clazz; @@ -666,8 +658,7 @@ public abstract class ReflectionUtils { * (or {@code null} for a static field) * @return the field's current value */ - @Nullable - public static Object getField(Field field, @Nullable Object target) { + public static @Nullable Object getField(Field field, @Nullable Object target) { try { return field.get(target); } diff --git a/spring-core/src/main/java/org/springframework/util/ResourceUtils.java b/spring-core/src/main/java/org/springframework/util/ResourceUtils.java index 9a2f12f1cd..7cf9c53cc7 100644 --- a/spring-core/src/main/java/org/springframework/util/ResourceUtils.java +++ b/spring-core/src/main/java/org/springframework/util/ResourceUtils.java @@ -26,7 +26,7 @@ import java.net.URL; import java.net.URLConnection; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Utility methods for resolving resource locations to files in the diff --git a/spring-core/src/main/java/org/springframework/util/RouteMatcher.java b/spring-core/src/main/java/org/springframework/util/RouteMatcher.java index 166f9e677d..3011300cb7 100644 --- a/spring-core/src/main/java/org/springframework/util/RouteMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/RouteMatcher.java @@ -19,7 +19,7 @@ package org.springframework.util; import java.util.Comparator; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Contract for matching routes to patterns. @@ -74,8 +74,7 @@ public interface RouteMatcher { * @param route the route to extract template variables from * @return a map with template variables and values */ - @Nullable - Map matchAndExtract(String pattern, Route route); + @Nullable Map matchAndExtract(String pattern, Route route); /** * Given a route, return a {@link Comparator} suitable for sorting patterns diff --git a/spring-core/src/main/java/org/springframework/util/SerializationUtils.java b/spring-core/src/main/java/org/springframework/util/SerializationUtils.java index 1eb905a785..a8f34a7908 100644 --- a/spring-core/src/main/java/org/springframework/util/SerializationUtils.java +++ b/spring-core/src/main/java/org/springframework/util/SerializationUtils.java @@ -23,7 +23,7 @@ import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Static utilities for serialization and deserialization using @@ -47,8 +47,7 @@ public abstract class SerializationUtils { * @param object the object to serialize * @return an array of bytes representing the object in a portable fashion */ - @Nullable - public static byte[] serialize(@Nullable Object object) { + public static byte @Nullable [] serialize(@Nullable Object object) { if (object == null) { return null; } @@ -74,8 +73,7 @@ public abstract class SerializationUtils { * any other format) which is regularly checked and updated for not allowing RCE. */ @Deprecated - @Nullable - public static Object deserialize(@Nullable byte[] bytes) { + public static @Nullable Object deserialize(byte @Nullable [] bytes) { if (bytes == null) { return null; } diff --git a/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java b/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java index ead414e1f3..dbb3710e49 100644 --- a/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java +++ b/spring-core/src/main/java/org/springframework/util/SimpleRouteMatcher.java @@ -19,7 +19,7 @@ package org.springframework.util; import java.util.Comparator; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@code RouteMatcher} that delegates to a {@link PathMatcher}. @@ -75,8 +75,7 @@ public class SimpleRouteMatcher implements RouteMatcher { } @Override - @Nullable - public Map matchAndExtract(String pattern, Route route) { + public @Nullable Map matchAndExtract(String pattern, Route route) { if (!match(pattern, route)) { return null; } diff --git a/spring-core/src/main/java/org/springframework/util/SingleToMultiValueMapAdapter.java b/spring-core/src/main/java/org/springframework/util/SingleToMultiValueMapAdapter.java index f02bb4ee94..013e9d0a0b 100644 --- a/spring-core/src/main/java/org/springframework/util/SingleToMultiValueMapAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/SingleToMultiValueMapAdapter.java @@ -28,7 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.function.BiConsumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Adapts a given {@link MultiValueMap} to the {@link Map} contract. The @@ -47,11 +47,9 @@ final class SingleToMultiValueMapAdapter implements MultiValueMap, S private final Map targetMap; - @Nullable - private transient Collection> values; + private transient @Nullable Collection> values; - @Nullable - private transient Set>> entries; + private transient @Nullable Set>> entries; /** @@ -67,8 +65,7 @@ final class SingleToMultiValueMapAdapter implements MultiValueMap, S // MultiValueMap implementation @Override - @Nullable - public V getFirst(K key) { + public @Nullable V getFirst(K key) { return this.targetMap.get(key); } @@ -154,15 +151,13 @@ final class SingleToMultiValueMapAdapter implements MultiValueMap, S } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { V value = this.targetMap.get(key); return (value != null) ? Collections.singletonList(value) : null; } @Override - @Nullable - public List put(K key, List values) { + public @Nullable List put(K key, List values) { if (values.isEmpty()) { V result = this.targetMap.put(key, null); return (result != null) ? Collections.singletonList(result) : null; @@ -177,8 +172,7 @@ final class SingleToMultiValueMapAdapter implements MultiValueMap, S } @Override - @Nullable - public List remove(Object key) { + public @Nullable List remove(Object key) { V result = this.targetMap.remove(key); return (result != null) ? Collections.singletonList(result) : null; } 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 49b888dd93..1211f0388c 100644 --- a/spring-core/src/main/java/org/springframework/util/StopWatch.java +++ b/spring-core/src/main/java/org/springframework/util/StopWatch.java @@ -22,7 +22,7 @@ import java.util.List; import java.util.Locale; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple stop watch, allowing for timing of a number of tasks, exposing total @@ -60,18 +60,15 @@ public class StopWatch { */ private final String id; - @Nullable - private List taskList = new ArrayList<>(1); + private @Nullable List taskList = new ArrayList<>(1); /** Start time of the current task. */ private long startTimeNanos; /** Name of the current task. */ - @Nullable - private String currentTaskName; + private @Nullable String currentTaskName; - @Nullable - private TaskInfo lastTaskInfo; + private @Nullable TaskInfo lastTaskInfo; private int taskCount; @@ -181,8 +178,7 @@ public class StopWatch { * @since 4.2.2 * @see #isRunning() */ - @Nullable - public String currentTaskName() { + public @Nullable 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 99b44e03f2..c169d3cc77 100644 --- a/spring-core/src/main/java/org/springframework/util/StreamUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StreamUtils.java @@ -25,8 +25,9 @@ import java.io.InputStreamReader; import java.io.OutputStream; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Simple utility methods for dealing with streams. The copy methods of this class are 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 86fc164c8c..246960e150 100644 --- a/spring-core/src/main/java/org/springframework/util/StringUtils.java +++ b/spring-core/src/main/java/org/springframework/util/StringUtils.java @@ -36,8 +36,9 @@ import java.util.StringTokenizer; import java.util.TimeZone; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Miscellaneous {@link String} utility methods. @@ -515,8 +516,7 @@ public abstract class StringUtils { * @return the quoted {@code String} (for example, "'myString'"), * or {@code null} if the input was {@code null} */ - @Nullable - public static String quote(@Nullable String str) { + public static @Nullable String quote(@Nullable String str) { return (str != null ? "'" + str + "'" : null); } @@ -527,8 +527,7 @@ public abstract class StringUtils { * @return the quoted {@code String} (for example, "'myString'"), * or the input object as-is if not a {@code String} */ - @Nullable - public static Object quoteIfString(@Nullable Object obj) { + public static @Nullable Object quoteIfString(@Nullable Object obj) { return (obj instanceof String str ? quote(str) : obj); } @@ -619,8 +618,7 @@ public abstract class StringUtils { * @param path the file path (may be {@code null}) * @return the extracted filename, or {@code null} if none */ - @Nullable - public static String getFilename(@Nullable String path) { + public static @Nullable String getFilename(@Nullable String path) { if (path == null) { return null; } @@ -635,8 +633,7 @@ public abstract class StringUtils { * @param path the file path (may be {@code null}) * @return the extracted filename extension, or {@code null} if none */ - @Nullable - public static String getFilenameExtension(@Nullable String path) { + public static @Nullable String getFilenameExtension(@Nullable String path) { if (path == null) { return null; } @@ -866,8 +863,7 @@ public abstract class StringUtils { * @see #parseLocaleString * @see Locale#forLanguageTag */ - @Nullable - public static Locale parseLocale(String localeValue) { + public static @Nullable Locale parseLocale(String localeValue) { if (!localeValue.contains("_") && !localeValue.contains(" ")) { validateLocalePart(localeValue); Locale resolved = Locale.forLanguageTag(localeValue); @@ -893,8 +889,7 @@ public abstract class StringUtils { * @throws IllegalArgumentException in case of an invalid locale specification */ @SuppressWarnings("deprecation") // for Locale constructors on JDK 19 - @Nullable - public static Locale parseLocaleString(String localeString) { + public static @Nullable Locale parseLocaleString(String localeString) { if (localeString.isEmpty()) { return null; } @@ -990,7 +985,7 @@ public abstract class StringUtils { * @param str the {@code String} to append * @return the new array (never {@code null}) */ - public static String[] addStringToArray(@Nullable String[] array, String str) { + public static String[] addStringToArray(String @Nullable [] array, String str) { if (ObjectUtils.isEmpty(array)) { return new String[] {str}; } @@ -1009,8 +1004,7 @@ 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}) */ - @Nullable - public static String[] concatenateStringArrays(@Nullable String[] array1, @Nullable String[] array2) { + public static String @Nullable [] concatenateStringArrays(String @Nullable [] array1, String @Nullable [] array2) { if (ObjectUtils.isEmpty(array1)) { return array2; } @@ -1081,8 +1075,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(@Nullable String toSplit, @Nullable String delimiter) { + public static String @Nullable [] split(@Nullable String toSplit, @Nullable String delimiter) { if (!hasLength(toSplit) || !hasLength(delimiter)) { return null; } @@ -1106,8 +1099,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) { + public static @Nullable Properties splitArrayElementsIntoProperties(String[] array, String delimiter) { return splitArrayElementsIntoProperties(array, delimiter, null); } @@ -1125,8 +1117,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( + public static @Nullable Properties splitArrayElementsIntoProperties( String[] array, String delimiter, @Nullable String charsToDelete) { if (ObjectUtils.isEmpty(array)) { @@ -1353,7 +1344,7 @@ public abstract class StringUtils { * @param delim the delimiter to use (typically a ",") * @return the delimited {@code String} */ - public static String arrayToDelimitedString(@Nullable Object[] arr, String delim) { + public static String arrayToDelimitedString(@Nullable Object @Nullable [] arr, String delim) { if (ObjectUtils.isEmpty(arr)) { return ""; } @@ -1375,7 +1366,7 @@ public abstract class StringUtils { * @param arr the array to display (potentially {@code null} or empty) * @return the delimited {@code String} */ - public static String arrayToCommaDelimitedString(@Nullable Object[] arr) { + public static String arrayToCommaDelimitedString(@Nullable Object @Nullable [] arr) { return arrayToDelimitedString(arr, ","); } 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 1335de9586..822840af46 100644 --- a/spring-core/src/main/java/org/springframework/util/StringValueResolver.java +++ b/spring-core/src/main/java/org/springframework/util/StringValueResolver.java @@ -16,7 +16,7 @@ package org.springframework.util; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple strategy interface for resolving a String value. @@ -38,7 +38,6 @@ public interface StringValueResolver { * to resolve or when ignoring unresolvable placeholders) * @throws IllegalArgumentException in case of an unresolvable String value */ - @Nullable - String resolveStringValue(String strVal); + @Nullable String resolveStringValue(String strVal); } diff --git a/spring-core/src/main/java/org/springframework/util/SystemPropertyUtils.java b/spring-core/src/main/java/org/springframework/util/SystemPropertyUtils.java index eb962efc5b..802a456764 100644 --- a/spring-core/src/main/java/org/springframework/util/SystemPropertyUtils.java +++ b/spring-core/src/main/java/org/springframework/util/SystemPropertyUtils.java @@ -16,7 +16,7 @@ package org.springframework.util; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Helper class for resolving placeholders in texts. Usually applied to file paths. @@ -104,8 +104,7 @@ public abstract class SystemPropertyUtils { } @Override - @Nullable - public String resolvePlaceholder(String placeholderName) { + public @Nullable String resolvePlaceholder(String placeholderName) { try { String propVal = System.getProperty(placeholderName); if (propVal == null) { diff --git a/spring-core/src/main/java/org/springframework/util/TypeUtils.java b/spring-core/src/main/java/org/springframework/util/TypeUtils.java index b118aa2eee..e45d1e011d 100644 --- a/spring-core/src/main/java/org/springframework/util/TypeUtils.java +++ b/spring-core/src/main/java/org/springframework/util/TypeUtils.java @@ -21,7 +21,7 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.WildcardType; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Utility to work with generic type parameters. diff --git a/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java b/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java index 9a14150156..b7b8ff7778 100644 --- a/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java +++ b/spring-core/src/main/java/org/springframework/util/UnmodifiableMultiValueMap.java @@ -33,7 +33,7 @@ import java.util.function.Predicate; import java.util.stream.Stream; import java.util.stream.StreamSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Unmodifiable wrapper for {@link MultiValueMap}. @@ -49,14 +49,11 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial private final MultiValueMap delegate; - @Nullable - private transient Set keySet; + private transient @Nullable Set keySet; - @Nullable - private transient Set>> entrySet; + private transient @Nullable Set>> entrySet; - @Nullable - private transient Collection> values; + private transient @Nullable Collection> values; @SuppressWarnings("unchecked") @@ -89,15 +86,13 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { List result = this.delegate.get(key); return (result != null ? Collections.unmodifiableList(result) : null); } @Override - @Nullable - public V getFirst(K key) { + public @Nullable V getFirst(K key) { return this.delegate.getFirst(key); } @@ -169,9 +164,8 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial // unsupported - @Nullable @Override - public List put(K key, List value) { + public @Nullable List put(K key, List value) { throw new UnsupportedOperationException(); } @@ -433,8 +427,7 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - @Nullable - public Spliterator>> trySplit() { + public @Nullable Spliterator>> trySplit() { Spliterator>> split = this.delegate.trySplit(); if (split != null) { return new UnmodifiableEntrySpliterator<>(split); @@ -677,8 +670,7 @@ final class UnmodifiableMultiValueMap implements MultiValueMap, Serial } @Override - @Nullable - public Spliterator> trySplit() { + public @Nullable Spliterator> trySplit() { Spliterator> split = this.delegate.trySplit(); if (split != null) { return new UnmodifiableValueSpliterator<>(split); 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 071542a7a1..c4e680b5a1 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,9 +1,7 @@ /** * A generic back-off abstraction. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util.backoff; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java index 6f65f92d5b..f3626f84b2 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/BooleanComparator.java @@ -19,7 +19,7 @@ package org.springframework.util.comparator; import java.io.Serializable; import java.util.Comparator; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A {@link Comparator} for {@link Boolean} objects that can sort either diff --git a/spring-core/src/main/java/org/springframework/util/comparator/InstanceComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/InstanceComparator.java index 66d4b4f37d..e56384cedc 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/InstanceComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/InstanceComparator.java @@ -18,7 +18,8 @@ package org.springframework.util.comparator; import java.util.Comparator; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java index 77dce76082..3c89ec9713 100644 --- a/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java +++ b/spring-core/src/main/java/org/springframework/util/comparator/NullSafeComparator.java @@ -18,7 +18,8 @@ package org.springframework.util.comparator; import java.util.Comparator; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 3d4ebd53b7..7fae7e8e4c 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,9 +2,7 @@ * Useful generic {@code java.util.Comparator} implementations, * such as an invertible comparator and a compound comparator. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util.comparator; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java b/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java index 43afe42b30..8864d4477c 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/FutureAdapter.java @@ -21,7 +21,8 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -40,8 +41,7 @@ public abstract class FutureAdapter implements Future { private final Future adaptee; - @Nullable - private Object result; + private @Nullable Object result; private State state = State.NEW; @@ -81,20 +81,17 @@ public abstract class FutureAdapter implements Future { } @Override - @Nullable - public T get() throws InterruptedException, ExecutionException { + public @Nullable T get() throws InterruptedException, ExecutionException { return adaptInternal(this.adaptee.get()); } @Override - @Nullable - public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { + public @Nullable T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return adaptInternal(this.adaptee.get(timeout, unit)); } @SuppressWarnings("unchecked") - @Nullable - final T adaptInternal(S adapteeResult) throws ExecutionException { + final @Nullable T adaptInternal(S adapteeResult) throws ExecutionException { synchronized (this.mutex) { return switch (this.state) { case SUCCESS -> (T) this.result; @@ -129,8 +126,7 @@ public abstract class FutureAdapter implements Future { * Adapts the given adaptee's result into T. * @return the adapted result */ - @Nullable - protected abstract T adapt(S adapteeResult) throws ExecutionException; + protected abstract @Nullable T adapt(S adapteeResult) throws ExecutionException; private enum State {NEW, SUCCESS, FAILURE} 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 fc4777eff0..556f3300be 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,9 +1,7 @@ /** * Useful generic {@code java.util.concurrent.Future} extensions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util.concurrent; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java b/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java index 9cd7f7b33f..270bc494b4 100644 --- a/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java +++ b/spring-core/src/main/java/org/springframework/util/function/SingletonSupplier.java @@ -20,7 +20,8 @@ import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -39,14 +40,11 @@ import org.springframework.util.Assert; */ public class SingletonSupplier implements Supplier { - @Nullable - private final Supplier instanceSupplier; + private final @Nullable Supplier instanceSupplier; - @Nullable - private final Supplier defaultSupplier; + private final @Nullable Supplier defaultSupplier; - @Nullable - private volatile T singletonInstance; + private volatile @Nullable T singletonInstance; /** * Guards access to write operations on the {@code singletonInstance} field. @@ -94,8 +92,7 @@ public class SingletonSupplier implements Supplier { * @return the singleton instance (or {@code null} if none) */ @Override - @Nullable - public T get() { + public @Nullable T get() { T instance = this.singletonInstance; if (instance == null) { this.writeLock.lock(); @@ -144,8 +141,7 @@ public class SingletonSupplier implements Supplier { * @param instance the singleton instance (potentially {@code null}) * @return the singleton supplier, or {@code null} if the instance was {@code null} */ - @Nullable - public static SingletonSupplier ofNullable(@Nullable T instance) { + public static @Nullable SingletonSupplier ofNullable(@Nullable T instance) { return (instance != null ? new SingletonSupplier<>(instance) : null); } @@ -163,8 +159,7 @@ public class SingletonSupplier implements Supplier { * @param supplier the instance supplier (potentially {@code null}) * @return the singleton supplier, or {@code null} if the instance supplier was {@code null} */ - @Nullable - public static SingletonSupplier ofNullable(@Nullable Supplier supplier) { + public static @Nullable SingletonSupplier ofNullable(@Nullable Supplier supplier) { return (supplier != null ? new SingletonSupplier<>(supplier) : null); } diff --git a/spring-core/src/main/java/org/springframework/util/function/SupplierUtils.java b/spring-core/src/main/java/org/springframework/util/function/SupplierUtils.java index af97e2fd99..1513ec2ca3 100644 --- a/spring-core/src/main/java/org/springframework/util/function/SupplierUtils.java +++ b/spring-core/src/main/java/org/springframework/util/function/SupplierUtils.java @@ -18,7 +18,7 @@ package org.springframework.util.function; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Convenience utilities for {@link java.util.function.Supplier} handling. @@ -35,8 +35,7 @@ public abstract class SupplierUtils { * @param supplier the supplier to resolve * @return the supplier's result, or {@code null} if none */ - @Nullable - public static T resolve(@Nullable Supplier supplier) { + public static @Nullable T resolve(@Nullable Supplier supplier) { return (supplier != null ? supplier.get() : null); } @@ -47,8 +46,7 @@ public abstract class SupplierUtils { * @return a supplier's result or the given Object as-is * @since 6.1.4 */ - @Nullable - public static Object resolve(@Nullable Object candidate) { + public static @Nullable Object resolve(@Nullable Object candidate) { return (candidate instanceof Supplier supplier ? supplier.get() : candidate); } diff --git a/spring-core/src/main/java/org/springframework/util/function/package-info.java b/spring-core/src/main/java/org/springframework/util/function/package-info.java index 7c16649bd9..8ecebcf9a3 100644 --- a/spring-core/src/main/java/org/springframework/util/function/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/function/package-info.java @@ -1,9 +1,7 @@ /** * Useful generic {@code java.util.function} helper classes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util.function; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 1c57d89eed..55dca7cc13 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,9 +2,7 @@ * Miscellaneous utility classes, such as utilities for working with strings, * classes, collections, reflection, etc. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/util/unit/DataSize.java b/spring-core/src/main/java/org/springframework/util/unit/DataSize.java index 33f76e9586..25c234c5d4 100644 --- a/spring-core/src/main/java/org/springframework/util/unit/DataSize.java +++ b/spring-core/src/main/java/org/springframework/util/unit/DataSize.java @@ -20,7 +20,8 @@ import java.io.Serializable; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-core/src/main/java/org/springframework/util/unit/package-info.java b/spring-core/src/main/java/org/springframework/util/unit/package-info.java index bad1762bf6..91c7390e4f 100644 --- a/spring-core/src/main/java/org/springframework/util/unit/package-info.java +++ b/spring-core/src/main/java/org/springframework/util/unit/package-info.java @@ -1,9 +1,7 @@ /** * Useful unit data types. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util.unit; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxHandler.java b/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxHandler.java index 4a4c443e21..e440f5e6a8 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxHandler.java +++ b/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxHandler.java @@ -25,13 +25,12 @@ import javax.xml.XMLConstants; import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; +import org.jspecify.annotations.Nullable; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; -import org.springframework.lang.Nullable; - /** * Abstract base class for SAX {@code ContentHandler} and {@code LexicalHandler} * implementations that use StAX as a basis. All methods delegate to internal template diff --git a/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java index 7d3e03b8d5..ef128895e1 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/AbstractStaxXMLReader.java @@ -23,6 +23,7 @@ import javax.xml.namespace.QName; import javax.xml.stream.Location; import javax.xml.stream.XMLStreamException; +import org.jspecify.annotations.Nullable; import org.xml.sax.InputSource; import org.xml.sax.Locator; import org.xml.sax.SAXException; @@ -30,7 +31,6 @@ import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.SAXNotSupportedException; import org.xml.sax.SAXParseException; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -57,8 +57,7 @@ abstract class AbstractStaxXMLReader extends AbstractXMLReader { private boolean namespacePrefixesFeature = false; - @Nullable - private Boolean isStandalone; + private @Nullable Boolean isStandalone; private final Map namespaces = new LinkedHashMap<>(); diff --git a/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLReader.java index 3cf3108db6..08f597e306 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/AbstractXMLReader.java @@ -16,6 +16,7 @@ package org.springframework.util.xml; +import org.jspecify.annotations.Nullable; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver; @@ -25,8 +26,6 @@ import org.xml.sax.SAXNotSupportedException; import org.xml.sax.XMLReader; import org.xml.sax.ext.LexicalHandler; -import org.springframework.lang.Nullable; - /** * Abstract base class for SAX {@code XMLReader} implementations. * Contains properties as defined in {@link XMLReader}, and does not recognize any features. @@ -41,20 +40,15 @@ import org.springframework.lang.Nullable; */ abstract class AbstractXMLReader implements XMLReader { - @Nullable - private DTDHandler dtdHandler; + private @Nullable DTDHandler dtdHandler; - @Nullable - private ContentHandler contentHandler; + private @Nullable ContentHandler contentHandler; - @Nullable - private EntityResolver entityResolver; + private @Nullable EntityResolver entityResolver; - @Nullable - private ErrorHandler errorHandler; + private @Nullable ErrorHandler errorHandler; - @Nullable - private LexicalHandler lexicalHandler; + private @Nullable LexicalHandler lexicalHandler; @Override @@ -63,8 +57,7 @@ abstract class AbstractXMLReader implements XMLReader { } @Override - @Nullable - public ContentHandler getContentHandler() { + public @Nullable ContentHandler getContentHandler() { return this.contentHandler; } @@ -74,8 +67,7 @@ abstract class AbstractXMLReader implements XMLReader { } @Override - @Nullable - public DTDHandler getDTDHandler() { + public @Nullable DTDHandler getDTDHandler() { return this.dtdHandler; } @@ -85,8 +77,7 @@ abstract class AbstractXMLReader implements XMLReader { } @Override - @Nullable - public EntityResolver getEntityResolver() { + public @Nullable EntityResolver getEntityResolver() { return this.entityResolver; } @@ -96,13 +87,11 @@ abstract class AbstractXMLReader implements XMLReader { } @Override - @Nullable - public ErrorHandler getErrorHandler() { + public @Nullable ErrorHandler getErrorHandler() { return this.errorHandler; } - @Nullable - protected LexicalHandler getLexicalHandler() { + protected @Nullable LexicalHandler getLexicalHandler() { return this.lexicalHandler; } @@ -144,8 +133,7 @@ abstract class AbstractXMLReader implements XMLReader { * handler. The property name for a lexical handler is {@code http://xml.org/sax/properties/lexical-handler}. */ @Override - @Nullable - public Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { + public @Nullable Object getProperty(String name) throws SAXNotRecognizedException, SAXNotSupportedException { if ("http://xml.org/sax/properties/lexical-handler".equals(name)) { return this.lexicalHandler; } 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 e50a5dd0dd..3709dc8b92 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,7 +21,7 @@ import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract base class for {@code XMLStreamReader}s. @@ -161,8 +161,7 @@ abstract class AbstractXMLStreamReader implements XMLStreamReader { } @Override - @Nullable - public String getAttributeValue(@Nullable String namespaceURI, String localName) { + public @Nullable String getAttributeValue(@Nullable String namespaceURI, String localName) { for (int i = 0; i < getAttributeCount(); i++) { QName name = getAttributeName(i); if (name.getLocalPart().equals(localName) && 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 6481dbba30..9dc17011cc 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 @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.CharacterData; import org.w3c.dom.Comment; import org.w3c.dom.Element; @@ -29,7 +30,6 @@ 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; /** @@ -92,8 +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) { + public static @Nullable Element getChildElementByTagName(Element ele, String childEleName) { Assert.notNull(ele, "Element must not be null"); Assert.notNull(childEleName, "Element name must not be null"); NodeList nl = ele.getChildNodes(); @@ -112,8 +111,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) { + public static @Nullable 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 488b70b47d..b5708256ab 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 @@ -25,7 +25,8 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Characters; import javax.xml.stream.events.XMLEvent; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -40,8 +41,7 @@ class ListBasedXMLEventReader extends AbstractXMLEventReader { private final List events; - @Nullable - private XMLEvent currentEvent; + private @Nullable XMLEvent currentEvent; private int cursor = 0; @@ -70,8 +70,7 @@ class ListBasedXMLEventReader extends AbstractXMLEventReader { } @Override - @Nullable - public XMLEvent peek() { + public @Nullable XMLEvent peek() { if (hasNext()) { return this.events.get(this.cursor); } @@ -105,8 +104,7 @@ class ListBasedXMLEventReader extends AbstractXMLEventReader { } @Override - @Nullable - public XMLEvent nextTag() throws XMLStreamException { + public @Nullable XMLEvent nextTag() throws XMLStreamException { checkIfClosed(); while (true) { diff --git a/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java b/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java index 4b8abba390..76e09ef395 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java +++ b/spring-core/src/main/java/org/springframework/util/xml/SimpleNamespaceContext.java @@ -26,7 +26,8 @@ import java.util.Set; import javax.xml.XMLConstants; import javax.xml.namespace.NamespaceContext; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -66,8 +67,7 @@ public class SimpleNamespaceContext implements NamespaceContext { } @Override - @Nullable - public String getPrefix(String namespaceUri) { + public @Nullable String getPrefix(String namespaceUri) { Set prefixes = getPrefixesSet(namespaceUri); return (!prefixes.isEmpty() ? prefixes.iterator().next() : null); } diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java b/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java index e57141af1e..67281a9dc7 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxEventHandler.java @@ -28,12 +28,11 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.events.Attribute; import javax.xml.stream.events.Namespace; +import org.jspecify.annotations.Nullable; import org.xml.sax.Attributes; import org.xml.sax.Locator; import org.xml.sax.ext.LexicalHandler; -import org.springframework.lang.Nullable; - /** * SAX {@link org.xml.sax.ContentHandler} and {@link LexicalHandler} * that writes to a {@link javax.xml.stream.util.XMLEventConsumer}. diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java index f5179707ca..b40477896c 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxEventXMLReader.java @@ -37,13 +37,13 @@ import javax.xml.stream.events.StartDocument; import javax.xml.stream.events.StartElement; import javax.xml.stream.events.XMLEvent; +import org.jspecify.annotations.Nullable; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.Locator2; import org.xml.sax.helpers.AttributesImpl; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -67,8 +67,7 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { private String xmlVersion = DEFAULT_XML_VERSION; - @Nullable - private String encoding; + private @Nullable String encoding; /** @@ -164,13 +163,11 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { return (location != null ? location.getLineNumber() : -1); } @Override - @Nullable - public String getPublicId() { + public @Nullable String getPublicId() { return (location != null ? location.getPublicId() : null); } @Override - @Nullable - public String getSystemId() { + public @Nullable String getSystemId() { return (location != null ? location.getSystemId() : null); } @Override @@ -178,8 +175,7 @@ class StaxEventXMLReader extends AbstractStaxXMLReader { return xmlVersion; } @Override - @Nullable - public String getEncoding() { + public @Nullable String getEncoding() { return encoding; } }); 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 80a86a04a3..767af71cf1 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 @@ -20,11 +20,10 @@ import javax.xml.stream.XMLEventWriter; import javax.xml.stream.XMLStreamWriter; import javax.xml.transform.sax.SAXResult; +import org.jspecify.annotations.Nullable; 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}. @@ -48,11 +47,9 @@ import org.springframework.lang.Nullable; */ class StaxResult extends SAXResult { - @Nullable - private XMLEventWriter eventWriter; + private @Nullable XMLEventWriter eventWriter; - @Nullable - private XMLStreamWriter streamWriter; + private @Nullable XMLStreamWriter streamWriter; /** @@ -85,8 +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() { + public @Nullable XMLEventWriter getXMLEventWriter() { return this.eventWriter; } @@ -97,8 +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() { + public @Nullable 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 392cd123c9..dcd0e82422 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 @@ -20,11 +20,10 @@ import javax.xml.stream.XMLEventReader; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.sax.SAXSource; +import org.jspecify.annotations.Nullable; 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}. @@ -47,11 +46,9 @@ import org.springframework.lang.Nullable; */ class StaxSource extends SAXSource { - @Nullable - private XMLEventReader eventReader; + private @Nullable XMLEventReader eventReader; - @Nullable - private XMLStreamReader streamReader; + private @Nullable XMLStreamReader streamReader; /** @@ -86,8 +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() { + @Nullable XMLEventReader getXMLEventReader() { return this.eventReader; } @@ -98,8 +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() { + @Nullable XMLStreamReader getXMLStreamReader() { return this.streamReader; } diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java index ebc5386ff1..55889f2330 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxStreamXMLReader.java @@ -22,13 +22,13 @@ import javax.xml.stream.XMLStreamConstants; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import org.jspecify.annotations.Nullable; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; import org.xml.sax.ext.Locator2; import org.xml.sax.helpers.AttributesImpl; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -51,8 +51,7 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { private String xmlVersion = DEFAULT_XML_VERSION; - @Nullable - private String encoding; + private @Nullable String encoding; /** @@ -142,13 +141,11 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { return (location != null ? location.getLineNumber() : -1); } @Override - @Nullable - public String getPublicId() { + public @Nullable String getPublicId() { return (location != null ? location.getPublicId() : null); } @Override - @Nullable - public String getSystemId() { + public @Nullable String getSystemId() { return (location != null ? location.getSystemId() : null); } @Override @@ -156,8 +153,7 @@ class StaxStreamXMLReader extends AbstractStaxXMLReader { return xmlVersion; } @Override - @Nullable - public String getEncoding() { + public @Nullable String getEncoding() { return encoding; } }); diff --git a/spring-core/src/main/java/org/springframework/util/xml/StaxUtils.java b/spring-core/src/main/java/org/springframework/util/xml/StaxUtils.java index 3555606de4..de4d578c2b 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/StaxUtils.java +++ b/spring-core/src/main/java/org/springframework/util/xml/StaxUtils.java @@ -34,11 +34,10 @@ import javax.xml.transform.Source; import javax.xml.transform.stax.StAXResult; import javax.xml.transform.stax.StAXSource; +import org.jspecify.annotations.Nullable; import org.xml.sax.ContentHandler; import org.xml.sax.XMLReader; -import org.springframework.lang.Nullable; - /** * Convenience methods for working with the StAX API. Partly historic due to JAXP 1.3 * compatibility; as of Spring 4.0, relying on JAXP 1.4 as included in JDK 1.6 and higher. @@ -134,8 +133,7 @@ public abstract class StaxUtils { * @throws IllegalArgumentException if {@code source} isn't a JAXP 1.4 {@link StAXSource} * or custom StAX Source */ - @Nullable - public static XMLStreamReader getXMLStreamReader(Source source) { + public static @Nullable XMLStreamReader getXMLStreamReader(Source source) { if (source instanceof StAXSource stAXSource) { return stAXSource.getXMLStreamReader(); } @@ -154,8 +152,7 @@ public abstract class StaxUtils { * @throws IllegalArgumentException if {@code source} isn't a JAXP 1.4 {@link StAXSource} * or custom StAX Source */ - @Nullable - public static XMLEventReader getXMLEventReader(Source source) { + public static @Nullable XMLEventReader getXMLEventReader(Source source) { if (source instanceof StAXSource stAXSource) { return stAXSource.getXMLEventReader(); } @@ -220,8 +217,7 @@ public abstract class StaxUtils { * @throws IllegalArgumentException if {@code source} isn't a JAXP 1.4 {@link StAXResult} * or custom StAX Result */ - @Nullable - public static XMLStreamWriter getXMLStreamWriter(Result result) { + public static @Nullable XMLStreamWriter getXMLStreamWriter(Result result) { if (result instanceof StAXResult stAXResult) { return stAXResult.getXMLStreamWriter(); } @@ -240,8 +236,7 @@ public abstract class StaxUtils { * @throws IllegalArgumentException if {@code source} isn't a JAXP 1.4 {@link StAXResult} * or custom StAX Result */ - @Nullable - public static XMLEventWriter getXMLEventWriter(Result result) { + public static @Nullable XMLEventWriter getXMLEventWriter(Result result) { if (result instanceof StAXResult stAXResult) { return stAXResult.getXMLEventWriter(); } 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 67d37d5e5f..5fec714d6f 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 @@ -31,7 +31,7 @@ import javax.xml.stream.events.ProcessingInstruction; import javax.xml.stream.events.StartDocument; import javax.xml.stream.events.XMLEvent; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Implementation of the {@link javax.xml.stream.XMLStreamReader} interface that wraps a @@ -79,8 +79,7 @@ class XMLEventStreamReader extends AbstractXMLStreamReader { } @Override - @Nullable - public String getVersion() { + public @Nullable String getVersion() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).getVersion(); } @@ -115,14 +114,12 @@ class XMLEventStreamReader extends AbstractXMLStreamReader { } @Override - @Nullable - public String getEncoding() { + public @Nullable String getEncoding() { return null; } @Override - @Nullable - public String getCharacterEncodingScheme() { + public @Nullable String getCharacterEncodingScheme() { return null; } diff --git a/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java b/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java index 1248ab0b39..06c242062f 100644 --- a/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java +++ b/spring-core/src/main/java/org/springframework/util/xml/XmlValidationModeDetector.java @@ -22,7 +22,8 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -170,8 +171,7 @@ public class XmlValidationModeDetector { * Consume the next comment token, update the "inComment" flag, * and return the remaining content. */ - @Nullable - private String consume(String line) { + private @Nullable String consume(String line) { int index = (this.inComment ? endComment(line) : startComment(line)); return (index == -1 ? null : line.substring(index)); } 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 b077891dd6..bc39307e92 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,9 +2,7 @@ * Miscellaneous utility classes for XML parsing and transformation, * such as error handlers that log warnings via Commons Logging. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.util.xml; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-core/src/test/java/org/springframework/aot/generate/DefaultMethodReferenceTests.java b/spring-core/src/test/java/org/springframework/aot/generate/DefaultMethodReferenceTests.java index bc62da2b9b..083e0583dd 100644 --- a/spring-core/src/test/java/org/springframework/aot/generate/DefaultMethodReferenceTests.java +++ b/spring-core/src/test/java/org/springframework/aot/generate/DefaultMethodReferenceTests.java @@ -18,6 +18,7 @@ package org.springframework.aot.generate; import javax.lang.model.element.Modifier; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.MethodReference.ArgumentCodeGenerator; @@ -26,7 +27,6 @@ import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.MethodSpec.Builder; import org.springframework.javapoet.TypeName; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; diff --git a/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java b/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java index 5c45bca599..952f5fc7d7 100644 --- a/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java +++ b/spring-core/src/test/java/org/springframework/aot/generate/GeneratedFilesTests.java @@ -24,6 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import javax.lang.model.element.Modifier; import org.assertj.core.api.AbstractStringAssert; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GeneratedFiles.FileHandler; @@ -34,7 +35,6 @@ import org.springframework.core.io.Resource; import org.springframework.javapoet.JavaFile; import org.springframework.javapoet.MethodSpec; import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; import org.springframework.util.function.ThrowingConsumer; import static org.assertj.core.api.Assertions.assertThat; @@ -226,11 +226,9 @@ class GeneratedFilesTests { static class TestGeneratedFiles implements GeneratedFiles { - @Nullable - private Kind kind; + private @Nullable Kind kind; - @Nullable - private String path; + private @Nullable String path; private TestFileHandler fileHandler = new TestFileHandler(); @@ -256,8 +254,7 @@ class GeneratedFilesTests { private static class GeneratedFileAssert extends AbstractStringAssert { - @Nullable - private final Boolean override; + private final @Nullable Boolean override; GeneratedFileAssert(InputStreamSource content, @Nullable Boolean override) throws IOException { super(readSource(content), GeneratedFileAssert.class); @@ -272,11 +269,9 @@ class GeneratedFilesTests { private static class TestFileHandler extends FileHandler { - @Nullable - private InputStreamSource content; + private @Nullable InputStreamSource content; - @Nullable - private Boolean override; + private @Nullable Boolean override; TestFileHandler(@Nullable InputStreamSource content) { super(content != null, () -> content); diff --git a/spring-core/src/test/java/org/springframework/aot/generate/ValueCodeGeneratorTests.java b/spring-core/src/test/java/org/springframework/aot/generate/ValueCodeGeneratorTests.java index dc755467ec..ad0733c6ba 100644 --- a/spring-core/src/test/java/org/springframework/aot/generate/ValueCodeGeneratorTests.java +++ b/spring-core/src/test/java/org/springframework/aot/generate/ValueCodeGeneratorTests.java @@ -33,6 +33,7 @@ import java.util.Set; import org.assertj.core.api.AbstractAssert; import org.assertj.core.api.AssertProvider; import org.assertj.core.api.StringAssert; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -47,7 +48,6 @@ import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.FieldSpec; import org.springframework.javapoet.JavaFile; import org.springframework.javapoet.TypeSpec; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java index 7756980bdb..1b7c0ecd1a 100644 --- a/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java +++ b/spring-core/src/test/java/org/springframework/aot/hint/ReflectionHintsTests.java @@ -22,9 +22,9 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -246,8 +246,7 @@ class ReflectionHintsTests { @SuppressWarnings("unused") static class TestType { - @Nullable - private String field; + private @Nullable String field; void setName(String name) { diff --git a/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java b/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java index e01f0275ce..22433969be 100644 --- a/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java +++ b/spring-core/src/test/java/org/springframework/core/MethodParameterTests.java @@ -237,7 +237,19 @@ class MethodParameterTests { assertThat(m3.getTypeIndexForCurrentLevel()).isEqualTo(3); } - public int method(String p1, long p2) { + @Test + void nullableWithSpringAnnotation() { + MethodParameter m = MethodParameter.forExecutable(method, 1); + assertThat(m.isOptional()).isTrue(); + } + + @Test + void nullableWithJSpecifyAnnotation() { + MethodParameter m = MethodParameter.forExecutable(method, 0); + assertThat(m.isOptional()).isTrue(); + } + + public int method(@org.jspecify.annotations.Nullable String p1, @org.springframework.lang.Nullable long p2) { return 42; } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index bf6a82bb57..353ba3d313 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -36,6 +36,7 @@ import javax.annotation.ParametersAreNonnullByDefault; import javax.annotation.meta.When; import jakarta.annotation.Resource; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -47,7 +48,6 @@ import org.springframework.core.annotation.AnnotationUtilsTests.WebMapping; import org.springframework.core.testfixture.stereotype.Component; import org.springframework.core.testfixture.stereotype.Indexed; import org.springframework.lang.NonNullApi; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import static java.util.Arrays.asList; @@ -1548,15 +1548,13 @@ class AnnotatedElementUtilsTests { interface TransactionalService { @Transactional - @Nullable - Object doIt(); + @Nullable Object doIt(); } class TransactionalServiceImpl implements TransactionalService { @Override - @Nullable - public Object doIt() { + public @Nullable Object doIt() { return null; } } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationFilterTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationFilterTests.java index de5319b4f9..56695ac3fb 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationFilterTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationFilterTests.java @@ -21,9 +21,10 @@ import java.lang.annotation.RetentionPolicy; import javax.annotation.Nonnull; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; +import org.springframework.lang.Contract; import org.springframework.util.ObjectUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -70,7 +71,7 @@ class AnnotationFilterTests { @Test void plainWhenSpringLangAnnotationReturnsTrue() { - assertThat(AnnotationFilter.PLAIN.matches(Nullable.class)).isTrue(); + assertThat(AnnotationFilter.PLAIN.matches(Contract.class)).isTrue(); } @Test diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationTypeMappingsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationTypeMappingsTests.java index 16c5425116..1e99bc44f9 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationTypeMappingsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationTypeMappingsTests.java @@ -476,14 +476,12 @@ class AnnotationTypeMappingsTests { return result; } - @Nullable - private Method getAliasMapping(AnnotationTypeMapping mapping, int attributeIndex) { + private @Nullable Method getAliasMapping(AnnotationTypeMapping mapping, int attributeIndex) { int mapped = mapping.getAliasMapping(attributeIndex); return mapped != -1 ? mapping.getRoot().getAttributes().get(mapped) : null; } - @Nullable - private Method getConventionMapping(AnnotationTypeMapping mapping, int attributeIndex) { + private @Nullable Method getConventionMapping(AnnotationTypeMapping mapping, int attributeIndex) { int mapped = mapping.getConventionMapping(attributeIndex); return mapped != -1 ? mapping.getRoot().getAttributes().get(mapped) : null; } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java index 4185df3c4a..b127137cfc 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationUtilsTests.java @@ -40,7 +40,6 @@ import org.springframework.core.Ordered; import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass; import org.springframework.core.testfixture.ide.IdeUtils; import org.springframework.core.testfixture.stereotype.Component; -import org.springframework.lang.NonNullApi; import static java.util.Arrays.asList; import static java.util.Arrays.stream; @@ -429,8 +428,7 @@ class AnnotationUtilsTests { @Test void isAnnotationMetaPresentForPlainType() { assertThat(isAnnotationMetaPresent(Order.class, Documented.class)).isTrue(); - assertThat(isAnnotationMetaPresent(NonNullApi.class, Documented.class)).isTrue(); - assertThat(isAnnotationMetaPresent(NonNullApi.class, Nonnull.class)).isTrue(); + assertThat(isAnnotationMetaPresent(ParametersAreNonnullByDefault.class, Documented.class)).isTrue(); assertThat(isAnnotationMetaPresent(ParametersAreNonnullByDefault.class, Nonnull.class)).isTrue(); } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java index 6400a880c3..1c5e508eb3 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotationsScannerTests.java @@ -29,11 +29,11 @@ import java.util.Objects; import java.util.function.Predicate; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.annotation.MergedAnnotations.Search; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -469,15 +469,13 @@ class AnnotationsScannerTests { new AnnotationsProcessor() { @Override - @Nullable public String doWithAggregate(Object context, int aggregateIndex) { return ""; } @Override - @Nullable public String doWithAnnotations(Object context, int aggregateIndex, - Object source, Annotation[] annotations) { + @Nullable Object source, Annotation[] annotations) { throw new IllegalStateException("Should not call"); } @@ -503,15 +501,13 @@ class AnnotationsScannerTests { new AnnotationsProcessor() { @Override - @Nullable public String doWithAnnotations(Object context, int aggregateIndex, - Object source, Annotation[] annotations) { + @Nullable Object source, Annotation[] annotations) { return "K"; } @Override - @Nullable - public String finish(String result) { + public String finish(@Nullable String result) { return "O" + result; } @@ -793,13 +789,11 @@ class AnnotationsScannerTests { interface IgnorableOverrideInterface1 { - @Nullable void method(); } interface IgnorableOverrideInterface2 { - @Nullable void method(); } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java index 093b570a53..d0d2477e1f 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/MergedAnnotationsTests.java @@ -36,6 +36,7 @@ import java.util.NoSuchElementException; import java.util.stream.Stream; import jakarta.annotation.Resource; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -49,7 +50,6 @@ import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass; import org.springframework.core.testfixture.ide.IdeUtils; import org.springframework.core.testfixture.stereotype.Component; import org.springframework.core.testfixture.stereotype.Indexed; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; import org.springframework.util.ReflectionUtils; @@ -2875,8 +2875,7 @@ class MergedAnnotationsTests { interface NullableAnnotatedInterface { - @Nullable - void fromInterfaceImplementedByRoot(); + @Nullable String fromInterfaceImplementedByRoot(); } static class Root implements AnnotatedInterface { diff --git a/spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java b/spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java index 0d325a2eef..1e45d29949 100644 --- a/spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java +++ b/spring-core/src/test/java/org/springframework/core/codec/ResourceEncoderTests.java @@ -18,6 +18,7 @@ package org.springframework.core.codec; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -29,7 +30,6 @@ import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.testfixture.codec.AbstractEncoderTests; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java index 81d6174794..f1b35cc7c0 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java @@ -43,6 +43,7 @@ import java.util.UUID; import java.util.regex.Pattern; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; @@ -50,7 +51,6 @@ import org.springframework.core.convert.ConversionFailedException; import org.springframework.core.convert.ConverterNotFoundException; import org.springframework.core.convert.TypeDescriptor; import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java index 3faacdbfeb..c39a5a0d90 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java @@ -30,6 +30,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.convert.ConversionFailedException; @@ -41,7 +42,6 @@ import org.springframework.core.convert.converter.ConverterFactory; import org.springframework.core.convert.converter.GenericConverter; import org.springframework.core.io.DescriptiveResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import static java.util.Comparator.naturalOrder; @@ -681,8 +681,7 @@ class GenericConversionServiceTests { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return null; } } @@ -704,8 +703,7 @@ class GenericConversionServiceTests { } @Override - @Nullable - public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { return null; } diff --git a/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java b/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java index c408bce244..cbd026ebbe 100644 --- a/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java +++ b/spring-core/src/test/java/org/springframework/core/env/CustomEnvironmentTests.java @@ -20,10 +20,9 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; - import static org.assertj.core.api.Assertions.assertThat; /** @@ -109,13 +108,11 @@ class CustomEnvironmentTests { void withNoProfileProperties() { ConfigurableEnvironment env = new AbstractEnvironment() { @Override - @Nullable - protected String doGetActiveProfilesProperty() { + protected @Nullable String doGetActiveProfilesProperty() { return null; } @Override - @Nullable - protected String doGetDefaultProfilesProperty() { + protected @Nullable String doGetDefaultProfilesProperty() { return null; } }; @@ -143,8 +140,7 @@ class CustomEnvironmentTests { super(propertySources); } @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return super.getProperty(key) + "-test"; } } diff --git a/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTests.java b/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTests.java index 67647495cc..00bcae5668 100644 --- a/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTests.java +++ b/spring-core/src/test/java/org/springframework/core/type/CachingMetadataReaderLeakTests.java @@ -18,6 +18,7 @@ package org.springframework.core.type; import java.net.URL; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.io.Resource; @@ -26,7 +27,6 @@ import org.springframework.core.testfixture.EnabledForTestGroups; import org.springframework.core.type.classreading.CachingMetadataReaderFactory; import org.springframework.core.type.classreading.MetadataReader; import org.springframework.core.type.classreading.MetadataReaderFactory; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING; diff --git a/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java b/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java index 1a96590db7..bfbdeadaa1 100644 --- a/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/CollectionUtilsTests.java @@ -31,10 +31,9 @@ import java.util.SortedSet; import java.util.TreeSet; import java.util.Vector; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; - import static org.assertj.core.api.Assertions.assertThat; /** diff --git a/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java b/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java index 95a148ae98..f39b95131c 100644 --- a/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java +++ b/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java @@ -26,9 +26,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.util.ConcurrentReferenceHashMap.Entry; import org.springframework.util.ConcurrentReferenceHashMap.Reference; import org.springframework.util.ConcurrentReferenceHashMap.Restructure; diff --git a/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java b/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java index 7f51d8af08..ce00140acb 100644 --- a/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java +++ b/spring-core/src/test/java/org/springframework/util/xml/AbstractStaxXMLReaderTests.java @@ -29,6 +29,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.sax.SAXSource; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; @@ -44,7 +45,6 @@ import org.xml.sax.helpers.AttributesImpl; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.tests.MockitoUtils; import org.springframework.tests.MockitoUtils.InvocationArgumentsAdapter; diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractDecoderTests.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractDecoderTests.java index 9614579429..4e6aec96de 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractDecoderTests.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractDecoderTests.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.function.Consumer; import io.netty5.buffer.Buffer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -31,7 +32,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.codec.Decoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.testfixture.io.buffer.AbstractLeakCheckingTests; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java index fdc5c191c7..0127e40fd2 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/codec/AbstractEncoderTests.java @@ -19,6 +19,7 @@ package org.springframework.core.testfixture.codec; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -29,7 +30,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.testfixture.io.buffer.AbstractLeakCheckingTests; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; diff --git a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java index 307cac0b78..0fc5aef20f 100644 --- a/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java +++ b/spring-core/src/testFixtures/java/org/springframework/core/testfixture/security/TestPrincipal.java @@ -18,7 +18,7 @@ package org.springframework.core.testfixture.security; import java.security.Principal; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An implementation of {@link Principal} for testing. 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 3c9c232c3e..886644f281 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/ConstructorResolver.java @@ -18,8 +18,9 @@ package org.springframework.expression; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * A constructor resolver attempts to locate a constructor and returns a @@ -50,8 +51,7 @@ public interface ConstructorResolver { * @return a {@code ConstructorExecutor} that can invoke the constructor, * or {@code null} if the constructor cannot be found */ - @Nullable - ConstructorExecutor resolve(EvaluationContext context, String typeName, List argumentTypes) + @Nullable ConstructorExecutor resolve(EvaluationContext context, String typeName, List argumentTypes) throws AccessException; } diff --git a/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java index 0fb89de103..64e86bb81c 100644 --- a/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/EvaluationContext.java @@ -20,7 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Expressions are executed in an evaluation context. It is in this context that @@ -89,8 +89,7 @@ public interface EvaluationContext { /** * Return a bean resolver that can look up beans by name. */ - @Nullable - BeanResolver getBeanResolver(); + @Nullable BeanResolver getBeanResolver(); /** * Return a type locator that can be used to find types, either by short or @@ -150,8 +149,7 @@ public interface EvaluationContext { * @param name the name of the variable to look up * @return the value of the variable, or {@code null} if not found */ - @Nullable - Object lookupVariable(String name); + @Nullable Object lookupVariable(String name); /** * Determine if assignment is enabled within expressions evaluated by this evaluation diff --git a/spring-expression/src/main/java/org/springframework/expression/EvaluationException.java b/spring-expression/src/main/java/org/springframework/expression/EvaluationException.java index ec66a52682..1ee1d34b00 100644 --- a/spring-expression/src/main/java/org/springframework/expression/EvaluationException.java +++ b/spring-expression/src/main/java/org/springframework/expression/EvaluationException.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represent an exception that occurs during expression evaluation. diff --git a/spring-expression/src/main/java/org/springframework/expression/Expression.java b/spring-expression/src/main/java/org/springframework/expression/Expression.java index a34daa068e..4da51d7cb2 100644 --- a/spring-expression/src/main/java/org/springframework/expression/Expression.java +++ b/spring-expression/src/main/java/org/springframework/expression/Expression.java @@ -16,8 +16,9 @@ package org.springframework.expression; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * An expression capable of evaluating itself against context objects. @@ -44,8 +45,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - Object getValue() throws EvaluationException; + @Nullable Object getValue() throws EvaluationException; /** * Evaluate this expression in the default context and return the result of evaluation. @@ -55,8 +55,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - T getValue(@Nullable Class desiredResultType) throws EvaluationException; + @Nullable T getValue(@Nullable Class desiredResultType) throws EvaluationException; /** * Evaluate this expression in the default context against the specified root object @@ -65,8 +64,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - Object getValue(@Nullable Object rootObject) throws EvaluationException; + @Nullable Object getValue(@Nullable Object rootObject) throws EvaluationException; /** * Evaluate this expression in the default context against the specified root object @@ -78,8 +76,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType) + @Nullable T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException; /** @@ -88,8 +85,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - Object getValue(EvaluationContext context) throws EvaluationException; + @Nullable Object getValue(EvaluationContext context) throws EvaluationException; /** * Evaluate this expression in the provided context against the specified root object @@ -101,8 +97,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - Object getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException; + @Nullable Object getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException; /** * Evaluate this expression in the provided context and return the result of evaluation. @@ -113,8 +108,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - T getValue(EvaluationContext context, @Nullable Class desiredResultType) + @Nullable T getValue(EvaluationContext context, @Nullable Class desiredResultType) throws EvaluationException; /** @@ -130,8 +124,7 @@ public interface Expression { * @return the evaluation result * @throws EvaluationException if there is a problem during evaluation */ - @Nullable - T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class desiredResultType) + @Nullable T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException; /** @@ -140,8 +133,7 @@ public interface Expression { * @return the most general type of value that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - Class getValueType() throws EvaluationException; + @Nullable Class getValueType() throws EvaluationException; /** * Return the most general type that can be passed to the @@ -150,8 +142,7 @@ public interface Expression { * @return the most general type of value that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - Class getValueType(@Nullable Object rootObject) throws EvaluationException; + @Nullable Class getValueType(@Nullable Object rootObject) throws EvaluationException; /** * Return the most general type that can be passed to the @@ -160,8 +151,7 @@ public interface Expression { * @return the most general type of value that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - Class getValueType(EvaluationContext context) throws EvaluationException; + @Nullable Class getValueType(EvaluationContext context) throws EvaluationException; /** * Return the most general type that can be passed to the @@ -173,8 +163,7 @@ public interface Expression { * @return the most general type of value that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - Class getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException; + @Nullable Class getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException; /** * Return a descriptor for the most general type that can be passed to one of @@ -182,8 +171,7 @@ public interface Expression { * @return a type descriptor for values that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - TypeDescriptor getValueTypeDescriptor() throws EvaluationException; + @Nullable TypeDescriptor getValueTypeDescriptor() throws EvaluationException; /** * Return a descriptor for the most general type that can be passed to the @@ -192,8 +180,7 @@ public interface Expression { * @return a type descriptor for values that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException; + @Nullable TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException; /** * Return a descriptor for the most general type that can be passed to the @@ -202,8 +189,7 @@ public interface Expression { * @return a type descriptor for values that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException; + @Nullable TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException; /** * Return a descriptor for the most general type that can be passed to the @@ -216,8 +202,7 @@ public interface Expression { * @return a type descriptor for values that can be set in this context * @throws EvaluationException if there is a problem determining the type */ - @Nullable - TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) + @Nullable TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException; /** diff --git a/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java b/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java index 925a18e05b..a79b9fad56 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java +++ b/spring-expression/src/main/java/org/springframework/expression/ExpressionException.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Superclass for exceptions that can occur whilst processing expressions. @@ -28,8 +28,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ExpressionException extends RuntimeException { - @Nullable - protected final String expressionString; + protected final @Nullable String expressionString; protected int position; // -1 if not known; should be known in all reasonable cases @@ -105,8 +104,7 @@ public class ExpressionException extends RuntimeException { /** * Return the expression string. */ - @Nullable - public final String getExpressionString() { + public final @Nullable String getExpressionString() { return this.expressionString; } diff --git a/spring-expression/src/main/java/org/springframework/expression/ExpressionInvocationTargetException.java b/spring-expression/src/main/java/org/springframework/expression/ExpressionInvocationTargetException.java index 1cb24e5d16..87000d450a 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ExpressionInvocationTargetException.java +++ b/spring-expression/src/main/java/org/springframework/expression/ExpressionInvocationTargetException.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * This exception wraps (as cause) a checked exception thrown by some method that SpEL diff --git a/spring-expression/src/main/java/org/springframework/expression/IndexAccessor.java b/spring-expression/src/main/java/org/springframework/expression/IndexAccessor.java index 1471ad48df..adf4c3db5f 100644 --- a/spring-expression/src/main/java/org/springframework/expression/IndexAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/IndexAccessor.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An index accessor is able to read from and possibly write to an indexed 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 9fb9137c8e..314159311a 100644 --- a/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/MethodResolver.java @@ -18,8 +18,9 @@ package org.springframework.expression; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * A method resolver attempts to locate a method and returns a @@ -50,8 +51,7 @@ public interface MethodResolver { * @return a {@code MethodExecutor} that can invoke the method, or {@code null} * if the method cannot be found */ - @Nullable - MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, + @Nullable MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List argumentTypes) throws AccessException; } diff --git a/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java b/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java index 8bece1f0fe..3c6d36d681 100644 --- a/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java +++ b/spring-expression/src/main/java/org/springframework/expression/OperatorOverloader.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * By default, the mathematical operators defined in {@link Operation} support simple diff --git a/spring-expression/src/main/java/org/springframework/expression/ParseException.java b/spring-expression/src/main/java/org/springframework/expression/ParseException.java index 3c85016d16..ed23f06bf8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/ParseException.java +++ b/spring-expression/src/main/java/org/springframework/expression/ParseException.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represent an exception that occurs during expression parsing. 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 84e4fe5ac1..5dd20f33b0 100644 --- a/spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/PropertyAccessor.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A property accessor is able to read from (and possibly write to) an object's diff --git a/spring-expression/src/main/java/org/springframework/expression/TargetedAccessor.java b/spring-expression/src/main/java/org/springframework/expression/TargetedAccessor.java index 6403f9ca07..556036cf17 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TargetedAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/TargetedAccessor.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy for types that access elements of specific target classes. @@ -52,7 +52,6 @@ public interface TargetedAccessor { * @return an array of classes that this accessor is suitable for * (or {@code null} or an empty array if a generic accessor) */ - @Nullable - Class[] getSpecificTargetClasses(); + Class @Nullable [] getSpecificTargetClasses(); } diff --git a/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java b/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java index 88d07d39fb..d940e0f5c8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypeComparator.java @@ -16,7 +16,7 @@ package org.springframework.expression; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Instances of a type comparator should be able to compare pairs of objects for equality. 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 6974d6b874..7e83e8eff5 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypeConverter.java @@ -16,8 +16,9 @@ package org.springframework.expression; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * A type converter can convert values between different types encountered during @@ -54,7 +55,6 @@ public interface TypeConverter { * @return the converted value * @throws EvaluationException if conversion failed or is not possible to begin with */ - @Nullable - Object convertValue(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType); + @Nullable Object convertValue(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType); } diff --git a/spring-expression/src/main/java/org/springframework/expression/TypedValue.java b/spring-expression/src/main/java/org/springframework/expression/TypedValue.java index b97020a259..204c68a340 100644 --- a/spring-expression/src/main/java/org/springframework/expression/TypedValue.java +++ b/spring-expression/src/main/java/org/springframework/expression/TypedValue.java @@ -16,8 +16,9 @@ package org.springframework.expression; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -38,11 +39,9 @@ public class TypedValue { public static final TypedValue NULL = new TypedValue(null); - @Nullable - private final Object value; + private final @Nullable Object value; - @Nullable - private TypeDescriptor typeDescriptor; + private @Nullable TypeDescriptor typeDescriptor; /** @@ -67,13 +66,11 @@ public class TypedValue { } - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } - @Nullable - public TypeDescriptor getTypeDescriptor() { + public @Nullable TypeDescriptor getTypeDescriptor() { if (this.typeDescriptor == null && this.value != null) { this.typeDescriptor = TypeDescriptor.forObject(this.value); } diff --git a/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java b/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java index 8bb6dcf195..0b1349720a 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/CompositeStringExpression.java @@ -16,12 +16,13 @@ package org.springframework.expression.common; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; import org.springframework.expression.Expression; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; /** * Represents a template expression broken into pieces. @@ -78,8 +79,7 @@ public class CompositeStringExpression implements Expression { } @Override - @Nullable - public T getValue(@Nullable Class expectedResultType) throws EvaluationException { + public @Nullable T getValue(@Nullable Class expectedResultType) throws EvaluationException { String value = getValue(); return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType); } @@ -97,8 +97,7 @@ public class CompositeStringExpression implements Expression { } @Override - @Nullable - public T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { + public @Nullable T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { String value = getValue(rootObject); return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType); } @@ -116,8 +115,7 @@ public class CompositeStringExpression implements Expression { } @Override - @Nullable - public T getValue(EvaluationContext context, @Nullable Class expectedResultType) + public @Nullable T getValue(EvaluationContext context, @Nullable Class expectedResultType) throws EvaluationException { String value = getValue(context); @@ -137,8 +135,7 @@ public class CompositeStringExpression implements Expression { } @Override - @Nullable - public T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class desiredResultType) + public @Nullable T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { String value = getValue(context,rootObject); diff --git a/spring-expression/src/main/java/org/springframework/expression/common/ExpressionUtils.java b/spring-expression/src/main/java/org/springframework/expression/common/ExpressionUtils.java index 3ea264baf7..9489f9f3bc 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/ExpressionUtils.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/ExpressionUtils.java @@ -16,12 +16,13 @@ package org.springframework.expression.common; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeConverter; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -45,8 +46,7 @@ public abstract class ExpressionUtils { * of the value to the specified type is not supported */ @SuppressWarnings("unchecked") - @Nullable - public static T convertTypedValue( + public static @Nullable T convertTypedValue( @Nullable EvaluationContext context, TypedValue typedValue, @Nullable Class targetType) { Object value = typedValue.getValue(); diff --git a/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java b/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java index ca9275ad21..3876b0488b 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/LiteralExpression.java @@ -16,12 +16,13 @@ package org.springframework.expression.common; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; import org.springframework.expression.Expression; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; /** * A very simple, hard-coded implementation of the {@link Expression} interface @@ -62,8 +63,7 @@ public class LiteralExpression implements Expression { } @Override - @Nullable - public T getValue(@Nullable Class expectedResultType) throws EvaluationException { + public @Nullable T getValue(@Nullable Class expectedResultType) throws EvaluationException { String value = getValue(); return ExpressionUtils.convertTypedValue(null, new TypedValue(value), expectedResultType); } @@ -74,8 +74,7 @@ public class LiteralExpression implements Expression { } @Override - @Nullable - public T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { + public @Nullable T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { String value = getValue(rootObject); return ExpressionUtils.convertTypedValue(null, new TypedValue(value), desiredResultType); } @@ -86,8 +85,7 @@ public class LiteralExpression implements Expression { } @Override - @Nullable - public T getValue(EvaluationContext context, @Nullable Class expectedResultType) throws EvaluationException { + public @Nullable T getValue(EvaluationContext context, @Nullable Class expectedResultType) throws EvaluationException { String value = getValue(context); return ExpressionUtils.convertTypedValue(context, new TypedValue(value), expectedResultType); } @@ -98,8 +96,7 @@ public class LiteralExpression implements Expression { } @Override - @Nullable - public T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class desiredResultType) + public @Nullable T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class desiredResultType) throws EvaluationException { String value = getValue(context, rootObject); diff --git a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java index bdf4ad1660..967950551b 100644 --- a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java @@ -21,11 +21,12 @@ import java.util.ArrayList; import java.util.Deque; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; import org.springframework.expression.ParseException; import org.springframework.expression.ParserContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 080af63ff9..f91c56608f 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,9 +1,7 @@ /** * Common utility classes behind the Spring Expression Language. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.expression.common; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 48a91d1553..bd9caff613 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,9 +1,7 @@ /** * Core abstractions behind the Spring Expression Language. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.expression; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 85e9bb61db..19ad503887 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 @@ -23,11 +23,12 @@ import java.util.ArrayList; import java.util.Deque; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.ClassWriter; import org.springframework.asm.MethodVisitor; import org.springframework.asm.Opcodes; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -69,8 +70,7 @@ public class CodeFlow implements Opcodes { * they can register to add a field to this class. Any registered FieldAdders * will be called after the main evaluation function has finished being generated. */ - @Nullable - private List fieldAdders; + private @Nullable List fieldAdders; /** * As SpEL AST nodes are called to generate code for the main evaluation method @@ -78,8 +78,7 @@ public class CodeFlow implements Opcodes { * registered ClinitAdders will be called after the main evaluation function * has finished being generated. */ - @Nullable - private List clinitAdders; + private @Nullable List clinitAdders; /** * When code generation requires holding a value in a class level field, this @@ -157,8 +156,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() { + public @Nullable String lastDescriptor() { return CollectionUtils.lastElement(this.compilationScopes.peek()); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/CompiledExpression.java b/spring-expression/src/main/java/org/springframework/expression/spel/CompiledExpression.java index acab38946d..27eb79d2a3 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/CompiledExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/CompiledExpression.java @@ -16,9 +16,10 @@ package org.springframework.expression.spel; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; -import org.springframework.lang.Nullable; /** * Base superclass for compiled expressions. Each generated compiled expression class 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 eaf5e4d9ec..b8bde30149 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 @@ -22,6 +22,8 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; @@ -31,7 +33,6 @@ 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; import org.springframework.util.CollectionUtils; @@ -59,8 +60,7 @@ public class ExpressionState { private final SpelParserConfiguration configuration; - @Nullable - private Deque contextObjects; + private @Nullable Deque contextObjects; // When entering a new scope there is a new base object which should be used // for '#this' references (or to act as a target for unqualified references). @@ -69,8 +69,7 @@ public class ExpressionState { // #list1.?[#list2.contains(#this)] // On entering the selection we enter a new scope, and #this is now the // element from list1. - @Nullable - private Deque scopeRootObjects; + private @Nullable Deque scopeRootObjects; public ExpressionState(EvaluationContext context) { @@ -190,8 +189,7 @@ public class ExpressionState { return result; } - @Nullable - public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { + public @Nullable Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor) throws EvaluationException { Object val = value.getValue(); return this.relatedContext.getTypeConverter().convertValue( val, TypeDescriptor.forObject(val), targetTypeDescriptor); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/InternalParseException.java b/spring-expression/src/main/java/org/springframework/expression/spel/InternalParseException.java index d6e173c5f1..434192b365 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/InternalParseException.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/InternalParseException.java @@ -16,7 +16,7 @@ package org.springframework.expression.spel; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Wraps a real parse exception. This exception flows to the top parse method and then @@ -33,8 +33,7 @@ public class InternalParseException extends RuntimeException { } @Override - @Nullable - public SpelParseException getCause() { + public @Nullable SpelParseException getCause() { return (SpelParseException) super.getCause(); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java index 9817ba4134..cc9e533771 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelEvaluationException.java @@ -16,8 +16,9 @@ package org.springframework.expression.spel; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationException; -import org.springframework.lang.Nullable; /** * Root exception for Spring EL related exceptions. @@ -36,8 +37,7 @@ public class SpelEvaluationException extends EvaluationException { private final SpelMessage message; - @Nullable - private final Object[] inserts; + private final @Nullable Object[] inserts; public SpelEvaluationException(SpelMessage message, @Nullable Object... inserts) { @@ -82,8 +82,7 @@ public class SpelEvaluationException extends EvaluationException { /** * Return the message inserts. */ - @Nullable - public Object[] getInserts() { + public @Nullable Object @Nullable [] getInserts() { return this.inserts; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java index 03c7fd1312..3808a89f9a 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelMessage.java @@ -18,7 +18,7 @@ package org.springframework.expression.spel; import java.text.MessageFormat; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Contains all the messages that can be produced by the Spring Expression Language. 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 3e2036d031..bf4bc8c65b 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 @@ -16,10 +16,11 @@ package org.springframework.expression.spel; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; /** * Represents a node in the abstract syntax tree (AST) for a parsed Spring @@ -38,8 +39,7 @@ public interface SpelNode { * @return the value of this node evaluated against the specified state * @throws EvaluationException if any problem occurs evaluating the expression */ - @Nullable - Object getValue(ExpressionState expressionState) throws EvaluationException; + @Nullable Object getValue(ExpressionState expressionState) throws EvaluationException; /** * Evaluate the expression node in the context of the supplied expression state @@ -96,8 +96,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(@Nullable Object obj); + @Nullable Class getObjectClass(@Nullable Object obj); /** * Return the start position of this AST node in the expression string. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParseException.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParseException.java index 4b5e4c5010..7ec863a489 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParseException.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParseException.java @@ -16,8 +16,9 @@ package org.springframework.expression.spel; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.ParseException; -import org.springframework.lang.Nullable; /** * Root exception for Spring EL related exceptions. Rather than holding a hard coded diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java index 27b6ccff35..701c72cbdd 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/SpelParserConfiguration.java @@ -18,8 +18,9 @@ package org.springframework.expression.spel; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.core.SpringProperties; -import org.springframework.lang.Nullable; /** * Configuration object for the SpEL expression parser. @@ -54,8 +55,7 @@ public class SpelParserConfiguration { private final SpelCompilerMode compilerMode; - @Nullable - private final ClassLoader compilerClassLoader; + private final @Nullable ClassLoader compilerClassLoader; private final boolean autoGrowNullReferences; @@ -150,8 +150,7 @@ public class SpelParserConfiguration { /** * Return the ClassLoader to use as the basis for expression compilation. */ - @Nullable - public ClassLoader getCompilerClassLoader() { + public @Nullable ClassLoader getCompilerClassLoader() { return this.compilerClassLoader; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/AccessorUtils.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/AccessorUtils.java index fcb03ced3b..78ef30847d 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/AccessorUtils.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/AccessorUtils.java @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.TargetedAccessor; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** 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 e4253f7eee..8196a2234b 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 @@ -24,6 +24,8 @@ import java.util.ArrayList; import java.util.List; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; @@ -39,7 +41,6 @@ import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectiveConstructorExecutor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -73,12 +74,10 @@ public class ConstructorReference extends SpelNodeImpl { private final boolean isArrayConstructor; - @Nullable - private final SpelNodeImpl[] dimensions; + private final SpelNodeImpl @Nullable [] dimensions; /** The cached executor that may be reused on subsequent evaluations. */ - @Nullable - private volatile ConstructorExecutor cachedExecutor; + private volatile @Nullable ConstructorExecutor cachedExecutor; /** diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java index c05cfad674..a3d5a2dad3 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FormatHelper.java @@ -19,8 +19,9 @@ package org.springframework.expression.spel.ast; import java.util.List; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; /** * Utility methods (formatters, etc) used during parsing and evaluation. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java index 20ee8e20b5..5734b40fb8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/FunctionReference.java @@ -23,6 +23,8 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.core.MethodParameter; import org.springframework.core.convert.TypeDescriptor; @@ -34,7 +36,6 @@ import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectionHelper; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -62,8 +63,7 @@ public class FunctionReference extends SpelNodeImpl { // Captures the most recently used method for the function invocation *if* the method // can safely be used for compilation (i.e. no argument conversion is going on) - @Nullable - private volatile Method method; + private volatile @Nullable Method method; public FunctionReference(String functionName, int startPos, int endPos, SpelNodeImpl... arguments) { @@ -174,6 +174,7 @@ public class FunctionReference extends SpelNodeImpl { * @throws EvaluationException if there is any problem invoking the method * @since 6.1 */ + @SuppressWarnings("NullAway") // TODO Remove when NullAway 0.12.2 is released, see https://github.com/uber/NullAway/pull/1089 private TypedValue executeFunctionViaMethodHandle(ExpressionState state, MethodHandle methodHandle) throws EvaluationException { Object[] functionArgs = getArguments(state); MethodType declaredParams = methodHandle.type(); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java index b6b09c1fb7..5134fe8368 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; import org.springframework.core.convert.TypeDescriptor; @@ -39,7 +41,6 @@ import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectivePropertyAccessor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -101,26 +102,19 @@ public class Indexer extends SpelNodeImpl { private final boolean nullSafe; - @Nullable - private IndexedType indexedType; + private @Nullable IndexedType indexedType; - @Nullable - private volatile String originalPrimitiveExitTypeDescriptor; + private volatile @Nullable String originalPrimitiveExitTypeDescriptor; - @Nullable - private volatile String arrayTypeDescriptor; + private volatile @Nullable String arrayTypeDescriptor; - @Nullable - private volatile CachedPropertyState cachedPropertyReadState; + private volatile @Nullable CachedPropertyState cachedPropertyReadState; - @Nullable - private volatile CachedPropertyState cachedPropertyWriteState; + private volatile @Nullable CachedPropertyState cachedPropertyWriteState; - @Nullable - private volatile CachedIndexState cachedIndexReadState; + private volatile @Nullable CachedIndexState cachedIndexReadState; - @Nullable - private volatile CachedIndexState cachedIndexWriteState; + private volatile @Nullable CachedIndexState cachedIndexWriteState; /** @@ -669,8 +663,7 @@ public class Indexer extends SpelNodeImpl { private final Map map; - @Nullable - private final Object key; + private final @Nullable Object key; private final TypeDescriptor mapEntryDescriptor; @@ -905,8 +898,7 @@ public class Indexer extends SpelNodeImpl { return (this.collection instanceof List); } - @Nullable - private static Constructor getDefaultConstructor(Class type) { + private static @Nullable Constructor getDefaultConstructor(Class type) { try { return ReflectionUtils.accessibleConstructor(type); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java index 4498d9f6a5..5a2cc0c6f8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineList.java @@ -21,6 +21,8 @@ import java.util.Collections; import java.util.List; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; @@ -28,7 +30,6 @@ import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelNode; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,8 +43,7 @@ import org.springframework.util.Assert; */ public class InlineList extends SpelNodeImpl { - @Nullable - private final TypedValue constant; + private final @Nullable TypedValue constant; public InlineList(int startPos, int endPos, SpelNodeImpl... args) { @@ -58,8 +58,7 @@ public class InlineList extends SpelNodeImpl { *

    This will speed up later getValue calls and reduce the amount of garbage * created. */ - @Nullable - private TypedValue computeConstantValue() { + private @Nullable TypedValue computeConstantValue() { for (int c = 0, max = getChildCount(); c < max; c++) { SpelNode child = getChild(c); if (!(child instanceof Literal)) { @@ -125,8 +124,7 @@ public class InlineList extends SpelNodeImpl { } @SuppressWarnings("unchecked") - @Nullable - public List getConstantValue() { + public @Nullable List getConstantValue() { Assert.state(this.constant != null, "No constant"); return (List) this.constant.getValue(); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java index b9450134f2..abffdd0996 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/InlineMap.java @@ -20,12 +20,13 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelNode; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,8 +40,7 @@ import org.springframework.util.Assert; */ public class InlineMap extends SpelNodeImpl { - @Nullable - private final TypedValue constant; + private final @Nullable TypedValue constant; public InlineMap(int startPos, int endPos, SpelNodeImpl... args) { @@ -55,8 +55,7 @@ public class InlineMap extends SpelNodeImpl { *

    This will speed up later getValue calls and reduce the amount of garbage * created. */ - @Nullable - private TypedValue computeConstantValue() { + private @Nullable TypedValue computeConstantValue() { for (int c = 0, max = getChildCount(); c < max; c++) { SpelNode child = getChild(c); if (!(child instanceof Literal)) { @@ -163,8 +162,7 @@ public class InlineMap extends SpelNodeImpl { } @SuppressWarnings("unchecked") - @Nullable - public Map getConstantValue() { + public @Nullable Map getConstantValue() { Assert.state(this.constant != null, "No constant"); return (Map) this.constant.getValue(); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Literal.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Literal.java index dbd9e0f283..abe35c6cc9 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Literal.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Literal.java @@ -16,13 +16,14 @@ package org.springframework.expression.spel.ast; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.InternalParseException; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.SpelParseException; -import org.springframework.lang.Nullable; /** * Common superclass for nodes representing literals (boolean, string, number, etc). @@ -33,8 +34,7 @@ import org.springframework.lang.Nullable; */ public abstract class Literal extends SpelNodeImpl { - @Nullable - private final String originalValue; + private final @Nullable String originalValue; public Literal(@Nullable String originalValue, int startPos, int endPos) { @@ -43,8 +43,7 @@ public abstract class Literal extends SpelNodeImpl { } - @Nullable - public final String getOriginalValue() { + public final @Nullable String getOriginalValue() { return this.originalValue; } 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 e8d15e5b05..5f02f79071 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 @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; import org.springframework.core.convert.TypeDescriptor; @@ -41,7 +43,6 @@ 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; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -59,11 +60,9 @@ public class MethodReference extends SpelNodeImpl { private final String name; - @Nullable - private Character originalPrimitiveExitTypeDescriptor; + private @Nullable Character originalPrimitiveExitTypeDescriptor; - @Nullable - private volatile CachedMethodExecutor cachedExecutor; + private volatile @Nullable CachedMethodExecutor cachedExecutor; public MethodReference(boolean nullSafe, String methodName, int startPos, int endPos, SpelNodeImpl... arguments) { @@ -191,8 +190,7 @@ public class MethodReference extends SpelNodeImpl { return Collections.unmodifiableList(descriptors); } - @Nullable - private MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, + private @Nullable MethodExecutor getCachedExecutor(EvaluationContext evaluationContext, Object value, @Nullable TypeDescriptor target, List argumentTypes) { List methodResolvers = evaluationContext.getMethodResolvers(); @@ -378,11 +376,9 @@ public class MethodReference extends SpelNodeImpl { private final EvaluationContext evaluationContext; - @Nullable - private final Object value; + private final @Nullable Object value; - @Nullable - private final TypeDescriptor targetType; + private final @Nullable TypeDescriptor targetType; private final Object[] arguments; @@ -417,11 +413,9 @@ public class MethodReference extends SpelNodeImpl { private final MethodExecutor methodExecutor; - @Nullable - private final Class staticClass; + private final @Nullable Class staticClass; - @Nullable - private final TypeDescriptor target; + private final @Nullable TypeDescriptor target; private final List argumentTypes; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java index 99c5694095..e91050a3d0 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpAnd.java @@ -16,6 +16,8 @@ package org.springframework.expression.spel.ast; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationException; @@ -26,7 +28,6 @@ import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.BooleanTypedValue; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Represents the boolean AND operation. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpOr.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpOr.java index 4caf753c85..4383b68b49 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpOr.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpOr.java @@ -16,6 +16,8 @@ package org.springframework.expression.spel.ast; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationException; @@ -25,7 +27,6 @@ import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.BooleanTypedValue; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; /** * Represents the boolean OR operation. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java index 9100310177..485aacb33a 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OpPlus.java @@ -19,6 +19,8 @@ package org.springframework.expression.spel.ast; import java.math.BigDecimal; import java.math.BigInteger; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationException; @@ -29,7 +31,6 @@ import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.NumberUtils; 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 a425fd4f4f..91c23cb595 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 @@ -19,11 +19,12 @@ package org.springframework.expression.spel.ast; import java.math.BigDecimal; import java.math.BigInteger; +import org.jspecify.annotations.Nullable; + 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.NumberUtils; import org.springframework.util.ObjectUtils; @@ -47,11 +48,9 @@ public abstract class Operator extends SpelNodeImpl { // whose accessors seem to only be returning 'Object' - the actual descriptors may // indicate 'int') - @Nullable - protected String leftActualDescriptor; + protected @Nullable String leftActualDescriptor; - @Nullable - protected String rightActualDescriptor; + protected @Nullable String rightActualDescriptor; public Operator(String payload, int startPos, int endPos, SpelNodeImpl... operands) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java index 36dfc4c436..d106ce507c 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/OperatorInstanceof.java @@ -16,6 +16,8 @@ package org.springframework.expression.spel.ast; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.asm.Type; import org.springframework.expression.EvaluationException; @@ -25,7 +27,6 @@ import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.BooleanTypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +38,7 @@ import org.springframework.util.Assert; */ public class OperatorInstanceof extends Operator { - @Nullable - private Class type; + private @Nullable Class type; public OperatorInstanceof(int startPos, int endPos, SpelNodeImpl... operands) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java index 56d0b2f34d..aaab0800c8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/Projection.java @@ -22,12 +22,13 @@ import java.util.Arrays; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java index c40dc8a61d..a493198456 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/PropertyOrFieldReference.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.Label; import org.springframework.asm.MethodVisitor; import org.springframework.core.convert.TypeDescriptor; @@ -37,7 +39,6 @@ import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectivePropertyAccessor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -56,14 +57,11 @@ public class PropertyOrFieldReference extends SpelNodeImpl { private final String name; - @Nullable - private String originalPrimitiveExitTypeDescriptor; + private @Nullable String originalPrimitiveExitTypeDescriptor; - @Nullable - private volatile PropertyAccessor cachedReadAccessor; + private volatile @Nullable PropertyAccessor cachedReadAccessor; - @Nullable - private volatile PropertyAccessor cachedWriteAccessor; + private volatile @Nullable PropertyAccessor cachedWriteAccessor; public PropertyOrFieldReference(boolean nullSafe, String propertyOrFieldName, int startPos, int endPos) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/QualifiedIdentifier.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/QualifiedIdentifier.java index d66a4c39ce..1acd99787c 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/QualifiedIdentifier.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/QualifiedIdentifier.java @@ -16,10 +16,11 @@ package org.springframework.expression.spel.ast; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.ExpressionState; -import org.springframework.lang.Nullable; /** * Represents a dot separated sequence of strings that indicate a package qualified type @@ -32,8 +33,7 @@ import org.springframework.lang.Nullable; */ public class QualifiedIdentifier extends SpelNodeImpl { - @Nullable - private TypedValue value; + private @Nullable TypedValue value; public QualifiedIdentifier(int startPos, int endPos, SpelNodeImpl... operands) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java index b5ed9d0e2c..6543cf5527 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/SpelNodeImpl.java @@ -20,6 +20,8 @@ import java.lang.reflect.Executable; import java.lang.reflect.Member; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.asm.Opcodes; import org.springframework.asm.Type; @@ -31,7 +33,6 @@ import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.SpelNode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -57,8 +58,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { protected SpelNodeImpl[] children = SpelNodeImpl.NO_CHILDREN; - @Nullable - private SpelNodeImpl parent; + private @Nullable SpelNodeImpl parent; /** * Indicates the type descriptor for the result of this expression node. @@ -69,11 +69,10 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { * It does not include the trailing semicolon (for non array reference types). * Some examples: Ljava/lang/String, I, [I */ - @Nullable - protected volatile String exitTypeDescriptor; + protected volatile @Nullable String exitTypeDescriptor; - public SpelNodeImpl(int startPos, int endPos, @Nullable SpelNodeImpl... operands) { + public SpelNodeImpl(int startPos, int endPos, SpelNodeImpl @Nullable ... operands) { this.startPos = startPos; this.endPos = endPos; if (!ObjectUtils.isEmpty(operands)) { @@ -111,8 +110,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { } @Override - @Nullable - public final Object getValue(ExpressionState expressionState) throws EvaluationException { + public final @Nullable Object getValue(ExpressionState expressionState) throws EvaluationException { return getValueInternal(expressionState).getValue(); } @@ -165,8 +163,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { } @Override - @Nullable - public Class getObjectClass(@Nullable Object obj) { + public @Nullable Class getObjectClass(@Nullable Object obj) { if (obj == null) { return null; } @@ -193,13 +190,11 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { return false; } - @Nullable - public String getExitDescriptor() { + public @Nullable String getExitDescriptor() { return this.exitTypeDescriptor; } - @Nullable - protected final T getValue(ExpressionState state, Class desiredReturnType) throws EvaluationException { + protected final @Nullable T getValue(ExpressionState state, Class desiredReturnType) throws EvaluationException { return ExpressionUtils.convertTypedValue(state.getEvaluationContext(), getValueInternal(state), desiredReturnType); } @@ -302,8 +297,7 @@ public abstract class SpelNodeImpl implements SpelNode, Opcodes { } } - @Nullable - private static Class loadClassForExitDescriptor(@Nullable String exitDescriptor, ClassLoader classLoader) { + private static @Nullable Class loadClassForExitDescriptor(@Nullable String exitDescriptor, ClassLoader classLoader) { if (!StringUtils.hasText(exitDescriptor)) { return null; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java index 360e7598fa..21cd5c4694 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/TypeReference.java @@ -19,13 +19,14 @@ package org.springframework.expression.spel.ast; import java.lang.reflect.Array; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.asm.Type; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.ExpressionState; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,8 +40,7 @@ public class TypeReference extends SpelNodeImpl { private final int dimensions; - @Nullable - private transient Class type; + private transient @Nullable Class type; public TypeReference(int startPos, int endPos, SpelNodeImpl qualifiedId) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java index dd199ccb54..c38c0c9b0e 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/ValueRef.java @@ -16,10 +16,11 @@ package org.springframework.expression.spel.ast; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.TypedValue; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; /** * Represents a reference to a value. With a reference it is possible to get or set the diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ast/VariableReference.java b/spring-expression/src/main/java/org/springframework/expression/spel/ast/VariableReference.java index 31cf1f699d..7bb013b9c8 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ast/VariableReference.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ast/VariableReference.java @@ -19,6 +19,8 @@ package org.springframework.expression.spel.ast; import java.lang.reflect.Modifier; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; @@ -26,7 +28,6 @@ import org.springframework.expression.TypedValue; import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.ExpressionState; import org.springframework.expression.spel.SpelEvaluationException; -import org.springframework.lang.Nullable; /** * Represents a variable reference — for example, {@code #root}, {@code #this}, 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 d6c0b5ec6d..cba46a2d7d 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,9 +1,7 @@ /** * SpEL's abstract syntax tree. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.expression.spel.ast; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 81dc5f52c6..27ee130225 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,9 +1,7 @@ /** * SpEL's central implementation package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.expression.spel; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c6bbfbfc29..05111daa74 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 @@ -26,6 +26,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.ParseException; import org.springframework.expression.ParserContext; import org.springframework.expression.common.TemplateAwareExpressionParser; @@ -78,7 +80,6 @@ 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.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -165,9 +166,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { // | (DEFAULT^ logicalOrExpression) // | (QMARK^ expression COLON! expression) // | (ELVIS^ expression))?; - @Nullable @SuppressWarnings("NullAway") - private SpelNodeImpl eatExpression() { + private @Nullable SpelNodeImpl eatExpression() { SpelNodeImpl expr = eatLogicalOrExpression(); Token t = peekToken(); if (t != null) { @@ -205,8 +205,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } //logicalOrExpression : logicalAndExpression (OR^ logicalAndExpression)*; - @Nullable - private SpelNodeImpl eatLogicalOrExpression() { + private @Nullable SpelNodeImpl eatLogicalOrExpression() { SpelNodeImpl expr = eatLogicalAndExpression(); while (peekIdentifierToken("or") || peekToken(TokenKind.SYMBOLIC_OR)) { Token t = takeToken(); //consume OR @@ -218,8 +217,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // logicalAndExpression : relationalExpression (AND^ relationalExpression)*; - @Nullable - private SpelNodeImpl eatLogicalAndExpression() { + private @Nullable SpelNodeImpl eatLogicalAndExpression() { SpelNodeImpl expr = eatRelationalExpression(); while (peekIdentifierToken("and") || peekToken(TokenKind.SYMBOLIC_AND)) { Token t = takeToken(); // consume 'AND' @@ -231,8 +229,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // relationalExpression : sumExpression (relationalOperator^ sumExpression)?; - @Nullable - private SpelNodeImpl eatRelationalExpression() { + private @Nullable SpelNodeImpl eatRelationalExpression() { SpelNodeImpl expr = eatSumExpression(); Token relationalOperatorToken = maybeEatRelationalOperator(); if (relationalOperatorToken != null) { @@ -276,9 +273,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } //sumExpression: productExpression ( (PLUS^ | MINUS^) productExpression)*; - @Nullable @SuppressWarnings("NullAway") - private SpelNodeImpl eatSumExpression() { + private @Nullable SpelNodeImpl eatSumExpression() { SpelNodeImpl expr = eatProductExpression(); while (peekToken(TokenKind.PLUS, TokenKind.MINUS, TokenKind.INC)) { Token t = takeToken(); //consume PLUS or MINUS or INC @@ -295,8 +291,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // productExpression: powerExpr ((STAR^ | DIV^| MOD^) powerExpr)* ; - @Nullable - private SpelNodeImpl eatProductExpression() { + private @Nullable SpelNodeImpl eatProductExpression() { SpelNodeImpl expr = eatPowerIncDecExpression(); while (peekToken(TokenKind.STAR, TokenKind.DIV, TokenKind.MOD)) { Token t = takeToken(); // consume STAR/DIV/MOD @@ -316,9 +311,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // powerExpr : unaryExpression (POWER^ unaryExpression)? (INC || DEC) ; - @Nullable @SuppressWarnings("NullAway") - private SpelNodeImpl eatPowerIncDecExpression() { + private @Nullable SpelNodeImpl eatPowerIncDecExpression() { SpelNodeImpl expr = eatUnaryExpression(); if (peekToken(TokenKind.POWER)) { Token t = takeToken(); //consume POWER @@ -337,9 +331,8 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // unaryExpression: (PLUS^ | MINUS^ | BANG^ | INC^ | DEC^) unaryExpression | primaryExpression ; - @Nullable @SuppressWarnings("NullAway") - private SpelNodeImpl eatUnaryExpression() { + private @Nullable SpelNodeImpl eatUnaryExpression() { if (peekToken(TokenKind.NOT, TokenKind.PLUS, TokenKind.MINUS)) { Token t = takeToken(); SpelNodeImpl expr = eatUnaryExpression(); @@ -370,8 +363,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // primaryExpression : startNode (node)? -> ^(EXPRESSION startNode (node)?); - @Nullable - private SpelNodeImpl eatPrimaryExpression() { + private @Nullable SpelNodeImpl eatPrimaryExpression() { SpelNodeImpl start = eatStartNode(); // always a start node List nodes = null; SpelNodeImpl node = eatNode(); @@ -391,14 +383,12 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // node : ((DOT dottedNode) | (SAFE_NAVI dottedNode) | nonDottedNode)+; - @Nullable - private SpelNodeImpl eatNode() { + private @Nullable SpelNodeImpl eatNode() { return (peekToken(TokenKind.DOT, TokenKind.SAFE_NAVI) ? eatDottedNode() : eatNonDottedNode()); } // nonDottedNode: indexer; - @Nullable - private SpelNodeImpl eatNonDottedNode() { + private @Nullable SpelNodeImpl eatNonDottedNode() { if (peekToken(TokenKind.LSQUARE)) { if (maybeEatIndexer(false)) { return pop(); @@ -457,8 +447,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { } // methodArgs : LPAREN! (argument (COMMA! argument)* (COMMA!)?)? RPAREN!; - @Nullable - private SpelNodeImpl[] maybeEatMethodArgs() { + private SpelNodeImpl @Nullable [] maybeEatMethodArgs() { if (!peekToken(TokenKind.LPAREN)) { return null; } @@ -524,8 +513,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { // | lastSelection // | indexer // | constructor - @Nullable - private SpelNodeImpl eatStartNode() { + private @Nullable SpelNodeImpl eatStartNode() { if (maybeEatLiteral()) { return pop(); } @@ -917,8 +905,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() { + private @Nullable Token maybeEatRelationalOperator() { Token t = peekToken(); if (t == null) { return null; @@ -1022,16 +1009,14 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser { return this.tokenStream.get(this.tokenStreamPointer++); } - @Nullable - private Token nextToken() { + private @Nullable Token nextToken() { if (this.tokenStreamPointer >= this.tokenStreamLength) { return null; } return this.tokenStream.get(this.tokenStreamPointer++); } - @Nullable - private Token peekToken() { + private @Nullable 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 e8802052bd..39e563e0a3 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 @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.asm.ClassWriter; import org.springframework.asm.MethodVisitor; @@ -32,7 +33,6 @@ 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; @@ -98,8 +98,7 @@ public final class SpelCompiler implements Opcodes { * @return an instance of the class implementing the compiled expression, * or {@code null} if compilation is not possible */ - @Nullable - public CompiledExpression compile(SpelNodeImpl expression) { + public @Nullable CompiledExpression compile(SpelNodeImpl expression) { if (expression.isCompilable()) { if (logger.isDebugEnabled()) { logger.debug("SpEL: compiling " + expression.toStringAST()); @@ -133,8 +132,7 @@ public final 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) { + private @Nullable Class createExpressionClass(SpelNodeImpl expressionToCompile) { // Create class outline: // org.springframework.expression.spel.generated.CompiledExpression##### extends org.springframework.expression.spel.CompiledExpression String className = "org/springframework/expression/spel/generated/CompiledExpression" + getNextSuffix(); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java index f4ea32211f..a101d38453 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpression.java @@ -18,6 +18,8 @@ package org.springframework.expression.spel.standard; import java.util.concurrent.atomic.AtomicInteger; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; @@ -33,7 +35,6 @@ import org.springframework.expression.spel.SpelNode; import org.springframework.expression.spel.SpelParserConfiguration; import org.springframework.expression.spel.ast.SpelNodeImpl; import org.springframework.expression.spel.support.StandardEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -63,12 +64,10 @@ public class SpelExpression implements Expression { private final SpelParserConfiguration configuration; // The default context is used if no override is supplied by the user - @Nullable - private EvaluationContext evaluationContext; + private @Nullable EvaluationContext evaluationContext; // Holds the compiled form of the expression (if it has been compiled) - @Nullable - private volatile CompiledExpression compiledAst; + private volatile @Nullable CompiledExpression compiledAst; // Count of many times as the expression been interpreted - can trigger compilation // when certain limit reached @@ -117,8 +116,7 @@ public class SpelExpression implements Expression { } @Override - @Nullable - public Object getValue() throws EvaluationException { + public @Nullable Object getValue() throws EvaluationException { CompiledExpression compiledAst = this.compiledAst; if (compiledAst != null) { try { @@ -146,8 +144,7 @@ public class SpelExpression implements Expression { @SuppressWarnings("unchecked") @Override - @Nullable - public T getValue(@Nullable Class expectedResultType) throws EvaluationException { + public @Nullable T getValue(@Nullable Class expectedResultType) throws EvaluationException { CompiledExpression compiledAst = this.compiledAst; if (compiledAst != null) { try { @@ -182,8 +179,7 @@ public class SpelExpression implements Expression { } @Override - @Nullable - public Object getValue(@Nullable Object rootObject) throws EvaluationException { + public @Nullable Object getValue(@Nullable Object rootObject) throws EvaluationException { CompiledExpression compiledAst = this.compiledAst; if (compiledAst != null) { try { @@ -211,8 +207,7 @@ public class SpelExpression implements Expression { @SuppressWarnings("unchecked") @Override - @Nullable - public T getValue(@Nullable Object rootObject, @Nullable Class expectedResultType) throws EvaluationException { + public @Nullable T getValue(@Nullable Object rootObject, @Nullable Class expectedResultType) throws EvaluationException { CompiledExpression compiledAst = this.compiledAst; if (compiledAst != null) { try { @@ -247,8 +242,7 @@ public class SpelExpression implements Expression { } @Override - @Nullable - public Object getValue(EvaluationContext context) throws EvaluationException { + public @Nullable Object getValue(EvaluationContext context) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); CompiledExpression compiledAst = this.compiledAst; @@ -277,8 +271,7 @@ public class SpelExpression implements Expression { @SuppressWarnings("unchecked") @Override - @Nullable - public T getValue(EvaluationContext context, @Nullable Class expectedResultType) throws EvaluationException { + public @Nullable T getValue(EvaluationContext context, @Nullable Class expectedResultType) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); CompiledExpression compiledAst = this.compiledAst; @@ -312,8 +305,7 @@ public class SpelExpression implements Expression { } @Override - @Nullable - public Object getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException { + public @Nullable Object getValue(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); CompiledExpression compiledAst = this.compiledAst; @@ -342,8 +334,7 @@ public class SpelExpression implements Expression { @SuppressWarnings("unchecked") @Override - @Nullable - public T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class expectedResultType) + public @Nullable T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable Class expectedResultType) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); @@ -379,20 +370,17 @@ public class SpelExpression implements Expression { } @Override - @Nullable - public Class getValueType() throws EvaluationException { + public @Nullable Class getValueType() throws EvaluationException { return getValueType(getEvaluationContext()); } @Override - @Nullable - public Class getValueType(@Nullable Object rootObject) throws EvaluationException { + public @Nullable Class getValueType(@Nullable Object rootObject) throws EvaluationException { return getValueType(getEvaluationContext(), rootObject); } @Override - @Nullable - public Class getValueType(EvaluationContext context) throws EvaluationException { + public @Nullable Class getValueType(EvaluationContext context) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); ExpressionState expressionState = new ExpressionState(context, this.configuration); TypeDescriptor typeDescriptor = this.ast.getValueInternal(expressionState).getTypeDescriptor(); @@ -400,38 +388,33 @@ public class SpelExpression implements Expression { } @Override - @Nullable - public Class getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException { + public @Nullable Class getValueType(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException { ExpressionState expressionState = new ExpressionState(context, toTypedValue(rootObject), this.configuration); TypeDescriptor typeDescriptor = this.ast.getValueInternal(expressionState).getTypeDescriptor(); return (typeDescriptor != null ? typeDescriptor.getType() : null); } @Override - @Nullable - public TypeDescriptor getValueTypeDescriptor() throws EvaluationException { + public @Nullable TypeDescriptor getValueTypeDescriptor() throws EvaluationException { return getValueTypeDescriptor(getEvaluationContext()); } @Override - @Nullable - public TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException { + public @Nullable TypeDescriptor getValueTypeDescriptor(@Nullable Object rootObject) throws EvaluationException { ExpressionState expressionState = new ExpressionState(getEvaluationContext(), toTypedValue(rootObject), this.configuration); return this.ast.getValueInternal(expressionState).getTypeDescriptor(); } @Override - @Nullable - public TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException { + public @Nullable TypeDescriptor getValueTypeDescriptor(EvaluationContext context) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); ExpressionState expressionState = new ExpressionState(context, this.configuration); return this.ast.getValueInternal(expressionState).getTypeDescriptor(); } @Override - @Nullable - public TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) + public @Nullable TypeDescriptor getValueTypeDescriptor(EvaluationContext context, @Nullable Object rootObject) throws EvaluationException { Assert.notNull(context, "EvaluationContext must not be null"); diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpressionParser.java index ee64ba4da2..e122017ed2 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpressionParser.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/SpelExpressionParser.java @@ -16,11 +16,12 @@ package org.springframework.expression.spel.standard; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.ParseException; import org.springframework.expression.ParserContext; import org.springframework.expression.common.TemplateAwareExpressionParser; import org.springframework.expression.spel.SpelParserConfiguration; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/Token.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/Token.java index 61ccc8267f..f56a57193c 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/Token.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/Token.java @@ -16,7 +16,7 @@ package org.springframework.expression.spel.standard; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Holder for a kind of token, the associated data, and its position in the input @@ -29,8 +29,7 @@ class Token { final TokenKind kind; - @Nullable - final String data; + final @Nullable String data; final int startPos; @@ -55,7 +54,7 @@ class Token { * @param startPos the exact start position * @param endPos the index of the last character */ - Token(TokenKind tokenKind, @Nullable char[] tokenData, int startPos, int endPos) { + Token(TokenKind tokenKind, char @Nullable [] tokenData, int startPos, int endPos) { this.kind = tokenKind; this.data = (tokenData != null ? new String(tokenData) : null); this.startPos = startPos; 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 e26fe15427..b9ac97ce14 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,9 +1,7 @@ /** * SpEL's standard parser implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.expression.spel.standard; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/DataBindingMethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/DataBindingMethodResolver.java index 120bb08061..9684ce9085 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/DataBindingMethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/DataBindingMethodResolver.java @@ -20,11 +20,12 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.MethodExecutor; -import org.springframework.lang.Nullable; /** * An {@link org.springframework.expression.MethodResolver} variant for data binding @@ -46,8 +47,7 @@ public final class DataBindingMethodResolver extends ReflectiveMethodResolver { } @Override - @Nullable - public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, + public @Nullable MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List argumentTypes) throws AccessException { if (targetObject instanceof Class) { 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 c45464e545..d038043d74 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 @@ -24,13 +24,14 @@ import java.lang.reflect.Method; import java.util.List; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; 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.CollectionUtils; @@ -57,8 +58,7 @@ public abstract class ReflectionHelper { * @return an {@code ArgumentsMatchInfo} object indicating what kind of match it was, * or {@code null} if it was not a match */ - @Nullable - static ArgumentsMatchKind compareArguments( + static @Nullable ArgumentsMatchKind compareArguments( List expectedArgTypes, List suppliedArgTypes, TypeConverter typeConverter) { Assert.isTrue(expectedArgTypes.size() == suppliedArgTypes.size(), @@ -146,8 +146,7 @@ public abstract class ReflectionHelper { * @return an {@code ArgumentsMatchKind} object indicating what kind of match it was, * or {@code null} if it was not a match */ - @Nullable - static ArgumentsMatchKind compareArgumentsVarargs( + static @Nullable ArgumentsMatchKind compareArgumentsVarargs( List expectedArgTypes, List suppliedArgTypes, TypeConverter typeConverter) { Assert.isTrue(!CollectionUtils.isEmpty(expectedArgTypes), diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java index e77eaa3ac5..b2122be888 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorExecutor.java @@ -18,11 +18,12 @@ package org.springframework.expression.spel.support; import java.lang.reflect.Constructor; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.AccessException; import org.springframework.expression.ConstructorExecutor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -37,8 +38,7 @@ public class ReflectiveConstructorExecutor implements ConstructorExecutor { private final Constructor ctor; - @Nullable - private final Integer varargsPosition; + private final @Nullable Integer varargsPosition; public ReflectiveConstructorExecutor(Constructor ctor) { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java index ea2c5b054a..d5039e6a60 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveConstructorResolver.java @@ -22,6 +22,8 @@ import java.util.Arrays; import java.util.Comparator; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.AccessException; @@ -31,7 +33,6 @@ import org.springframework.expression.EvaluationContext; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeConverter; import org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind; -import org.springframework.lang.Nullable; /** * A constructor resolver that uses reflection to locate the constructor that @@ -56,8 +57,7 @@ public class ReflectiveConstructorResolver implements ConstructorResolver { * */ @Override - @Nullable - public ConstructorExecutor resolve(EvaluationContext context, String typeName, List argumentTypes) + public @Nullable ConstructorExecutor resolve(EvaluationContext context, String typeName, List argumentTypes) throws AccessException { try { diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveIndexAccessor.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveIndexAccessor.java index 601f2792c2..011557ae46 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveIndexAccessor.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveIndexAccessor.java @@ -19,6 +19,8 @@ package org.springframework.expression.spel.support; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.expression.EvaluationContext; import org.springframework.expression.IndexAccessor; @@ -26,7 +28,6 @@ import org.springframework.expression.TypedValue; import org.springframework.expression.spel.CodeFlow; import org.springframework.expression.spel.CompilableIndexAccessor; import org.springframework.expression.spel.SpelNode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -114,8 +115,7 @@ public class ReflectiveIndexAccessor implements CompilableIndexAccessor { private final Method readMethodToInvoke; - @Nullable - private final Method writeMethodToInvoke; + private final @Nullable Method writeMethodToInvoke; /** 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 b66312328f..e4addc8762 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 @@ -19,13 +19,14 @@ package org.springframework.expression.spel.support; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.TypeDescriptor; 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.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -46,11 +47,9 @@ public class ReflectiveMethodExecutor implements MethodExecutor { */ private final Method methodToInvoke; - @Nullable - private final Integer varargsPosition; + private final @Nullable Integer varargsPosition; - @Nullable - private final Class publicDeclaringClass; + private final @Nullable Class publicDeclaringClass; private boolean argumentConversionOccurred = false; @@ -93,8 +92,7 @@ public class ReflectiveMethodExecutor implements MethodExecutor { * @return the public class or interface that declares the method, or {@code null} if * no such public type could be found */ - @Nullable - public Class getPublicDeclaringClass() { + public @Nullable Class getPublicDeclaringClass() { return this.publicDeclaringClass; } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java index 5ee9027873..df3dbd3e85 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/ReflectiveMethodResolver.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.BridgeMethodResolver; import org.springframework.core.MethodParameter; import org.springframework.core.convert.TypeDescriptor; @@ -40,7 +42,6 @@ import org.springframework.expression.TypeConverter; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; import org.springframework.expression.spel.support.ReflectionHelper.ArgumentsMatchKind; -import org.springframework.lang.Nullable; /** * Reflection-based {@link MethodResolver} used by default in {@link StandardEvaluationContext} @@ -59,8 +60,7 @@ public class ReflectiveMethodResolver implements MethodResolver { // more closely following the Java rules. private final boolean useDistance; - @Nullable - private Map, MethodFilter> filters; + private @Nullable Map, MethodFilter> filters; public ReflectiveMethodResolver() { @@ -113,8 +113,7 @@ public class ReflectiveMethodResolver implements MethodResolver { * */ @Override - @Nullable - public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, + public @Nullable MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, List argumentTypes) throws AccessException { 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 9139d08cb4..fec2427874 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 @@ -33,6 +33,7 @@ import kotlin.reflect.KMutableProperty; import kotlin.reflect.KProperty; import kotlin.reflect.full.KClasses; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import org.springframework.asm.MethodVisitor; import org.springframework.core.KotlinDetector; @@ -46,7 +47,6 @@ 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.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -109,8 +109,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { * Returns {@code null} which means this is a general purpose accessor. */ @Override - @Nullable - public Class[] getSpecificTargetClasses() { + public Class @Nullable [] getSpecificTargetClasses() { return null; } @@ -329,8 +328,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { } - @Nullable - private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object target, String name) { + private @Nullable TypeDescriptor getTypeDescriptor(EvaluationContext context, Object target, String name) { Class type = (target instanceof Class clazz ? clazz : target.getClass()); if (type.isArray() && name.equals("length")) { @@ -352,8 +350,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { return typeDescriptor; } - @Nullable - private Method findGetterForProperty(String propertyName, Class clazz, Object target) { + private @Nullable Method findGetterForProperty(String propertyName, Class clazz, Object target) { boolean targetIsAClass = (target instanceof Class); Method method = findGetterForProperty(propertyName, clazz, targetIsAClass); if (method == null && targetIsAClass) { @@ -363,8 +360,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { return method; } - @Nullable - private Method findSetterForProperty(String propertyName, Class clazz, Object target) { + private @Nullable Method findSetterForProperty(String propertyName, Class clazz, Object target) { Method method = findSetterForProperty(propertyName, clazz, target instanceof Class); // In contrast to findGetterForProperty(), we do not look for setters in // java.lang.Class as a fallback, since Class doesn't have any public setters. @@ -374,8 +370,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { /** * Find a getter method for the specified property. */ - @Nullable - protected Method findGetterForProperty(String propertyName, Class clazz, boolean mustBeStatic) { + protected @Nullable Method findGetterForProperty(String propertyName, Class clazz, boolean mustBeStatic) { Method method = findMethodForProperty(getPropertyMethodSuffixes(propertyName), "get", clazz, mustBeStatic, 0, ANY_TYPES); if (method == null) { @@ -393,14 +388,12 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { /** * Find a setter method for the specified property. */ - @Nullable - protected Method findSetterForProperty(String propertyName, Class clazz, boolean mustBeStatic) { + protected @Nullable Method findSetterForProperty(String propertyName, Class clazz, boolean mustBeStatic) { return findMethodForProperty(getPropertyMethodSuffixes(propertyName), "set", clazz, mustBeStatic, 1, ANY_TYPES); } - @Nullable - private Method findMethodForProperty(String[] methodSuffixes, String prefix, Class clazz, + private @Nullable Method findMethodForProperty(String[] methodSuffixes, String prefix, Class clazz, boolean mustBeStatic, int numberOfParams, Set> requiredReturnTypes) { Method[] methods = getSortedMethods(clazz); @@ -467,8 +460,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { return StringUtils.capitalize(propertyName); } - @Nullable - private Field findField(String name, Class clazz, Object target) { + private @Nullable Field findField(String name, Class clazz, Object target) { Field field = findField(name, clazz, target instanceof Class); if (field == null && target instanceof Class) { field = findField(name, target.getClass(), false); @@ -479,8 +471,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) { + protected @Nullable Field findField(String name, Class clazz, boolean mustBeStatic) { Field[] fields = clazz.getFields(); for (Field field : fields) { if (field.getName().equals(name) && (!mustBeStatic || Modifier.isStatic(field.getModifiers()))) { @@ -619,8 +610,7 @@ public class ReflectivePropertyAccessor implements PropertyAccessor { } @Override - @Nullable - public Class[] getSpecificTargetClasses() { + public Class @Nullable [] getSpecificTargetClasses() { throw new UnsupportedOperationException("Should not be called on an OptimalPropertyAccessor"); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java index 3a11e8277e..ed1f8e076c 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/SimpleEvaluationContext.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.BeanResolver; @@ -37,7 +39,6 @@ import org.springframework.expression.TypeLocator; import org.springframework.expression.TypedValue; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; /** * A basic implementation of {@link EvaluationContext} that focuses on a subset @@ -178,8 +179,7 @@ public final class SimpleEvaluationContext implements EvaluationContext { * @return always {@code null} */ @Override - @Nullable - public BeanResolver getBeanResolver() { + public @Nullable BeanResolver getBeanResolver() { return null; } @@ -257,8 +257,7 @@ public final class SimpleEvaluationContext implements EvaluationContext { * @return the value of the variable or function, or {@code null} if not found */ @Override - @Nullable - public Object lookupVariable(String name) { + public @Nullable Object lookupVariable(String name) { return this.variables.get(name); } @@ -344,11 +343,9 @@ public final class SimpleEvaluationContext implements EvaluationContext { private List resolvers = Collections.emptyList(); - @Nullable - private TypeConverter typeConverter; + private @Nullable TypeConverter typeConverter; - @Nullable - private TypedValue rootObject; + private @Nullable TypedValue rootObject; private boolean assignmentEnabled = true; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java index 5d196b7e93..7dcca874ce 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardEvaluationContext.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.BeanResolver; import org.springframework.expression.ConstructorResolver; @@ -36,7 +38,6 @@ import org.springframework.expression.TypeComparator; import org.springframework.expression.TypeConverter; import org.springframework.expression.TypeLocator; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -81,29 +82,21 @@ public class StandardEvaluationContext implements EvaluationContext { private TypedValue rootObject; - @Nullable - private volatile List propertyAccessors; + private volatile @Nullable List propertyAccessors; - @Nullable - private volatile List indexAccessors; + private volatile @Nullable List indexAccessors; - @Nullable - private volatile List constructorResolvers; + private volatile @Nullable List constructorResolvers; - @Nullable - private volatile List methodResolvers; + private volatile @Nullable List methodResolvers; - @Nullable - private volatile ReflectiveMethodResolver reflectiveMethodResolver; + private volatile @Nullable ReflectiveMethodResolver reflectiveMethodResolver; - @Nullable - private BeanResolver beanResolver; + private @Nullable BeanResolver beanResolver; - @Nullable - private TypeLocator typeLocator; + private @Nullable TypeLocator typeLocator; - @Nullable - private TypeConverter typeConverter; + private @Nullable TypeConverter typeConverter; private TypeComparator typeComparator = StandardTypeComparator.INSTANCE; @@ -248,8 +241,7 @@ public class StandardEvaluationContext implements EvaluationContext { } @Override - @Nullable - public BeanResolver getBeanResolver() { + public @Nullable BeanResolver getBeanResolver() { return this.beanResolver; } @@ -400,8 +392,7 @@ public class StandardEvaluationContext implements EvaluationContext { * @return the value of the variable or function, or {@code null} if not found */ @Override - @Nullable - public Object lookupVariable(String name) { + public @Nullable Object lookupVariable(String name) { return this.variables.get(name); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardOperatorOverloader.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardOperatorOverloader.java index 7b8d892b0d..21f7727953 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardOperatorOverloader.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardOperatorOverloader.java @@ -16,10 +16,11 @@ package org.springframework.expression.spel.support; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationException; import org.springframework.expression.Operation; import org.springframework.expression.OperatorOverloader; -import org.springframework.lang.Nullable; /** * Standard implementation of {@link OperatorOverloader}. diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java index fc913470dc..aa6bcb8c51 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java @@ -19,10 +19,11 @@ package org.springframework.expression.spel.support; import java.math.BigDecimal; import java.math.BigInteger; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.TypeComparator; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.NumberUtils; diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java index eeb1c09397..9d57d9bb46 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeConverter.java @@ -18,6 +18,8 @@ package org.springframework.expression.spel.support; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; @@ -25,7 +27,6 @@ import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.expression.TypeConverter; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -76,8 +77,7 @@ public class StandardTypeConverter implements TypeConverter { } @Override - @Nullable - public Object convertValue(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { + public @Nullable Object convertValue(@Nullable Object value, @Nullable TypeDescriptor sourceType, TypeDescriptor targetType) { try { return this.conversionService.get().convert(value, sourceType, targetType); } diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java index 816b66cb71..1ad740b02d 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeLocator.java @@ -22,12 +22,13 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.SmartClassLoader; import org.springframework.expression.EvaluationException; import org.springframework.expression.TypeLocator; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.SpelMessage; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -46,8 +47,7 @@ import org.springframework.util.ClassUtils; */ public class StandardTypeLocator implements TypeLocator { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final List importPrefixes = new ArrayList<>(1); @@ -129,8 +129,7 @@ public class StandardTypeLocator implements TypeLocator { throw new SpelEvaluationException(SpelMessage.TYPE_NOT_FOUND, typeName); } - @Nullable - private Class loadType(String typeName) { + private @Nullable Class loadType(String typeName) { try { return ClassUtils.forName(typeName, this.classLoader); } 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 d77cb741fa..7c9c08fd9c 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,9 +1,7 @@ /** * SpEL's default implementations for various core abstractions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.expression.spel.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/ComparatorTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/ComparatorTests.java index 6aede670ad..a909159c06 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/ComparatorTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/ComparatorTests.java @@ -18,6 +18,7 @@ package org.springframework.expression.spel; import java.math.BigDecimal; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.expression.EvaluationException; @@ -27,7 +28,6 @@ import org.springframework.expression.TypeComparator; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeComparator; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/CompilableMapAccessor.java b/spring-expression/src/test/java/org/springframework/expression/spel/CompilableMapAccessor.java index 3bbb9411f8..f32b3a0632 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/CompilableMapAccessor.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/CompilableMapAccessor.java @@ -18,11 +18,12 @@ package org.springframework.expression.spel; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.asm.MethodVisitor; import org.springframework.expression.AccessException; import org.springframework.expression.EvaluationContext; import org.springframework.expression.TypedValue; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java index 52b9e4c020..6eadff9af7 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/IndexingTests.java @@ -38,6 +38,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.NullNode; import com.fasterxml.jackson.databind.node.TextNode; import example.Color; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -51,7 +52,6 @@ import org.springframework.expression.spel.support.ReflectiveIndexAccessor; import org.springframework.expression.spel.support.SimpleEvaluationContext; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.testresources.Person; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java index a05e52ccb2..0bae62c0dc 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java @@ -36,6 +36,7 @@ import java.util.stream.Stream; import example.Color; import example.FruitMap; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -60,7 +61,6 @@ import org.springframework.expression.spel.support.ReflectiveIndexAccessor; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.testdata.PersonInOtherPackage; import org.springframework.expression.spel.testresources.Person; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static java.util.stream.Collectors.joining; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java index 5e7d4987da..3ec7587e0c 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java @@ -37,6 +37,7 @@ import java.util.Properties; import java.util.concurrent.atomic.AtomicInteger; import org.assertj.core.api.InstanceOfAssertFactories; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; @@ -61,7 +62,6 @@ import org.springframework.expression.spel.support.ReflectivePropertyAccessor; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeLocator; import org.springframework.expression.spel.testresources.le.div.mod.reserved.Reserver; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -1169,7 +1169,6 @@ class SpelReproTests extends AbstractExpressionTests { TypedValue value = accessor.read(context, target, "property"); assertThat(value.getValue()).isEqualTo(1); assertThat(value.getTypeDescriptor().getType()).isEqualTo(Integer.class); - assertThat(value.getTypeDescriptor().getAnnotations()).isNotEmpty(); } @Test @@ -2158,8 +2157,7 @@ class SpelReproTests extends AbstractExpressionTests { } @Override - @Nullable - public Integer getProperty() { + public @Nullable Integer getProperty() { return this.value; } } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/ast/AccessorUtilsTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/ast/AccessorUtilsTests.java index 659a99a87a..23e1978e70 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/ast/AccessorUtilsTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/ast/AccessorUtilsTests.java @@ -18,10 +18,10 @@ package org.springframework.expression.spel.ast; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.expression.TargetedAccessor; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; @@ -102,8 +102,7 @@ class AccessorUtilsTests { private record DemoAccessor(String name, Class[] types) implements TargetedAccessor { @Override - @Nullable - public Class[] getSpecificTargetClasses() { + public Class @Nullable [] getSpecificTargetClasses() { return this.types; } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java b/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java index 945cc4e7c6..a99072ac7c 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java @@ -16,7 +16,7 @@ package org.springframework.expression.spel.testresources; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; public class PlaceOfBirth { diff --git a/spring-expression/src/test/kotlin/org/springframework/expression/spel/SpelReproKotlinTests.kt b/spring-expression/src/test/kotlin/org/springframework/expression/spel/SpelReproKotlinTests.kt index 24fc744adf..a88dde59f6 100644 --- a/spring-expression/src/test/kotlin/org/springframework/expression/spel/SpelReproKotlinTests.kt +++ b/spring-expression/src/test/kotlin/org/springframework/expression/spel/SpelReproKotlinTests.kt @@ -40,9 +40,9 @@ class SpelReproKotlinTests { val expr = parser.parseExpression("#key.startsWith('hello')") context.registerFunction("get", Config::class.java.getMethod("get", String::class.java)) context.setVariable("key", "hello world") - assertThat(expr.getValue(context, Boolean::class.java)).isTrue() + assertThat(expr.getValue(context, Boolean::class.java)!!).isTrue() context.setVariable("key", "") - assertThat(expr.getValue(context, Boolean::class.java)).isFalse() + assertThat(expr.getValue(context, Boolean::class.java)!!).isFalse() } @Test @@ -50,23 +50,23 @@ class SpelReproKotlinTests { val expr = parser.parseExpression("#key.startsWith('hello')") context.registerFunction("suspendingGet", Config::class.java.getMethod("suspendingGet", String::class.java, Continuation::class.java)) context.setVariable("key", "hello world") - assertThat(expr.getValue(context, Boolean::class.java)).isTrue() + assertThat(expr.getValue(context, Boolean::class.java)!!).isTrue() context.setVariable("key", "") - assertThat(expr.getValue(context, Boolean::class.java)).isFalse() + assertThat(expr.getValue(context, Boolean::class.java)!!).isFalse() } @Test fun `gh-30468 Unmangle Kotlin inlined class getter`() { context.setVariable("something", Something(UUID(123), "name")) val expr = parser.parseExpression("#something.id") - assertThat(expr.getValue(context, Int::class.java)).isEqualTo(123) + assertThat(expr.getValue(context, Int::class.java)!!).isEqualTo(123) } @Test fun `gh-30468 Unmangle Kotlin inlined class setter`() { context.setVariable("something", Something(UUID(123), "name")) val expr = parser.parseExpression("#something.id = 456") - assertThat(expr.getValue(context, Int::class.java)).isEqualTo(456) + assertThat(expr.getValue(context, Int::class.java)!!).isEqualTo(456) } @Suppress("UNUSED_PARAMETER") diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/BadSqlGrammarException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/BadSqlGrammarException.java index eb0eb0f184..6fa6d3ef3f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/BadSqlGrammarException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/BadSqlGrammarException.java @@ -18,8 +18,9 @@ package org.springframework.jdbc; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessResourceUsageException; -import org.springframework.lang.Nullable; /** * Exception thrown when SQL specified is invalid. Such exceptions always have @@ -53,8 +54,7 @@ public class BadSqlGrammarException extends InvalidDataAccessResourceUsageExcept /** * Return the wrapped SQLException. */ - @Nullable - public SQLException getSQLException() { + public @Nullable SQLException getSQLException() { return (SQLException) getCause(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/CannotGetJdbcConnectionException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/CannotGetJdbcConnectionException.java index 1439b89db1..4cf6fd3816 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/CannotGetJdbcConnectionException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/CannotGetJdbcConnectionException.java @@ -18,8 +18,9 @@ package org.springframework.jdbc; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; /** * Fatal exception thrown when we can't connect to an RDBMS using JDBC. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/InvalidResultSetAccessException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/InvalidResultSetAccessException.java index d671af15f7..9b76ad5a8d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/InvalidResultSetAccessException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/InvalidResultSetAccessException.java @@ -18,8 +18,9 @@ package org.springframework.jdbc; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessResourceUsageException; -import org.springframework.lang.Nullable; /** * Exception thrown when a ResultSet has been accessed in an invalid fashion. @@ -36,8 +37,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class InvalidResultSetAccessException extends InvalidDataAccessResourceUsageException { - @Nullable - private final String sql; + private final @Nullable String sql; /** @@ -64,8 +64,7 @@ public class InvalidResultSetAccessException extends InvalidDataAccessResourceUs /** * Return the wrapped SQLException. */ - @Nullable - public SQLException getSQLException() { + public @Nullable SQLException getSQLException() { return (SQLException) getCause(); } @@ -73,8 +72,7 @@ public class InvalidResultSetAccessException extends InvalidDataAccessResourceUs * Return the SQL that caused the problem. * @return the offending SQL, if known */ - @Nullable - public String getSql() { + public @Nullable String getSql() { return this.sql; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/SQLWarningException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/SQLWarningException.java index 2019b2ebd2..7acc07e8f5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/SQLWarningException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/SQLWarningException.java @@ -18,8 +18,9 @@ package org.springframework.jdbc; import java.sql.SQLWarning; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.UncategorizedDataAccessException; -import org.springframework.lang.Nullable; /** * Exception thrown when we're not ignoring {@link java.sql.SQLWarning SQLWarnings}. @@ -50,8 +51,7 @@ public class SQLWarningException extends UncategorizedDataAccessException { * Return the underlying {@link SQLWarning}. * @since 5.3.29 */ - @Nullable - public SQLWarning getSQLWarning() { + public @Nullable SQLWarning getSQLWarning() { return (SQLWarning) getCause(); } @@ -60,8 +60,7 @@ public class SQLWarningException extends UncategorizedDataAccessException { * @deprecated as of 5.3.29, in favor of {@link #getSQLWarning()} */ @Deprecated(since = "5.3.29") - @Nullable - public SQLWarning SQLWarning() { + public @Nullable SQLWarning SQLWarning() { return getSQLWarning(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/UncategorizedSQLException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/UncategorizedSQLException.java index 897acfbdbd..e64155f7d8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/UncategorizedSQLException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/UncategorizedSQLException.java @@ -18,8 +18,9 @@ package org.springframework.jdbc; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.UncategorizedDataAccessException; -import org.springframework.lang.Nullable; /** * Exception thrown when we can't classify an SQLException into @@ -32,8 +33,7 @@ import org.springframework.lang.Nullable; public class UncategorizedSQLException extends UncategorizedDataAccessException { /** SQL that led to the problem. */ - @Nullable - private final String sql; + private final @Nullable String sql; /** @@ -53,16 +53,14 @@ public class UncategorizedSQLException extends UncategorizedDataAccessException /** * Return the underlying SQLException. */ - @Nullable - public SQLException getSQLException() { + public @Nullable SQLException getSQLException() { return (SQLException) getCause(); } /** * Return the SQL that led to the problem (if known). */ - @Nullable - public String getSql() { + public @Nullable String getSql() { return this.sql; } 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 08d07565bc..cd6e09e94f 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 @@ -18,6 +18,7 @@ package org.springframework.jdbc.config; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.BeanMetadataElement; @@ -27,7 +28,6 @@ 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; @@ -48,8 +48,7 @@ abstract class DatabasePopulatorConfigUtils { } } - @Nullable - private static BeanDefinition createDatabasePopulator(Element element, List scripts, String execution) { + private static @Nullable BeanDefinition createDatabasePopulator(Element element, List scripts, String execution) { BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(CompositeDatabasePopulator.class); boolean ignoreFailedDrops = element.getAttribute("ignore-failures").equals("DROPS"); @@ -90,8 +89,7 @@ abstract class DatabasePopulatorConfigUtils { return builder.getBeanDefinition(); } - @Nullable - private static String getSeparator(Element element, Element scriptElement) { + private static @Nullable String getSeparator(Element element, Element scriptElement) { String scriptSeparator = scriptElement.getAttribute("separator"); if (StringUtils.hasLength(scriptSeparator)) { return 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 83cdb23a5c..2a8c795d13 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,9 +1,7 @@ /** * Defines the Spring JDBC configuration namespace. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java index 2053b3f87a..5f0c77cb62 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentPreparedStatementSetter.java @@ -19,7 +19,7 @@ package org.springframework.jdbc.core; import java.sql.PreparedStatement; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple adapter for {@link PreparedStatementSetter} that applies a given array @@ -30,15 +30,14 @@ import org.springframework.lang.Nullable; */ public class ArgumentPreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer { - @Nullable - private final Object[] args; + private final @Nullable Object @Nullable [] args; /** * Create a new {@code ArgumentPreparedStatementSetter} for the given arguments. * @param args the arguments to set */ - public ArgumentPreparedStatementSetter(@Nullable Object[] args) { + public ArgumentPreparedStatementSetter(@Nullable Object @Nullable [] args) { this.args = args; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java index 28227f98e0..c174e3e039 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ArgumentTypePreparedStatementSetter.java @@ -21,8 +21,9 @@ import java.sql.SQLException; import java.sql.Types; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; /** * Simple adapter for {@link PreparedStatementSetter} that applies the given @@ -33,11 +34,9 @@ import org.springframework.lang.Nullable; */ public class ArgumentTypePreparedStatementSetter implements PreparedStatementSetter, ParameterDisposer { - @Nullable - private final Object[] args; + private final @Nullable Object @Nullable [] args; - @Nullable - private final int[] argTypes; + private final int @Nullable [] argTypes; /** @@ -47,7 +46,7 @@ public class ArgumentTypePreparedStatementSetter implements PreparedStatementSet * @param argTypes the corresponding SQL types of the arguments */ @SuppressWarnings("NullAway") - public ArgumentTypePreparedStatementSetter(@Nullable Object[] args, @Nullable int[] argTypes) { + public ArgumentTypePreparedStatementSetter(@Nullable Object @Nullable [] args, int @Nullable [] argTypes) { if ((args != null && argTypes == null) || (args == null && argTypes != null) || (args != null && args.length != argTypes.length)) { throw new InvalidDataAccessApiUsageException("args and argTypes parameters must match"); 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 ca9a8e4a48..c615fac24d 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 @@ -28,6 +28,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapper; @@ -40,7 +41,6 @@ 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; @@ -95,8 +95,7 @@ public class BeanPropertyRowMapper implements RowMapper { protected final Log logger = LogFactory.getLog(getClass()); /** The class we are mapping to. */ - @Nullable - private Class mappedClass; + private @Nullable Class mappedClass; /** Whether we're strictly validating. */ private boolean checkFullyPopulated = false; @@ -109,16 +108,13 @@ public class BeanPropertyRowMapper implements RowMapper { private boolean primitivesDefaultedForNullValue = false; /** ConversionService for binding JDBC values to bean properties. */ - @Nullable - private ConversionService conversionService = DefaultConversionService.getSharedInstance(); + private @Nullable ConversionService conversionService = DefaultConversionService.getSharedInstance(); /** Map of the properties we provide mapping for. */ - @Nullable - private Map mappedProperties; + private @Nullable Map mappedProperties; /** Set of bean property names we provide mapping for. */ - @Nullable - private Set mappedPropertyNames; + private @Nullable Set mappedPropertyNames; /** @@ -168,8 +164,7 @@ public class BeanPropertyRowMapper implements RowMapper { /** * Get the class that we are mapping to. */ - @Nullable - public final Class getMappedClass() { + public final @Nullable Class getMappedClass() { return this.mappedClass; } @@ -233,8 +228,7 @@ public class BeanPropertyRowMapper implements RowMapper { * or {@code null} if none. * @since 4.3 */ - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -426,8 +420,7 @@ public class BeanPropertyRowMapper implements RowMapper { * @throws SQLException in case of extraction failure * @see #getColumnValue(ResultSet, int, Class) */ - @Nullable - protected Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) throws SQLException { + protected @Nullable Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) throws SQLException { return JdbcUtils.getResultSetValue(rs, index, pd.getPropertyType()); } @@ -445,8 +438,7 @@ public class BeanPropertyRowMapper implements RowMapper { * @since 5.3 * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class) */ - @Nullable - protected Object getColumnValue(ResultSet rs, int index, Class paramType) throws SQLException { + protected @Nullable Object getColumnValue(ResultSet rs, int index, Class paramType) throws SQLException { return JdbcUtils.getResultSetValue(rs, index, paramType); } 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 7fb2ad7f0a..dc929ea873 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 @@ -19,8 +19,9 @@ package org.springframework.jdbc.core; import java.sql.CallableStatement; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a CallableStatement. @@ -74,7 +75,6 @@ public interface CallableStatementCallback { * into a DataAccessException by an SQLExceptionTranslator * @throws DataAccessException in case of custom exceptions */ - @Nullable - T doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException; + @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 501938d45e..03208b18b7 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 @@ -25,8 +25,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; /** * Helper class that efficiently creates multiple {@link CallableStatementCreator} @@ -130,11 +131,9 @@ public class CallableStatementCreatorFactory { */ private class CallableStatementCreatorImpl implements CallableStatementCreator, SqlProvider, ParameterDisposer { - @Nullable - private ParameterMapper inParameterMapper; + private @Nullable ParameterMapper inParameterMapper; - @Nullable - private Map inParameters; + private @Nullable Map inParameters; /** * Create a new CallableStatementCreatorImpl. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java index e6ea97a98c..f310823c74 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/ColumnMapRowMapper.java @@ -21,8 +21,9 @@ import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedCaseInsensitiveMap; /** @@ -90,8 +91,7 @@ public class ColumnMapRowMapper implements RowMapper> { * @return the Object returned * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue */ - @Nullable - protected Object getColumnValue(ResultSet rs, int index) throws SQLException { + protected @Nullable Object getColumnValue(ResultSet rs, int index) throws SQLException { return JdbcUtils.getResultSetValue(rs, index); } 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 25bbfd4949..19eac368c4 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 @@ -19,8 +19,9 @@ package org.springframework.jdbc.core; import java.sql.Connection; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a JDBC Connection. @@ -64,7 +65,6 @@ public interface ConnectionCallback { * @see JdbcTemplate#queryForObject(String, Class) * @see JdbcTemplate#queryForRowSet(String) */ - @Nullable - T doInConnection(Connection con) throws SQLException, DataAccessException; + @Nullable T doInConnection(Connection con) throws SQLException, DataAccessException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/DataClassRowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/DataClassRowMapper.java index a8ba50dae0..b14bf961cc 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/DataClassRowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/DataClassRowMapper.java @@ -20,12 +20,13 @@ import java.lang.reflect.Constructor; import java.sql.ResultSet; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.TypeConverter; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -61,14 +62,11 @@ import org.springframework.util.Assert; */ public class DataClassRowMapper extends BeanPropertyRowMapper { - @Nullable - private Constructor mappedConstructor; + private @Nullable Constructor mappedConstructor; - @Nullable - private String[] constructorParameterNames; + private String @Nullable [] constructorParameterNames; - @Nullable - private TypeDescriptor[] constructorParameterTypes; + private TypeDescriptor @Nullable [] constructorParameterTypes; /** 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 9824337edc..acbdd5b569 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 @@ -21,10 +21,11 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; 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. @@ -67,8 +68,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} if none * @throws DataAccessException if there is any problem */ - @Nullable - T execute(ConnectionCallback action) throws DataAccessException; + @Nullable T execute(ConnectionCallback action) throws DataAccessException; //------------------------------------------------------------------------- @@ -87,8 +87,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} if none * @throws DataAccessException if there is any problem */ - @Nullable - T execute(StatementCallback action) throws DataAccessException; + @Nullable T execute(StatementCallback action) throws DataAccessException; /** * Issue a single SQL execute, typically a DDL statement. @@ -109,8 +108,7 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem executing the query * @see #query(String, ResultSetExtractor, Object...) */ - @Nullable - T query(String sql, ResultSetExtractor rse) throws DataAccessException; + @Nullable T query(String sql, ResultSetExtractor rse) throws DataAccessException; /** * Execute a query given static SQL, reading the ResultSet on a per-row @@ -171,8 +169,7 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem executing the query * @see #queryForObject(String, RowMapper, Object...) */ - @Nullable - T queryForObject(String sql, RowMapper rowMapper) throws DataAccessException; + @Nullable T queryForObject(String sql, RowMapper rowMapper) throws DataAccessException; /** * Execute a query for a result object, given static SQL. @@ -193,8 +190,7 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem executing the query * @see #queryForObject(String, Class, Object...) */ - @Nullable - T queryForObject(String sql, Class requiredType) throws DataAccessException; + @Nullable T queryForObject(String sql, Class requiredType) throws DataAccessException; /** * Execute a query for a result map, given static SQL. @@ -303,8 +299,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} if none * @throws DataAccessException if there is any problem */ - @Nullable - T execute(PreparedStatementCreator psc, PreparedStatementCallback action) throws DataAccessException; + @Nullable T execute(PreparedStatementCreator psc, PreparedStatementCallback action) throws DataAccessException; /** * Execute a JDBC data access operation, implemented as callback action @@ -319,8 +314,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} if none * @throws DataAccessException if there is any problem */ - @Nullable - T execute(String sql, PreparedStatementCallback action) throws DataAccessException; + @Nullable T execute(String sql, PreparedStatementCallback action) throws DataAccessException; /** * Query using a prepared statement, reading the ResultSet with a ResultSetExtractor. @@ -332,8 +326,7 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem * @see PreparedStatementCreatorFactory */ - @Nullable - T query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException; + @Nullable T query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException; /** * Query using a prepared statement, reading the ResultSet with a ResultSetExtractor. @@ -346,8 +339,7 @@ public interface JdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if there is any problem */ - @Nullable - T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) + @Nullable T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException; /** @@ -362,8 +354,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see java.sql.Types */ - @Nullable - T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor rse) throws DataAccessException; + @Nullable T query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, ResultSetExtractor rse) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of arguments @@ -379,8 +370,7 @@ public interface JdbcOperations { * @deprecated as of 5.3, in favor of {@link #query(String, ResultSetExtractor, Object...)} */ @Deprecated - @Nullable - T query(String sql, @Nullable Object[] args, ResultSetExtractor rse) throws DataAccessException; + @Nullable T query(String sql, @Nullable Object @Nullable [] args, ResultSetExtractor rse) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of arguments @@ -395,8 +385,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @since 3.0.1 */ - @Nullable - T query(String sql, ResultSetExtractor rse, @Nullable Object... args) throws DataAccessException; + @Nullable T query(String sql, ResultSetExtractor rse, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query using a prepared statement, reading the ResultSet on a per-row basis @@ -436,7 +425,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see java.sql.Types */ - void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException; + void query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -452,7 +441,7 @@ public interface JdbcOperations { * @deprecated as of 5.3, in favor of {@link #query(String, RowCallbackHandler, Object...)} */ @Deprecated - void query(String sql, @Nullable Object[] args, RowCallbackHandler rch) throws DataAccessException; + void query(String sql, @Nullable Object @Nullable [] args, RowCallbackHandler rch) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -467,7 +456,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @since 3.0.1 */ - void query(String sql, RowCallbackHandler rch, @Nullable Object... args) throws DataAccessException; + void query(String sql, RowCallbackHandler rch, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query using a prepared statement, mapping each row to a result object @@ -511,7 +500,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see java.sql.Types */ - List query(String sql, Object[] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException; + List query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -528,7 +517,7 @@ public interface JdbcOperations { * @deprecated as of 5.3, in favor of {@link #query(String, RowMapper, Object...)} */ @Deprecated - List query(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException; + List query(String sql, @Nullable Object @Nullable [] args, RowMapper rowMapper) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -544,7 +533,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @since 3.0.1 */ - List query(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException; + List query(String sql, RowMapper rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query using a prepared statement, mapping each row to a result object @@ -595,7 +584,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @since 5.3 */ - Stream queryForStream(String sql, RowMapper rowMapper, @Nullable Object... args) + Stream queryForStream(String sql, RowMapper rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException; /** @@ -614,8 +603,7 @@ public interface JdbcOperations { * if the query does not return exactly one row * @throws DataAccessException if the query fails */ - @Nullable - T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper rowMapper) + @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException; /** @@ -636,8 +624,7 @@ public interface JdbcOperations { * @deprecated as of 5.3, in favor of {@link #queryForObject(String, RowMapper, Object...)} */ @Deprecated - @Nullable - T queryForObject(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException; + @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, RowMapper rowMapper) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list @@ -656,8 +643,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @since 3.0.1 */ - @Nullable - T queryForObject(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException; + @Nullable T queryForObject(String sql, RowMapper rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -678,8 +664,7 @@ public interface JdbcOperations { * @see #queryForObject(String, Class) * @see java.sql.Types */ - @Nullable - T queryForObject(String sql, Object[] args, int[] argTypes, Class requiredType) + @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class requiredType) throws DataAccessException; /** @@ -703,8 +688,7 @@ public interface JdbcOperations { * @deprecated as of 5.3, in favor of {@link #queryForObject(String, Class, Object...)} */ @Deprecated - @Nullable - T queryForObject(String sql, @Nullable Object[] args, Class requiredType) throws DataAccessException; + @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, Class requiredType) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -726,8 +710,7 @@ public interface JdbcOperations { * @since 3.0.1 * @see #queryForObject(String, Class) */ - @Nullable - T queryForObject(String sql, Class requiredType, @Nullable Object... args) throws DataAccessException; + @Nullable T queryForObject(String sql, Class requiredType, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -746,7 +729,7 @@ public interface JdbcOperations { * @see ColumnMapRowMapper * @see java.sql.Types */ - Map queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException; + Map queryForMap(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -769,7 +752,7 @@ public interface JdbcOperations { * @see #queryForMap(String) * @see ColumnMapRowMapper */ - Map queryForMap(String sql, @Nullable Object... args) throws DataAccessException; + Map queryForMap(String sql, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -787,7 +770,7 @@ public interface JdbcOperations { * @see #queryForList(String, Class) * @see SingleColumnRowMapper */ - List queryForList(String sql, Object[] args, int[] argTypes, Class elementType) + List queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class elementType) throws DataAccessException; /** @@ -809,7 +792,7 @@ public interface JdbcOperations { * @deprecated as of 5.3, in favor of {@link #queryForList(String, Class, Object...)} */ @Deprecated - List queryForList(String sql, @Nullable Object[] args, Class elementType) throws DataAccessException; + List queryForList(String sql, @Nullable Object @Nullable [] args, Class elementType) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -829,7 +812,7 @@ public interface JdbcOperations { * @see #queryForList(String, Class) * @see SingleColumnRowMapper */ - List queryForList(String sql, Class elementType, @Nullable Object... args) throws DataAccessException; + List queryForList(String sql, Class elementType, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -847,7 +830,7 @@ public interface JdbcOperations { * @see #queryForList(String) * @see java.sql.Types */ - List> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException; + List> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -865,7 +848,7 @@ public interface JdbcOperations { * @throws DataAccessException if the query fails * @see #queryForList(String) */ - List> queryForList(String sql, @Nullable Object... args) throws DataAccessException; + List> queryForList(String sql, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -887,7 +870,7 @@ public interface JdbcOperations { * @see javax.sql.rowset.CachedRowSet * @see java.sql.Types */ - SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) throws DataAccessException; + SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -909,7 +892,7 @@ public interface JdbcOperations { * @see SqlRowSetResultSetExtractor * @see javax.sql.rowset.CachedRowSet */ - SqlRowSet queryForRowSet(String sql, @Nullable Object... args) throws DataAccessException; + SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Issue a single SQL update operation (such as an insert, update or delete @@ -965,7 +948,7 @@ public interface JdbcOperations { * @throws DataAccessException if there is any problem issuing the update * @see java.sql.Types */ - int update(String sql, Object[] args, int[] argTypes) throws DataAccessException; + int update(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException; /** * Issue a single SQL update operation (such as an insert, update or delete statement) @@ -978,7 +961,7 @@ public interface JdbcOperations { * @return the number of rows affected * @throws DataAccessException if there is any problem issuing the update */ - int update(String sql, @Nullable Object... args) throws DataAccessException; + int update(String sql, @Nullable Object @Nullable ... args) throws DataAccessException; /** * Issue multiple update statements on a single PreparedStatement, @@ -1081,8 +1064,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} if none * @throws DataAccessException if there is any problem */ - @Nullable - T execute(CallableStatementCreator csc, CallableStatementCallback action) throws DataAccessException; + @Nullable T execute(CallableStatementCreator csc, CallableStatementCallback action) throws DataAccessException; /** * Execute a JDBC data access operation, implemented as callback action @@ -1097,8 +1079,7 @@ public interface JdbcOperations { * @return a result object returned by the action, or {@code null} if none * @throws DataAccessException if there is any problem */ - @Nullable - T execute(String callString, CallableStatementCallback action) throws DataAccessException; + @Nullable T execute(String callString, CallableStatementCallback action) throws DataAccessException; /** * Execute an SQL call using a CallableStatementCreator to provide SQL and 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 9401a8feba..17b67c5a7f 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 @@ -41,6 +41,8 @@ import java.util.stream.StreamSupport; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.dao.support.DataAccessUtils; @@ -53,7 +55,6 @@ 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.CollectionUtils; import org.springframework.util.LinkedCaseInsensitiveMap; @@ -335,8 +336,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { //------------------------------------------------------------------------- @Override - @Nullable - public T execute(ConnectionCallback action) throws DataAccessException { + public @Nullable T execute(ConnectionCallback action) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); Connection con = DataSourceUtils.getConnection(obtainDataSource()); @@ -381,8 +381,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { // Methods dealing with static SQL (java.sql.Statement) //------------------------------------------------------------------------- - @Nullable - private T execute(StatementCallback action, boolean closeResources) throws DataAccessException { + private @Nullable T execute(StatementCallback action, boolean closeResources) throws DataAccessException { Assert.notNull(action, "Callback object must not be null"); Connection con = DataSourceUtils.getConnection(obtainDataSource()); @@ -416,8 +415,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public T execute(StatementCallback action) throws DataAccessException { + public @Nullable T execute(StatementCallback action) throws DataAccessException { return execute(action, true); } @@ -430,8 +428,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { // Callback to execute the statement. class ExecuteStatementCallback implements StatementCallback, SqlProvider { @Override - @Nullable - public Object doInStatement(Statement stmt) throws SQLException { + public @Nullable Object doInStatement(Statement stmt) throws SQLException { stmt.execute(sql); return null; } @@ -445,8 +442,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public T query(final String sql, final ResultSetExtractor rse) throws DataAccessException { + public @Nullable T query(final String sql, final ResultSetExtractor rse) throws DataAccessException { Assert.notNull(sql, "SQL must not be null"); Assert.notNull(rse, "ResultSetExtractor must not be null"); if (logger.isDebugEnabled()) { @@ -456,8 +452,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { // Callback to execute the query. class QueryStatementCallback implements StatementCallback, SqlProvider { @Override - @Nullable - public T doInStatement(Statement stmt) throws SQLException { + public @Nullable T doInStatement(Statement stmt) throws SQLException { ResultSet rs = null; try { rs = stmt.executeQuery(sql); @@ -514,15 +509,13 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public T queryForObject(String sql, RowMapper rowMapper) throws DataAccessException { + public @Nullable T queryForObject(String sql, RowMapper rowMapper) throws DataAccessException { List results = query(sql, rowMapper); return DataAccessUtils.nullableSingleResult(results); } @Override - @Nullable - public T queryForObject(String sql, Class requiredType) throws DataAccessException { + public @Nullable T queryForObject(String sql, Class requiredType) throws DataAccessException { return queryForObject(sql, getSingleColumnRowMapper(requiredType)); } @@ -577,8 +570,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { // Callback to execute the batch update. class BatchUpdateStatementCallback implements StatementCallback, SqlProvider { - @Nullable - private String currSql; + private @Nullable String currSql; @Override public int[] doInStatement(Statement stmt) throws SQLException, DataAccessException { @@ -623,8 +615,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public String getSql() { + public @Nullable String getSql() { return this.currSql; } } @@ -639,8 +630,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { // Methods dealing with prepared statements //------------------------------------------------------------------------- - @Nullable - private T execute(PreparedStatementCreator psc, PreparedStatementCallback action, boolean closeResources) + private @Nullable T execute(PreparedStatementCreator psc, PreparedStatementCallback action, boolean closeResources) throws DataAccessException { Assert.notNull(psc, "PreparedStatementCreator must not be null"); @@ -688,16 +678,14 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public T execute(PreparedStatementCreator psc, PreparedStatementCallback action) + public @Nullable T execute(PreparedStatementCreator psc, PreparedStatementCallback action) throws DataAccessException { return execute(psc, action, true); } @Override - @Nullable - public T execute(String sql, PreparedStatementCallback action) throws DataAccessException { + public @Nullable T execute(String sql, PreparedStatementCallback action) throws DataAccessException { return execute(new SimplePreparedStatementCreator(sql), action, true); } @@ -712,9 +700,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if there is any problem */ - @Nullable - public T query( - PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss, final ResultSetExtractor rse) + public @Nullable T query( + PreparedStatementCreator psc, final @Nullable PreparedStatementSetter pss, final ResultSetExtractor rse) throws DataAccessException { Assert.notNull(rse, "ResultSetExtractor must not be null"); @@ -722,8 +709,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { return execute(psc, new PreparedStatementCallback<>() { @Override - @Nullable - public T doInPreparedStatement(PreparedStatement ps) throws SQLException { + public @Nullable T doInPreparedStatement(PreparedStatement ps) throws SQLException { ResultSet rs = null; try { if (pss != null) { @@ -743,33 +729,28 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public T query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException { + public @Nullable T query(PreparedStatementCreator psc, ResultSetExtractor rse) throws DataAccessException { return query(psc, null, rse); } @Override - @Nullable - public T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException { + public @Nullable T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtractor rse) throws DataAccessException { return query(new SimplePreparedStatementCreator(sql), pss, rse); } @Override - @Nullable - public T query(String sql, Object[] args, int[] argTypes, ResultSetExtractor rse) throws DataAccessException { + public @Nullable T query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, ResultSetExtractor rse) throws DataAccessException { return query(sql, newArgTypePreparedStatementSetter(args, argTypes), rse); } @Deprecated @Override - @Nullable - public T query(String sql, @Nullable Object[] args, ResultSetExtractor rse) throws DataAccessException { + public @Nullable T query(String sql, @Nullable Object @Nullable [] args, ResultSetExtractor rse) throws DataAccessException { return query(sql, newArgPreparedStatementSetter(args), rse); } @Override - @Nullable - public T query(String sql, ResultSetExtractor rse, @Nullable Object... args) throws DataAccessException { + public @Nullable T query(String sql, ResultSetExtractor rse, @Nullable Object @Nullable ... args) throws DataAccessException { return query(sql, newArgPreparedStatementSetter(args), rse); } @@ -784,18 +765,18 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public void query(String sql, Object[] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException { + public void query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowCallbackHandler rch) throws DataAccessException { query(sql, newArgTypePreparedStatementSetter(args, argTypes), rch); } @Deprecated @Override - public void query(String sql, @Nullable Object[] args, RowCallbackHandler rch) throws DataAccessException { + public void query(String sql, @Nullable Object @Nullable [] args, RowCallbackHandler rch) throws DataAccessException { query(sql, newArgPreparedStatementSetter(args), rch); } @Override - public void query(String sql, RowCallbackHandler rch, @Nullable Object... args) throws DataAccessException { + public void query(String sql, RowCallbackHandler rch, @Nullable Object @Nullable ... args) throws DataAccessException { query(sql, newArgPreparedStatementSetter(args), rch); } @@ -810,18 +791,18 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public List query(String sql, Object[] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException { + public List query(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException { return result(query(sql, args, argTypes, new RowMapperResultSetExtractor<>(rowMapper))); } @Deprecated @Override - public List query(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException { + public List query(String sql, @Nullable Object @Nullable [] args, RowMapper rowMapper) throws DataAccessException { return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper))); } @Override - public List query(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException { + public List query(String sql, RowMapper rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException { return result(query(sql, args, new RowMapperResultSetExtractor<>(rowMapper))); } @@ -869,13 +850,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public Stream queryForStream(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException { + public Stream queryForStream(String sql, RowMapper rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException { return queryForStream(new SimplePreparedStatementCreator(sql), newArgPreparedStatementSetter(args), rowMapper); } @Override - @Nullable - public T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper rowMapper) + public @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, RowMapper rowMapper) throws DataAccessException { List results = query(sql, args, argTypes, new RowMapperResultSetExtractor<>(rowMapper, 1)); @@ -884,22 +864,19 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @Deprecated @Override - @Nullable - public T queryForObject(String sql, @Nullable Object[] args, RowMapper rowMapper) throws DataAccessException { + public @Nullable T queryForObject(String sql,@Nullable Object @Nullable [] args, RowMapper rowMapper) throws DataAccessException { List results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1)); return DataAccessUtils.nullableSingleResult(results); } @Override - @Nullable - public T queryForObject(String sql, RowMapper rowMapper, @Nullable Object... args) throws DataAccessException { + public @Nullable T queryForObject(String sql, RowMapper rowMapper, @Nullable Object @Nullable ... args) throws DataAccessException { List results = query(sql, args, new RowMapperResultSetExtractor<>(rowMapper, 1)); return DataAccessUtils.nullableSingleResult(results); } @Override - @Nullable - public T queryForObject(String sql, Object[] args, int[] argTypes, Class requiredType) + public @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class requiredType) throws DataAccessException { return queryForObject(sql, args, argTypes, getSingleColumnRowMapper(requiredType)); @@ -907,64 +884,62 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { @Deprecated @Override - @Nullable - public T queryForObject(String sql, @Nullable Object[] args, Class requiredType) throws DataAccessException { + public @Nullable T queryForObject(String sql, @Nullable Object @Nullable [] args, Class requiredType) throws DataAccessException { return queryForObject(sql, args, getSingleColumnRowMapper(requiredType)); } @Override - @Nullable - public T queryForObject(String sql, Class requiredType, @Nullable Object... args) throws DataAccessException { + public @Nullable T queryForObject(String sql, Class requiredType, @Nullable Object @Nullable ... args) throws DataAccessException { return queryForObject(sql, args, getSingleColumnRowMapper(requiredType)); } @Override - public Map queryForMap(String sql, Object[] args, int[] argTypes) throws DataAccessException { + public Map queryForMap(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException { return result(queryForObject(sql, args, argTypes, getColumnMapRowMapper())); } @Override - public Map queryForMap(String sql, @Nullable Object... args) throws DataAccessException { + public Map queryForMap(String sql, @Nullable Object @Nullable ... args) throws DataAccessException { return result(queryForObject(sql, args, getColumnMapRowMapper())); } @Override - public List queryForList(String sql, Object[] args, int[] argTypes, Class elementType) throws DataAccessException { + public List queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes, Class elementType) throws DataAccessException { return query(sql, args, argTypes, getSingleColumnRowMapper(elementType)); } @Deprecated @Override - public List queryForList(String sql, @Nullable Object[] args, Class elementType) throws DataAccessException { + public List queryForList(String sql, @Nullable Object @Nullable [] args, Class elementType) throws DataAccessException { return query(sql, args, getSingleColumnRowMapper(elementType)); } @Override - public List queryForList(String sql, Class elementType, @Nullable Object... args) throws DataAccessException { + public List queryForList(String sql, Class elementType, @Nullable Object @Nullable ... args) throws DataAccessException { return query(sql, args, getSingleColumnRowMapper(elementType)); } @Override - public List> queryForList(String sql, Object[] args, int[] argTypes) throws DataAccessException { + public List> queryForList(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException { return query(sql, args, argTypes, getColumnMapRowMapper()); } @Override - public List> queryForList(String sql, @Nullable Object... args) throws DataAccessException { + public List> queryForList(String sql, @Nullable Object @Nullable ... args) throws DataAccessException { return query(sql, args, getColumnMapRowMapper()); } @Override - public SqlRowSet queryForRowSet(String sql, Object[] args, int[] argTypes) throws DataAccessException { + public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException { return result(query(sql, args, argTypes, new SqlRowSetResultSetExtractor())); } @Override - public SqlRowSet queryForRowSet(String sql, @Nullable Object... args) throws DataAccessException { + public SqlRowSet queryForRowSet(String sql, @Nullable Object @Nullable ... args) throws DataAccessException { return result(query(sql, args, new SqlRowSetResultSetExtractor())); } - protected int update(final PreparedStatementCreator psc, @Nullable final PreparedStatementSetter pss) + protected int update(final PreparedStatementCreator psc, final @Nullable PreparedStatementSetter pss) throws DataAccessException { logger.debug("Executing prepared SQL update"); @@ -1017,12 +992,12 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - public int update(String sql, Object[] args, int[] argTypes) throws DataAccessException { + public int update(String sql, @Nullable Object @Nullable [] args, int[] argTypes) throws DataAccessException { return update(sql, newArgTypePreparedStatementSetter(args, argTypes)); } @Override - public int update(String sql, @Nullable Object... args) throws DataAccessException { + public int update(String sql, @Nullable Object @Nullable ... args) throws DataAccessException { return update(sql, newArgPreparedStatementSetter(args)); } @@ -1153,8 +1128,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { //------------------------------------------------------------------------- @Override - @Nullable - public T execute(CallableStatementCreator csc, CallableStatementCallback action) + public @Nullable T execute(CallableStatementCreator csc, CallableStatementCallback action) throws DataAccessException { Assert.notNull(csc, "CallableStatementCreator must not be null"); @@ -1200,8 +1174,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public T execute(String callString, CallableStatementCallback action) throws DataAccessException { + public @Nullable T execute(String callString, CallableStatementCallback action) throws DataAccessException { return execute(new SimpleCallableStatementCreator(callString), action); } @@ -1461,7 +1434,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * @param args object array with arguments * @return the new PreparedStatementSetter to use */ - protected PreparedStatementSetter newArgPreparedStatementSetter(@Nullable Object[] args) { + protected PreparedStatementSetter newArgPreparedStatementSetter(@Nullable Object @Nullable [] args) { return new ArgumentPreparedStatementSetter(args); } @@ -1473,7 +1446,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * @param argTypes int array of SQLTypes for the associated arguments * @return the new PreparedStatementSetter to use */ - protected PreparedStatementSetter newArgTypePreparedStatementSetter(Object[] args, int[] argTypes) { + protected PreparedStatementSetter newArgTypePreparedStatementSetter(@Nullable Object @Nullable [] args, int[] argTypes) { return new ArgumentTypePreparedStatementSetter(args, argTypes); } @@ -1564,8 +1537,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { * @return the SQL string, or {@code null} if not known * @see SqlProvider */ - @Nullable - private static String getSql(Object obj) { + private static @Nullable String getSql(Object obj) { return (obj instanceof SqlProvider sqlProvider ? sqlProvider.getSql() : null); } @@ -1662,8 +1634,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... return switch (method.getName()) { @@ -1764,8 +1735,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public Object extractData(ResultSet rs) throws SQLException { + public @Nullable Object extractData(ResultSet rs) throws SQLException { while (rs.next()) { this.rch.processRow(rs); } @@ -1806,8 +1776,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } @Override - @Nullable - public Spliterator trySplit() { + public @Nullable Spliterator trySplit() { return null; } 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 97c9f32aa9..235bf55234 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 @@ -19,8 +19,9 @@ package org.springframework.jdbc.core; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a PreparedStatement. @@ -74,7 +75,6 @@ public interface PreparedStatementCallback { * @see JdbcTemplate#queryForObject(String, Object[], Class) * @see JdbcTemplate#queryForList(String, Object[]) */ - @Nullable - T doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException; + @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 ddc9ac073c..f98468641d 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 @@ -29,8 +29,9 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; /** * Helper class that efficiently creates multiple {@link PreparedStatementCreator} @@ -47,8 +48,7 @@ public class PreparedStatementCreatorFactory { private final String sql; /** List of SqlParameter objects (may be {@code null}). */ - @Nullable - private List declaredParameters; + private @Nullable List declaredParameters; private int resultSetType = ResultSet.TYPE_FORWARD_ONLY; @@ -56,8 +56,7 @@ public class PreparedStatementCreatorFactory { private boolean returnGeneratedKeys = false; - @Nullable - private String[] generatedKeysColumnNames; + private String @Nullable [] generatedKeysColumnNames; /** @@ -155,7 +154,7 @@ public class PreparedStatementCreatorFactory { * Return a new PreparedStatementSetter for the given parameters. * @param params the parameter array (may be {@code null}) */ - public PreparedStatementSetter newPreparedStatementSetter(@Nullable Object[] params) { + public PreparedStatementSetter newPreparedStatementSetter(Object @Nullable [] params) { return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList()); } @@ -171,7 +170,7 @@ public class PreparedStatementCreatorFactory { * Return a new PreparedStatementCreator for the given parameters. * @param params the parameter array (may be {@code null}) */ - public PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] params) { + public PreparedStatementCreator newPreparedStatementCreator(Object @Nullable [] params) { return new PreparedStatementCreatorImpl(params != null ? Arrays.asList(params) : Collections.emptyList()); } @@ -181,7 +180,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, @Nullable Object[] params) { + public PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object @Nullable [] 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 0acaf0620d..33a7ba541d 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 @@ -19,8 +19,9 @@ package org.springframework.jdbc.core; import java.sql.ResultSet; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Callback interface used by {@link JdbcTemplate}'s query methods. @@ -61,7 +62,6 @@ 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; + @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 0c8b9b42b6..3ef1703bf7 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 @@ -18,7 +18,7 @@ package org.springframework.jdbc.core; import java.sql.ResultSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Common base class for ResultSet-supporting SqlParameters like @@ -29,14 +29,11 @@ import org.springframework.lang.Nullable; */ public class ResultSetSupportingSqlParameter extends SqlParameter { - @Nullable - private ResultSetExtractor resultSetExtractor; + private @Nullable ResultSetExtractor resultSetExtractor; - @Nullable - private RowCallbackHandler rowCallbackHandler; + private @Nullable RowCallbackHandler rowCallbackHandler; - @Nullable - private RowMapper rowMapper; + private @Nullable RowMapper rowMapper; /** @@ -114,24 +111,21 @@ public class ResultSetSupportingSqlParameter extends SqlParameter { /** * Return the ResultSetExtractor held by this parameter, if any. */ - @Nullable - public ResultSetExtractor getResultSetExtractor() { + public @Nullable ResultSetExtractor getResultSetExtractor() { return this.resultSetExtractor; } /** * Return the RowCallbackHandler held by this parameter, if any. */ - @Nullable - public RowCallbackHandler getRowCallbackHandler() { + public @Nullable RowCallbackHandler getRowCallbackHandler() { return this.rowCallbackHandler; } /** * Return the RowMapper held by this parameter, if any. */ - @Nullable - public RowMapper getRowMapper() { + public @Nullable RowMapper getRowMapper() { return this.rowMapper; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowCountCallbackHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowCountCallbackHandler.java index 2d2b09ac9a..35161ec92b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowCountCallbackHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowCountCallbackHandler.java @@ -20,8 +20,9 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; /** * Implementation of RowCallbackHandler. Convenient superclass for callback handlers. @@ -55,14 +56,12 @@ public class RowCountCallbackHandler implements RowCallbackHandler { * Indexed from 0. Type (as in java.sql.Types) for the columns * as returned by ResultSetMetaData object. */ - @Nullable - private int[] columnTypes; + private int @Nullable [] columnTypes; /** * Indexed from 0. Column name as returned by ResultSetMetaData object. */ - @Nullable - private String[] columnNames; + private String @Nullable [] columnNames; /** @@ -105,8 +104,7 @@ public class RowCountCallbackHandler implements RowCallbackHandler { * @return the types of the columns as java.sql.Types constants. * Indexed from 0 to n-1. */ - @Nullable - public final int[] getColumnTypes() { + public final int @Nullable [] getColumnTypes() { return this.columnTypes; } @@ -116,8 +114,7 @@ public class RowCountCallbackHandler implements RowCallbackHandler { * @return the names of the columns. * Indexed from 0 to n-1. */ - @Nullable - public final String[] getColumnNames() { + public final String @Nullable [] getColumnNames() { return this.columnNames; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowMapper.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowMapper.java index 291d3f2ac1..92cbb414c8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowMapper.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/RowMapper.java @@ -19,7 +19,7 @@ package org.springframework.jdbc.core; import java.sql.ResultSet; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An interface used by {@link JdbcTemplate} for mapping rows of a @@ -61,7 +61,6 @@ public interface RowMapper { * @throws SQLException if an SQLException is encountered while getting * column values (that is, there's no need to catch SQLException) */ - @Nullable - T mapRow(ResultSet rs, int rowNum) throws SQLException; + @Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException; } 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 43dffc066e..1b8f3b6af5 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 @@ -20,12 +20,13 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.DefaultConversionService; 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; @@ -47,11 +48,9 @@ import org.springframework.util.NumberUtils; */ public class SingleColumnRowMapper implements RowMapper { - @Nullable - private Class requiredType; + private @Nullable Class requiredType; - @Nullable - private ConversionService conversionService = DefaultConversionService.getSharedInstance(); + private @Nullable ConversionService conversionService = DefaultConversionService.getSharedInstance(); /** @@ -102,8 +101,7 @@ public class SingleColumnRowMapper implements RowMapper { */ @Override @SuppressWarnings("unchecked") - @Nullable - public T mapRow(ResultSet rs, int rowNum) throws SQLException { + public @Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException { // Validate column count. ResultSetMetaData rsmd = rs.getMetaData(); int nrOfColumns = rsmd.getColumnCount(); @@ -144,8 +142,7 @@ public class SingleColumnRowMapper implements RowMapper { * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int, Class) * @see #getColumnValue(java.sql.ResultSet, int) */ - @Nullable - protected Object getColumnValue(ResultSet rs, int index, @Nullable Class requiredType) throws SQLException { + protected @Nullable Object getColumnValue(ResultSet rs, int index, @Nullable Class requiredType) throws SQLException { if (requiredType != null) { return JdbcUtils.getResultSetValue(rs, index, requiredType); } @@ -169,8 +166,7 @@ public class SingleColumnRowMapper implements RowMapper { * @throws SQLException in case of extraction failure * @see org.springframework.jdbc.support.JdbcUtils#getResultSetValue(java.sql.ResultSet, int) */ - @Nullable - protected Object getColumnValue(ResultSet rs, int index) throws SQLException { + protected @Nullable Object getColumnValue(ResultSet rs, int index) throws SQLException { return JdbcUtils.getResultSetValue(rs, index); } @@ -190,8 +186,7 @@ public class SingleColumnRowMapper implements RowMapper { * @see #getColumnValue(java.sql.ResultSet, int, Class) */ @SuppressWarnings("unchecked") - @Nullable - protected Object convertValueToRequiredType(Object value, Class requiredType) { + protected @Nullable Object convertValueToRequiredType(Object value, Class requiredType) { if (String.class == requiredType) { return value.toString(); } 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 a43ec1a0dd..c7b177a42b 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 @@ -18,7 +18,7 @@ package org.springframework.jdbc.core; import java.sql.ResultSet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Subclass of {@link SqlParameter} to represent an output parameter. @@ -34,8 +34,7 @@ import org.springframework.lang.Nullable; */ public class SqlOutParameter extends ResultSetSupportingSqlParameter { - @Nullable - private SqlReturnType sqlReturnType; + private @Nullable SqlReturnType sqlReturnType; /** @@ -114,8 +113,7 @@ public class SqlOutParameter extends ResultSetSupportingSqlParameter { /** * Return the custom return type, if any. */ - @Nullable - public SqlReturnType getSqlReturnType() { + public @Nullable 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 339611df68..609ed04b31 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,7 +19,8 @@ package org.springframework.jdbc.core; import java.util.ArrayList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -36,19 +37,16 @@ import org.springframework.util.Assert; public class SqlParameter { // The name of the parameter, if any - @Nullable - private String name; + private @Nullable String name; // SQL type constant from {@code java.sql.Types} private final int sqlType; // Used for types that are user-named like: STRUCT, DISTINCT, JAVA_OBJECT, named array types - @Nullable - private String typeName; + private @Nullable String typeName; // The scale to apply in case of a NUMERIC or DECIMAL type, if any - @Nullable - private Integer scale; + private @Nullable Integer scale; /** @@ -131,8 +129,7 @@ public class SqlParameter { /** * Return the name of the parameter, or {@code null} if anonymous. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -146,16 +143,14 @@ public class SqlParameter { /** * Return the type name of the parameter, if any. */ - @Nullable - public String getTypeName() { + public @Nullable String getTypeName() { return this.typeName; } /** * Return the scale of the parameter, if any. */ - @Nullable - public Integer getScale() { + public @Nullable Integer getScale() { return this.scale; } @@ -183,7 +178,7 @@ public class SqlParameter { * Convert a list of JDBC types, as defined in {@code java.sql.Types}, * to a List of SqlParameter objects as used in this package. */ - public static List sqlTypesToAnonymousParameterList(@Nullable int... types) { + public static List sqlTypesToAnonymousParameterList(int @Nullable ... types) { if (types == null) { return new ArrayList<>(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameterValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameterValue.java index 30159fe4dc..d693b8bc8b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameterValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlParameterValue.java @@ -16,7 +16,7 @@ package org.springframework.jdbc.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Object to represent an SQL parameter value, including parameter meta-data @@ -38,8 +38,7 @@ import org.springframework.lang.Nullable; */ public class SqlParameterValue extends SqlParameter { - @Nullable - private final Object value; + private final @Nullable Object value; /** @@ -89,8 +88,7 @@ public class SqlParameterValue extends SqlParameter { /** * Return the value object that this parameter value holds. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } 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 e060bc1522..01b8c0b226 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,7 +16,7 @@ package org.springframework.jdbc.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that can provide SQL strings. @@ -38,7 +38,6 @@ public interface SqlProvider { * typically the SQL used for creating statements. * @return the SQL string, or {@code null} if not available */ - @Nullable - String getSql(); + @Nullable String getSql(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlReturnType.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlReturnType.java index f2558c6691..c2d609b7b5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlReturnType.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlReturnType.java @@ -19,7 +19,7 @@ package org.springframework.jdbc.core; import java.sql.CallableStatement; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented for retrieving values for more complex database-specific diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlTypeValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlTypeValue.java index 2349ac1cb2..8c30cda093 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlTypeValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/SqlTypeValue.java @@ -19,8 +19,9 @@ package org.springframework.jdbc.core; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; /** * Interface to be implemented for setting values for more complex database-specific 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 1297b94dea..907027d5d3 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 @@ -19,8 +19,9 @@ package org.springframework.jdbc.core; import java.sql.SQLException; import java.sql.Statement; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Generic callback interface for code that operates on a JDBC Statement. @@ -67,7 +68,6 @@ public interface StatementCallback { * @see JdbcTemplate#queryForObject(String, Class) * @see JdbcTemplate#queryForRowSet(String) */ - @Nullable - T doInStatement(Statement stmt) throws SQLException, DataAccessException; + @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 3eea1df606..0f3fb0f2a5 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 @@ -40,10 +40,10 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.SpringProperties; import org.springframework.jdbc.support.SqlValue; -import org.springframework.lang.Nullable; /** * Utility methods for PreparedStatementSetter/Creator and CallableStatementCreator @@ -85,8 +85,7 @@ public abstract class StatementCreatorUtils { private static final Map, Integer> javaTypeToSqlTypeMap = new HashMap<>(64); - @Nullable - static Boolean shouldIgnoreGetParameterType; + static @Nullable Boolean shouldIgnoreGetParameterType; static { javaTypeToSqlTypeMap.put(boolean.class, Types.BOOLEAN); @@ -494,7 +493,7 @@ public abstract class StatementCreatorUtils { * @see DisposableSqlTypeValue#cleanup() * @see org.springframework.jdbc.core.support.SqlLobValue#cleanup() */ - public static void cleanupParameters(@Nullable Object... paramValues) { + public static void cleanupParameters(@Nullable Object @Nullable ... paramValues) { if (paramValues != null) { cleanupParameters(Arrays.asList(paramValues)); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java index fdc66aa1c3..d291aa37df 100755 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java @@ -28,6 +28,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.RowMapper; @@ -38,7 +39,6 @@ import org.springframework.jdbc.core.SqlReturnResultSet; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils; import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -58,23 +58,19 @@ public class CallMetaDataContext { protected final Log logger = LogFactory.getLog(getClass()); // Name of procedure to call - @Nullable - private String procedureName; + private @Nullable String procedureName; // Name of catalog for call - @Nullable - private String catalogName; + private @Nullable String catalogName; // Name of schema for call - @Nullable - private String schemaName; + private @Nullable String schemaName; // List of SqlParameter objects to be used in call execution private List callParameters = new ArrayList<>(); // Actual name to use for the return value in the output map - @Nullable - private String actualFunctionReturnName; + private @Nullable String actualFunctionReturnName; // Set of in parameter names to exclude use for any not listed private Set limitedInParameterNames = new HashSet<>(); @@ -95,8 +91,7 @@ public class CallMetaDataContext { private boolean namedBinding; // The provider of call meta-data - @Nullable - private CallMetaDataProvider metaDataProvider; + private @Nullable CallMetaDataProvider metaDataProvider; /** @@ -151,8 +146,7 @@ public class CallMetaDataContext { /** * Get the name of the procedure. */ - @Nullable - public String getProcedureName() { + public @Nullable String getProcedureName() { return this.procedureName; } @@ -166,8 +160,7 @@ public class CallMetaDataContext { /** * Get the name of the catalog. */ - @Nullable - public String getCatalogName() { + public @Nullable String getCatalogName() { return this.catalogName; } @@ -181,8 +174,7 @@ public class CallMetaDataContext { /** * Get the name of the schema. */ - @Nullable - public String getSchemaName() { + public @Nullable String getSchemaName() { return this.schemaName; } @@ -285,8 +277,7 @@ public class CallMetaDataContext { * Get the name of the single out parameter for this call. * If there are multiple parameters, the name of the first one will be returned. */ - @Nullable - public String getScalarOutParameterName() { + public @Nullable String getScalarOutParameterName() { if (isFunction()) { return getFunctionReturnName(); } 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 a13a43161f..1d564f16bf 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 @@ -20,8 +20,9 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.SqlParameter; -import org.springframework.lang.Nullable; /** * Interface specifying the API to be implemented by a class providing call meta-data. @@ -67,46 +68,40 @@ public interface CallMetaDataProvider { * 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(@Nullable String procedureName); + @Nullable String procedureNameToUse(@Nullable 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(@Nullable String catalogName); + @Nullable String catalogNameToUse(@Nullable 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(@Nullable String schemaName); + @Nullable String schemaNameToUse(@Nullable String schemaName); /** * Provide any modification of the catalog name passed in to match the meta-data currently used. *

    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(@Nullable String catalogName) ; + @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) ; /** * Provide any modification of the schema name passed in to match the meta-data currently used. *

    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(@Nullable String schemaName); + @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName); /** * Provide any modification of the column name passed in to match the meta-data currently used. *

    This could include altering the case. * @param parameterName name of the parameter of column */ - @Nullable - String parameterNameToUse(@Nullable String parameterName); + @Nullable String parameterNameToUse(@Nullable String parameterName); /** * Return the name of the named parameter to use for binding the given parameter name. @@ -147,8 +142,7 @@ public interface CallMetaDataProvider { * Get the name of the current user. Useful for meta-data lookups etc. * @return current user name from database connection */ - @Nullable - String getUserName(); + @Nullable String getUserName(); /** * Are we using the meta-data for the procedure columns? diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java index 2b7a61c069..5103f03491 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallParameterMetaData.java @@ -18,7 +18,7 @@ package org.springframework.jdbc.core.metadata; import java.sql.DatabaseMetaData; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Holder of meta-data for a specific parameter that is used for call processing. @@ -32,15 +32,13 @@ public class CallParameterMetaData { private final boolean function; - @Nullable - private final String parameterName; + private final @Nullable String parameterName; private final int parameterType; private final int sqlType; - @Nullable - private final String typeName; + private final @Nullable String typeName; private final boolean nullable; @@ -72,8 +70,7 @@ public class CallParameterMetaData { /** * Return the parameter name. */ - @Nullable - public String getParameterName() { + public @Nullable String getParameterName() { return this.parameterName; } @@ -129,8 +126,7 @@ public class CallParameterMetaData { /** * Return the parameter type name. */ - @Nullable - public String getTypeName() { + public @Nullable String getTypeName() { return this.typeName; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java index 66c4956468..0de476af1f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/Db2CallMetaDataProvider.java @@ -20,7 +20,7 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * DB2 specific implementation for the {@link CallMetaDataProvider} interface. @@ -66,8 +66,7 @@ public class Db2CallMetaDataProvider extends GenericCallMetaDataProvider { } @Override - @Nullable - public String metaDataSchemaNameToUse(@Nullable String schemaName) { + public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) { if (schemaName != null) { return super.metaDataSchemaNameToUse(schemaName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java index efaa556cf6..84767aa76f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/DerbyCallMetaDataProvider.java @@ -20,7 +20,7 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Derby specific implementation for the {@link CallMetaDataProvider} interface. @@ -38,8 +38,7 @@ public class DerbyCallMetaDataProvider extends GenericCallMetaDataProvider { @Override - @Nullable - public String metaDataSchemaNameToUse(@Nullable String schemaName) { + public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) { if (schemaName != null) { return super.metaDataSchemaNameToUse(schemaName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java index 5eb124b063..96de2873a2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProvider.java @@ -26,12 +26,12 @@ import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.SqlInOutParameter; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -125,26 +125,22 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } @Override - @Nullable - public String procedureNameToUse(@Nullable String procedureName) { + public @Nullable String procedureNameToUse(@Nullable String procedureName) { return identifierNameToUse(procedureName); } @Override - @Nullable - public String catalogNameToUse(@Nullable String catalogName) { + public @Nullable String catalogNameToUse(@Nullable String catalogName) { return identifierNameToUse(catalogName); } @Override - @Nullable - public String schemaNameToUse(@Nullable String schemaName) { + public @Nullable String schemaNameToUse(@Nullable String schemaName) { return identifierNameToUse(schemaName); } @Override - @Nullable - public String metaDataCatalogNameToUse(@Nullable String catalogName) { + public @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) { if (isSupportsCatalogsInProcedureCalls()) { return catalogNameToUse(catalogName); } @@ -154,8 +150,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } @Override - @Nullable - public String metaDataSchemaNameToUse(@Nullable String schemaName) { + public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) { if (isSupportsSchemasInProcedureCalls()) { return schemaNameToUse(schemaName); } @@ -165,8 +160,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } @Override - @Nullable - public String parameterNameToUse(@Nullable String parameterName) { + public @Nullable String parameterNameToUse(@Nullable String parameterName) { return identifierNameToUse(parameterName); } @@ -279,8 +273,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { } - @Nullable - private String identifierNameToUse(@Nullable String identifierName) { + private @Nullable String identifierNameToUse(@Nullable String identifierName) { if (identifierName == null) { return null; } @@ -438,8 +431,7 @@ public class GenericCallMetaDataProvider implements CallMetaDataProvider { return new ProcedureMetadata(schemaName, procedureName, matches, true); } - @Nullable - private static String escapeNamePattern(@Nullable String name, @Nullable String escape) { + private static @Nullable String escapeNamePattern(@Nullable String name, @Nullable String escape) { if (name == null || escape == null) { return name; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java index b5e65f418b..defbd02b89 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java @@ -29,10 +29,10 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; /** * A generic implementation of the {@link TableMetaDataProvider} interface @@ -54,12 +54,10 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider { /** The name of the user currently connected. */ - @Nullable - private final String userName; + private final @Nullable String userName; /** The version of the database. */ - @Nullable - private String databaseVersion; + private @Nullable String databaseVersion; /** Indicates whether column meta-data has been used. */ private boolean tableColumnMetaDataUsed = false; @@ -186,31 +184,26 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider { } @Override - @Nullable - public String tableNameToUse(@Nullable String tableName) { + public @Nullable String tableNameToUse(@Nullable String tableName) { return identifierNameToUse(tableName); } @Override - @Nullable - public String columnNameToUse(@Nullable String columnName) { + public @Nullable String columnNameToUse(@Nullable String columnName) { return identifierNameToUse(columnName); } @Override - @Nullable - public String catalogNameToUse(@Nullable String catalogName) { + public @Nullable String catalogNameToUse(@Nullable String catalogName) { return identifierNameToUse(catalogName); } @Override - @Nullable - public String schemaNameToUse(@Nullable String schemaName) { + public @Nullable String schemaNameToUse(@Nullable String schemaName) { return identifierNameToUse(schemaName); } - @Nullable - private String identifierNameToUse(@Nullable String identifierName) { + private @Nullable String identifierNameToUse(@Nullable String identifierName) { if (identifierName == null) { return null; } @@ -226,14 +219,12 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider { } @Override - @Nullable - public String metaDataCatalogNameToUse(@Nullable String catalogName) { + public @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) { return catalogNameToUse(catalogName); } @Override - @Nullable - public String metaDataSchemaNameToUse(@Nullable String schemaName) { + public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) { if (schemaName == null) { return schemaNameToUse(getDefaultSchema()); } @@ -243,16 +234,14 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider { /** * Provide access to the default schema for subclasses. */ - @Nullable - protected String getDefaultSchema() { + protected @Nullable String getDefaultSchema() { return this.userName; } /** * Provide access to the version info for subclasses. */ - @Nullable - protected String getDatabaseVersion() { + protected @Nullable String getDatabaseVersion() { return this.databaseVersion; } @@ -276,8 +265,7 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider { } @Override - @Nullable - public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { + public @Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { return null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleCallMetaDataProvider.java index f655eb0903..cc64c1a3be 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleCallMetaDataProvider.java @@ -20,10 +20,11 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.sql.Types; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; -import org.springframework.lang.Nullable; /** * Oracle-specific implementation for the {@link CallMetaDataProvider} interface. @@ -58,15 +59,13 @@ public class OracleCallMetaDataProvider extends GenericCallMetaDataProvider { } @Override - @Nullable - public String metaDataCatalogNameToUse(@Nullable String catalogName) { + public @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) { // Oracle uses catalog name for package name or an empty string if no package return (catalogName == null ? "" : catalogNameToUse(catalogName)); } @Override - @Nullable - public String metaDataSchemaNameToUse(@Nullable String schemaName) { + public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) { // Use current user schema if no schema specified return (schemaName == null ? getUserName() : super.metaDataSchemaNameToUse(schemaName)); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java index 5374099fee..b2535c1c51 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/OracleTableMetaDataProvider.java @@ -23,8 +23,9 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.sql.Types; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -43,8 +44,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider { private final boolean includeSynonyms; - @Nullable - private final String defaultSchema; + private final @Nullable String defaultSchema; /** @@ -72,8 +72,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider { /* * Oracle-based implementation for detecting the current schema. */ - @Nullable - private static String lookupDefaultSchema(DatabaseMetaData databaseMetaData) { + private static @Nullable String lookupDefaultSchema(DatabaseMetaData databaseMetaData) { try { CallableStatement cstmt = null; try { @@ -100,8 +99,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider { } @Override - @Nullable - protected String getDefaultSchema() { + protected @Nullable String getDefaultSchema() { if (this.defaultSchema != null) { return this.defaultSchema; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/PostgresCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/PostgresCallMetaDataProvider.java index 31275e90eb..93a77e8814 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/PostgresCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/PostgresCallMetaDataProvider.java @@ -20,10 +20,11 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.sql.Types; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.ColumnMapRowMapper; import org.springframework.jdbc.core.SqlOutParameter; import org.springframework.jdbc.core.SqlParameter; -import org.springframework.lang.Nullable; /** * Postgres-specific implementation for the {@link CallMetaDataProvider} interface. @@ -65,8 +66,7 @@ public class PostgresCallMetaDataProvider extends GenericCallMetaDataProvider { } @Override - @Nullable - public String metaDataSchemaNameToUse(@Nullable String schemaName) { + public @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) { return (schemaName == null ? this.schemaName : super.metaDataSchemaNameToUse(schemaName)); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java index 5e74593081..794de56f24 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SqlServerCallMetaDataProvider.java @@ -19,7 +19,7 @@ package org.springframework.jdbc.core.metadata; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * SQL Server specific implementation for the {@link CallMetaDataProvider} interface. @@ -42,8 +42,7 @@ public class SqlServerCallMetaDataProvider extends GenericCallMetaDataProvider { @Override - @Nullable - public String parameterNameToUse(@Nullable String parameterName) { + public @Nullable String parameterNameToUse(@Nullable String parameterName) { if (parameterName == null) { return null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java index 5663615312..7e3b454b81 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/SybaseCallMetaDataProvider.java @@ -19,7 +19,7 @@ package org.springframework.jdbc.core.metadata; import java.sql.DatabaseMetaData; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Sybase specific implementation for the {@link CallMetaDataProvider} interface. @@ -42,8 +42,7 @@ public class SybaseCallMetaDataProvider extends GenericCallMetaDataProvider { @Override - @Nullable - public String parameterNameToUse(@Nullable String parameterName) { + public @Nullable String parameterNameToUse(@Nullable String parameterName) { if (parameterName == null) { return null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java index e7cb34de8f..f31e7ef68d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java @@ -27,13 +27,13 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.SqlTypeValue; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils; import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -53,16 +53,13 @@ public class TableMetaDataContext { protected final Log logger = LogFactory.getLog(getClass()); // Name of table for this context - @Nullable - private String tableName; + private @Nullable String tableName; // Name of catalog for this context - @Nullable - private String catalogName; + private @Nullable String catalogName; // Name of schema for this context - @Nullable - private String schemaName; + private @Nullable String schemaName; // Should we access insert parameter meta-data info or not private boolean accessTableColumnMetaData = true; @@ -74,8 +71,7 @@ public class TableMetaDataContext { private boolean quoteIdentifiers = false; // The provider of table meta-data - @Nullable - private TableMetaDataProvider metaDataProvider; + private @Nullable TableMetaDataProvider metaDataProvider; // List of columns objects to be used in this context private List tableColumns = new ArrayList<>(); @@ -94,8 +90,7 @@ public class TableMetaDataContext { /** * Get the name of the table for this context. */ - @Nullable - public String getTableName() { + public @Nullable String getTableName() { return this.tableName; } @@ -109,8 +104,7 @@ public class TableMetaDataContext { /** * Get the name of the catalog for this context. */ - @Nullable - public String getCatalogName() { + public @Nullable String getCatalogName() { return this.catalogName; } @@ -124,8 +118,7 @@ public class TableMetaDataContext { /** * Get the name of the schema for this context. */ - @Nullable - public String getSchemaName() { + public @Nullable String getSchemaName() { return this.schemaName; } @@ -411,8 +404,7 @@ public class TableMetaDataContext { * retrieving generated keys is not supported. * @see #isGetGeneratedKeysSimulated() */ - @Nullable - public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { + public @Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { return obtainMetaDataProvider().getSimpleQueryForGetGeneratedKey(tableName, keyColumnName); } @@ -428,8 +420,7 @@ public class TableMetaDataContext { private static final class QuoteHandler { - @Nullable - private final String identifierQuoteString; + private final @Nullable String identifierQuoteString; private final boolean quoting; 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 1af80eec37..299d782ca3 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,7 +20,7 @@ import java.sql.DatabaseMetaData; import java.sql.SQLException; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface specifying the API to be implemented by a class providing table meta-data. @@ -63,30 +63,26 @@ public interface TableMetaDataProvider { * Get the table name formatted based on meta-data information. *

    This could include altering the case. */ - @Nullable - String tableNameToUse(@Nullable String tableName); + @Nullable String tableNameToUse(@Nullable String tableName); /** * Get the column name formatted based on meta-data information. *

    This could include altering the case. * @since 6.1 */ - @Nullable - String columnNameToUse(@Nullable String columnName); + @Nullable String columnNameToUse(@Nullable String columnName); /** * Get the catalog name formatted based on meta-data information. *

    This could include altering the case. */ - @Nullable - String catalogNameToUse(@Nullable String catalogName); + @Nullable String catalogNameToUse(@Nullable String catalogName); /** * Get the schema name formatted based on meta-data information. *

    This could include altering the case. */ - @Nullable - String schemaNameToUse(@Nullable String schemaName); + @Nullable String schemaNameToUse(@Nullable String schemaName); /** * Provide any modification of the catalog name passed in to match the meta-data @@ -95,8 +91,7 @@ public interface TableMetaDataProvider { *

    This could include altering the case used or providing a base catalog * if none is provided. */ - @Nullable - String metaDataCatalogNameToUse(@Nullable String catalogName) ; + @Nullable String metaDataCatalogNameToUse(@Nullable String catalogName) ; /** * Provide any modification of the schema name passed in to match the meta-data @@ -105,8 +100,7 @@ public interface TableMetaDataProvider { *

    This could include altering the case used or providing a base schema * if none is provided. */ - @Nullable - String metaDataSchemaNameToUse(@Nullable String schemaName) ; + @Nullable String metaDataSchemaNameToUse(@Nullable String schemaName) ; /** * Are we using the meta-data for the table columns? @@ -132,8 +126,7 @@ public interface TableMetaDataProvider { * retrieving generated keys is not supported. * @see #isGetGeneratedKeysSimulated() */ - @Nullable - String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); + @Nullable String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName); /** * Does this database support a column name String array for retrieving generated 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 3627e646b3..909f18d6f7 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 @@ -2,9 +2,7 @@ * Context metadata abstraction for the configuration and execution * of table inserts and stored procedure calls. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.core.metadata; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/AbstractSqlParameterSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/AbstractSqlParameterSource.java index a68f7899ca..4766feea57 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/AbstractSqlParameterSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/AbstractSqlParameterSource.java @@ -20,9 +20,10 @@ import java.util.HashMap; import java.util.Map; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.SqlParameterValue; import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -85,8 +86,7 @@ public abstract class AbstractSqlParameterSource implements SqlParameterSource { * or {@code null} if not registered */ @Override - @Nullable - public String getTypeName(String paramName) { + public @Nullable String getTypeName(String paramName) { Assert.notNull(paramName, "Parameter name must not be null"); return this.typeNames.get(paramName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java index bb2c595b65..4eb53d8541 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java @@ -20,13 +20,14 @@ import java.beans.PropertyDescriptor; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanWrapper; import org.springframework.beans.NotReadablePropertyException; import org.springframework.beans.PropertyAccessor; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.jdbc.core.StatementCreatorUtils; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -47,8 +48,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource { private final BeanWrapper beanWrapper; - @Nullable - private String[] propertyNames; + private String @Nullable [] propertyNames; /** @@ -66,8 +66,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource { } @Override - @Nullable - public Object getValue(String paramName) throws IllegalArgumentException { + public @Nullable Object getValue(String paramName) throws IllegalArgumentException { try { return this.beanWrapper.getPropertyValue(paramName); } @@ -91,8 +90,7 @@ public class BeanPropertySqlParameterSource extends AbstractSqlParameterSource { } @Override - @NonNull - public String[] getParameterNames() { + public @NonNull String[] getParameterNames() { return getReadablePropertyNames(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java index f3034c9daa..e4a8d09e82 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/EmptySqlParameterSource.java @@ -16,7 +16,7 @@ package org.springframework.jdbc.core.namedparam; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A simple empty implementation of the {@link SqlParameterSource} interface. @@ -38,8 +38,7 @@ public class EmptySqlParameterSource implements SqlParameterSource { } @Override - @Nullable - public Object getValue(String paramName) throws IllegalArgumentException { + public @Nullable Object getValue(String paramName) throws IllegalArgumentException { throw new IllegalArgumentException("This SqlParameterSource is empty"); } @@ -49,14 +48,12 @@ public class EmptySqlParameterSource implements SqlParameterSource { } @Override - @Nullable - public String getTypeName(String paramName) { + public @Nullable String getTypeName(String paramName) { return null; } @Override - @Nullable - public String[] getParameterNames() { + public String @Nullable [] getParameterNames() { return null; } 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 e3502ac63d..b7bd54ed69 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 @@ -20,9 +20,10 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.SqlParameterValue; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -165,8 +166,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource { } @Override - @Nullable - public Object getValue(String paramName) { + public @Nullable Object getValue(String paramName) { if (!hasValue(paramName)) { throw new IllegalArgumentException("No value registered for key '" + paramName + "'"); } @@ -174,8 +174,7 @@ public class MapSqlParameterSource extends AbstractSqlParameterSource { } @Override - @NonNull - public String[] getParameterNames() { + public @NonNull String[] getParameterNames() { return StringUtils.toStringArray(this.values.keySet()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcDaoSupport.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcDaoSupport.java index 5de5917194..ca0503d468 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcDaoSupport.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcDaoSupport.java @@ -16,9 +16,10 @@ package org.springframework.jdbc.core.namedparam; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.support.JdbcDaoSupport; -import org.springframework.lang.Nullable; /** * Extension of JdbcDaoSupport that exposes a NamedParameterJdbcTemplate as well. @@ -30,8 +31,7 @@ import org.springframework.lang.Nullable; */ public class NamedParameterJdbcDaoSupport extends JdbcDaoSupport { - @Nullable - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + private @Nullable NamedParameterJdbcTemplate namedParameterJdbcTemplate; /** @@ -48,8 +48,7 @@ public class NamedParameterJdbcDaoSupport extends JdbcDaoSupport { /** * Return a NamedParameterJdbcTemplate wrapping the configured JdbcTemplate. */ - @Nullable - public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { + public @Nullable NamedParameterJdbcTemplate getNamedParameterJdbcTemplate() { return this.namedParameterJdbcTemplate; } 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 f594c5e536..4edfe6aae5 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 @@ -20,6 +20,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.PreparedStatementCallback; @@ -28,7 +30,6 @@ 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 @@ -75,8 +76,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) + @Nullable T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action) throws DataAccessException; /** @@ -94,8 +94,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) + @Nullable T execute(String sql, Map paramMap, PreparedStatementCallback action) throws DataAccessException; /** @@ -111,8 +110,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; + @Nullable T execute(String sql, PreparedStatementCallback action) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list @@ -124,8 +122,7 @@ public interface NamedParameterJdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if the query fails */ - @Nullable - T query(String sql, SqlParameterSource paramSource, ResultSetExtractor rse) + @Nullable T query(String sql, SqlParameterSource paramSource, ResultSetExtractor rse) throws DataAccessException; /** @@ -139,8 +136,7 @@ public interface NamedParameterJdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if the query fails */ - @Nullable - T query(String sql, Map paramMap, ResultSetExtractor rse) + @Nullable T query(String sql, Map paramMap, ResultSetExtractor rse) throws DataAccessException; /** @@ -154,8 +150,7 @@ public interface NamedParameterJdbcOperations { * @return an arbitrary result object, as returned by the ResultSetExtractor * @throws DataAccessException if the query fails */ - @Nullable - T query(String sql, ResultSetExtractor rse) throws DataAccessException; + @Nullable T query(String sql, ResultSetExtractor rse) throws DataAccessException; /** * Query given SQL to create a prepared statement from SQL and a list of @@ -277,8 +272,7 @@ public interface NamedParameterJdbcOperations { * if the query does not return exactly one row * @throws DataAccessException if the query fails */ - @Nullable - T queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper) + @Nullable T queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper) throws DataAccessException; /** @@ -295,8 +289,7 @@ public interface NamedParameterJdbcOperations { * if the query does not return exactly one row * @throws DataAccessException if the query fails */ - @Nullable - T queryForObject(String sql, Map paramMap, RowMapper rowMapper) + @Nullable T queryForObject(String sql, Map paramMap, RowMapper rowMapper) throws DataAccessException; /** @@ -316,8 +309,7 @@ public interface NamedParameterJdbcOperations { * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) * @see org.springframework.jdbc.core.SingleColumnRowMapper */ - @Nullable - T queryForObject(String sql, SqlParameterSource paramSource, Class requiredType) + @Nullable T queryForObject(String sql, SqlParameterSource paramSource, Class requiredType) throws DataAccessException; /** @@ -337,8 +329,7 @@ public interface NamedParameterJdbcOperations { * @throws DataAccessException if the query fails * @see org.springframework.jdbc.core.JdbcTemplate#queryForObject(String, Class) */ - @Nullable - T queryForObject(String sql, Map paramMap, Class requiredType) + @Nullable T queryForObject(String sql, Map paramMap, Class requiredType) throws DataAccessException; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java index cba5c9bda0..ec51624fe0 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java @@ -25,6 +25,8 @@ import java.util.stream.Stream; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.BatchPreparedStatementSetter; @@ -42,7 +44,6 @@ import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.SqlRowSetResultSetExtractor; 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.ConcurrentLruCache; @@ -149,46 +150,40 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations @Override - @Nullable - public T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action) + public @Nullable T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallback action) throws DataAccessException { return getJdbcOperations().execute(getPreparedStatementCreator(sql, paramSource), action); } @Override - @Nullable - public T execute(String sql, Map paramMap, PreparedStatementCallback action) + public @Nullable T execute(String sql, Map paramMap, PreparedStatementCallback action) throws DataAccessException { return execute(sql, new MapSqlParameterSource(paramMap), action); } @Override - @Nullable - public T execute(String sql, PreparedStatementCallback action) throws DataAccessException { + public @Nullable T execute(String sql, PreparedStatementCallback action) throws DataAccessException { return execute(sql, EmptySqlParameterSource.INSTANCE, action); } @Override - @Nullable - public T query(String sql, SqlParameterSource paramSource, ResultSetExtractor rse) + public @Nullable T query(String sql, SqlParameterSource paramSource, ResultSetExtractor rse) throws DataAccessException { return getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rse); } @Override - @Nullable - public T query(String sql, Map paramMap, ResultSetExtractor rse) + public @Nullable T query(String sql, Map paramMap, ResultSetExtractor rse) throws DataAccessException { return query(sql, new MapSqlParameterSource(paramMap), rse); } @Override - @Nullable - public T query(String sql, ResultSetExtractor rse) throws DataAccessException { + public @Nullable T query(String sql, ResultSetExtractor rse) throws DataAccessException { return query(sql, EmptySqlParameterSource.INSTANCE, rse); } @@ -245,8 +240,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations } @Override - @Nullable - public T queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper) + public @Nullable T queryForObject(String sql, SqlParameterSource paramSource, RowMapper rowMapper) throws DataAccessException { List results = getJdbcOperations().query(getPreparedStatementCreator(sql, paramSource), rowMapper); @@ -254,24 +248,21 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations } @Override - @Nullable - public T queryForObject(String sql, Map paramMap, RowMapperrowMapper) + public @Nullable T queryForObject(String sql, Map paramMap, RowMapperrowMapper) throws DataAccessException { return queryForObject(sql, new MapSqlParameterSource(paramMap), rowMapper); } @Override - @Nullable - public T queryForObject(String sql, SqlParameterSource paramSource, Class requiredType) + public @Nullable T queryForObject(String sql, SqlParameterSource paramSource, Class requiredType) throws DataAccessException { return queryForObject(sql, paramSource, new SingleColumnRowMapper<>(requiredType)); } @Override - @Nullable - public T queryForObject(String sql, Map paramMap, Class requiredType) + public @Nullable T queryForObject(String sql, Map paramMap, Class requiredType) throws DataAccessException { return queryForObject(sql, paramMap, new SingleColumnRowMapper<>(requiredType)); @@ -351,7 +342,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations @Override public int update( - String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, @Nullable String[] keyColumnNames) + String sql, SqlParameterSource paramSource, KeyHolder generatedKeyHolder, String @Nullable [] keyColumnNames) throws DataAccessException { PreparedStatementCreator psc = getPreparedStatementCreator(sql, paramSource, pscf -> { @@ -401,7 +392,7 @@ public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations @Override public int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder generatedKeyHolder, - @Nullable String[] keyColumnNames) { + String @Nullable [] keyColumnNames) { if (batchArgs.length == 0) { return new int[0]; 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 4d9f1141df..750cf85ad0 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 @@ -22,10 +22,11 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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; /** @@ -387,8 +388,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( + private static @Nullable SqlParameter findParameter( @Nullable List declaredParams, String paramName, int paramIndex) { if (declaredParams != null) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SimplePropertySqlParameterSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SimplePropertySqlParameterSource.java index 60583679a7..ca018cfd6d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SimplePropertySqlParameterSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SimplePropertySqlParameterSource.java @@ -21,9 +21,10 @@ import java.lang.reflect.Field; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.jdbc.core.StatementCreatorUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -72,8 +73,7 @@ public class SimplePropertySqlParameterSource extends AbstractSqlParameterSource } @Override - @Nullable - public Object getValue(String paramName) throws IllegalArgumentException { + public @Nullable Object getValue(String paramName) throws IllegalArgumentException { Object desc = getDescriptor(paramName); if (desc instanceof PropertyDescriptor pd) { ReflectionUtils.makeAccessible(pd.getReadMethod()); 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 63747b2528..48340f4abd 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 @@ -16,8 +16,9 @@ package org.springframework.jdbc.core.namedparam; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.support.JdbcUtils; -import org.springframework.lang.Nullable; /** * Interface that defines common functionality for objects that can @@ -63,8 +64,7 @@ public interface SqlParameterSource { * @return the value of the specified parameter * @throws IllegalArgumentException if there is no value for the requested parameter */ - @Nullable - Object getValue(String paramName) throws IllegalArgumentException; + @Nullable Object getValue(String paramName) throws IllegalArgumentException; /** * Determine the SQL type for the specified named parameter. @@ -83,8 +83,7 @@ public interface SqlParameterSource { * @return the type name of the specified parameter, * or {@code null} if not known */ - @Nullable - default String getTypeName(String paramName) { + default @Nullable String getTypeName(String paramName) { return null; } @@ -97,8 +96,7 @@ public interface SqlParameterSource { * @since 5.0.3 * @see SqlParameterSourceUtils#extractCaseInsensitiveParameterNames */ - @Nullable - default String[] getParameterNames() { + default String @Nullable [] getParameterNames() { return null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSourceUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSourceUtils.java index 9709561eb2..81c303c8ee 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSourceUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSourceUtils.java @@ -22,8 +22,9 @@ import java.util.HashMap; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.SqlParameterValue; -import org.springframework.lang.Nullable; /** * Class that provides helper methods for the use of {@link SqlParameterSource}, @@ -95,8 +96,7 @@ public abstract class SqlParameterSourceUtils { * @return the value object * @see SqlParameterValue */ - @Nullable - public static Object getTypedValue(SqlParameterSource source, String parameterName) { + public static @Nullable Object getTypedValue(SqlParameterSource source, String parameterName) { int sqlType = source.getSqlType(parameterName); if (sqlType != SqlParameterSource.TYPE_UNKNOWN) { return new SqlParameterValue(sqlType, source.getTypeName(parameterName), source.getValue(parameterName)); 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 d3fc2928d6..1b4a01787c 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,9 +10,7 @@ * the {@code getJdbcOperations()} method of NamedParameterJdbcTemplate and * work with the returned classic template, or use a JdbcTemplate instance directly. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.core.namedparam; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2d79acddb0..0d0e604d4e 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,9 +2,7 @@ * Provides the core JDBC framework, based on JdbcTemplate * and its associated callback interfaces and helper objects. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.core; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java index d09c7e9e6c..ba027c5705 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java @@ -26,6 +26,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.core.CallableStatementCreator; @@ -35,7 +36,6 @@ import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.metadata.CallMetaDataContext; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -73,15 +73,13 @@ public abstract class AbstractJdbcCall { private volatile boolean compiled; /** The generated string used for call statement. */ - @Nullable - private String callString; + private @Nullable String callString; /** * A delegate enabling us to create CallableStatementCreators * efficiently, based on this class's declared parameters. */ - @Nullable - private CallableStatementCreatorFactory callableStatementFactory; + private @Nullable CallableStatementCreatorFactory callableStatementFactory; /** @@ -119,8 +117,7 @@ public abstract class AbstractJdbcCall { /** * Get the name of the stored procedure. */ - @Nullable - public String getProcedureName() { + public @Nullable String getProcedureName() { return this.callMetaDataContext.getProcedureName(); } @@ -148,8 +145,7 @@ public abstract class AbstractJdbcCall { /** * Get the catalog name used. */ - @Nullable - public String getCatalogName() { + public @Nullable String getCatalogName() { return this.callMetaDataContext.getCatalogName(); } @@ -163,8 +159,7 @@ public abstract class AbstractJdbcCall { /** * Get the schema name used. */ - @Nullable - public String getSchemaName() { + public @Nullable String getSchemaName() { return this.callMetaDataContext.getSchemaName(); } @@ -226,8 +221,7 @@ public abstract class AbstractJdbcCall { /** * Get the call string that should be used based on parameters and meta-data. */ - @Nullable - public String getCallString() { + public @Nullable String getCallString() { return this.callString; } @@ -417,8 +411,7 @@ public abstract class AbstractJdbcCall { * Get the name of a single out parameter or return value. * Used for functions or procedures with one out parameter. */ - @Nullable - protected String getScalarOutParameterName() { + protected @Nullable String getScalarOutParameterName() { return this.callMetaDataContext.getScalarOutParameterName(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java index 6b86dbb673..fbda7f1a32 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java @@ -33,6 +33,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.InvalidDataAccessApiUsageException; @@ -47,7 +48,6 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.KeyHolder; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -131,8 +131,7 @@ public abstract class AbstractJdbcInsert { /** * Get the name of the table for this insert. */ - @Nullable - public String getTableName() { + public @Nullable String getTableName() { return this.tableMetaDataContext.getTableName(); } @@ -147,8 +146,7 @@ public abstract class AbstractJdbcInsert { /** * Get the name of the schema for this insert. */ - @Nullable - public String getSchemaName() { + public @Nullable String getSchemaName() { return this.tableMetaDataContext.getSchemaName(); } @@ -163,8 +161,7 @@ public abstract class AbstractJdbcInsert { /** * Get the name of the catalog for this insert. */ - @Nullable - public String getCatalogName() { + public @Nullable String getCatalogName() { return this.tableMetaDataContext.getCatalogName(); } @@ -616,7 +613,7 @@ public abstract class AbstractJdbcInsert { * @param preparedStatement the PreparedStatement * @param values the values to be set */ - private void setParameterValues(PreparedStatement preparedStatement, List values, @Nullable int... columnTypes) + private void setParameterValues(PreparedStatement preparedStatement, List values, int @Nullable ... columnTypes) throws SQLException { int colIndex = 0; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java index 7ef7d6ccfc..c6f030456d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/DefaultJdbcClient.java @@ -25,6 +25,8 @@ import java.util.stream.Stream; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.JdbcTemplate; @@ -43,7 +45,6 @@ import org.springframework.jdbc.core.namedparam.SimplePropertySqlParameterSource import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.rowset.SqlRowSet; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -268,7 +269,7 @@ final class DefaultJdbcClient implements JdbcClient { return new PreparedStatementCreatorFactory(this.sql).newPreparedStatementCreator(this.indexedParams); } - private PreparedStatementCreator statementCreatorForIndexedParamsWithKeys(@Nullable String[] keyColumnNames) { + private PreparedStatementCreator statementCreatorForIndexedParamsWithKeys(String @Nullable [] keyColumnNames) { PreparedStatementCreatorFactory pscf = new PreparedStatementCreatorFactory(this.sql); if (keyColumnNames != null) { pscf.setGeneratedKeysColumnNames(keyColumnNames); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java index 5f80796b1a..92f646fc69 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/JdbcClient.java @@ -26,6 +26,8 @@ import java.util.stream.Stream; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.ResultSetExtractor; @@ -35,7 +37,6 @@ import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations; import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.KeyHolder; import org.springframework.jdbc.support.rowset.SqlRowSet; -import org.springframework.lang.Nullable; /** * A fluent {@code JdbcClient} with common JDBC query and update operations, diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java index 6331423200..ffcdcfc6f9 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java @@ -22,11 +22,12 @@ import java.util.Map; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.lang.Nullable; /** * A SimpleJdbcCall is a multithreaded, reusable object representing a call @@ -149,44 +150,38 @@ public class SimpleJdbcCall extends AbstractJdbcCall implements SimpleJdbcCallOp } @Override - @Nullable @SuppressWarnings("unchecked") - public T executeFunction(Class returnType, Object... args) { + public @Nullable T executeFunction(Class returnType, Object... args) { return (T) doExecute(args).get(getScalarOutParameterName()); } @Override - @Nullable @SuppressWarnings("unchecked") - public T executeFunction(Class returnType, Map args) { + public @Nullable T executeFunction(Class returnType, Map args) { return (T) doExecute(args).get(getScalarOutParameterName()); } @Override - @Nullable @SuppressWarnings("unchecked") - public T executeFunction(Class returnType, SqlParameterSource args) { + public @Nullable T executeFunction(Class returnType, SqlParameterSource args) { return (T) doExecute(args).get(getScalarOutParameterName()); } @Override - @Nullable @SuppressWarnings("unchecked") - public T executeObject(Class returnType, Object... args) { + public @Nullable T executeObject(Class returnType, Object... args) { return (T) doExecute(args).get(getScalarOutParameterName()); } @Override - @Nullable @SuppressWarnings("unchecked") - public T executeObject(Class returnType, Map args) { + public @Nullable T executeObject(Class returnType, Map args) { return (T) doExecute(args).get(getScalarOutParameterName()); } @Override - @Nullable @SuppressWarnings("unchecked") - public T executeObject(Class returnType, SqlParameterSource args) { + public @Nullable T executeObject(Class returnType, SqlParameterSource args) { return (T) doExecute(args).get(getScalarOutParameterName()); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCallOperations.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCallOperations.java index 91db984792..ea784a4038 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCallOperations.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCallOperations.java @@ -18,10 +18,11 @@ package org.springframework.jdbc.core.simple; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.RowMapper; import org.springframework.jdbc.core.SqlParameter; import org.springframework.jdbc.core.namedparam.SqlParameterSource; -import org.springframework.lang.Nullable; /** * Interface specifying the API for a Simple JDBC Call implemented by {@link SimpleJdbcCall}. @@ -118,8 +119,7 @@ public interface SimpleJdbcCallOperations { * Parameter values must be provided in the same order as the parameters are defined * for the stored procedure. */ - @Nullable - T executeFunction(Class returnType, Object... args); + @Nullable T executeFunction(Class returnType, Object... args); /** * Execute the stored function and return the results obtained as an Object of the @@ -127,8 +127,7 @@ public interface SimpleJdbcCallOperations { * @param returnType the type of the value to return * @param args a Map containing the parameter values to be used in the call */ - @Nullable - T executeFunction(Class returnType, Map args); + @Nullable T executeFunction(Class returnType, Map args); /** * Execute the stored function and return the results obtained as an Object of the @@ -136,8 +135,7 @@ public interface SimpleJdbcCallOperations { * @param returnType the type of the value to return * @param args the MapSqlParameterSource containing the parameter values to be used in the call */ - @Nullable - T executeFunction(Class returnType, SqlParameterSource args); + @Nullable T executeFunction(Class returnType, SqlParameterSource args); /** * Execute the stored procedure and return the single out parameter as an Object @@ -148,8 +146,7 @@ public interface SimpleJdbcCallOperations { * Parameter values must be provided in the same order as the parameters are defined for * the stored procedure. */ - @Nullable - T executeObject(Class returnType, Object... args); + @Nullable T executeObject(Class returnType, Object... args); /** * Execute the stored procedure and return the single out parameter as an Object @@ -158,8 +155,7 @@ public interface SimpleJdbcCallOperations { * @param returnType the type of the value to return * @param args a Map containing the parameter values to be used in the call */ - @Nullable - T executeObject(Class returnType, Map args); + @Nullable T executeObject(Class returnType, Map args); /** * Execute the stored procedure and return the single out parameter as an Object @@ -168,8 +164,7 @@ public interface SimpleJdbcCallOperations { * @param returnType the type of the value to return * @param args the MapSqlParameterSource containing the parameter values to be used in the call */ - @Nullable - T executeObject(Class returnType, SqlParameterSource args); + @Nullable T executeObject(Class returnType, SqlParameterSource args); /** * Execute the stored procedure and return a map of output params, keyed by name 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 d8a3bb7e53..59c640dc11 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 @@ -8,9 +8,7 @@ * meta-data 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 meta-data. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.core.simple; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java index c56e4a2811..a6d8516df4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractLobStreamingResultSetExtractor.java @@ -20,12 +20,13 @@ import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.jdbc.LobRetrievalFailureException; import org.springframework.jdbc.core.ResultSetExtractor; -import org.springframework.lang.Nullable; /** * Abstract ResultSetExtractor implementation that assumes streaming of LOB data. @@ -70,8 +71,7 @@ public abstract class AbstractLobStreamingResultSetExtractor implements Resul * @see org.springframework.jdbc.LobRetrievalFailureException */ @Override - @Nullable - public final T extractData(ResultSet rs) throws SQLException, DataAccessException { + public final @Nullable T extractData(ResultSet rs) throws SQLException, DataAccessException { if (!rs.next()) { handleNoRowFound(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractSqlTypeValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractSqlTypeValue.java index 28e10a9852..fb04aeb083 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractSqlTypeValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/AbstractSqlTypeValue.java @@ -20,8 +20,9 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.SqlTypeValue; -import org.springframework.lang.Nullable; /** * Abstract implementation of the SqlTypeValue interface, for convenient diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java index 9f932a5cfd..c6db333402 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcBeanDefinitionReader.java @@ -20,9 +20,10 @@ import java.util.Properties; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -49,8 +50,7 @@ public class JdbcBeanDefinitionReader { private final org.springframework.beans.factory.support.PropertiesBeanDefinitionReader propReader; - @Nullable - private JdbcTemplate jdbcTemplate; + private @Nullable JdbcTemplate jdbcTemplate; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcDaoSupport.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcDaoSupport.java index f9a5ceb934..5ff1f765f7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcDaoSupport.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/JdbcDaoSupport.java @@ -20,12 +20,13 @@ import java.sql.Connection; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.support.DaoSupport; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.support.SQLExceptionTranslator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -47,8 +48,7 @@ import org.springframework.util.Assert; */ public abstract class JdbcDaoSupport extends DaoSupport { - @Nullable - private JdbcTemplate jdbcTemplate; + private @Nullable JdbcTemplate jdbcTemplate; /** @@ -77,8 +77,7 @@ public abstract class JdbcDaoSupport extends DaoSupport { /** * Return the JDBC DataSource used by this DAO. */ - @Nullable - public final DataSource getDataSource() { + public final @Nullable DataSource getDataSource() { return (this.jdbcTemplate != null ? this.jdbcTemplate.getDataSource() : null); } @@ -95,8 +94,7 @@ public abstract class JdbcDaoSupport extends DaoSupport { * Return the JdbcTemplate for this DAO, * pre-initialized with the DataSource or set explicitly. */ - @Nullable - public final JdbcTemplate getJdbcTemplate() { + public final @Nullable JdbcTemplate getJdbcTemplate() { return this.jdbcTemplate; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlBinaryValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlBinaryValue.java index 08a9f3019c..7f113eb5f6 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlBinaryValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlBinaryValue.java @@ -23,10 +23,11 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.InputStreamSource; import org.springframework.core.io.Resource; import org.springframework.jdbc.core.SqlTypeValue; -import org.springframework.lang.Nullable; /** * Object to represent a binary parameter value for a SQL statement, for example, diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlCharacterValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlCharacterValue.java index aaaf80d798..6ef5e04fa2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlCharacterValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlCharacterValue.java @@ -24,8 +24,9 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.SqlTypeValue; -import org.springframework.lang.Nullable; /** * Object to represent a character-based parameter value for a SQL statement, diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java index c208be0e3f..15bd704aaf 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/support/SqlLobValue.java @@ -22,11 +22,12 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.DisposableSqlTypeValue; import org.springframework.jdbc.support.lob.DefaultLobHandler; import org.springframework.jdbc.support.lob.LobCreator; import org.springframework.jdbc.support.lob.LobHandler; -import org.springframework.lang.Nullable; /** * Object to represent an SQL BLOB/CLOB value parameter. BLOBs can either be an @@ -73,8 +74,7 @@ import org.springframework.lang.Nullable; @Deprecated(since = "6.2") public class SqlLobValue implements DisposableSqlTypeValue { - @Nullable - private final Object content; + private final @Nullable Object content; private final int length; @@ -90,7 +90,7 @@ public class SqlLobValue implements DisposableSqlTypeValue { * @param bytes the byte array containing the BLOB value * @see org.springframework.jdbc.support.lob.DefaultLobHandler */ - public SqlLobValue(@Nullable byte[] bytes) { + public SqlLobValue(byte @Nullable [] bytes) { this(bytes, new DefaultLobHandler()); } @@ -99,7 +99,7 @@ public class SqlLobValue implements DisposableSqlTypeValue { * @param bytes the byte array containing the BLOB value * @param lobHandler the LobHandler to be used */ - public SqlLobValue(@Nullable byte[] bytes, LobHandler lobHandler) { + public SqlLobValue(byte @Nullable [] bytes, LobHandler lobHandler) { this.content = bytes; this.length = (bytes != null ? bytes.length : 0); this.lobCreator = lobHandler.getLobCreator(); 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 7e0621e774..b8969eabd1 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,9 +2,7 @@ * Classes supporting the {@code org.springframework.jdbc.core} package. * Contains a DAO base class for JdbcTemplate usage. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.core.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 df6df3e627..075d983f49 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,7 +20,7 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Properties; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract base class for JDBC {@link javax.sql.DataSource} implementations @@ -33,23 +33,17 @@ import org.springframework.lang.Nullable; */ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { - @Nullable - private String url; + private @Nullable String url; - @Nullable - private String username; + private @Nullable String username; - @Nullable - private String password; + private @Nullable String password; - @Nullable - private String catalog; + private @Nullable String catalog; - @Nullable - private String schema; + private @Nullable String schema; - @Nullable - private Properties connectionProperties; + private @Nullable Properties connectionProperties; /** @@ -63,8 +57,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { /** * Return the JDBC URL to use for connecting through the Driver. */ - @Nullable - public String getUrl() { + public @Nullable String getUrl() { return this.url; } @@ -79,8 +72,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { /** * Return the JDBC username to use for connecting through the Driver. */ - @Nullable - public String getUsername() { + public @Nullable String getUsername() { return this.username; } @@ -95,8 +87,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { /** * Return the JDBC password to use for connecting through the Driver. */ - @Nullable - public String getPassword() { + public @Nullable String getPassword() { return this.password; } @@ -113,8 +104,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() { + public @Nullable String getCatalog() { return this.catalog; } @@ -131,8 +121,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() { + public @Nullable String getSchema() { return this.schema; } @@ -151,8 +140,7 @@ public abstract class AbstractDriverBasedDataSource extends AbstractDataSource { /** * Return the connection properties to be passed to the Driver, if any. */ - @Nullable - public Properties getConnectionProperties() { + public @Nullable Properties getConnectionProperties() { return this.connectionProperties; } 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 c8f01712c8..644036065e 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,7 +20,8 @@ import java.sql.Connection; import java.sql.SQLException; import java.sql.Savepoint; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.support.ResourceHolderSupport; import org.springframework.util.Assert; @@ -47,16 +48,13 @@ public class ConnectionHolder extends ResourceHolderSupport { public static final String SAVEPOINT_NAME_PREFIX = "SAVEPOINT_"; - @Nullable - private ConnectionHandle connectionHandle; + private @Nullable ConnectionHandle connectionHandle; - @Nullable - private Connection currentConnection; + private @Nullable Connection currentConnection; private boolean transactionActive = false; - @Nullable - private Boolean savepointsSupported; + private @Nullable Boolean savepointsSupported; private int savepointCounter = 0; @@ -99,8 +97,7 @@ public class ConnectionHolder extends ResourceHolderSupport { /** * Return the ConnectionHandle held by this ConnectionHolder. */ - @Nullable - public ConnectionHandle getConnectionHandle() { + public @Nullable ConnectionHandle getConnectionHandle() { return this.connectionHandle; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java index 49d111d3d6..6069e2016b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceTransactionManager.java @@ -22,8 +22,9 @@ import java.sql.Statement; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionSystemException; @@ -121,8 +122,7 @@ import org.springframework.util.Assert; public class DataSourceTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, InitializingBean { - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; private boolean enforceReadOnly = false; @@ -180,8 +180,7 @@ public class DataSourceTransactionManager extends AbstractPlatformTransactionMan /** * Return the JDBC {@code DataSource} that this instance manages transactions for. */ - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { return this.dataSource; } 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 ad99f2e2d5..05adc17892 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 @@ -24,9 +24,9 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jdbc.CannotGetJdbcConnectionException; -import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -174,8 +174,7 @@ public abstract class DataSourceUtils { * @see Connection#setTransactionIsolation * @see Connection#setReadOnly */ - @Nullable - public static Integer prepareConnectionForTransaction(Connection con, @Nullable TransactionDefinition definition) + public static @Nullable Integer prepareConnectionForTransaction(Connection con, @Nullable TransactionDefinition definition) throws SQLException { Assert.notNull(con, "No Connection specified"); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java index fccd2b69b6..d99de4f802 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DelegatingDataSource.java @@ -25,8 +25,9 @@ import java.util.logging.Logger; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -43,8 +44,7 @@ import org.springframework.util.Assert; */ public class DelegatingDataSource implements DataSource, InitializingBean { - @Nullable - private DataSource targetDataSource; + private @Nullable DataSource targetDataSource; /** @@ -73,8 +73,7 @@ public class DelegatingDataSource implements DataSource, InitializingBean { /** * Return the target DataSource that this DataSource should delegate to. */ - @Nullable - public DataSource getTargetDataSource() { + public @Nullable DataSource getTargetDataSource() { return this.targetDataSource; } 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 86a7b91de7..6a624e4708 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,7 +20,8 @@ import java.sql.Connection; import java.sql.SQLException; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -69,8 +70,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd ); - @Nullable - private Integer isolationLevel; + private @Nullable Integer isolationLevel; /** @@ -122,8 +122,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd * Return the statically specified isolation level, * or {@code null} if none. */ - @Nullable - protected Integer getIsolationLevel() { + protected @Nullable Integer getIsolationLevel() { return this.isolationLevel; } @@ -155,8 +154,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd * @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionIsolationLevel() * @see #setIsolationLevel */ - @Nullable - protected Integer getCurrentIsolationLevel() { + protected @Nullable Integer getCurrentIsolationLevel() { Integer isolationLevelToUse = TransactionSynchronizationManager.getCurrentTransactionIsolationLevel(); if (isolationLevelToUse == null) { isolationLevelToUse = getIsolationLevel(); @@ -170,8 +168,7 @@ public class IsolationLevelDataSourceAdapter extends UserCredentialsDataSourceAd * @return whether there is a read-only hint for the current scope * @see org.springframework.transaction.support.TransactionSynchronizationManager#isCurrentTransactionReadOnly() */ - @Nullable - protected Boolean getCurrentReadOnlyFlag() { + protected @Nullable Boolean getCurrentReadOnlyFlag() { boolean txReadOnly = TransactionSynchronizationManager.isCurrentTransactionReadOnly(); return (txReadOnly ? Boolean.TRUE : null); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/JdbcTransactionObjectSupport.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/JdbcTransactionObjectSupport.java index 49421e52fc..580eba7c38 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/JdbcTransactionObjectSupport.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/JdbcTransactionObjectSupport.java @@ -20,7 +20,8 @@ import java.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.sql.Savepoint; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.NestedTransactionNotSupportedException; import org.springframework.transaction.SavepointManager; @@ -46,11 +47,9 @@ import org.springframework.util.Assert; */ public abstract class JdbcTransactionObjectSupport implements SavepointManager, SmartTransactionObject { - @Nullable - private ConnectionHolder connectionHolder; + private @Nullable ConnectionHolder connectionHolder; - @Nullable - private Integer previousIsolationLevel; + private @Nullable Integer previousIsolationLevel; private boolean readOnly = false; @@ -89,8 +88,7 @@ public abstract class JdbcTransactionObjectSupport implements SavepointManager, /** * Return the retained previous isolation level, if any. */ - @Nullable - public Integer getPreviousIsolationLevel() { + public @Nullable Integer getPreviousIsolationLevel() { return this.previousIsolationLevel; } 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 38cd26a627..313bfb944e 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 @@ -29,8 +29,8 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -104,14 +104,11 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { private static final Log logger = LogFactory.getLog(LazyConnectionDataSourceProxy.class); - @Nullable - private DataSource readOnlyDataSource; + private @Nullable DataSource readOnlyDataSource; - @Nullable - private volatile Boolean defaultAutoCommit; + private volatile @Nullable Boolean defaultAutoCommit; - @Nullable - private volatile Integer defaultTransactionIsolation; + private volatile @Nullable Integer defaultTransactionIsolation; /** @@ -238,16 +235,14 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { /** * Expose the default auto-commit value. */ - @Nullable - protected Boolean defaultAutoCommit() { + protected @Nullable Boolean defaultAutoCommit() { return this.defaultAutoCommit; } /** * Expose the default transaction isolation value. */ - @Nullable - protected Integer defaultTransactionIsolation() { + protected @Nullable Integer defaultTransactionIsolation() { return this.defaultTransactionIsolation; } @@ -295,17 +290,13 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { */ private class LazyConnectionInvocationHandler implements InvocationHandler { - @Nullable - private String username; + private @Nullable String username; - @Nullable - private String password; + private @Nullable String password; - @Nullable - private Boolean autoCommit; + private @Nullable Boolean autoCommit; - @Nullable - private Integer transactionIsolation; + private @Nullable Integer transactionIsolation; private boolean readOnly = false; @@ -313,8 +304,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { private boolean closed = false; - @Nullable - private Connection target; + private @Nullable Connection target; public LazyConnectionInvocationHandler() { this.autoCommit = defaultAutoCommit(); @@ -328,8 +318,7 @@ public class LazyConnectionDataSourceProxy extends DelegatingDataSource { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... switch (method.getName()) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java index 13194ec754..73e97529e0 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyDataSourceAdapter.java @@ -23,7 +23,7 @@ import java.sql.ShardingKey; import javax.sql.DataSource; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An adapter for a target {@link DataSource}, designed to apply sharding keys, if specified, @@ -53,8 +53,7 @@ import org.springframework.lang.Nullable; */ public class ShardingKeyDataSourceAdapter extends DelegatingDataSource { - @Nullable - private ShardingKeyProvider shardingkeyProvider; + private @Nullable ShardingKeyProvider shardingkeyProvider; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyProvider.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyProvider.java index f9c99b177f..3f868dc19f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyProvider.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/ShardingKeyProvider.java @@ -19,7 +19,7 @@ package org.springframework.jdbc.datasource; import java.sql.SQLException; import java.sql.ShardingKey; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for determining sharding keys which are used to establish direct @@ -43,8 +43,7 @@ public interface ShardingKeyProvider { * @return the sharding key, or {@code null} if it is not available or cannot be determined * @throws SQLException if an error occurs while obtaining the sharding key */ - @Nullable - ShardingKey getShardingKey() throws SQLException; + @Nullable ShardingKey getShardingKey() throws SQLException; /** * Determine the super sharding key, if any. This method returns the super sharding key @@ -53,8 +52,7 @@ public interface ShardingKeyProvider { * determined (the default) * @throws SQLException if an error occurs while obtaining the super sharding key */ - @Nullable - default ShardingKey getSuperShardingKey() throws SQLException { + default @Nullable ShardingKey getSuperShardingKey() throws SQLException { return null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java index 99a00687e4..e81365a540 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SimpleDriverDataSource.java @@ -21,8 +21,9 @@ import java.sql.Driver; import java.sql.SQLException; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -54,8 +55,7 @@ import org.springframework.util.Assert; */ public class SimpleDriverDataSource extends AbstractDriverBasedDataSource { - @Nullable - private Driver driver; + private @Nullable Driver driver; /** @@ -127,8 +127,7 @@ public class SimpleDriverDataSource extends AbstractDriverBasedDataSource { /** * Return the JDBC Driver instance to use. */ - @Nullable - public Driver getDriver() { + public @Nullable Driver getDriver() { return this.driver; } 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 a258aa3a21..6fdef5d1ff 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 @@ -25,8 +25,9 @@ import java.sql.SQLException; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.DisposableBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -64,16 +65,13 @@ public class SingleConnectionDataSource extends DriverManagerDataSource private boolean rollbackBeforeClose; /** Override auto-commit state? */ - @Nullable - private Boolean autoCommit; + private @Nullable Boolean autoCommit; /** Wrapped Connection. */ - @Nullable - private Connection target; + private @Nullable Connection target; /** Proxy Connection. */ - @Nullable - private Connection connection; + private @Nullable Connection connection; /** Lifecycle lock for the shared Connection. */ private final Lock connectionLock = new ReentrantLock(); @@ -175,8 +173,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource * 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() { + protected @Nullable Boolean getAutoCommitValue() { return this.autoCommit; } @@ -368,8 +365,7 @@ public class SingleConnectionDataSource extends DriverManagerDataSource } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... return switch (method.getName()) { 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 d9cfce3885..f3f95f2e30 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 @@ -26,7 +26,8 @@ import java.sql.Statement; import javax.sql.DataSource; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.support.TransactionSynchronizationManager; /** @@ -180,8 +181,7 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource { private final DataSource targetDataSource; - @Nullable - private Connection target; + private @Nullable Connection target; private boolean closed = false; @@ -190,8 +190,7 @@ public class TransactionAwareDataSourceProxy extends DelegatingDataSource { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on ConnectionProxy interface coming in... switch (method.getName()) { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java index 98203528fc..b47a3ca381 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.java @@ -19,8 +19,9 @@ package org.springframework.jdbc.datasource; import java.sql.Connection; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -62,17 +63,13 @@ import org.springframework.util.StringUtils; */ public class UserCredentialsDataSourceAdapter extends DelegatingDataSource { - @Nullable - private String username; + private @Nullable String username; - @Nullable - private String password; + private @Nullable String password; - @Nullable - private String catalog; + private @Nullable String catalog; - @Nullable - private String schema; + private @Nullable String schema; private final ThreadLocal threadBoundCredentials = new NamedThreadLocal<>("Current JDBC user credentials"); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java index 7375d7044e..f764a3b08c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/DerbyEmbeddedDatabaseConfigurer.java @@ -23,8 +23,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.LogFactory; import org.apache.derby.jdbc.EmbeddedDriver; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link EmbeddedDatabaseConfigurer} for the Apache Derby database. @@ -39,8 +38,7 @@ final class DerbyEmbeddedDatabaseConfigurer implements EmbeddedDatabaseConfigure private static final String URL_TEMPLATE = "jdbc:derby:memory:%s;%s"; - @Nullable - private static DerbyEmbeddedDatabaseConfigurer instance; + private static @Nullable DerbyEmbeddedDatabaseConfigurer instance; /** 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 0b08b5955d..d7205235ca 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 @@ -26,11 +26,11 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; /** @@ -80,14 +80,11 @@ public class EmbeddedDatabaseFactory { private DataSourceFactory dataSourceFactory = new SimpleDriverDataSourceFactory(); - @Nullable - private EmbeddedDatabaseConfigurer databaseConfigurer; + private @Nullable EmbeddedDatabaseConfigurer databaseConfigurer; - @Nullable - private DatabasePopulator databasePopulator; + private @Nullable DatabasePopulator databasePopulator; - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; /** @@ -248,8 +245,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() { + protected final @Nullable DataSource getDataSource() { return this.dataSource; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java index a1e0502367..a5659ac564 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBean.java @@ -18,12 +18,13 @@ package org.springframework.jdbc.datasource.embedded; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.datasource.init.DatabasePopulator; import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils; -import org.springframework.lang.Nullable; /** * A subclass of {@link EmbeddedDatabaseFactory} that implements {@link FactoryBean} @@ -44,8 +45,7 @@ import org.springframework.lang.Nullable; public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory implements FactoryBean, InitializingBean, DisposableBean { - @Nullable - private DatabasePopulator databaseCleaner; + private @Nullable DatabasePopulator databaseCleaner; /** @@ -66,8 +66,7 @@ public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory @Override - @Nullable - public DataSource getObject() { + public @Nullable DataSource getObject() { return getDataSource(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java index 9f44861ed8..dc4f5e1cf9 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryRuntimeHints.java @@ -18,10 +18,11 @@ package org.springframework.jdbc.datasource.embedded; import java.util.Collections; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that registers reflection hints diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java index c3a816e0cf..14e92dba38 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/H2EmbeddedDatabaseConfigurer.java @@ -18,7 +18,8 @@ package org.springframework.jdbc.datasource.embedded; import java.sql.Driver; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -33,8 +34,7 @@ import org.springframework.util.ClassUtils; */ final class H2EmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer { - @Nullable - private static H2EmbeddedDatabaseConfigurer instance; + private static @Nullable H2EmbeddedDatabaseConfigurer instance; private final Class driverClass; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java index 8f3c69fe3b..e8c04da4c8 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/HsqlEmbeddedDatabaseConfigurer.java @@ -18,7 +18,8 @@ package org.springframework.jdbc.datasource.embedded; import java.sql.Driver; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -32,8 +33,7 @@ import org.springframework.util.ClassUtils; */ final class HsqlEmbeddedDatabaseConfigurer extends AbstractEmbeddedDatabaseConfigurer { - @Nullable - private static HsqlEmbeddedDatabaseConfigurer instance; + private static @Nullable HsqlEmbeddedDatabaseConfigurer instance; private final Class driverClass; 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 2f9576f22e..2c181736a5 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,9 +1,7 @@ /** * Provides extensible support for creating embedded database instances. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.datasource.embedded; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DataSourceInitializer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DataSourceInitializer.java index 4a57474b55..5e5cec82fc 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DataSourceInitializer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/DataSourceInitializer.java @@ -18,9 +18,10 @@ package org.springframework.jdbc.datasource.init; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -35,14 +36,11 @@ import org.springframework.util.Assert; */ public class DataSourceInitializer implements InitializingBean, DisposableBean { - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; - @Nullable - private DatabasePopulator databasePopulator; + private @Nullable DatabasePopulator databasePopulator; - @Nullable - private DatabasePopulator databaseCleaner; + private @Nullable DatabasePopulator databaseCleaner; private boolean enabled = true; 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 214a857620..45d768bb1a 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 @@ -23,9 +23,10 @@ import java.util.List; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + 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; @@ -57,8 +58,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { List scripts = new ArrayList<>(); - @Nullable - private String sqlScriptEncoding; + private @Nullable String sqlScriptEncoding; private String separator = ScriptUtils.DEFAULT_STATEMENT_SEPARATOR; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptException.java index eb782d1e98..09cd90d48d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptException.java @@ -16,8 +16,9 @@ package org.springframework.jdbc.datasource.init; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Root of the hierarchy of data access exceptions that are related to processing diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptParseException.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptParseException.java index 7c9f3f06b1..d414a82263 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptParseException.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptParseException.java @@ -16,8 +16,9 @@ package org.springframework.jdbc.datasource.init; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.support.EncodedResource; -import org.springframework.lang.Nullable; /** * Thrown by {@link ScriptUtils} if an SQL script cannot be properly parsed. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java index cf1d803b61..0fbfd7b824 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java @@ -27,10 +27,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -330,7 +330,7 @@ public abstract class ScriptUtils { } } - private static String readScript(LineNumberReader lineNumberReader, @Nullable String[] commentPrefixes, + private static String readScript(LineNumberReader lineNumberReader, String @Nullable [] commentPrefixes, @Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException { String currentStatement = lineNumberReader.readLine(); 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 1e1d53e3a6..ac625201d2 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,9 +1,7 @@ /** * Provides extensible support for initializing databases through scripts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.datasource.init; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java index b9d203f202..02065d765d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/AbstractRoutingDataSource.java @@ -25,9 +25,10 @@ import java.util.Map; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.datasource.AbstractDataSource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -44,21 +45,17 @@ import org.springframework.util.CollectionUtils; */ public abstract class AbstractRoutingDataSource extends AbstractDataSource implements InitializingBean { - @Nullable - private Map targetDataSources; + private @Nullable Map targetDataSources; - @Nullable - private Object defaultTargetDataSource; + private @Nullable Object defaultTargetDataSource; private boolean lenientFallback = true; private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); - @Nullable - private Map resolvedDataSources; + private @Nullable Map resolvedDataSources; - @Nullable - private DataSource resolvedDefaultDataSource; + private @Nullable DataSource resolvedDefaultDataSource; /** @@ -202,8 +199,7 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple * @since 5.2.9 * @see #setDefaultTargetDataSource */ - @Nullable - public DataSource getResolvedDefaultDataSource() { + public @Nullable DataSource getResolvedDefaultDataSource() { return this.resolvedDefaultDataSource; } @@ -271,7 +267,6 @@ public abstract class AbstractRoutingDataSource extends AbstractDataSource imple * to match the stored lookup key type, as resolved by the * {@link #resolveSpecifiedLookupKey} method. */ - @Nullable - protected abstract Object determineCurrentLookupKey(); + protected abstract @Nullable Object determineCurrentLookupKey(); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookup.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookup.java index ff7e8825ae..a8eb53048b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookup.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/BeanFactoryDataSourceLookup.java @@ -18,10 +18,11 @@ package org.springframework.jdbc.datasource.lookup; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +38,7 @@ import org.springframework.util.Assert; */ public class BeanFactoryDataSourceLookup implements DataSourceLookup, BeanFactoryAware { - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java index 1ee290230a..70ca89daab 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/lookup/IsolationLevelDataSourceRouter.java @@ -18,7 +18,8 @@ package org.springframework.jdbc.datasource.lookup; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -133,8 +134,7 @@ public class IsolationLevelDataSourceRouter extends AbstractRoutingDataSource { } @Override - @Nullable - protected Object determineCurrentLookupKey() { + protected @Nullable Object determineCurrentLookupKey() { return TransactionSynchronizationManager.getCurrentTransactionIsolationLevel(); } 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 297a8051c1..19a17d079f 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 @@ -22,7 +22,8 @@ import java.util.Map; import javax.sql.DataSource; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** 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 e5dd2ecb86..901256a8a6 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,9 +1,7 @@ /** * Provides a strategy for looking up JDBC DataSources by name. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.datasource.lookup; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 baa79a5f86..619f2e139d 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,9 +3,7 @@ * a PlatformTransactionManager for a single DataSource, * and various simple DataSource implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.datasource; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/GenericSqlQuery.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/GenericSqlQuery.java index c27089201d..fd9f17ac06 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/GenericSqlQuery.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/GenericSqlQuery.java @@ -18,9 +18,10 @@ package org.springframework.jdbc.object; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.jdbc.core.RowMapper; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -36,12 +37,10 @@ import org.springframework.util.Assert; */ public class GenericSqlQuery extends SqlQuery { - @Nullable - private RowMapper rowMapper; + private @Nullable RowMapper rowMapper; @SuppressWarnings("rawtypes") - @Nullable - private Class rowMapperClass; + private @Nullable Class rowMapperClass; /** @@ -71,7 +70,7 @@ public class GenericSqlQuery extends SqlQuery { @Override @SuppressWarnings("unchecked") - protected RowMapper newRowMapper(@Nullable Object[] parameters, @Nullable Map context) { + protected RowMapper newRowMapper(Object @Nullable [] parameters, @Nullable Map context) { if (this.rowMapper != null) { return this.rowMapper; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQuery.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQuery.java index 86e38b0200..b10136dca5 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQuery.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQuery.java @@ -22,7 +22,7 @@ import java.util.Map; import javax.sql.DataSource; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Reusable query in which concrete subclasses must implement the abstract @@ -63,8 +63,7 @@ public abstract class MappingSqlQuery extends MappingSqlQueryWithParameters context) + protected final @Nullable T mapRow(ResultSet rs, int rowNum, Object @Nullable [] parameters, @Nullable Map context) throws SQLException { return mapRow(rs, rowNum); @@ -83,7 +82,6 @@ public abstract class MappingSqlQuery extends MappingSqlQueryWithParameters extends SqlQuery { * implementation of the mapRow() method. */ @Override - protected RowMapper newRowMapper(@Nullable Object[] parameters, @Nullable Map context) { + protected RowMapper newRowMapper(Object @Nullable [] parameters, @Nullable Map context) { return new RowMapperImpl(parameters, context); } @@ -92,8 +93,7 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery { * Subclasses can simply not catch SQLExceptions, relying on the * framework to clean up. */ - @Nullable - protected abstract T mapRow(ResultSet rs, int rowNum, @Nullable Object[] parameters, @Nullable Map context) + protected abstract @Nullable T mapRow(ResultSet rs, int rowNum, Object @Nullable [] parameters, @Nullable Map context) throws SQLException; @@ -103,23 +103,20 @@ public abstract class MappingSqlQueryWithParameters extends SqlQuery { */ protected class RowMapperImpl implements RowMapper { - @Nullable - private final Object[] params; + private final Object @Nullable [] params; - @Nullable - private final Map context; + private final @Nullable Map context; /** * Use an array results. More efficient if we know how many results to expect. */ - public RowMapperImpl(@Nullable Object[] parameters, @Nullable Map context) { + public RowMapperImpl(Object @Nullable [] parameters, @Nullable Map context) { this.params = parameters; this.context = context; } @Override - @Nullable - public T mapRow(ResultSet rs, int rowNum) throws SQLException { + public @Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException { return MappingSqlQueryWithParameters.this.mapRow(rs, rowNum, this.params, this.context); } } 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 fe7b05b111..19acf5eb70 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 @@ -28,12 +28,12 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; import org.springframework.util.Assert; /** @@ -73,11 +73,9 @@ public abstract class RdbmsOperation implements InitializingBean { private boolean returnGeneratedKeys = false; - @Nullable - private String[] generatedKeysColumnNames; + private String @Nullable [] generatedKeysColumnNames; - @Nullable - private String sql; + private @Nullable String sql; private final List declaredParameters = new ArrayList<>(); @@ -212,7 +210,7 @@ public abstract class RdbmsOperation implements InitializingBean { * Set the column names of the auto-generated keys. * @see java.sql.Connection#prepareStatement(String, String[]) */ - public void setGeneratedKeysColumnNames(@Nullable String... names) { + public void setGeneratedKeysColumnNames(String @Nullable ... names) { if (isCompiled()) { throw new InvalidDataAccessApiUsageException( "The column names for the generated keys must be set before the operation is compiled"); @@ -223,8 +221,7 @@ public abstract class RdbmsOperation implements InitializingBean { /** * Return the column names of the auto generated keys. */ - @Nullable - public String[] getGeneratedKeysColumnNames() { + public String @Nullable [] getGeneratedKeysColumnNames() { return this.generatedKeysColumnNames; } @@ -239,8 +236,7 @@ public abstract class RdbmsOperation implements InitializingBean { * Subclasses can override this to supply dynamic SQL if they wish, but SQL is * normally set by calling the {@link #setSql} method or in a subclass constructor. */ - @Nullable - public String getSql() { + public @Nullable String getSql() { return this.sql; } @@ -264,7 +260,7 @@ public abstract class RdbmsOperation implements InitializingBean { * {@code java.sql.Types} class * @throws InvalidDataAccessApiUsageException if the operation is already compiled */ - public void setTypes(@Nullable int[] types) throws InvalidDataAccessApiUsageException { + public void setTypes(int @Nullable [] types) throws InvalidDataAccessApiUsageException { if (isCompiled()) { throw new InvalidDataAccessApiUsageException("Cannot add parameters once query is compiled"); } @@ -390,7 +386,7 @@ public abstract class RdbmsOperation implements InitializingBean { * @param parameters the parameters supplied (may be {@code null}) * @throws InvalidDataAccessApiUsageException if the parameters are invalid */ - protected void validateParameters(@Nullable Object[] parameters) throws InvalidDataAccessApiUsageException { + protected void validateParameters(Object @Nullable [] parameters) throws InvalidDataAccessApiUsageException { checkCompiled(); int declaredInParameters = 0; for (SqlParameter param : this.declaredParameters) { 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 0f8600659f..5c3c182c57 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 @@ -21,11 +21,12 @@ import java.util.Map; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + 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; import org.springframework.util.Assert; /** @@ -58,15 +59,13 @@ public abstract class SqlCall extends RdbmsOperation { * String of form {call add_invoice(?, ?, ?)} or {? = call get_invoice_count(?)} * if isFunction is set to true. Updated after each parameter is added. */ - @Nullable - private String callString; + private @Nullable String callString; /** * Object enabling us to create CallableStatementCreators * efficiently, based on this class's declared parameters. */ - @Nullable - private CallableStatementCreatorFactory callableStatementFactory; + private @Nullable CallableStatementCreatorFactory callableStatementFactory; /** @@ -177,8 +176,7 @@ public abstract class SqlCall extends RdbmsOperation { /** * Get the call string. */ - @Nullable - public String getCallString() { + public @Nullable String getCallString() { return this.callString; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java index 59408ac658..c9be8bd09e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlFunction.java @@ -21,9 +21,10 @@ import java.sql.SQLException; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.TypeMismatchDataAccessException; import org.springframework.jdbc.core.SingleColumnRowMapper; -import org.springframework.lang.Nullable; /** * SQL "function" wrapper for a query that returns a single row of results. @@ -129,8 +130,7 @@ public class SqlFunction extends MappingSqlQuery { * of rows returned, this is treated as an error. */ @Override - @Nullable - protected T mapRow(ResultSet rs, int rowNum) throws SQLException { + protected @Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException { return this.rowMapper.mapRow(rs, rowNum); } @@ -172,8 +172,7 @@ public class SqlFunction extends MappingSqlQuery { * returning the value as an object. * @return the value of the function */ - @Nullable - public Object runGeneric() { + public @Nullable Object runGeneric() { return findObject((Object[]) null, null); } @@ -182,8 +181,7 @@ public class SqlFunction extends MappingSqlQuery { * @param parameter single int parameter * @return the value of the function as an Object */ - @Nullable - public Object runGeneric(int parameter) { + public @Nullable Object runGeneric(int parameter) { return findObject(parameter); } @@ -195,8 +193,7 @@ public class SqlFunction extends MappingSqlQuery { * @return the value of the function, as an Object * @see #execute(Object[]) */ - @Nullable - public Object runGeneric(Object[] parameters) { + public @Nullable Object runGeneric(Object[] parameters) { return findObject(parameters); } 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 94c4af9eba..de6e817374 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 @@ -16,12 +16,13 @@ package org.springframework.jdbc.object; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.PreparedStatementCreator; 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; import org.springframework.util.Assert; /** @@ -40,12 +41,10 @@ public abstract class SqlOperation extends RdbmsOperation { * Object enabling us to create PreparedStatementCreators efficiently, * based on this class's declared parameters. */ - @Nullable - private PreparedStatementCreatorFactory preparedStatementFactory; + private @Nullable PreparedStatementCreatorFactory preparedStatementFactory; /** Parsed representation of the SQL statement. */ - @Nullable - private ParsedSql cachedSql; + private @Nullable ParsedSql cachedSql; /** Monitor for locking the cached representation of the parsed SQL statement. */ private final Object parsedSqlMonitor = new Object(); @@ -95,7 +94,7 @@ public abstract class SqlOperation extends RdbmsOperation { * with the given parameters. * @param params the parameter array (may be {@code null}) */ - protected final PreparedStatementSetter newPreparedStatementSetter(@Nullable Object[] params) { + protected final PreparedStatementSetter newPreparedStatementSetter(Object @Nullable [] params) { Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available"); return this.preparedStatementFactory.newPreparedStatementSetter(params); } @@ -105,7 +104,7 @@ public abstract class SqlOperation extends RdbmsOperation { * with the given parameters. * @param params the parameter array (may be {@code null}) */ - protected final PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] params) { + protected final PreparedStatementCreator newPreparedStatementCreator(Object @Nullable [] params) { Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available"); return this.preparedStatementFactory.newPreparedStatementCreator(params); } @@ -117,7 +116,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, @Nullable Object[] params) { + protected final PreparedStatementCreator newPreparedStatementCreator(String sqlToUse, Object @Nullable [] params) { Assert.state(this.preparedStatementFactory != null, "No PreparedStatementFactory available"); 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 170771928e..ad0d7b03c2 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 @@ -21,13 +21,14 @@ import java.util.Map; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.dao.support.DataAccessUtils; 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 an SQL query. @@ -108,7 +109,7 @@ public abstract class SqlQuery extends SqlOperation { * @return a List of objects, one per row of the ResultSet. Normally all these * will be of the same class, although it is possible to use different types. */ - public List execute(@Nullable Object[] params, @Nullable Map context) throws DataAccessException { + public List execute(Object @Nullable [] params, @Nullable Map context) throws DataAccessException { validateParameters(params); RowMapper rowMapper = newRowMapper(params, context); return getJdbcTemplate().query(newPreparedStatementCreator(params), rowMapper); @@ -250,8 +251,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(@Nullable Object[] params, @Nullable Map context) throws DataAccessException { + public @Nullable T findObject(Object @Nullable [] params, @Nullable Map context) throws DataAccessException { List results = execute(params, context); return DataAccessUtils.singleResult(results); } @@ -259,8 +259,7 @@ public abstract class SqlQuery extends SqlOperation { /** * Convenient method to find a single object without context. */ - @Nullable - public T findObject(Object... params) throws DataAccessException { + public @Nullable T findObject(Object... params) throws DataAccessException { return findObject(params, null); } @@ -268,16 +267,14 @@ public abstract class SqlQuery extends SqlOperation { * Convenient method to find a single object given a single int parameter * and a context. */ - @Nullable - public T findObject(int p1, @Nullable Map context) throws DataAccessException { + public @Nullable T findObject(int p1, @Nullable Map context) throws DataAccessException { return findObject(new Object[] {p1}, context); } /** * Convenient method to find a single object given a single int parameter. */ - @Nullable - public T findObject(int p1) throws DataAccessException { + public @Nullable T findObject(int p1) throws DataAccessException { return findObject(p1, null); } @@ -285,16 +282,14 @@ public abstract class SqlQuery extends SqlOperation { * Convenient method to find a single object given two int parameters * and a context. */ - @Nullable - public T findObject(int p1, int p2, @Nullable Map context) throws DataAccessException { + public @Nullable T findObject(int p1, int p2, @Nullable Map context) throws DataAccessException { return findObject(new Object[] {p1, p2}, context); } /** * Convenient method to find a single object given two int parameters. */ - @Nullable - public T findObject(int p1, int p2) throws DataAccessException { + public @Nullable T findObject(int p1, int p2) throws DataAccessException { return findObject(p1, p2, null); } @@ -302,16 +297,14 @@ public abstract class SqlQuery extends SqlOperation { * Convenient method to find a single object given a single long parameter * and a context. */ - @Nullable - public T findObject(long p1, @Nullable Map context) throws DataAccessException { + public @Nullable T findObject(long p1, @Nullable Map context) throws DataAccessException { return findObject(new Object[] {p1}, context); } /** * Convenient method to find a single object given a single long parameter. */ - @Nullable - public T findObject(long p1) throws DataAccessException { + public @Nullable T findObject(long p1) throws DataAccessException { return findObject(p1, null); } @@ -319,16 +312,14 @@ public abstract class SqlQuery extends SqlOperation { * Convenient method to find a single object given a single String parameter * and a context. */ - @Nullable - public T findObject(String p1, @Nullable Map context) throws DataAccessException { + public @Nullable T findObject(String p1, @Nullable Map context) throws DataAccessException { return findObject(new Object[] {p1}, context); } /** * Convenient method to find a single object given a single String parameter. */ - @Nullable - public T findObject(String p1) throws DataAccessException { + public @Nullable T findObject(String p1) throws DataAccessException { return findObject(p1, null); } @@ -343,8 +334,7 @@ public abstract class SqlQuery extends SqlOperation { * @return a List of objects, one per row of the ResultSet. Normally all these * will be of the same class, although it is possible to use different types. */ - @Nullable - public T findObjectByNamedParam(Map paramMap, @Nullable Map context) throws DataAccessException { + public @Nullable T findObjectByNamedParam(Map paramMap, @Nullable Map context) throws DataAccessException { List results = executeByNamedParam(paramMap, context); return DataAccessUtils.singleResult(results); } @@ -355,8 +345,7 @@ public abstract class SqlQuery extends SqlOperation { * matching named parameters specified in the SQL statement. * Ordering is not significant. */ - @Nullable - public T findObjectByNamedParam(Map paramMap) throws DataAccessException { + public @Nullable T findObjectByNamedParam(Map paramMap) throws DataAccessException { return findObjectByNamedParam(paramMap, null); } @@ -372,6 +361,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(@Nullable Object[] parameters, @Nullable Map context); + protected abstract RowMapper newRowMapper(Object @Nullable [] parameters, @Nullable Map context); } 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 1c3fa977d2..9e4e3ad1a9 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 @@ -22,8 +22,9 @@ import java.util.Map; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.core.RowMapper; -import org.springframework.lang.Nullable; /** * Reusable RDBMS query in which concrete subclasses must implement @@ -62,7 +63,7 @@ public abstract class UpdatableSqlQuery extends SqlQuery { * implementation of the {@code updateRow()} method. */ @Override - protected RowMapper newRowMapper(@Nullable Object[] parameters, @Nullable Map context) { + protected RowMapper newRowMapper(Object @Nullable [] parameters, @Nullable Map context) { return new RowMapperImpl(context); } @@ -90,8 +91,7 @@ public abstract class UpdatableSqlQuery extends SqlQuery { */ protected class RowMapperImpl implements RowMapper { - @Nullable - private final Map context; + private final @Nullable Map context; public RowMapperImpl(@Nullable Map context) { this.context = context; 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 727aa94964..1274437764 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,9 +14,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.object; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 86f4c59af6..b2a919f527 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,9 +17,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f82e8475ce..89ac060fcf 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 @@ -20,9 +20,9 @@ import java.sql.SQLException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -41,11 +41,9 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private SQLExceptionTranslator fallbackTranslator; + private @Nullable SQLExceptionTranslator fallbackTranslator; - @Nullable - private SQLExceptionTranslator customTranslator; + private @Nullable SQLExceptionTranslator customTranslator; /** @@ -60,8 +58,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep * Return the fallback exception translator, if any. * @see #setFallbackTranslator */ - @Nullable - public SQLExceptionTranslator getFallbackTranslator() { + public @Nullable SQLExceptionTranslator getFallbackTranslator() { return this.fallbackTranslator; } @@ -80,8 +77,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep * @since 6.1 * @see #setCustomTranslator */ - @Nullable - public SQLExceptionTranslator getCustomTranslator() { + public @Nullable SQLExceptionTranslator getCustomTranslator() { return this.customTranslator; } @@ -91,8 +87,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep * {@link #getFallbackTranslator() fallback translator} if necessary. */ @Override - @Nullable - public DataAccessException translate(String task, @Nullable String sql, SQLException ex) { + public @Nullable DataAccessException translate(String task, @Nullable String sql, SQLException ex) { Assert.notNull(ex, "Cannot translate a null SQLException"); SQLExceptionTranslator custom = getCustomTranslator(); @@ -130,8 +125,7 @@ public abstract class AbstractFallbackSQLExceptionTranslator implements SQLExcep * @return the DataAccessException, wrapping the {@code SQLException}; * or {@code null} if no exception match found */ - @Nullable - protected abstract DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex); + protected abstract @Nullable DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex); /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLErrorCodesTranslation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLErrorCodesTranslation.java index 8c84cb3407..d27d479310 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLErrorCodesTranslation.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/CustomSQLErrorCodesTranslation.java @@ -16,8 +16,9 @@ package org.springframework.jdbc.support; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -33,8 +34,7 @@ public class CustomSQLErrorCodesTranslation { private String[] errorCodes = new String[0]; - @Nullable - private Class exceptionClass; + private @Nullable Class exceptionClass; /** @@ -65,8 +65,7 @@ public class CustomSQLErrorCodesTranslation { /** * Return the exception class for the specified error codes. */ - @Nullable - public Class getExceptionClass() { + public @Nullable Class getExceptionClass() { return this.exceptionClass; } 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 259353a04f..ce8e6d2844 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 @@ -21,8 +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.jspecify.annotations.Nullable; /** * Registry for custom {@link SQLExceptionTranslator} instances associated with @@ -91,8 +90,7 @@ public final class CustomSQLExceptionTranslatorRegistry { * @param dbName the database name * @return the custom translator, or {@code null} if none found */ - @Nullable - public SQLExceptionTranslator findTranslatorForDatabase(String dbName) { + public @Nullable SQLExceptionTranslator findTranslatorForDatabase(String dbName) { return this.translatorMap.get(dbName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java index f518103d2e..19cde00c58 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/DatabaseStartupValidator.java @@ -25,10 +25,10 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.jdbc.CannotGetJdbcConnectionException; -import org.springframework.lang.Nullable; /** * Bean that checks if a database has already started up. To be referenced @@ -57,11 +57,9 @@ public class DatabaseStartupValidator implements InitializingBean { protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; - @Nullable - private String validationQuery; + private @Nullable String validationQuery; private int interval = DEFAULT_INTERVAL; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java index d1c26195ed..4bca6a858d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/GeneratedKeyHolder.java @@ -21,9 +21,10 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataRetrievalFailureException; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; /** * The standard implementation of the {@link KeyHolder} interface, to be used for @@ -60,14 +61,12 @@ public class GeneratedKeyHolder implements KeyHolder { @Override - @Nullable - public Number getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException { + public @Nullable Number getKey() throws InvalidDataAccessApiUsageException, DataRetrievalFailureException { return getKeyAs(Number.class); } @Override - @Nullable - public T getKeyAs(Class keyType) throws InvalidDataAccessApiUsageException, DataRetrievalFailureException { + public @Nullable T getKeyAs(Class keyType) throws InvalidDataAccessApiUsageException, DataRetrievalFailureException { if (this.keyList.isEmpty()) { return null; } @@ -94,8 +93,7 @@ public class GeneratedKeyHolder implements KeyHolder { } @Override - @Nullable - public Map getKeys() throws InvalidDataAccessApiUsageException { + public @Nullable Map getKeys() throws InvalidDataAccessApiUsageException { if (this.keyList.isEmpty()) { return null; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcAccessor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcAccessor.java index 5178b4a0f4..7b778b73d7 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcAccessor.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcAccessor.java @@ -20,9 +20,9 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -43,11 +43,9 @@ public abstract class JdbcAccessor implements InitializingBean { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; - @Nullable - private volatile SQLExceptionTranslator exceptionTranslator; + private volatile @Nullable SQLExceptionTranslator exceptionTranslator; private boolean lazyInit = true; @@ -62,8 +60,7 @@ public abstract class JdbcAccessor implements InitializingBean { /** * Return the DataSource used by this template. */ - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { return this.dataSource; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcTransactionManager.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcTransactionManager.java index 6d630cc5f5..82770bde48 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcTransactionManager.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcTransactionManager.java @@ -20,9 +20,10 @@ import java.sql.SQLException; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.jdbc.datasource.DataSourceTransactionManager; -import org.springframework.lang.Nullable; /** * {@link JdbcAccessor}-aligned subclass of the plain {@link DataSourceTransactionManager}, @@ -52,8 +53,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class JdbcTransactionManager extends DataSourceTransactionManager { - @Nullable - private volatile SQLExceptionTranslator exceptionTranslator; + private volatile @Nullable SQLExceptionTranslator exceptionTranslator; private boolean lazyInit = true; 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 84867940ef..84a37f8bcf 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 @@ -36,10 +36,10 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jdbc.CannotGetJdbcConnectionException; import org.springframework.jdbc.datasource.DataSourceUtils; -import org.springframework.lang.Nullable; import org.springframework.util.NumberUtils; import org.springframework.util.StringUtils; @@ -150,8 +150,7 @@ public abstract class JdbcUtils { * @throws SQLException if thrown by the JDBC API * @see #getResultSetValue(ResultSet, int) */ - @Nullable - public static Object getResultSetValue(ResultSet rs, int index, @Nullable Class requiredType) throws SQLException { + public static @Nullable Object getResultSetValue(ResultSet rs, int index, @Nullable Class requiredType) throws SQLException { if (requiredType == null) { return getResultSetValue(rs, index); } @@ -274,8 +273,7 @@ public abstract class JdbcUtils { * @see java.sql.Clob * @see java.sql.Timestamp */ - @Nullable - public static Object getResultSetValue(ResultSet rs, int index) throws SQLException { + public static @Nullable Object getResultSetValue(ResultSet rs, int index) throws SQLException { Object obj = rs.getObject(index); String className = null; if (obj != null) { @@ -445,8 +443,7 @@ public abstract class JdbcUtils { * @param source the name as provided in database meta-data * @return the common name to be used (for example, "DB2" or "Sybase") */ - @Nullable - public static String commonDatabaseName(@Nullable String source) { + public static @Nullable String commonDatabaseName(@Nullable String source) { String name = source; if (source != null && source.startsWith("DB2")) { name = "DB2"; @@ -479,8 +476,7 @@ public abstract class JdbcUtils { * (for example, "VARCHAR"/"NUMERIC"), or {@code null} if not resolvable * @since 5.2 */ - @Nullable - public static String resolveTypeName(int sqlType) { + public static @Nullable String resolveTypeName(int sqlType) { return typeNames.get(sqlType); } 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 e022341d27..15274ef211 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 @@ -19,8 +19,9 @@ package org.springframework.jdbc.support; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; /** * Interface for retrieving keys, typically used for auto-generated keys @@ -58,8 +59,7 @@ public interface KeyHolder { * @throws InvalidDataAccessApiUsageException if multiple keys are encountered * @see #getKeyAs(Class) */ - @Nullable - Number getKey() throws InvalidDataAccessApiUsageException; + @Nullable Number getKey() throws InvalidDataAccessApiUsageException; /** * Retrieve the first item from the first map, assuming that there is just @@ -76,8 +76,7 @@ public interface KeyHolder { * @since 5.3 * @see #getKey() */ - @Nullable - T getKeyAs(Class keyType) throws InvalidDataAccessApiUsageException; + @Nullable T getKeyAs(Class keyType) throws InvalidDataAccessApiUsageException; /** * Retrieve the first map of keys. @@ -86,8 +85,7 @@ public interface KeyHolder { * @return the Map of generated keys for a single row * @throws InvalidDataAccessApiUsageException if keys for multiple rows are encountered */ - @Nullable - Map getKeys() throws InvalidDataAccessApiUsageException; + @Nullable Map getKeys() throws InvalidDataAccessApiUsageException; /** * Return a reference to the List that contains the keys. 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 b7e0af91d5..f402e9e1b2 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 @@ -23,6 +23,8 @@ import java.util.Arrays; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.ClassPathResource; import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.DataAccessException; @@ -33,7 +35,6 @@ 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; import org.springframework.util.function.SingletonSupplier; import org.springframework.util.function.SupplierUtils; @@ -84,8 +85,7 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep new ClassPathResource(SQLErrorCodesFactory.SQL_ERROR_CODE_OVERRIDE_PATH, SQLErrorCodesFactory.class.getClassLoader()).exists(); - @Nullable - private SingletonSupplier sqlErrorCodes; + private @Nullable SingletonSupplier sqlErrorCodes; /** @@ -173,16 +173,14 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep * Usually determined via a DataSource. * @see #setDataSource */ - @Nullable - public SQLErrorCodes getSqlErrorCodes() { + public @Nullable SQLErrorCodes getSqlErrorCodes() { return SupplierUtils.resolve(this.sqlErrorCodes); } @SuppressWarnings("deprecation") @Override - @Nullable - protected DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) { + protected @Nullable DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) { SQLException sqlEx = ex; if (sqlEx instanceof BatchUpdateException && sqlEx.getNextException() != null) { SQLException nestedSqlEx = sqlEx.getNextException(); @@ -312,8 +310,7 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep * @deprecated as of 6.1, in favor of {@link #setCustomTranslator} */ @Deprecated(since = "6.1") - @Nullable - protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) { + protected @Nullable DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlEx) { return null; } @@ -330,8 +327,7 @@ public class SQLErrorCodeSQLExceptionTranslator extends AbstractFallbackSQLExcep * {@code sqlEx} parameter as a nested root cause. * @see CustomSQLErrorCodesTranslation#setExceptionClass */ - @Nullable - protected DataAccessException createCustomException( + protected @Nullable DataAccessException createCustomException( String task, @Nullable String sql, SQLException sqlEx, Class exceptionClass) { // Find appropriate constructor for the given exception class diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodes.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodes.java index 5d4498c052..a990e33401 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodes.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLErrorCodes.java @@ -16,7 +16,8 @@ package org.springframework.jdbc.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -35,8 +36,7 @@ import org.springframework.util.StringUtils; */ public class SQLErrorCodes { - @Nullable - private String[] databaseProductNames; + private String @Nullable [] databaseProductNames; private boolean useSqlStateForTranslation = false; @@ -60,11 +60,9 @@ public class SQLErrorCodes { private String[] cannotSerializeTransactionCodes = new String[0]; - @Nullable - private CustomSQLErrorCodesTranslation[] customTranslations; + private CustomSQLErrorCodesTranslation @Nullable [] customTranslations; - @Nullable - private SQLExceptionTranslator customSqlExceptionTranslator; + private @Nullable SQLExceptionTranslator customSqlExceptionTranslator; /** @@ -75,8 +73,7 @@ public class SQLErrorCodes { this.databaseProductNames = new String[] {databaseProductName}; } - @Nullable - public String getDatabaseProductName() { + public @Nullable String getDatabaseProductName() { return (this.databaseProductNames != null && this.databaseProductNames.length > 0 ? this.databaseProductNames[0] : null); } @@ -85,12 +82,11 @@ public class SQLErrorCodes { * Set this property to specify multiple database names that contains spaces, * in which case we can not use bean names for lookup. */ - public void setDatabaseProductNames(@Nullable String... databaseProductNames) { + public void setDatabaseProductNames(String @Nullable ... databaseProductNames) { this.databaseProductNames = databaseProductNames; } - @Nullable - public String[] getDatabaseProductNames() { + public String @Nullable [] getDatabaseProductNames() { return this.databaseProductNames; } @@ -190,8 +186,7 @@ public class SQLErrorCodes { this.customTranslations = customTranslations; } - @Nullable - public CustomSQLErrorCodesTranslation[] getCustomTranslations() { + public CustomSQLErrorCodesTranslation @Nullable [] getCustomTranslations() { return this.customTranslations; } @@ -214,8 +209,7 @@ public class SQLErrorCodes { this.customSqlExceptionTranslator = customSqlExceptionTranslator; } - @Nullable - public SQLExceptionTranslator getCustomSqlExceptionTranslator() { + public @Nullable SQLExceptionTranslator getCustomSqlExceptionTranslator() { return this.customSqlExceptionTranslator; } 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 4b4575cc8e..65461393da 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 @@ -24,13 +24,13 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; 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; @@ -71,8 +71,7 @@ public class SQLErrorCodesFactory { * Lazily initialized in order to avoid making {@code SQLErrorCodesFactory} constructor * reachable on native images when not needed. */ - @Nullable - private static SQLErrorCodesFactory instance; + private static @Nullable SQLErrorCodesFactory instance; /** @@ -156,8 +155,7 @@ public class SQLErrorCodesFactory { * @return the resource, or {@code null} if the resource wasn't found * @see #getInstance */ - @Nullable - protected Resource loadResource(String path) { + protected @Nullable Resource loadResource(String path) { return new ClassPathResource(path, getClass().getClassLoader()); } @@ -223,8 +221,7 @@ public class SQLErrorCodesFactory { * @since 5.2.9 * @see java.sql.DatabaseMetaData#getDatabaseProductName() */ - @Nullable - public SQLErrorCodes resolveErrorCodes(DataSource dataSource) { + public @Nullable SQLErrorCodes resolveErrorCodes(DataSource dataSource) { Assert.notNull(dataSource, "DataSource must not be null"); if (logger.isDebugEnabled()) { logger.debug("Looking up default SQLErrorCodes for DataSource [" + identify(dataSource) + "]"); @@ -286,8 +283,7 @@ public class SQLErrorCodesFactory { * @since 4.3.5 * @see #registerDatabase(DataSource, String) */ - @Nullable - public SQLErrorCodes unregisterDatabase(DataSource dataSource) { + public @Nullable SQLErrorCodes unregisterDatabase(DataSource dataSource) { return this.dataSourceCache.remove(dataSource); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java index eb5fdcd250..214c1d92ce 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java @@ -30,6 +30,8 @@ import java.sql.SQLTransactionRollbackException; import java.sql.SQLTransientConnectionException; import java.sql.SQLTransientException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; @@ -42,7 +44,6 @@ import org.springframework.dao.QueryTimeoutException; import org.springframework.dao.RecoverableDataAccessException; import org.springframework.dao.TransientDataAccessResourceException; import org.springframework.jdbc.BadSqlGrammarException; -import org.springframework.lang.Nullable; /** * {@link SQLExceptionTranslator} implementation which analyzes the specific @@ -67,8 +68,7 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException } @Override - @Nullable - protected DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) { + protected @Nullable DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) { if (ex instanceof SQLTransientException) { if (ex instanceof SQLTransientConnectionException) { return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); 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 349ea1d29c..4c52546c9c 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 @@ -18,8 +18,9 @@ package org.springframework.jdbc.support; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Strategy interface for translating between {@link SQLException SQLExceptions} @@ -52,7 +53,6 @@ public interface SQLExceptionTranslator { * or {@code null} if no specific translation could be applied * @see org.springframework.dao.DataAccessException#getRootCause() */ - @Nullable - DataAccessException translate(String task, @Nullable 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/SQLStateSQLExceptionTranslator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java index ad68fcf54d..2e9e04b1d2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslator.java @@ -19,6 +19,8 @@ package org.springframework.jdbc.support; import java.sql.SQLException; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; @@ -28,7 +30,6 @@ import org.springframework.dao.PessimisticLockingFailureException; import org.springframework.dao.QueryTimeoutException; import org.springframework.dao.TransientDataAccessResourceException; import org.springframework.jdbc.BadSqlGrammarException; -import org.springframework.lang.Nullable; /** * {@link SQLExceptionTranslator} implementation that analyzes the SQL state in @@ -99,8 +100,7 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException @Override - @Nullable - protected DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) { + protected @Nullable DataAccessException doTranslate(String task, @Nullable String sql, SQLException ex) { // First, the getSQLState check... String sqlState = getSqlState(ex); if (sqlState != null && sqlState.length() >= 2) { @@ -149,8 +149,7 @@ public class SQLStateSQLExceptionTranslator extends AbstractFallbackSQLException * is to be extracted * @return the SQL state code */ - @Nullable - private String getSqlState(SQLException ex) { + private @Nullable String getSqlState(SQLException ex) { String sqlState = ex.getSQLState(); if (sqlState == null) { SQLException nestedEx = ex.getNextException(); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SqlArrayValue.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SqlArrayValue.java index a6834efaed..4f4fc11396 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/SqlArrayValue.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/SqlArrayValue.java @@ -20,8 +20,9 @@ import java.sql.Array; import java.sql.PreparedStatement; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -41,8 +42,7 @@ public class SqlArrayValue implements SqlValue { private final Object[] elements; - @Nullable - private Array array; + private @Nullable Array array; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java index 6f761ea986..8022eec12c 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/AbstractDataFieldMaxValueIncrementer.java @@ -18,9 +18,10 @@ package org.springframework.jdbc.support.incrementer; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -35,12 +36,10 @@ import org.springframework.util.Assert; */ public abstract class AbstractDataFieldMaxValueIncrementer implements DataFieldMaxValueIncrementer, InitializingBean { - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; /** The name of the sequence/table containing the sequence. */ - @Nullable - private String incrementerName; + private @Nullable String incrementerName; /** The length to which a string result should be pre-pended with zeroes. */ protected int paddingLength = 0; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/package-info.java index dab17298db..4fc7bba19a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/package-info.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/package-info.java @@ -4,9 +4,7 @@ * *

    Can be used independently, for example in custom JDBC access code. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.support.incrementer; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java index d2ff13ec95..30d5490c15 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/AbstractLobHandler.java @@ -21,7 +21,7 @@ import java.io.Reader; import java.sql.ResultSet; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract base class for {@link LobHandler} implementations. @@ -39,26 +39,22 @@ import org.springframework.lang.Nullable; public abstract class AbstractLobHandler implements LobHandler { @Override - @Nullable - public byte[] getBlobAsBytes(ResultSet rs, String columnName) throws SQLException { + public byte @Nullable [] getBlobAsBytes(ResultSet rs, String columnName) throws SQLException { return getBlobAsBytes(rs, rs.findColumn(columnName)); } @Override - @Nullable - public InputStream getBlobAsBinaryStream(ResultSet rs, String columnName) throws SQLException { + public @Nullable InputStream getBlobAsBinaryStream(ResultSet rs, String columnName) throws SQLException { return getBlobAsBinaryStream(rs, rs.findColumn(columnName)); } @Override - @Nullable - public String getClobAsString(ResultSet rs, String columnName) throws SQLException { + public @Nullable String getClobAsString(ResultSet rs, String columnName) throws SQLException { return getClobAsString(rs, rs.findColumn(columnName)); } @Override - @Nullable - public InputStream getClobAsAsciiStream(ResultSet rs, String columnName) throws SQLException { + public @Nullable InputStream getClobAsAsciiStream(ResultSet rs, String columnName) throws SQLException { return getClobAsAsciiStream(rs, rs.findColumn(columnName)); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/DefaultLobHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/DefaultLobHandler.java index 01fe9316be..fc497a4f0a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/DefaultLobHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/DefaultLobHandler.java @@ -30,8 +30,7 @@ import java.sql.SQLException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Default implementation of the {@link LobHandler} interface. @@ -151,8 +150,7 @@ public class DefaultLobHandler extends AbstractLobHandler { @Override - @Nullable - public byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException { + public byte @Nullable [] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning BLOB as bytes"); if (this.wrapAsLob) { Blob blob = rs.getBlob(columnIndex); @@ -164,8 +162,7 @@ public class DefaultLobHandler extends AbstractLobHandler { } @Override - @Nullable - public InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { + public @Nullable InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning BLOB as binary stream"); if (this.wrapAsLob) { Blob blob = rs.getBlob(columnIndex); @@ -177,8 +174,7 @@ public class DefaultLobHandler extends AbstractLobHandler { } @Override - @Nullable - public String getClobAsString(ResultSet rs, int columnIndex) throws SQLException { + public @Nullable String getClobAsString(ResultSet rs, int columnIndex) throws SQLException { logger.debug("Returning CLOB as string"); if (this.wrapAsLob) { Clob clob = rs.getClob(columnIndex); @@ -226,7 +222,7 @@ public class DefaultLobHandler extends AbstractLobHandler { protected class DefaultLobCreator implements LobCreator { @Override - public void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content) + public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte @Nullable [] content) throws SQLException { if (streamAsLob) { 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 4c59328629..1b07cb2226 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,7 +22,7 @@ import java.io.Reader; import java.sql.PreparedStatement; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that abstracts potentially database-specific creation of large binary @@ -73,7 +73,7 @@ public interface LobCreator extends Closeable { * @throws SQLException if thrown by JDBC methods * @see java.sql.PreparedStatement#setBytes */ - void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content) + void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte @Nullable [] content) 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 11fea7e50d..1f852af0c9 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,7 +21,7 @@ import java.io.Reader; import java.sql.ResultSet; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstraction for handling large binary fields and large text fields in @@ -88,8 +88,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; + byte @Nullable [] getBlobAsBytes(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as bytes from the given ResultSet. @@ -101,8 +100,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; + byte @Nullable [] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as binary stream from the given ResultSet. @@ -114,8 +112,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; + @Nullable InputStream getBlobAsBinaryStream(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as binary stream from the given ResultSet. @@ -127,8 +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; + @Nullable InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as String from the given ResultSet. @@ -140,8 +136,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; + @Nullable String getClobAsString(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as String from the given ResultSet. @@ -153,8 +148,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; + @Nullable String getClobAsString(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as ASCII stream from the given ResultSet. @@ -166,8 +160,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; + @Nullable InputStream getClobAsAsciiStream(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as ASCII stream from the given ResultSet. @@ -179,8 +172,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; + @Nullable InputStream getClobAsAsciiStream(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as character stream from the given ResultSet. diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughBlob.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughBlob.java index 93238ea41e..4ca1e69d1a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughBlob.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughBlob.java @@ -22,7 +22,7 @@ import java.io.OutputStream; import java.sql.Blob; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple JDBC {@link Blob} adapter that exposes a given byte array or binary stream. @@ -34,11 +34,9 @@ import org.springframework.lang.Nullable; @Deprecated class PassThroughBlob implements Blob { - @Nullable - private byte[] content; + private byte @Nullable [] content; - @Nullable - private InputStream binaryStream; + private @Nullable InputStream binaryStream; private final long contentLength; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughClob.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughClob.java index 8dea8a2c84..5c7ca574cd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughClob.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/PassThroughClob.java @@ -28,7 +28,8 @@ import java.nio.charset.StandardCharsets; import java.sql.Clob; import java.sql.SQLException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.FileCopyUtils; /** @@ -41,14 +42,11 @@ import org.springframework.util.FileCopyUtils; @Deprecated class PassThroughClob implements Clob { - @Nullable - private String content; + private @Nullable String content; - @Nullable - private Reader characterStream; + private @Nullable Reader characterStream; - @Nullable - private InputStream asciiStream; + private @Nullable InputStream asciiStream; private final long contentLength; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/TemporaryLobCreator.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/TemporaryLobCreator.java index 7a0e18db9c..820ca7b8c2 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/TemporaryLobCreator.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/lob/TemporaryLobCreator.java @@ -28,9 +28,9 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -60,7 +60,7 @@ public class TemporaryLobCreator implements LobCreator { @Override - public void setBlobAsBytes(PreparedStatement ps, int paramIndex, @Nullable byte[] content) + public void setBlobAsBytes(PreparedStatement ps, int paramIndex, byte @Nullable [] content) throws SQLException { if (content != null) { 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 a07f8dac5d..85525271fe 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,9 +2,7 @@ * Provides a strategy interface for Large OBject handling, * as well as a customizable default implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.support.lob; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 bd868877a9..44d0b871a4 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,9 +6,7 @@ *

    Can be used independently, for example in custom JDBC access code, * or in JDBC-based O/R mapping layers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java index 04d90e000c..9f3c0feb95 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.java @@ -27,8 +27,9 @@ import java.util.Calendar; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.InvalidResultSetAccessException; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -173,8 +174,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getBigDecimal(int) */ @Override - @Nullable - public BigDecimal getBigDecimal(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable BigDecimal getBigDecimal(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getBigDecimal(columnIndex); } @@ -187,8 +187,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getBigDecimal(String) */ @Override - @Nullable - public BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException { return getBigDecimal(findColumn(columnLabel)); } @@ -238,8 +237,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getDate(int) */ @Override - @Nullable - public Date getDate(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable Date getDate(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getDate(columnIndex); } @@ -252,8 +250,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getDate(String) */ @Override - @Nullable - public Date getDate(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable Date getDate(String columnLabel) throws InvalidResultSetAccessException { return getDate(findColumn(columnLabel)); } @@ -261,8 +258,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getDate(int, Calendar) */ @Override - @Nullable - public Date getDate(int columnIndex, Calendar cal) throws InvalidResultSetAccessException { + public @Nullable Date getDate(int columnIndex, Calendar cal) throws InvalidResultSetAccessException { try { return this.resultSet.getDate(columnIndex, cal); } @@ -275,8 +271,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getDate(String, Calendar) */ @Override - @Nullable - public Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException { + public @Nullable Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException { return getDate(findColumn(columnLabel), cal); } @@ -368,8 +363,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getNString(int) */ @Override - @Nullable - public String getNString(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable String getNString(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getNString(columnIndex); } @@ -382,8 +376,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getNString(String) */ @Override - @Nullable - public String getNString(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable String getNString(String columnLabel) throws InvalidResultSetAccessException { return getNString(findColumn(columnLabel)); } @@ -391,8 +384,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getObject(int) */ @Override - @Nullable - public Object getObject(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable Object getObject(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getObject(columnIndex); } @@ -405,8 +397,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getObject(String) */ @Override - @Nullable - public Object getObject(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable Object getObject(String columnLabel) throws InvalidResultSetAccessException { return getObject(findColumn(columnLabel)); } @@ -414,8 +405,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getObject(int, Map) */ @Override - @Nullable - public Object getObject(int columnIndex, Map> map) throws InvalidResultSetAccessException { + public @Nullable Object getObject(int columnIndex, Map> map) throws InvalidResultSetAccessException { try { return this.resultSet.getObject(columnIndex, map); } @@ -428,8 +418,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getObject(String, Map) */ @Override - @Nullable - public Object getObject(String columnLabel, Map> map) throws InvalidResultSetAccessException { + public @Nullable Object getObject(String columnLabel, Map> map) throws InvalidResultSetAccessException { return getObject(findColumn(columnLabel), map); } @@ -437,8 +426,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getObject(int, Class) */ @Override - @Nullable - public T getObject(int columnIndex, Class type) throws InvalidResultSetAccessException { + public @Nullable T getObject(int columnIndex, Class type) throws InvalidResultSetAccessException { try { return this.resultSet.getObject(columnIndex, type); } @@ -451,8 +439,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getObject(String, Class) */ @Override - @Nullable - public T getObject(String columnLabel, Class type) throws InvalidResultSetAccessException { + public @Nullable T getObject(String columnLabel, Class type) throws InvalidResultSetAccessException { return getObject(findColumn(columnLabel), type); } @@ -481,8 +468,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getString(int) */ @Override - @Nullable - public String getString(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable String getString(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getString(columnIndex); } @@ -495,8 +481,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getString(String) */ @Override - @Nullable - public String getString(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable String getString(String columnLabel) throws InvalidResultSetAccessException { return getString(findColumn(columnLabel)); } @@ -504,8 +489,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTime(int) */ @Override - @Nullable - public Time getTime(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable Time getTime(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getTime(columnIndex); } @@ -518,8 +502,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTime(String) */ @Override - @Nullable - public Time getTime(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable Time getTime(String columnLabel) throws InvalidResultSetAccessException { return getTime(findColumn(columnLabel)); } @@ -527,8 +510,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTime(int, Calendar) */ @Override - @Nullable - public Time getTime(int columnIndex, Calendar cal) throws InvalidResultSetAccessException { + public @Nullable Time getTime(int columnIndex, Calendar cal) throws InvalidResultSetAccessException { try { return this.resultSet.getTime(columnIndex, cal); } @@ -541,8 +523,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTime(String, Calendar) */ @Override - @Nullable - public Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException { + public @Nullable Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException { return getTime(findColumn(columnLabel), cal); } @@ -550,8 +531,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTimestamp(int) */ @Override - @Nullable - public Timestamp getTimestamp(int columnIndex) throws InvalidResultSetAccessException { + public @Nullable Timestamp getTimestamp(int columnIndex) throws InvalidResultSetAccessException { try { return this.resultSet.getTimestamp(columnIndex); } @@ -564,8 +544,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTimestamp(String) */ @Override - @Nullable - public Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException { + public @Nullable Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException { return getTimestamp(findColumn(columnLabel)); } @@ -573,8 +552,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTimestamp(int, Calendar) */ @Override - @Nullable - public Timestamp getTimestamp(int columnIndex, Calendar cal) throws InvalidResultSetAccessException { + public @Nullable Timestamp getTimestamp(int columnIndex, Calendar cal) throws InvalidResultSetAccessException { try { return this.resultSet.getTimestamp(columnIndex, cal); } @@ -587,8 +565,7 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet { * @see java.sql.ResultSet#getTimestamp(String, Calendar) */ @Override - @Nullable - public Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException { + public @Nullable Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException { return getTimestamp(findColumn(columnLabel), cal); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSetMetaData.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSetMetaData.java index 88ad0941f5..8e8decbe1f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSetMetaData.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSetMetaData.java @@ -19,8 +19,9 @@ package org.springframework.jdbc.support.rowset; import java.sql.ResultSetMetaData; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.InvalidResultSetAccessException; -import org.springframework.lang.Nullable; /** * The default implementation of Spring's {@link SqlRowSetMetaData} interface, wrapping a @@ -38,8 +39,7 @@ public class ResultSetWrappingSqlRowSetMetaData implements SqlRowSetMetaData { private final ResultSetMetaData resultSetMetaData; - @Nullable - private String[] columnNames; + private String @Nullable [] columnNames; /** diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java index a460f81540..1de3e7d24f 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/rowset/SqlRowSet.java @@ -24,8 +24,9 @@ import java.sql.Timestamp; import java.util.Calendar; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.jdbc.InvalidResultSetAccessException; -import org.springframework.lang.Nullable; /** * Mirror interface for {@link javax.sql.RowSet}, representing a disconnected variant of @@ -75,8 +76,7 @@ public interface SqlRowSet extends Serializable { * @return an BigDecimal object representing the column value * @see java.sql.ResultSet#getBigDecimal(int) */ - @Nullable - BigDecimal getBigDecimal(int columnIndex) throws InvalidResultSetAccessException; + @Nullable BigDecimal getBigDecimal(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a BigDecimal object. @@ -84,8 +84,7 @@ public interface SqlRowSet extends Serializable { * @return an BigDecimal object representing the column value * @see java.sql.ResultSet#getBigDecimal(String) */ - @Nullable - BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException; + @Nullable BigDecimal getBigDecimal(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a boolean. @@ -125,8 +124,7 @@ public interface SqlRowSet extends Serializable { * @return a Date object representing the column value * @see java.sql.ResultSet#getDate(int) */ - @Nullable - Date getDate(int columnIndex) throws InvalidResultSetAccessException; + @Nullable Date getDate(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Date object. @@ -134,8 +132,7 @@ public interface SqlRowSet extends Serializable { * @return a Date object representing the column value * @see java.sql.ResultSet#getDate(String) */ - @Nullable - Date getDate(String columnLabel) throws InvalidResultSetAccessException; + @Nullable Date getDate(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Date object. @@ -144,8 +141,7 @@ public interface SqlRowSet extends Serializable { * @return a Date object representing the column value * @see java.sql.ResultSet#getDate(int, Calendar) */ - @Nullable - Date getDate(int columnIndex, Calendar cal) throws InvalidResultSetAccessException; + @Nullable Date getDate(int columnIndex, Calendar cal) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Date object. @@ -154,8 +150,7 @@ public interface SqlRowSet extends Serializable { * @return a Date object representing the column value * @see java.sql.ResultSet#getDate(String, Calendar) */ - @Nullable - Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException; + @Nullable Date getDate(String columnLabel, Calendar cal) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Double object. @@ -229,8 +224,7 @@ public interface SqlRowSet extends Serializable { * @since 4.1.3 * @see java.sql.ResultSet#getNString(int) */ - @Nullable - String getNString(int columnIndex) throws InvalidResultSetAccessException; + @Nullable String getNString(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a String @@ -240,8 +234,7 @@ public interface SqlRowSet extends Serializable { * @since 4.1.3 * @see java.sql.ResultSet#getNString(String) */ - @Nullable - String getNString(String columnLabel) throws InvalidResultSetAccessException; + @Nullable String getNString(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as an Object. @@ -249,8 +242,7 @@ public interface SqlRowSet extends Serializable { * @return an Object representing the column value * @see java.sql.ResultSet#getObject(int) */ - @Nullable - Object getObject(int columnIndex) throws InvalidResultSetAccessException; + @Nullable Object getObject(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as an Object. @@ -258,8 +250,7 @@ public interface SqlRowSet extends Serializable { * @return an Object representing the column value * @see java.sql.ResultSet#getObject(String) */ - @Nullable - Object getObject(String columnLabel) throws InvalidResultSetAccessException; + @Nullable Object getObject(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as an Object. @@ -268,8 +259,7 @@ public interface SqlRowSet extends Serializable { * @return an Object representing the column value * @see java.sql.ResultSet#getObject(int, Map) */ - @Nullable - Object getObject(int columnIndex, Map> map) throws InvalidResultSetAccessException; + @Nullable Object getObject(int columnIndex, Map> map) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as an Object. @@ -278,8 +268,7 @@ public interface SqlRowSet extends Serializable { * @return an Object representing the column value * @see java.sql.ResultSet#getObject(String, Map) */ - @Nullable - Object getObject(String columnLabel, Map> map) throws InvalidResultSetAccessException; + @Nullable Object getObject(String columnLabel, Map> map) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as an Object. @@ -289,8 +278,7 @@ public interface SqlRowSet extends Serializable { * @since 4.1.3 * @see java.sql.ResultSet#getObject(int, Class) */ - @Nullable - T getObject(int columnIndex, Class type) throws InvalidResultSetAccessException; + @Nullable T getObject(int columnIndex, Class type) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as an Object. @@ -300,8 +288,7 @@ public interface SqlRowSet extends Serializable { * @since 4.1.3 * @see java.sql.ResultSet#getObject(String, Class) */ - @Nullable - T getObject(String columnLabel, Class type) throws InvalidResultSetAccessException; + @Nullable T getObject(String columnLabel, Class type) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a short. @@ -325,8 +312,7 @@ public interface SqlRowSet extends Serializable { * @return a String representing the column value * @see java.sql.ResultSet#getString(int) */ - @Nullable - String getString(int columnIndex) throws InvalidResultSetAccessException; + @Nullable String getString(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a String. @@ -334,8 +320,7 @@ public interface SqlRowSet extends Serializable { * @return a String representing the column value * @see java.sql.ResultSet#getString(String) */ - @Nullable - String getString(String columnLabel) throws InvalidResultSetAccessException; + @Nullable String getString(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Time object. @@ -343,8 +328,7 @@ public interface SqlRowSet extends Serializable { * @return a Time object representing the column value * @see java.sql.ResultSet#getTime(int) */ - @Nullable - Time getTime(int columnIndex) throws InvalidResultSetAccessException; + @Nullable Time getTime(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Time object. @@ -352,8 +336,7 @@ public interface SqlRowSet extends Serializable { * @return a Time object representing the column value * @see java.sql.ResultSet#getTime(String) */ - @Nullable - Time getTime(String columnLabel) throws InvalidResultSetAccessException; + @Nullable Time getTime(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Time object. @@ -362,8 +345,7 @@ public interface SqlRowSet extends Serializable { * @return a Time object representing the column value * @see java.sql.ResultSet#getTime(int, Calendar) */ - @Nullable - Time getTime(int columnIndex, Calendar cal) throws InvalidResultSetAccessException; + @Nullable Time getTime(int columnIndex, Calendar cal) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Time object. @@ -372,8 +354,7 @@ public interface SqlRowSet extends Serializable { * @return a Time object representing the column value * @see java.sql.ResultSet#getTime(String, Calendar) */ - @Nullable - Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException; + @Nullable Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Timestamp object. @@ -381,8 +362,7 @@ public interface SqlRowSet extends Serializable { * @return a Timestamp object representing the column value * @see java.sql.ResultSet#getTimestamp(int) */ - @Nullable - Timestamp getTimestamp(int columnIndex) throws InvalidResultSetAccessException; + @Nullable Timestamp getTimestamp(int columnIndex) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Timestamp object. @@ -390,8 +370,7 @@ public interface SqlRowSet extends Serializable { * @return a Timestamp object representing the column value * @see java.sql.ResultSet#getTimestamp(String) */ - @Nullable - Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException; + @Nullable Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Timestamp object. @@ -400,8 +379,7 @@ public interface SqlRowSet extends Serializable { * @return a Timestamp object representing the column value * @see java.sql.ResultSet#getTimestamp(int, Calendar) */ - @Nullable - Timestamp getTimestamp(int columnIndex, Calendar cal) throws InvalidResultSetAccessException; + @Nullable Timestamp getTimestamp(int columnIndex, Calendar cal) throws InvalidResultSetAccessException; /** * Retrieve the value of the indicated column in the current row as a Timestamp object. @@ -410,8 +388,7 @@ public interface SqlRowSet extends Serializable { * @return a Timestamp object representing the column value * @see java.sql.ResultSet#getTimestamp(String, Calendar) */ - @Nullable - Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException; + @Nullable Timestamp getTimestamp(String columnLabel, Calendar cal) throws InvalidResultSetAccessException; // RowSet navigation methods 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 d38a51b1c6..4481066ea3 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,9 +2,7 @@ * Provides a convenient holder for disconnected result sets. * Supported by JdbcTemplate, but can be used independently too. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.support.rowset; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/Jdbc4SqlXmlHandler.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/Jdbc4SqlXmlHandler.java index 9a5775c712..75c1807cfd 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/Jdbc4SqlXmlHandler.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/xml/Jdbc4SqlXmlHandler.java @@ -30,10 +30,10 @@ import javax.xml.transform.Source; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; /** * Default implementation of the {@link SqlXmlHandler} interface. @@ -59,50 +59,43 @@ public class Jdbc4SqlXmlHandler implements SqlXmlHandler { //------------------------------------------------------------------------- @Override - @Nullable - public String getXmlAsString(ResultSet rs, String columnName) throws SQLException { + public @Nullable String getXmlAsString(ResultSet rs, String columnName) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnName); return (xmlObject != null ? xmlObject.getString() : null); } @Override - @Nullable - public String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException { + public @Nullable String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnIndex); return (xmlObject != null ? xmlObject.getString() : null); } @Override - @Nullable - public InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException { + public @Nullable InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnName); return (xmlObject != null ? xmlObject.getBinaryStream() : null); } @Override - @Nullable - public InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { + public @Nullable InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnIndex); return (xmlObject != null ? xmlObject.getBinaryStream() : null); } @Override - @Nullable - public Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException { + public @Nullable Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnName); return (xmlObject != null ? xmlObject.getCharacterStream() : null); } @Override - @Nullable - public Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException { + public @Nullable Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnIndex); return (xmlObject != null ? xmlObject.getCharacterStream() : null); } @Override - @Nullable - public Source getXmlAsSource(ResultSet rs, String columnName, @Nullable Class sourceClass) + public @Nullable Source getXmlAsSource(ResultSet rs, String columnName, @Nullable Class sourceClass) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnName); @@ -113,8 +106,7 @@ public class Jdbc4SqlXmlHandler implements SqlXmlHandler { } @Override - @Nullable - public Source getXmlAsSource(ResultSet rs, int columnIndex, @Nullable Class sourceClass) + public @Nullable Source getXmlAsSource(ResultSet rs, int columnIndex, @Nullable Class sourceClass) throws SQLException { SQLXML xmlObject = rs.getSQLXML(columnIndex); @@ -185,8 +177,7 @@ public class Jdbc4SqlXmlHandler implements SqlXmlHandler { */ private abstract static class AbstractJdbc4SqlXmlValue implements SqlXmlValue { - @Nullable - private SQLXML xmlObject; + private @Nullable SQLXML xmlObject; @Override public void setValue(PreparedStatement ps, int paramIndex) throws SQLException { 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 de37b3b95b..e9fd4304fa 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 @@ -25,10 +25,9 @@ import java.sql.SQLException; import javax.xml.transform.Result; import javax.xml.transform.Source; +import org.jspecify.annotations.Nullable; 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. @@ -69,8 +68,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getString * @see java.sql.ResultSet#getSQLXML */ - @Nullable - String getXmlAsString(ResultSet rs, String columnName) throws SQLException; + @Nullable String getXmlAsString(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as String from the given ResultSet. @@ -84,8 +82,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getString * @see java.sql.ResultSet#getSQLXML */ - @Nullable - String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException; + @Nullable String getXmlAsString(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as binary stream from the given ResultSet. @@ -99,8 +96,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getBinaryStream */ - @Nullable - InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException; + @Nullable InputStream getXmlAsBinaryStream(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as binary stream from the given ResultSet. @@ -114,8 +110,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getBinaryStream */ - @Nullable - InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException; + @Nullable InputStream getXmlAsBinaryStream(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as character stream from the given ResultSet. @@ -129,8 +124,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getCharacterStream */ - @Nullable - Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException; + @Nullable Reader getXmlAsCharacterStream(ResultSet rs, String columnName) throws SQLException; /** * Retrieve the given column as character stream from the given ResultSet. @@ -144,8 +138,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getCharacterStream */ - @Nullable - Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException; + @Nullable Reader getXmlAsCharacterStream(ResultSet rs, int columnIndex) throws SQLException; /** * Retrieve the given column as Source implemented using the specified source class @@ -160,8 +153,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getSource */ - @Nullable - Source getXmlAsSource(ResultSet rs, String columnName, @Nullable Class sourceClass) throws SQLException; + @Nullable Source getXmlAsSource(ResultSet rs, String columnName, @Nullable Class sourceClass) throws SQLException; /** * Retrieve the given column as Source implemented using the specified source class @@ -176,8 +168,7 @@ public interface SqlXmlHandler { * @see java.sql.ResultSet#getSQLXML * @see java.sql.SQLXML#getSource */ - @Nullable - Source getXmlAsSource(ResultSet rs, int columnIndex, @Nullable Class sourceClass) throws SQLException; + @Nullable Source getXmlAsSource(ResultSet rs, int columnIndex, @Nullable Class sourceClass) 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 24e863bfd6..d0553a560d 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,9 +1,7 @@ /** * Abstraction for handling fields of SQLXML data type. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jdbc.support.xml; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 1a7b808c23..f6480ab751 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 @@ -25,7 +25,7 @@ import java.sql.ResultSet * @since 5.0 */ inline fun JdbcOperations.queryForObject(sql: String): T = - queryForObject(sql, T::class.java) as T + queryForObject(sql, T::class.java as Class<*>) as T /** * Extensions for [JdbcOperations.queryForObject] providing a RowMapper-like function @@ -45,7 +45,7 @@ inline fun JdbcOperations.queryForObject(sql: String, vararg args: A * @since 5.0 */ inline fun JdbcOperations.queryForObject(sql: String, args: Array, argTypes: IntArray): T? = - queryForObject(sql, args, argTypes, T::class.java) as T + queryForObject(sql, args, argTypes, T::class.java as Class<*>) as T /** * Extension for [JdbcOperations.queryForObject] providing a @@ -57,7 +57,7 @@ inline fun JdbcOperations.queryForObject(sql: String, args: Array JdbcOperations.queryForObject(sql: String, args: Array): T? = - queryForObject(sql, args, T::class.java) as T + queryForObject(sql, args, T::class.java as Class<*>) as T /** * Extension for [JdbcOperations.queryForList] providing a `queryForList("...")` variant. @@ -66,7 +66,7 @@ inline fun JdbcOperations.queryForObject(sql: String, args: Array JdbcOperations.queryForList(sql: String): List = +inline fun JdbcOperations.queryForList(sql: String): List = queryForList(sql, T::class.java) /** @@ -77,7 +77,7 @@ inline fun JdbcOperations.queryForList(sql: String): List = * @since 5.0 */ @Suppress("EXTENSION_SHADOWED_BY_MEMBER") -inline fun JdbcOperations.queryForList(sql: String, args: Array, +inline fun JdbcOperations.queryForList(sql: String, args: Array, argTypes: IntArray): List = queryForList(sql, args, argTypes, T::class.java) @@ -90,7 +90,7 @@ inline fun JdbcOperations.queryForList(sql: String, args: Array JdbcOperations.queryForList(sql: String, args: Array): List = +inline fun JdbcOperations.queryForList(sql: String, args: Array): List = queryForList(sql, args, T::class.java) diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java index e03b2d3361..bc1065d4aa 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/config/JdbcNamespaceIntegrationTests.java @@ -18,6 +18,7 @@ package org.springframework.jdbc.config; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.PropertyValue; @@ -33,7 +34,6 @@ import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.AbstractDriverBasedDataSource; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseFactoryBean; import org.springframework.jdbc.datasource.init.DataSourceInitializer; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -188,8 +188,7 @@ class JdbcNamespaceIntegrationTests { } } - @Nullable - private String extractDataSourceUrl(String file) { + private @Nullable String extractDataSourceUrl(String file) { try (ConfigurableApplicationContext context = context(file)) { DataSource dataSource = context.getBean(DataSource.class); assertNumRowsInTestTable(new JdbcTemplate(dataSource), 1); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProviderTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProviderTests.java index a6c318ef1a..db12eeeec8 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProviderTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/metadata/GenericCallMetaDataProviderTests.java @@ -24,11 +24,11 @@ import java.util.Arrays; import java.util.List; import java.util.function.IntFunction; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.mockito.InOrder; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; import org.springframework.util.function.ThrowingBiFunction; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java index 1872fbe522..6b4243dd47 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsTests.java @@ -20,13 +20,13 @@ import java.util.ArrayList; import java.util.List; import org.assertj.core.util.Strings; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.support.EncodedResource; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.springframework.jdbc.datasource.init.ScriptUtils.DEFAULT_BLOCK_COMMENT_END_DELIMITER; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java index 1a525815aa..2af6f99322 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/object/SqlQueryTests.java @@ -29,6 +29,7 @@ import java.util.Map; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,7 +37,6 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.jdbc.Customer; import org.springframework.jdbc.core.SqlParameter; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -108,7 +108,7 @@ class SqlQueryTests { SqlQuery query = new MappingSqlQueryWithParameters<>() { @Override - protected Integer mapRow(ResultSet rs, int rownum, @Nullable Object[] params, @Nullable Map context) + protected Integer mapRow(ResultSet rs, int rownum, Object @Nullable [] params, @Nullable Map context) throws SQLException { assertThat(params).as("params were null").isNull(); assertThat(context).as("context was null").isNull(); diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSqlExceptionTranslator.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSqlExceptionTranslator.java index 1a5d833de0..750351ea0f 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSqlExceptionTranslator.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/CustomSqlExceptionTranslator.java @@ -18,9 +18,10 @@ package org.springframework.jdbc.support; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; import org.springframework.dao.TransientDataAccessResourceException; -import org.springframework.lang.Nullable; /** * Custom SQLException translation for testing. diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java index 76ec0720b3..4fc8995646 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLErrorCodeSQLExceptionTranslatorTests.java @@ -24,6 +24,7 @@ import java.sql.SQLException; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.dao.CannotAcquireLockException; @@ -33,7 +34,6 @@ import org.springframework.dao.DataIntegrityViolationException; import org.springframework.dao.DuplicateKeyException; import org.springframework.jdbc.BadSqlGrammarException; import org.springframework.jdbc.InvalidResultSetAccessException; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; @@ -139,8 +139,7 @@ class SQLErrorCodeSQLExceptionTranslatorTests { translator = new SQLErrorCodeSQLExceptionTranslator() { @SuppressWarnings("deprecation") @Override - @Nullable - protected DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlException) { + protected @Nullable DataAccessException customTranslate(String task, @Nullable String sql, SQLException sqlException) { assertThat(task).isEqualTo(TASK); assertThat(sql).isEqualTo(SQL); return (sqlException == badSqlEx) ? customDex : null; diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java index 28758b8745..b3156a7073 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/support/SQLStateSQLExceptionTranslatorTests.java @@ -18,6 +18,7 @@ package org.springframework.jdbc.support; import java.sql.SQLException; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.dao.CannotAcquireLockException; @@ -28,7 +29,6 @@ import org.springframework.dao.DuplicateKeyException; import org.springframework.dao.PessimisticLockingFailureException; import org.springframework.dao.TransientDataAccessResourceException; import org.springframework.jdbc.BadSqlGrammarException; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; 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 e3e086b30f..6ed59b8a46 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 @@ -16,13 +16,13 @@ package org.springframework.jdbc.core -import java.sql.* - import io.mockk.every import io.mockk.mockk import io.mockk.verify import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test +import java.sql.JDBCType +import java.sql.ResultSet /** * Mock object based tests for [JdbcOperations] Kotlin extensions @@ -54,7 +54,7 @@ class JdbcOperationsExtensionsTests { fun `queryForObject with nullable RowMapper-like function`() { every { template.queryForObject(sql, any>(), 3) } returns null assertThat(template.queryForObject(sql, 3) { _, _ -> null }).isNull() - verify { template.queryForObject(eq(sql), any>(), eq(3)) } + verify { template.queryForObject(eq(sql), any>(), eq(3)) } } @Test @@ -115,9 +115,9 @@ class JdbcOperationsExtensionsTests { @Test // gh-22682 fun `query with nullable ResultSetExtractor-like function`() { - every { template.query(eq(sql), any>(), eq(3)) } returns null + every { template.query(eq(sql), any>(), eq(3)) } returns null assertThat(template.query(sql, 3) { _ -> null }).isNull() - verify { template.query(eq(sql), any>(), eq(3)) } + verify { template.query(eq(sql), any>(), eq(3)) } } @Suppress("RemoveExplicitTypeArguments") 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 f8a74a4216..b8dd071e4d 100644 --- a/spring-jms/src/main/java/org/springframework/jms/JmsException.java +++ b/spring-jms/src/main/java/org/springframework/jms/JmsException.java @@ -17,9 +17,9 @@ package org.springframework.jms; import jakarta.jms.JMSException; +import org.jspecify.annotations.Nullable; import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Base class for exception thrown by the framework whenever it @@ -68,8 +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() { + public @Nullable String getErrorCode() { Throwable cause = getCause(); if (cause instanceof JMSException jmsException) { return jmsException.getErrorCode(); @@ -83,8 +82,7 @@ public abstract class JmsException extends NestedRuntimeException { * @see jakarta.jms.JMSException#getLinkedException() */ @Override - @Nullable - public String getMessage() { + public @Nullable String getMessage() { String message = super.getMessage(); Throwable cause = getCause(); if (cause instanceof JMSException jmsException) { diff --git a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java index d35c228f22..319069bd70 100644 --- a/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/annotation/JmsListenerAnnotationBeanPostProcessor.java @@ -27,6 +27,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.AopInfrastructureBean; import org.springframework.aop.framework.AopProxyUtils; @@ -52,7 +53,6 @@ import org.springframework.jms.config.JmsListenerContainerFactory; import org.springframework.jms.config.JmsListenerEndpointRegistrar; import org.springframework.jms.config.JmsListenerEndpointRegistry; import org.springframework.jms.config.MethodJmsListenerEndpoint; -import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory; import org.springframework.messaging.handler.annotation.support.MessageHandlerMethodFactory; import org.springframework.messaging.handler.invocation.InvocableHandlerMethod; @@ -99,20 +99,16 @@ public class JmsListenerAnnotationBeanPostProcessor protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private String containerFactoryBeanName = DEFAULT_JMS_LISTENER_CONTAINER_FACTORY_BEAN_NAME; + private @Nullable String containerFactoryBeanName = DEFAULT_JMS_LISTENER_CONTAINER_FACTORY_BEAN_NAME; - @Nullable - private JmsListenerEndpointRegistry endpointRegistry; + private @Nullable JmsListenerEndpointRegistry endpointRegistry; private final MessageHandlerMethodFactoryAdapter messageHandlerMethodFactory = new MessageHandlerMethodFactoryAdapter(); - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private final JmsListenerEndpointRegistrar registrar = new JmsListenerEndpointRegistrar(); @@ -324,8 +320,7 @@ public class JmsListenerAnnotationBeanPostProcessor } } - @Nullable - private String resolve(String value) { + private @Nullable String resolve(String value) { return (this.embeddedValueResolver != null ? this.embeddedValueResolver.resolveStringValue(value) : value); } @@ -338,8 +333,7 @@ public class JmsListenerAnnotationBeanPostProcessor */ private class MessageHandlerMethodFactoryAdapter implements MessageHandlerMethodFactory { - @Nullable - private MessageHandlerMethodFactory messageHandlerMethodFactory; + private @Nullable MessageHandlerMethodFactory messageHandlerMethodFactory; public void setMessageHandlerMethodFactory(MessageHandlerMethodFactory messageHandlerMethodFactory) { this.messageHandlerMethodFactory = messageHandlerMethodFactory; 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 7aca3605b6..3caf9f55bd 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,9 +1,7 @@ /** * Annotations and support classes for declarative JMS listener endpoints. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java index 32816c0092..6ba62252e7 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/AbstractJmsListenerContainerFactory.java @@ -21,12 +21,12 @@ import jakarta.jms.ConnectionFactory; import jakarta.jms.ExceptionListener; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jms.listener.AbstractMessageListenerContainer; 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.util.ErrorHandler; /** @@ -42,53 +42,37 @@ public abstract class AbstractJmsListenerContainerFactory element. diff --git a/spring-jms/src/main/java/org/springframework/jms/config/DefaultJcaListenerContainerFactory.java b/spring-jms/src/main/java/org/springframework/jms/config/DefaultJcaListenerContainerFactory.java index 0338478a08..48c16ac135 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/DefaultJcaListenerContainerFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/DefaultJcaListenerContainerFactory.java @@ -17,12 +17,12 @@ package org.springframework.jms.config; import jakarta.resource.spi.ResourceAdapter; +import org.jspecify.annotations.Nullable; import org.springframework.jms.listener.endpoint.JmsActivationSpecConfig; import org.springframework.jms.listener.endpoint.JmsActivationSpecFactory; import org.springframework.jms.listener.endpoint.JmsMessageEndpointManager; import org.springframework.jms.support.destination.DestinationResolver; -import org.springframework.lang.Nullable; /** * A {@link JmsListenerContainerFactory} implementation to build a @@ -34,20 +34,15 @@ import org.springframework.lang.Nullable; public class DefaultJcaListenerContainerFactory extends JmsActivationSpecConfig implements JmsListenerContainerFactory { - @Nullable - private ResourceAdapter resourceAdapter; + private @Nullable ResourceAdapter resourceAdapter; - @Nullable - private JmsActivationSpecFactory activationSpecFactory; + private @Nullable JmsActivationSpecFactory activationSpecFactory; - @Nullable - private DestinationResolver destinationResolver; + private @Nullable DestinationResolver destinationResolver; - @Nullable - private Object transactionManager; + private @Nullable Object transactionManager; - @Nullable - private Integer phase; + private @Nullable Integer phase; /** diff --git a/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java b/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java index f11d9ae7d8..d3290a5104 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/DefaultJmsListenerContainerFactory.java @@ -18,8 +18,9 @@ package org.springframework.jms.config; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.jms.listener.DefaultMessageListenerContainer; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.util.backoff.BackOff; @@ -36,32 +37,23 @@ import org.springframework.util.backoff.BackOff; public class DefaultJmsListenerContainerFactory extends AbstractJmsListenerContainerFactory { - @Nullable - private Executor taskExecutor; + private @Nullable Executor taskExecutor; - @Nullable - private PlatformTransactionManager transactionManager; + private @Nullable PlatformTransactionManager transactionManager; - @Nullable - private Integer cacheLevel; + private @Nullable Integer cacheLevel; - @Nullable - private String cacheLevelName; + private @Nullable String cacheLevelName; - @Nullable - private String concurrency; + private @Nullable String concurrency; - @Nullable - private Integer maxMessagesPerTask; + private @Nullable Integer maxMessagesPerTask; - @Nullable - private Long receiveTimeout; + private @Nullable Long receiveTimeout; - @Nullable - private Long recoveryInterval; + private @Nullable Long recoveryInterval; - @Nullable - private BackOff backOff; + private @Nullable BackOff backOff; /** diff --git a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java index 85d075415a..7eb7c6e19a 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/JmsListenerContainerParser.java @@ -19,6 +19,7 @@ package org.springframework.jms.config; import java.util.Locale; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.MutablePropertyValues; @@ -26,7 +27,6 @@ import org.springframework.beans.PropertyValues; import org.springframework.beans.factory.config.RuntimeBeanReference; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.ParserContext; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -59,8 +59,7 @@ class JmsListenerContainerParser extends AbstractListenerContainerParser { @Override - @Nullable - protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, + protected @Nullable RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) { RootBeanDefinition factoryDef = new RootBeanDefinition(); 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 faaf911973..f815d76df0 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 @@ -19,10 +19,11 @@ package org.springframework.jms.config; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; -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; @@ -37,20 +38,15 @@ import org.springframework.util.Assert; */ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, InitializingBean { - @Nullable - private JmsListenerEndpointRegistry endpointRegistry; + private @Nullable JmsListenerEndpointRegistry endpointRegistry; - @Nullable - private MessageHandlerMethodFactory messageHandlerMethodFactory; + private @Nullable MessageHandlerMethodFactory messageHandlerMethodFactory; - @Nullable - private JmsListenerContainerFactory containerFactory; + private @Nullable JmsListenerContainerFactory containerFactory; - @Nullable - private String containerFactoryBeanName; + private @Nullable String containerFactoryBeanName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; private final List endpointDescriptors = new ArrayList<>(); @@ -68,8 +64,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ * Return the {@link JmsListenerEndpointRegistry} instance for this * registrar, may be {@code null}. */ - @Nullable - public JmsListenerEndpointRegistry getEndpointRegistry() { + public @Nullable JmsListenerEndpointRegistry getEndpointRegistry() { return this.endpointRegistry; } @@ -88,8 +83,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ /** * Return the custom {@link MessageHandlerMethodFactory} to use, if any. */ - @Nullable - public MessageHandlerMethodFactory getMessageHandlerMethodFactory() { + public @Nullable MessageHandlerMethodFactory getMessageHandlerMethodFactory() { return this.messageHandlerMethodFactory; } @@ -197,8 +191,7 @@ public class JmsListenerEndpointRegistrar implements BeanFactoryAware, Initializ public final JmsListenerEndpoint endpoint; - @Nullable - public final JmsListenerContainerFactory containerFactory; + public final @Nullable JmsListenerContainerFactory containerFactory; public JmsListenerEndpointDescriptor(JmsListenerEndpoint endpoint, @Nullable JmsListenerContainerFactory containerFactory) { 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 b111fb1165..42ee66b1bb 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 @@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.DisposableBean; @@ -35,7 +36,6 @@ 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; /** @@ -69,8 +69,7 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc private int phase = DEFAULT_PHASE; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; private boolean contextRefreshed; @@ -96,8 +95,7 @@ public class JmsListenerEndpointRegistry implements DisposableBean, SmartLifecyc * @see JmsListenerEndpoint#getId() * @see #getListenerContainerIds() */ - @Nullable - public MessageListenerContainer getListenerContainer(String id) { + public @Nullable 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 3bedccadde..f6005558c4 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 @@ -19,6 +19,8 @@ package org.springframework.jms.config; import java.lang.reflect.Method; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopProxyUtils; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.BeanFactory; @@ -31,7 +33,6 @@ 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; @@ -49,20 +50,15 @@ import org.springframework.util.StringValueResolver; */ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint implements BeanFactoryAware { - @Nullable - private Object bean; + private @Nullable Object bean; - @Nullable - private Method method; + private @Nullable Method method; - @Nullable - private Method mostSpecificMethod; + private @Nullable Method mostSpecificMethod; - @Nullable - private MessageHandlerMethodFactory messageHandlerMethodFactory; + private @Nullable MessageHandlerMethodFactory messageHandlerMethodFactory; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; /** @@ -72,8 +68,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple this.bean = bean; } - @Nullable - public Object getBean() { + public @Nullable Object getBean() { return this.bean; } @@ -84,8 +79,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple this.method = method; } - @Nullable - public Method getMethod() { + public @Nullable Method getMethod() { return this.method; } @@ -99,8 +93,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple this.mostSpecificMethod = mostSpecificMethod; } - @Nullable - public Method getMostSpecificMethod() { + public @Nullable Method getMostSpecificMethod() { if (this.mostSpecificMethod != null) { return this.mostSpecificMethod; } @@ -188,8 +181,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple /** * Return the default response destination, if any. */ - @Nullable - protected String getDefaultResponseDestination() { + protected @Nullable String getDefaultResponseDestination() { Method specificMethod = getMostSpecificMethod(); if (specificMethod == null) { return null; @@ -206,8 +198,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple return null; } - @Nullable - private SendTo getSendTo(Method specificMethod) { + private @Nullable SendTo getSendTo(Method specificMethod) { SendTo ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod, SendTo.class); if (ann == null) { ann = AnnotatedElementUtils.findMergedAnnotation(specificMethod.getDeclaringClass(), SendTo.class); @@ -215,8 +206,7 @@ public class MethodJmsListenerEndpoint extends AbstractJmsListenerEndpoint imple return ann; } - @Nullable - private String resolve(String value) { + private @Nullable String resolve(String value) { return (this.embeddedValueResolver != null ? this.embeddedValueResolver.resolveStringValue(value) : value); } diff --git a/spring-jms/src/main/java/org/springframework/jms/config/SimpleJmsListenerEndpoint.java b/spring-jms/src/main/java/org/springframework/jms/config/SimpleJmsListenerEndpoint.java index 5dfc42ad28..6978e54659 100644 --- a/spring-jms/src/main/java/org/springframework/jms/config/SimpleJmsListenerEndpoint.java +++ b/spring-jms/src/main/java/org/springframework/jms/config/SimpleJmsListenerEndpoint.java @@ -17,9 +17,9 @@ package org.springframework.jms.config; import jakarta.jms.MessageListener; +import org.jspecify.annotations.Nullable; import org.springframework.jms.listener.MessageListenerContainer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -31,8 +31,7 @@ import org.springframework.util.Assert; */ public class SimpleJmsListenerEndpoint extends AbstractJmsListenerEndpoint { - @Nullable - private MessageListener messageListener; + private @Nullable MessageListener messageListener; /** @@ -47,8 +46,7 @@ public class SimpleJmsListenerEndpoint extends AbstractJmsListenerEndpoint { * Return the {@link MessageListener} to invoke when a message matching * the endpoint is received. */ - @Nullable - public MessageListener getMessageListener() { + public @Nullable MessageListener getMessageListener() { return this.messageListener; } 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 615ba9a71d..391ad07a19 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,9 +2,7 @@ * Support package for declarative messaging configuration, * with Java configuration and XML schema support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageConsumer.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageConsumer.java index 33c5708c43..a641866662 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageConsumer.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageConsumer.java @@ -24,8 +24,7 @@ import jakarta.jms.Queue; import jakarta.jms.QueueReceiver; import jakarta.jms.Topic; import jakarta.jms.TopicSubscriber; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * JMS MessageConsumer decorator that adapts all calls @@ -50,14 +49,12 @@ class CachedMessageConsumer implements MessageConsumer, QueueReceiver, TopicSubs } @Override - @Nullable - public Queue getQueue() throws JMSException { + public @Nullable Queue getQueue() throws JMSException { return (this.target instanceof QueueReceiver receiver ? receiver.getQueue() : null); } @Override - @Nullable - public Topic getTopic() throws JMSException { + public @Nullable Topic getTopic() throws JMSException { return (this.target instanceof TopicSubscriber subscriber ? subscriber.getTopic() : null); } diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageProducer.java b/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageProducer.java index 91f24ccd00..20cfc4b5fd 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageProducer.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/CachedMessageProducer.java @@ -25,8 +25,7 @@ import jakarta.jms.Queue; import jakarta.jms.QueueSender; import jakarta.jms.Topic; import jakarta.jms.TopicPublisher; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * JMS MessageProducer decorator that adapts calls to a shared MessageProducer @@ -39,14 +38,11 @@ class CachedMessageProducer implements MessageProducer, QueueSender, TopicPublis private final MessageProducer target; - @Nullable - private Boolean originalDisableMessageID; + private @Nullable Boolean originalDisableMessageID; - @Nullable - private Boolean originalDisableMessageTimestamp; + private @Nullable Boolean originalDisableMessageTimestamp; - @Nullable - private Long originalDeliveryDelay; + private @Nullable Long originalDeliveryDelay; private int deliveryMode; 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 6c24dc7828..9bca4e364b 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 @@ -42,8 +42,8 @@ import jakarta.jms.TemporaryQueue; import jakarta.jms.TemporaryTopic; import jakarta.jms.Topic; import jakarta.jms.TopicSession; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -240,8 +240,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { * Checks for a cached Session for the given mode. */ @Override - @Nullable - protected Session getSession(Connection con, Integer mode) throws JMSException { + protected @Nullable Session getSession(Connection con, Integer mode) throws JMSException { if (!this.active) { return null; } @@ -312,8 +311,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String methodName = method.getName(); if (methodName.equals("equals")) { // Only consider equal when proxies are identical. @@ -538,8 +536,7 @@ public class CachingConnectionFactory extends SingleConnectionFactory { private final Destination destination; - @Nullable - private String destinationString; + private @Nullable String destinationString; public DestinationCacheKey(Destination destination) { Assert.notNull(destination, "Destination must not be null"); @@ -592,14 +589,11 @@ public class CachingConnectionFactory extends SingleConnectionFactory { */ private static class ConsumerCacheKey extends DestinationCacheKey { - @Nullable - private final String selector; + private final @Nullable String selector; - @Nullable - private final Boolean noLocal; + private final @Nullable Boolean noLocal; - @Nullable - private final String subscription; + private final @Nullable String subscription; private final boolean durable; diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoriesRuntimeHints.java b/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoriesRuntimeHints.java index e0d98ba834..04c53b1f02 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoriesRuntimeHints.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/ConnectionFactoriesRuntimeHints.java @@ -21,11 +21,11 @@ import jakarta.jms.QueueConnection; import jakarta.jms.QueueSession; import jakarta.jms.TopicConnection; import jakarta.jms.TopicSession; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} to register hints for JMS connection factories. 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 f92537092d..25d34fbaec 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 @@ -28,8 +28,8 @@ import jakarta.jms.TopicConnectionFactory; import jakarta.jms.TopicSession; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -131,20 +131,17 @@ 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, - @Nullable final Connection existingCon, final boolean synchedLocalTransactionAllowed) + public static @Nullable Session getTransactionalSession(final ConnectionFactory cf, + final @Nullable Connection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return doGetTransactionalSession(cf, new ResourceFactory() { @Override - @Nullable - public Session getSession(JmsResourceHolder holder) { + public @Nullable Session getSession(JmsResourceHolder holder) { return holder.getSession(Session.class, existingCon); } @Override - @Nullable - public Connection getConnection(JmsResourceHolder holder) { + public @Nullable Connection getConnection(JmsResourceHolder holder) { return (existingCon != null ? existingCon : holder.getConnection()); } @Override @@ -176,20 +173,17 @@ 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, - @Nullable final QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) + public static @Nullable QueueSession getTransactionalQueueSession(final QueueConnectionFactory cf, + final @Nullable QueueConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (QueueSession) doGetTransactionalSession(cf, new ResourceFactory() { @Override - @Nullable - public Session getSession(JmsResourceHolder holder) { + public @Nullable Session getSession(JmsResourceHolder holder) { return holder.getSession(QueueSession.class, existingCon); } @Override - @Nullable - public Connection getConnection(JmsResourceHolder holder) { + public @Nullable Connection getConnection(JmsResourceHolder holder) { return (existingCon != null ? existingCon : holder.getConnection(QueueConnection.class)); } @Override @@ -221,20 +215,17 @@ 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, - @Nullable final TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) + public static @Nullable TopicSession getTransactionalTopicSession(final TopicConnectionFactory cf, + final @Nullable TopicConnection existingCon, final boolean synchedLocalTransactionAllowed) throws JMSException { return (TopicSession) doGetTransactionalSession(cf, new ResourceFactory() { @Override - @Nullable - public Session getSession(JmsResourceHolder holder) { + public @Nullable Session getSession(JmsResourceHolder holder) { return holder.getSession(TopicSession.class, existingCon); } @Override - @Nullable - public Connection getConnection(JmsResourceHolder holder) { + public @Nullable Connection getConnection(JmsResourceHolder holder) { return (existingCon != null ? existingCon : holder.getConnection(TopicConnection.class)); } @Override @@ -265,8 +256,7 @@ public abstract class ConnectionFactoryUtils { * @throws JMSException in case of JMS failure * @see #doGetTransactionalSession(jakarta.jms.ConnectionFactory, ResourceFactory, boolean) */ - @Nullable - public static Session doGetTransactionalSession( + public static @Nullable Session doGetTransactionalSession( ConnectionFactory connectionFactory, ResourceFactory resourceFactory) throws JMSException { return doGetTransactionalSession(connectionFactory, resourceFactory, true); @@ -284,9 +274,8 @@ public abstract class ConnectionFactoryUtils { * @return the transactional Session, or {@code null} if none found * @throws JMSException in case of JMS failure */ - @Nullable @SuppressWarnings("NullAway") - public static Session doGetTransactionalSession( + public static @Nullable Session doGetTransactionalSession( ConnectionFactory connectionFactory, ResourceFactory resourceFactory, boolean startConnection) throws JMSException { @@ -373,8 +362,7 @@ public abstract class ConnectionFactoryUtils { * @return an appropriate Session fetched from the holder, * or {@code null} if none found */ - @Nullable - Session getSession(JmsResourceHolder holder); + @Nullable Session getSession(JmsResourceHolder holder); /** * Fetch an appropriate Connection from the given JmsResourceHolder. @@ -382,8 +370,7 @@ public abstract class ConnectionFactoryUtils { * @return an appropriate Connection fetched from the holder, * or {@code null} if none found */ - @Nullable - Connection getConnection(JmsResourceHolder holder); + @Nullable Connection getConnection(JmsResourceHolder holder); /** * Create a new JMS Connection for registration with a JmsResourceHolder. diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java b/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java index 3dcbaf071b..b825aa339d 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/DelegatingConnectionFactory.java @@ -24,9 +24,9 @@ import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.TopicConnection; import jakarta.jms.TopicConnectionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -60,8 +60,7 @@ import org.springframework.util.Assert; public class DelegatingConnectionFactory implements SmartConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean { - @Nullable - private ConnectionFactory targetConnectionFactory; + private @Nullable ConnectionFactory targetConnectionFactory; private boolean shouldStopConnections = false; @@ -76,8 +75,7 @@ public class DelegatingConnectionFactory /** * Return the target ConnectionFactory that this ConnectionFactory delegates to. */ - @Nullable - public ConnectionFactory getTargetConnectionFactory() { + public @Nullable ConnectionFactory getTargetConnectionFactory() { return this.targetConnectionFactory; } 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 c559d09c9b..1e67056afe 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 @@ -29,8 +29,8 @@ import jakarta.jms.Session; import jakarta.jms.TransactionInProgressException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSupport; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -53,8 +53,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { private static final Log logger = LogFactory.getLog(JmsResourceHolder.class); - @Nullable - private ConnectionFactory connectionFactory; + private @Nullable ConnectionFactory connectionFactory; private boolean frozen = false; @@ -175,8 +174,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { * Return this resource holder's default Connection, * or {@code null} if none. */ - @Nullable - public Connection getConnection() { + public @Nullable Connection getConnection() { return this.connections.peek(); } @@ -184,8 +182,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { * Return this resource holder's Connection of the given type, * or {@code null} if none. */ - @Nullable - public C getConnection(Class connectionType) { + public @Nullable C getConnection(Class connectionType) { return CollectionUtils.findValueOfType(this.connections, connectionType); } @@ -194,8 +191,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { *

    In contrast to {@link #getSession()}, this must not lazily initialize * a new Session, not even in {@link JmsResourceHolder} subclasses. */ - @Nullable - Session getOriginalSession() { + @Nullable Session getOriginalSession() { return this.sessions.peek(); } @@ -203,8 +199,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { * Return this resource holder's default Session, * or {@code null} if none. */ - @Nullable - public Session getSession() { + public @Nullable Session getSession() { return this.sessions.peek(); } @@ -212,8 +207,7 @@ public class JmsResourceHolder extends ResourceHolderSupport { * Return this resource holder's Session of the given type, * or {@code null} if none. */ - @Nullable - public S getSession(Class sessionType) { + public @Nullable S getSession(Class sessionType) { return getSession(sessionType, null); } @@ -221,9 +215,8 @@ public class JmsResourceHolder extends ResourceHolderSupport { * Return this resource holder's Session of the given type * for the given connection, or {@code null} if none. */ - @Nullable @SuppressWarnings("NullAway") - public S getSession(Class sessionType, @Nullable Connection connection) { + public @Nullable S getSession(Class sessionType, @Nullable Connection connection) { Deque sessions = (connection != null ? this.sessionsPerConnection.get(connection) : this.sessions); return CollectionUtils.findValueOfType(sessions, sessionType); diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/JmsTransactionManager.java b/spring-jms/src/main/java/org/springframework/jms/connection/JmsTransactionManager.java index 3ffd27e867..99a6820e57 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/JmsTransactionManager.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/JmsTransactionManager.java @@ -21,9 +21,9 @@ import jakarta.jms.ConnectionFactory; import jakarta.jms.JMSException; import jakarta.jms.Session; import jakarta.jms.TransactionRolledBackException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.InvalidIsolationLevelException; import org.springframework.transaction.TransactionDefinition; @@ -93,8 +93,7 @@ import org.springframework.util.Assert; public class JmsTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, InitializingBean { - @Nullable - private ConnectionFactory connectionFactory; + private @Nullable ConnectionFactory connectionFactory; private boolean lazyResourceRetrieval = false; @@ -144,8 +143,7 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager /** * Return the JMS ConnectionFactory that this instance should manage transactions for. */ - @Nullable - public ConnectionFactory getConnectionFactory() { + public @Nullable ConnectionFactory getConnectionFactory() { return this.connectionFactory; } @@ -357,36 +355,31 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager } @Override - @Nullable - public Connection getConnection() { + public @Nullable Connection getConnection() { initializeConnection(); return super.getConnection(); } @Override - @Nullable - public C getConnection(Class connectionType) { + public @Nullable C getConnection(Class connectionType) { initializeConnection(); return super.getConnection(connectionType); } @Override - @Nullable - public Session getSession() { + public @Nullable Session getSession() { initializeSession(); return super.getSession(); } @Override - @Nullable - public S getSession(Class sessionType) { + public @Nullable S getSession(Class sessionType) { initializeSession(); return super.getSession(sessionType); } @Override - @Nullable - public S getSession(Class sessionType, @Nullable Connection connection) { + public @Nullable S getSession(Class sessionType, @Nullable Connection connection) { initializeSession(); return super.getSession(sessionType, connection); } @@ -428,8 +421,7 @@ public class JmsTransactionManager extends AbstractPlatformTransactionManager */ private static class JmsTransactionObject implements SmartTransactionObject { - @Nullable - private JmsResourceHolder resourceHolder; + private @Nullable JmsResourceHolder resourceHolder; public void setResourceHolder(@Nullable JmsResourceHolder resourceHolder) { this.resourceHolder = resourceHolder; 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 186fcaa3ba..5149d4aa53 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 @@ -39,11 +39,11 @@ import jakarta.jms.TopicConnection; import jakarta.jms.TopicConnectionFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.Lifecycle; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -92,28 +92,22 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ConnectionFactory targetConnectionFactory; + private @Nullable ConnectionFactory targetConnectionFactory; - @Nullable - private String clientId; + private @Nullable String clientId; - @Nullable - private ExceptionListener exceptionListener; + private @Nullable ExceptionListener exceptionListener; private boolean reconnectOnException = false; /** The target Connection. */ - @Nullable - private Connection connection; + private @Nullable Connection connection; /** A hint whether to create a queue or topic connection. */ - @Nullable - private Boolean pubSubMode; + private @Nullable Boolean pubSubMode; /** An internal aggregator allowing for per-connection ExceptionListeners. */ - @Nullable - private AggregatedExceptionListener aggregatedExceptionListener; + private @Nullable AggregatedExceptionListener aggregatedExceptionListener; /** Whether the shared Connection has been started. */ private int startedCount = 0; @@ -161,8 +155,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti * Return the target ConnectionFactory which will be used to lazily * create a single Connection, if any. */ - @Nullable - public ConnectionFactory getTargetConnectionFactory() { + public @Nullable ConnectionFactory getTargetConnectionFactory() { return this.targetConnectionFactory; } @@ -183,8 +176,7 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti * Return a JMS client ID for the single Connection created and exposed * by this ConnectionFactory, if any. */ - @Nullable - protected String getClientId() { + protected @Nullable String getClientId() { return this.clientId; } @@ -201,8 +193,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() { + protected @Nullable ExceptionListener getExceptionListener() { return this.exceptionListener; } @@ -519,8 +510,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 { + protected @Nullable Session getSession(Connection con, Integer mode) throws JMSException { return null; } @@ -616,14 +606,12 @@ public class SingleConnectionFactory implements ConnectionFactory, QueueConnecti */ private class SharedConnectionInvocationHandler implements InvocationHandler { - @Nullable - private ExceptionListener localExceptionListener; + private @Nullable ExceptionListener localExceptionListener; private boolean locallyStarted = false; @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { switch (method.getName()) { case "equals" -> { Object other = args[0]; diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java b/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java index e5ffb4b067..dab2aef3ac 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/TransactionAwareConnectionFactoryProxy.java @@ -35,8 +35,8 @@ import jakarta.jms.TopicConnection; import jakarta.jms.TopicConnectionFactory; import jakarta.jms.TopicSession; import jakarta.jms.TransactionInProgressException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -86,8 +86,7 @@ import org.springframework.util.ClassUtils; public class TransactionAwareConnectionFactoryProxy implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory { - @Nullable - private ConnectionFactory targetConnectionFactory; + private @Nullable ConnectionFactory targetConnectionFactory; private boolean synchedLocalTransactionAllowed = false; @@ -327,8 +326,7 @@ public class TransactionAwareConnectionFactoryProxy } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on SessionProxy interface coming in... return switch (method.getName()) { diff --git a/spring-jms/src/main/java/org/springframework/jms/connection/UserCredentialsConnectionFactoryAdapter.java b/spring-jms/src/main/java/org/springframework/jms/connection/UserCredentialsConnectionFactoryAdapter.java index 5d5868e8b9..ffce4224a1 100644 --- a/spring-jms/src/main/java/org/springframework/jms/connection/UserCredentialsConnectionFactoryAdapter.java +++ b/spring-jms/src/main/java/org/springframework/jms/connection/UserCredentialsConnectionFactoryAdapter.java @@ -24,10 +24,10 @@ import jakarta.jms.QueueConnection; import jakarta.jms.QueueConnectionFactory; import jakarta.jms.TopicConnection; import jakarta.jms.TopicConnectionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -81,14 +81,11 @@ import org.springframework.util.StringUtils; public class UserCredentialsConnectionFactoryAdapter implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory, InitializingBean { - @Nullable - private ConnectionFactory targetConnectionFactory; + private @Nullable ConnectionFactory targetConnectionFactory; - @Nullable - private String username; + private @Nullable String username; - @Nullable - private String password; + private @Nullable String password; private final ThreadLocal threadBoundCredentials = new NamedThreadLocal<>("Current JMS user credentials"); 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 f075ee2297..3bc4d6ccbc 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,9 +2,7 @@ * Provides a PlatformTransactionManager implementation for a single * JMS ConnectionFactory, and a SingleConnectionFactory adapter. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.connection; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 1a076bad50..303267cb3a 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 @@ -19,8 +19,7 @@ package org.springframework.jms.core; import jakarta.jms.JMSException; import jakarta.jms.QueueBrowser; import jakarta.jms.Session; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Callback for browsing the messages in a JMS queue. @@ -47,7 +46,6 @@ public interface BrowserCallback { * (or {@code null} if none) * @throws jakarta.jms.JMSException if thrown by JMS API methods */ - @Nullable - T doInJms(Session session, QueueBrowser browser) throws JMSException; + @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 ebb821da62..921cab42eb 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 @@ -19,8 +19,8 @@ package org.springframework.jms.core; import java.util.Map; import jakarta.jms.Destination; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.core.MessagePostProcessor; @@ -102,8 +102,7 @@ public interface JmsMessageOperations extends MessageSendingOperations receive(String destinationName) throws MessagingException; + @Nullable Message receive(String destinationName) throws MessagingException; /** * Receive a message from the given destination and convert its payload to the @@ -113,8 +112,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException; + @Nullable T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException; /** * Send a request message and receive the reply from the given destination. @@ -123,8 +121,7 @@ public interface JmsMessageOperations extends MessageSendingOperations sendAndReceive(String destinationName, Message requestMessage) throws MessagingException; + @Nullable Message sendAndReceive(String destinationName, Message requestMessage) throws MessagingException; /** * Convert the given request Object to serialized form, possibly using a @@ -137,8 +134,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Class targetClass) throws MessagingException; + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) throws MessagingException; /** * Convert the given request Object to serialized form, possibly using a @@ -152,8 +148,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass) + @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass) throws MessagingException; /** @@ -169,8 +164,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Class targetClass, + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; /** @@ -186,8 +180,7 @@ public interface JmsMessageOperations extends MessageSendingOperations T convertSendAndReceive(String destinationName, Object request, Map headers, + @Nullable 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/JmsMessagingTemplate.java b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java index 5c0aeb27b9..4b87ce0fb2 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/JmsMessagingTemplate.java @@ -22,6 +22,7 @@ import jakarta.jms.ConnectionFactory; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.jms.InvalidDestinationException; @@ -29,7 +30,6 @@ import org.springframework.jms.JmsException; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.converter.MessagingMessageConverter; import org.springframework.jms.support.converter.SimpleMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.converter.MessageConversionException; @@ -48,15 +48,13 @@ import org.springframework.util.Assert; public class JmsMessagingTemplate extends AbstractMessagingTemplate implements JmsMessageOperations, InitializingBean { - @Nullable - private JmsTemplate jmsTemplate; + private @Nullable JmsTemplate jmsTemplate; private MessageConverter jmsMessageConverter = new MessagingMessageConverter(); private boolean converterSet; - @Nullable - private String defaultDestinationName; + private @Nullable String defaultDestinationName; /** @@ -101,8 +99,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate * Return the ConnectionFactory that the underlying {@link JmsTemplate} uses. * @since 4.1.2 */ - @Nullable - public ConnectionFactory getConnectionFactory() { + public @Nullable ConnectionFactory getConnectionFactory() { return (this.jmsTemplate != null ? this.jmsTemplate.getConnectionFactory() : null); } @@ -116,8 +113,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate /** * Return the configured {@link JmsTemplate}. */ - @Nullable - public JmsTemplate getJmsTemplate() { + public @Nullable JmsTemplate getJmsTemplate() { return this.jmsTemplate; } @@ -158,8 +154,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate /** * Return the configured default destination name. */ - @Nullable - public String getDefaultDestinationName() { + public @Nullable String getDefaultDestinationName() { return this.defaultDestinationName; } @@ -233,8 +228,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - public Message receive() { + public @Nullable Message receive() { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return receive(defaultDestination); @@ -245,8 +239,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - public T receiveAndConvert(Class targetClass) { + public @Nullable T receiveAndConvert(Class targetClass) { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return receiveAndConvert(defaultDestination, targetClass); @@ -257,14 +250,12 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - public Message receive(String destinationName) throws MessagingException { + public @Nullable Message receive(String destinationName) throws MessagingException { return doReceive(destinationName); } @Override - @Nullable - public T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException { + public @Nullable T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException { Message message = doReceive(destinationName); if (message != null) { return doConvert(message, targetClass); @@ -275,8 +266,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - public Message sendAndReceive(Message requestMessage) { + public @Nullable Message sendAndReceive(Message requestMessage) { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return sendAndReceive(defaultDestination, requestMessage); @@ -287,36 +277,31 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - public Message sendAndReceive(String destinationName, Message requestMessage) throws MessagingException { + public @Nullable Message sendAndReceive(String destinationName, Message requestMessage) throws MessagingException { return doSendAndReceive(destinationName, requestMessage); } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, Class targetClass) + public @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) throws MessagingException { return convertSendAndReceive(destinationName, request, null, targetClass); } @Override - @Nullable - public T convertSendAndReceive(Object request, Class targetClass) { + public @Nullable T convertSendAndReceive(Object request, Class targetClass) { return convertSendAndReceive(request, targetClass, null); } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, + public @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass) throws MessagingException { return convertSendAndReceive(destinationName, request, headers, targetClass, null); } @Override - @Nullable - public T convertSendAndReceive(Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) { + public @Nullable T convertSendAndReceive(Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return convertSendAndReceive(defaultDestination, request, targetClass, postProcessor); @@ -327,8 +312,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, Class targetClass, + public @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException { return convertSendAndReceive(destinationName, request, null, targetClass, requestPostProcessor); @@ -336,8 +320,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate @SuppressWarnings("unchecked") @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, + public @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass, @Nullable MessagePostProcessor postProcessor) { Message requestMessage = doConvert(request, headers, postProcessor); @@ -365,8 +348,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - protected Message doReceive(Destination destination) { + protected @Nullable Message doReceive(Destination destination) { try { jakarta.jms.Message jmsMessage = obtainJmsTemplate().receive(destination); return convertJmsMessage(jmsMessage); @@ -376,8 +358,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } } - @Nullable - protected Message doReceive(String destinationName) { + protected @Nullable Message doReceive(String destinationName) { try { jakarta.jms.Message jmsMessage = obtainJmsTemplate().receive(destinationName); return convertJmsMessage(jmsMessage); @@ -388,8 +369,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } @Override - @Nullable - protected Message doSendAndReceive(Destination destination, Message requestMessage) { + protected @Nullable Message doSendAndReceive(Destination destination, Message requestMessage) { try { jakarta.jms.Message jmsMessage = obtainJmsTemplate().sendAndReceive( destination, createMessageCreator(requestMessage)); @@ -400,8 +380,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate } } - @Nullable - protected Message doSendAndReceive(String destinationName, Message requestMessage) { + protected @Nullable Message doSendAndReceive(String destinationName, Message requestMessage) { try { jakarta.jms.Message jmsMessage = obtainJmsTemplate().sendAndReceive( destinationName, createMessageCreator(requestMessage)); @@ -425,8 +404,7 @@ public class JmsMessagingTemplate extends AbstractMessagingTemplate return name; } - @Nullable - protected Message convertJmsMessage(@Nullable jakarta.jms.Message message) { + protected @Nullable Message convertJmsMessage(jakarta.jms.@Nullable Message message) { if (message == null) { return null; } 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 0aa7888819..2245d59652 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 @@ -19,9 +19,9 @@ package org.springframework.jms.core; import jakarta.jms.Destination; import jakarta.jms.Message; import jakarta.jms.Queue; +import org.jspecify.annotations.Nullable; import org.springframework.jms.JmsException; -import org.springframework.lang.Nullable; /** * Specifies a basic set of JMS operations. @@ -54,8 +54,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException if there is any problem */ - @Nullable - T execute(SessionCallback action) throws JmsException; + @Nullable T execute(SessionCallback action) throws JmsException; /** * Send messages to the default JMS destination (or one specified @@ -65,8 +64,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T execute(ProducerCallback action) throws JmsException; + @Nullable T execute(ProducerCallback action) throws JmsException; /** * Send messages to a JMS destination. The callback gives access to the JMS Session @@ -76,8 +74,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T execute(Destination destination, ProducerCallback action) throws JmsException; + @Nullable T execute(Destination destination, ProducerCallback action) throws JmsException; /** * Send messages to a JMS destination. The callback gives access to the JMS Session @@ -88,8 +85,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T execute(String destinationName, ProducerCallback action) throws JmsException; + @Nullable T execute(String destinationName, ProducerCallback action) throws JmsException; //--------------------------------------------------------------------------------------- @@ -207,8 +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; + @Nullable Message receive() throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -219,8 +214,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; + @Nullable Message receive(Destination destination) throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -232,8 +226,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; + @Nullable Message receive(String destinationName) throws JmsException; /** * Receive a message synchronously from the default destination, but only @@ -246,8 +239,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; + @Nullable Message receiveSelected(String messageSelector) throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -260,8 +252,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; + @Nullable Message receiveSelected(Destination destination, String messageSelector) throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -275,8 +266,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; + @Nullable Message receiveSelected(String destinationName, String messageSelector) throws JmsException; //--------------------------------------------------------------------------------------- @@ -293,8 +283,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; + @Nullable Object receiveAndConvert() throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -306,8 +295,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; + @Nullable Object receiveAndConvert(Destination destination) throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -320,8 +308,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; + @Nullable Object receiveAndConvert(String destinationName) throws JmsException; /** * Receive a message synchronously from the default destination, but only @@ -335,8 +322,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; + @Nullable Object receiveSelectedAndConvert(String messageSelector) throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -350,8 +336,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; + @Nullable Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException; /** * Receive a message synchronously from the specified destination, but only @@ -366,8 +351,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; + @Nullable Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException; //--------------------------------------------------------------------------------------- @@ -386,8 +370,7 @@ public interface JmsOperations { * @throws JmsException checked JMSException converted to unchecked * @since 4.1 */ - @Nullable - Message sendAndReceive(MessageCreator messageCreator) throws JmsException; + @Nullable Message sendAndReceive(MessageCreator messageCreator) throws JmsException; /** * Send a message and receive the reply from the specified destination. The @@ -401,8 +384,7 @@ public interface JmsOperations { * @throws JmsException checked JMSException converted to unchecked * @since 4.1 */ - @Nullable - Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException; + @Nullable Message sendAndReceive(Destination destination, MessageCreator messageCreator) throws JmsException; /** * Send a message and receive the reply from the specified destination. The @@ -417,8 +399,7 @@ public interface JmsOperations { * @throws JmsException checked JMSException converted to unchecked * @since 4.1 */ - @Nullable - Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException; + @Nullable Message sendAndReceive(String destinationName, MessageCreator messageCreator) throws JmsException; //--------------------------------------------------------------------------------------- @@ -432,8 +413,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T browse(BrowserCallback action) throws JmsException; + @Nullable T browse(BrowserCallback action) throws JmsException; /** * Browse messages in a JMS queue. The callback gives access to the JMS Session @@ -443,8 +423,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T browse(Queue queue, BrowserCallback action) throws JmsException; + @Nullable T browse(Queue queue, BrowserCallback action) throws JmsException; /** * Browse messages in a JMS queue. The callback gives access to the JMS Session @@ -455,8 +434,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T browse(String queueName, BrowserCallback action) throws JmsException; + @Nullable T browse(String queueName, BrowserCallback action) throws JmsException; /** * Browse selected messages in a JMS queue. The callback gives access to the JMS @@ -467,8 +445,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T browseSelected(String messageSelector, BrowserCallback action) throws JmsException; + @Nullable T browseSelected(String messageSelector, BrowserCallback action) throws JmsException; /** * Browse selected messages in a JMS queue. The callback gives access to the JMS @@ -480,8 +457,7 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T browseSelected(Queue queue, String messageSelector, BrowserCallback action) throws JmsException; + @Nullable T browseSelected(Queue queue, String messageSelector, BrowserCallback action) throws JmsException; /** * Browse selected messages in a JMS queue. The callback gives access to the JMS @@ -494,7 +470,6 @@ public interface JmsOperations { * @return the result object from working with the session * @throws JmsException checked JMSException converted to unchecked */ - @Nullable - T browseSelected(String queueName, String messageSelector, BrowserCallback action) throws JmsException; + @Nullable T browseSelected(String queueName, String messageSelector, BrowserCallback action) 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 ecae541c4e..3fef511277 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 @@ -30,6 +30,7 @@ import jakarta.jms.Queue; import jakarta.jms.QueueBrowser; import jakarta.jms.Session; import jakarta.jms.TemporaryQueue; +import org.jspecify.annotations.Nullable; import org.springframework.jms.JmsException; import org.springframework.jms.connection.ConnectionFactoryUtils; @@ -39,7 +40,6 @@ 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; @@ -99,11 +99,9 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations private final JmsTemplateResourceFactory transactionalResourceFactory = new JmsTemplateResourceFactory(); - @Nullable - private Object defaultDestination; + private @Nullable Object defaultDestination; - @Nullable - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; private boolean messageIdEnabled = true; @@ -125,8 +123,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations private long timeToLive = Message.DEFAULT_TIME_TO_LIVE; - @Nullable - private ObservationRegistry observationRegistry; + private @Nullable ObservationRegistry observationRegistry; /** @@ -181,13 +178,11 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * Return the destination to be used on send/receive operations that do not * have a destination parameter. */ - @Nullable - public Destination getDefaultDestination() { + public @Nullable Destination getDefaultDestination() { return (this.defaultDestination instanceof Destination dest ? dest : null); } - @Nullable - private Queue getDefaultQueue() { + private @Nullable Queue getDefaultQueue() { Destination defaultDestination = getDefaultDestination(); if (defaultDestination == null) { return null; @@ -218,8 +213,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * Return the destination name to be used on send/receive operations that * do not have a destination parameter. */ - @Nullable - public String getDefaultDestinationName() { + public @Nullable String getDefaultDestinationName() { return (this.defaultDestination instanceof String name ? name : null); } @@ -249,8 +243,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations /** * Return the message converter for this template. */ - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { return this.messageConverter; } @@ -485,8 +478,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations //--------------------------------------------------------------------------------------- @Override - @Nullable - public T execute(SessionCallback action) throws JmsException { + public @Nullable T execute(SessionCallback action) throws JmsException { return execute(action, false); } @@ -505,8 +497,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * @see #receive */ @SuppressWarnings("resource") - @Nullable - public T execute(SessionCallback action, boolean startConnection) throws JmsException { + public @Nullable T execute(SessionCallback action, boolean startConnection) throws JmsException { Assert.notNull(action, "Callback object must not be null"); Connection conToClose = null; Session sessionToClose = null; @@ -539,8 +530,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public T execute(ProducerCallback action) throws JmsException { + public @Nullable T execute(ProducerCallback action) throws JmsException { String defaultDestinationName = getDefaultDestinationName(); if (defaultDestinationName != null) { return execute(defaultDestinationName, action); @@ -551,8 +541,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public T execute(final @Nullable Destination destination, final ProducerCallback action) throws JmsException { + public @Nullable T execute(final @Nullable Destination destination, final ProducerCallback action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(session -> { MessageProducer producer = createProducer(session, destination); @@ -566,8 +555,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public T execute(final String destinationName, final ProducerCallback action) throws JmsException { + public @Nullable T execute(final String destinationName, final ProducerCallback action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); return execute(session -> { Destination destination = resolveDestinationName(session, destinationName); @@ -726,8 +714,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations //--------------------------------------------------------------------------------------- @Override - @Nullable - public Message receive() throws JmsException { + public @Nullable Message receive() throws JmsException { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return receive(defaultDestination); @@ -738,20 +725,17 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public Message receive(Destination destination) throws JmsException { + public @Nullable Message receive(Destination destination) throws JmsException { return receiveSelected(destination, null); } @Override - @Nullable - public Message receive(String destinationName) throws JmsException { + public @Nullable Message receive(String destinationName) throws JmsException { return receiveSelected(destinationName, null); } @Override - @Nullable - public Message receiveSelected(String messageSelector) throws JmsException { + public @Nullable Message receiveSelected(String messageSelector) throws JmsException { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return receiveSelected(defaultDestination, messageSelector); @@ -762,14 +746,12 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public Message receiveSelected(final Destination destination, @Nullable final String messageSelector) throws JmsException { + public @Nullable Message receiveSelected(final Destination destination, final @Nullable String messageSelector) throws JmsException { return execute(session -> doReceive(session, destination, messageSelector), true); } @Override - @Nullable - public Message receiveSelected(final String destinationName, @Nullable final String messageSelector) throws JmsException { + public @Nullable Message receiveSelected(final String destinationName, final @Nullable String messageSelector) throws JmsException { return execute(session -> { Destination destination = resolveDestinationName(session, destinationName); return doReceive(session, destination, messageSelector); @@ -784,8 +766,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, Destination destination, @Nullable String messageSelector) + protected @Nullable Message doReceive(Session session, Destination destination, @Nullable String messageSelector) throws JMSException { return doReceive(session, createConsumer(session, destination, messageSelector)); @@ -798,8 +779,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 { + protected @Nullable Message doReceive(Session session, MessageConsumer consumer) throws JMSException { try { // Use transaction timeout (if available). long timeout = getReceiveTimeout(); @@ -838,38 +818,32 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations //--------------------------------------------------------------------------------------- @Override - @Nullable - public Object receiveAndConvert() throws JmsException { + public @Nullable Object receiveAndConvert() throws JmsException { return doConvertFromMessage(receive()); } @Override - @Nullable - public Object receiveAndConvert(Destination destination) throws JmsException { + public @Nullable Object receiveAndConvert(Destination destination) throws JmsException { return doConvertFromMessage(receive(destination)); } @Override - @Nullable - public Object receiveAndConvert(String destinationName) throws JmsException { + public @Nullable Object receiveAndConvert(String destinationName) throws JmsException { return doConvertFromMessage(receive(destinationName)); } @Override - @Nullable - public Object receiveSelectedAndConvert(String messageSelector) throws JmsException { + public @Nullable Object receiveSelectedAndConvert(String messageSelector) throws JmsException { return doConvertFromMessage(receiveSelected(messageSelector)); } @Override - @Nullable - public Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException { + public @Nullable Object receiveSelectedAndConvert(Destination destination, String messageSelector) throws JmsException { return doConvertFromMessage(receiveSelected(destination, messageSelector)); } @Override - @Nullable - public Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException { + public @Nullable Object receiveSelectedAndConvert(String destinationName, String messageSelector) throws JmsException { return doConvertFromMessage(receiveSelected(destinationName, messageSelector)); } @@ -878,8 +852,7 @@ 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 */ - @Nullable - protected Object doConvertFromMessage(@Nullable Message message) { + protected @Nullable Object doConvertFromMessage(@Nullable Message message) { if (message != null) { try { return getRequiredMessageConverter().fromMessage(message); @@ -897,8 +870,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations //--------------------------------------------------------------------------------------- @Override - @Nullable - public Message sendAndReceive(MessageCreator messageCreator) throws JmsException { + public @Nullable Message sendAndReceive(MessageCreator messageCreator) throws JmsException { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return sendAndReceive(defaultDestination, messageCreator); @@ -909,14 +881,12 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public Message sendAndReceive(final Destination destination, final MessageCreator messageCreator) throws JmsException { + public @Nullable Message sendAndReceive(final Destination destination, final MessageCreator messageCreator) throws JmsException { return executeLocal(session -> doSendAndReceive(session, destination, messageCreator), true); } @Override - @Nullable - public Message sendAndReceive(final String destinationName, final MessageCreator messageCreator) throws JmsException { + public @Nullable Message sendAndReceive(final String destinationName, final MessageCreator messageCreator) throws JmsException { return executeLocal(session -> { Destination destination = resolveDestinationName(session, destinationName); return doSendAndReceive(session, destination, messageCreator); @@ -929,8 +899,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) + protected @Nullable Message doSendAndReceive(Session session, Destination destination, MessageCreator messageCreator) throws JMSException { Assert.notNull(messageCreator, "MessageCreator must not be null"); @@ -963,8 +932,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations * creates a non-transactional {@link Session}. The given {@link SessionCallback} * does not participate in an existing transaction. */ - @Nullable - private T executeLocal(SessionCallback action, boolean startConnection) throws JmsException { + private @Nullable T executeLocal(SessionCallback action, boolean startConnection) throws JmsException { Assert.notNull(action, "Callback object must not be null"); Connection con = null; Session session = null; @@ -997,8 +965,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations //--------------------------------------------------------------------------------------- @Override - @Nullable - public T browse(BrowserCallback action) throws JmsException { + public @Nullable T browse(BrowserCallback action) throws JmsException { Queue defaultQueue = getDefaultQueue(); if (defaultQueue != null) { return browse(defaultQueue, action); @@ -1009,20 +976,17 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public T browse(Queue queue, BrowserCallback action) throws JmsException { + public @Nullable T browse(Queue queue, BrowserCallback action) throws JmsException { return browseSelected(queue, null, action); } @Override - @Nullable - public T browse(String queueName, BrowserCallback action) throws JmsException { + public @Nullable T browse(String queueName, BrowserCallback action) throws JmsException { return browseSelected(queueName, null, action); } @Override - @Nullable - public T browseSelected(String messageSelector, BrowserCallback action) throws JmsException { + public @Nullable T browseSelected(String messageSelector, BrowserCallback action) throws JmsException { Queue defaultQueue = getDefaultQueue(); if (defaultQueue != null) { return browseSelected(defaultQueue, messageSelector, action); @@ -1033,8 +997,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public T browseSelected(final Queue queue, @Nullable final String messageSelector, final BrowserCallback action) + public @Nullable T browseSelected(final Queue queue, final @Nullable String messageSelector, final BrowserCallback action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); @@ -1050,8 +1013,7 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations } @Override - @Nullable - public T browseSelected(final String queueName, @Nullable final String messageSelector, final BrowserCallback action) + public @Nullable T browseSelected(final String queueName, final @Nullable String messageSelector, final BrowserCallback action) throws JmsException { Assert.notNull(action, "Callback object must not be null"); @@ -1075,8 +1037,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) { + protected @Nullable Connection getConnection(JmsResourceHolder holder) { return holder.getConnection(); } @@ -1087,8 +1048,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) { + protected @Nullable Session getSession(JmsResourceHolder holder) { return holder.getSession(); } @@ -1193,14 +1153,12 @@ public class JmsTemplate extends JmsDestinationAccessor implements JmsOperations private class JmsTemplateResourceFactory implements ConnectionFactoryUtils.ResourceFactory { @Override - @Nullable - public Connection getConnection(JmsResourceHolder holder) { + public @Nullable Connection getConnection(JmsResourceHolder holder) { return JmsTemplate.this.getConnection(holder); } @Override - @Nullable - public Session getSession(JmsResourceHolder holder) { + public @Nullable Session getSession(JmsResourceHolder holder) { return JmsTemplate.this.getSession(holder); } 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 952d3a6d15..e86c199801 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 @@ -19,8 +19,7 @@ package org.springframework.jms.core; import jakarta.jms.JMSException; import jakarta.jms.MessageProducer; import jakarta.jms.Session; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Callback for sending a message to a JMS destination. @@ -52,7 +51,6 @@ public interface ProducerCallback { * (or {@code null} if none) * @throws jakarta.jms.JMSException if thrown by JMS API methods */ - @Nullable - T doInJms(Session session, MessageProducer producer) throws JMSException; + @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 99dfe64b0c..1357b006e0 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 @@ -18,8 +18,7 @@ package org.springframework.jms.core; import jakarta.jms.JMSException; import jakarta.jms.Session; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Callback for executing any number of operations on a provided {@link Session}. @@ -43,7 +42,6 @@ public interface SessionCallback { * (or {@code null} if none) * @throws jakarta.jms.JMSException if thrown by JMS API methods */ - @Nullable - T doInJms(Session session) throws JMSException; + @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 4beb013c57..1270b14b6c 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,9 +2,7 @@ * Core package of the JMS support. * Provides a JmsTemplate class and various callback interfaces. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.core; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jms/src/main/java/org/springframework/jms/core/support/JmsGatewaySupport.java b/spring-jms/src/main/java/org/springframework/jms/core/support/JmsGatewaySupport.java index 627e5fc311..99de379a73 100644 --- a/spring-jms/src/main/java/org/springframework/jms/core/support/JmsGatewaySupport.java +++ b/spring-jms/src/main/java/org/springframework/jms/core/support/JmsGatewaySupport.java @@ -19,11 +19,11 @@ package org.springframework.jms.core.support; import jakarta.jms.ConnectionFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.InitializingBean; import org.springframework.jms.core.JmsTemplate; -import org.springframework.lang.Nullable; /** * Convenient superclass for application classes that need JMS access. @@ -45,8 +45,7 @@ public abstract class JmsGatewaySupport implements InitializingBean { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private JmsTemplate jmsTemplate; + private @Nullable JmsTemplate jmsTemplate; /** @@ -75,8 +74,7 @@ public abstract class JmsGatewaySupport implements InitializingBean { /** * Return the JMS ConnectionFactory used by the gateway. */ - @Nullable - public final ConnectionFactory getConnectionFactory() { + public final @Nullable ConnectionFactory getConnectionFactory() { return (this.jmsTemplate != null ? this.jmsTemplate.getConnectionFactory() : null); } @@ -91,8 +89,7 @@ public abstract class JmsGatewaySupport implements InitializingBean { /** * Return the JmsTemplate for the gateway. */ - @Nullable - public final JmsTemplate getJmsTemplate() { + public final @Nullable JmsTemplate getJmsTemplate() { return this.jmsTemplate; } 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 55535f37a3..dc74a7fea9 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,9 +2,7 @@ * Classes supporting the {@code org.springframework.jms.core} package. * Contains a base class for JmsTemplate usage. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.core.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 8ed0f74fe2..ad4fedb93c 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 @@ -25,6 +25,7 @@ import java.util.concurrent.locks.ReentrantLock; import jakarta.jms.Connection; import jakarta.jms.JMSException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; @@ -33,7 +34,6 @@ 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; /** @@ -65,18 +65,15 @@ import org.springframework.util.ClassUtils; public abstract class AbstractJmsListeningContainer extends JmsDestinationAccessor implements BeanNameAware, DisposableBean, SmartLifecycle { - @Nullable - private String clientId; + private @Nullable String clientId; private boolean autoStartup = true; private int phase = DEFAULT_PHASE; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private Connection sharedConnection; + private @Nullable Connection sharedConnection; private boolean sharedConnectionStarted = false; @@ -110,8 +107,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() { + public @Nullable String getClientId() { return this.clientId; } @@ -158,8 +154,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() { + protected final @Nullable 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 f803fc3aa1..5977d125f9 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 @@ -33,11 +33,11 @@ import jakarta.jms.MessageListener; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.Topic; +import org.jspecify.annotations.Nullable; 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.ClassUtils; import org.springframework.util.ErrorHandler; @@ -154,41 +154,31 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen private static final boolean micrometerJakartaPresent = ClassUtils.isPresent( "io.micrometer.jakarta9.instrument.jms.JmsInstrumentation", AbstractMessageListenerContainer.class.getClassLoader()); - @Nullable - private volatile Object destination; + private volatile @Nullable Object destination; - @Nullable - private volatile String messageSelector; + private volatile @Nullable String messageSelector; - @Nullable - private volatile Object messageListener; + private volatile @Nullable Object messageListener; private boolean subscriptionDurable = false; private boolean subscriptionShared = false; - @Nullable - private String subscriptionName; + private @Nullable String subscriptionName; - @Nullable - private Boolean replyPubSubDomain; + private @Nullable Boolean replyPubSubDomain; - @Nullable - private QosSettings replyQosSettings; + private @Nullable QosSettings replyQosSettings; private boolean pubSubNoLocal = false; - @Nullable - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; - @Nullable - private ExceptionListener exceptionListener; + private @Nullable ExceptionListener exceptionListener; - @Nullable - private ErrorHandler errorHandler; + private @Nullable ErrorHandler errorHandler; - @Nullable - private ObservationRegistry observationRegistry; + private @Nullable ObservationRegistry observationRegistry; private boolean exposeListenerSession = true; @@ -223,8 +213,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() { + public @Nullable Destination getDestination() { return (this.destination instanceof Destination _destination ? _destination : null); } @@ -249,8 +238,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() { + public @Nullable String getDestinationName() { return (this.destination instanceof String name ? name : null); } @@ -279,8 +267,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen /** * Return the JMS message selector expression (or {@code null} if none). */ - @Nullable - public String getMessageSelector() { + public @Nullable String getMessageSelector() { return this.messageSelector; } @@ -309,8 +296,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen /** * Return the message listener object to register. */ - @Nullable - public Object getMessageListener() { + public @Nullable Object getMessageListener() { return this.messageListener; } @@ -428,8 +414,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * Return the name of a subscription to create, if any. * @since 4.1 */ - @Nullable - public String getSubscriptionName() { + public @Nullable String getSubscriptionName() { return this.subscriptionName; } @@ -455,8 +440,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen /** * Return the name of a durable subscription to create, if any. */ - @Nullable - public String getDurableSubscriptionName() { + public @Nullable String getDurableSubscriptionName() { return (this.subscriptionDurable ? this.subscriptionName : null); } @@ -520,8 +504,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen } @Override - @Nullable - public QosSettings getReplyQosSettings() { + public @Nullable QosSettings getReplyQosSettings() { return this.replyQosSettings; } @@ -534,8 +517,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen } @Override - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { return this.messageConverter; } @@ -551,8 +533,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() { + public @Nullable ExceptionListener getExceptionListener() { return this.exceptionListener; } @@ -571,8 +552,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * thrown while processing a {@link Message}. * @since 4.1 */ - @Nullable - public ErrorHandler getErrorHandler() { + public @Nullable ErrorHandler getErrorHandler() { return this.errorHandler; } @@ -591,8 +571,7 @@ public abstract class AbstractMessageListenerContainer extends AbstractJmsListen * {@link JmsObservationDocumentation#JMS_MESSAGE_PROCESS JMS message processing observations}. * @since 6.1 */ - @Nullable - public ObservationRegistry getObservationRegistry() { + public @Nullable ObservationRegistry getObservationRegistry() { return this.observationRegistry; } 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 71c4ad360d..9de98b6127 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 @@ -23,12 +23,12 @@ import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; 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.TransactionException; import org.springframework.transaction.TransactionStatus; @@ -89,8 +89,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe private boolean sessionTransactedCalled = false; - @Nullable - private PlatformTransactionManager transactionManager; + private @Nullable PlatformTransactionManager transactionManager; private final DefaultTransactionDefinition transactionDefinition = new DefaultTransactionDefinition(); @@ -133,8 +132,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe * Return the Spring PlatformTransactionManager to use for transactional * wrapping of message receipt plus listener execution. */ - @Nullable - protected final PlatformTransactionManager getTransactionManager() { + protected final @Nullable PlatformTransactionManager getTransactionManager() { return this.transactionManager; } @@ -436,8 +434,7 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe * @return the Message, or {@code null} if none * @throws JMSException if thrown by JMS methods */ - @Nullable - protected Message receiveMessage(MessageConsumer consumer) throws JMSException { + protected @Nullable Message receiveMessage(MessageConsumer consumer) throws JMSException { return receiveFromConsumer(consumer, getReceiveTimeout()); } @@ -468,8 +465,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) { + protected @Nullable Connection getConnection(JmsResourceHolder holder) { return holder.getConnection(); } @@ -480,8 +476,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) { + protected @Nullable Session getSession(JmsResourceHolder holder) { return holder.getSession(); } @@ -492,14 +487,12 @@ public abstract class AbstractPollingMessageListenerContainer extends AbstractMe private class MessageListenerContainerResourceFactory implements ConnectionFactoryUtils.ResourceFactory { @Override - @Nullable - public Connection getConnection(JmsResourceHolder holder) { + public @Nullable Connection getConnection(JmsResourceHolder holder) { return AbstractPollingMessageListenerContainer.this.getConnection(holder); } @Override - @Nullable - public Session getSession(JmsResourceHolder holder) { + public @Nullable Session getSession(JmsResourceHolder holder) { return AbstractPollingMessageListenerContainer.this.getSession(holder); } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java index 91975cb88b..165315f138 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/DefaultMessageListenerContainer.java @@ -28,6 +28,7 @@ import jakarta.jms.Connection; import jakarta.jms.JMSException; import jakarta.jms.MessageConsumer; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.TaskExecutor; @@ -35,7 +36,6 @@ import org.springframework.jms.JmsException; import org.springframework.jms.support.JmsUtils; import org.springframework.jms.support.destination.CachingDestinationResolver; import org.springframework.jms.support.destination.DestinationResolver; -import org.springframework.lang.Nullable; import org.springframework.scheduling.SchedulingAwareRunnable; import org.springframework.scheduling.SchedulingTaskExecutor; import org.springframework.util.Assert; @@ -190,8 +190,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe ); - @Nullable - private Executor taskExecutor; + private @Nullable Executor taskExecutor; private boolean virtualThreads = false; @@ -221,8 +220,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe private volatile boolean interrupted; - @Nullable - private Runnable stopCallback; + private @Nullable Runnable stopCallback; private Object currentRecoveryMarker = new Object(); @@ -1246,14 +1244,11 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe */ private class AsyncMessageListenerInvoker implements SchedulingAwareRunnable { - @Nullable - private Session session; + private @Nullable Session session; - @Nullable - private MessageConsumer consumer; + private @Nullable MessageConsumer consumer; - @Nullable - private Object lastRecoveryMarker; + private @Nullable Object lastRecoveryMarker; private boolean lastMessageSucceeded; @@ -1261,8 +1256,7 @@ public class DefaultMessageListenerContainer extends AbstractPollingMessageListe private volatile boolean idle = true; - @Nullable - private volatile Thread currentReceiveThread; + private volatile @Nullable Thread currentReceiveThread; @Override public void run() { 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 a1fd33b3b1..90766c96cc 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 @@ -16,11 +16,12 @@ package org.springframework.jms.listener; +import org.jspecify.annotations.Nullable; + 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 @@ -42,15 +43,13 @@ public interface MessageListenerContainer extends SmartLifecycle { * Return the {@link MessageConverter} that can be used to * convert {@link jakarta.jms.Message}, if any. */ - @Nullable - MessageConverter getMessageConverter(); + @Nullable MessageConverter getMessageConverter(); /** * Return the {@link DestinationResolver} to use to resolve * destinations by names. */ - @Nullable - DestinationResolver getDestinationResolver(); + @Nullable DestinationResolver getDestinationResolver(); /** * Return whether the Publish/Subscribe domain ({@link jakarta.jms.Topic Topics}) is used. @@ -71,7 +70,6 @@ public interface MessageListenerContainer extends SmartLifecycle { * or {@code null} if the broker's defaults should be used. * @since 5.0 */ - @Nullable - QosSettings getReplyQosSettings(); + @Nullable QosSettings getReplyQosSettings(); } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java b/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java index e445eb34e1..5a32cf9550 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/SimpleMessageListenerContainer.java @@ -30,9 +30,9 @@ import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.jms.support.JmsUtils; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -73,14 +73,11 @@ public class SimpleMessageListenerContainer extends AbstractMessageListenerConta private int concurrentConsumers = 1; - @Nullable - private Executor taskExecutor; + private @Nullable Executor taskExecutor; - @Nullable - private Set sessions; + private @Nullable Set sessions; - @Nullable - private Set consumers; + private @Nullable Set consumers; private final Lock consumersLock = new ReentrantLock(); 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 8bb8d92c5c..fbfebabf9f 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 @@ -26,6 +26,7 @@ import jakarta.jms.MessageProducer; import jakarta.jms.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.jms.support.JmsHeaderMapper; @@ -39,7 +40,6 @@ 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; @@ -59,18 +59,15 @@ public abstract class AbstractAdaptableMessageListener /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Object defaultResponseDestination; + private @Nullable Object defaultResponseDestination; private DestinationResolver destinationResolver = new DynamicDestinationResolver(); - @Nullable - private MessageConverter messageConverter = new SimpleMessageConverter(); + private @Nullable MessageConverter messageConverter = new SimpleMessageConverter(); private final MessagingMessageConverterAdapter messagingMessageConverter = new MessagingMessageConverterAdapter(); - @Nullable - private QosSettings responseQosSettings; + private @Nullable QosSettings responseQosSettings; /** @@ -151,8 +148,7 @@ public abstract class AbstractAdaptableMessageListener * listener method arguments, and objects returned from listener * methods back to JMS messages. */ - @Nullable - protected MessageConverter getMessageConverter() { + protected @Nullable MessageConverter getMessageConverter() { return this.messageConverter; } @@ -190,8 +186,7 @@ public abstract class AbstractAdaptableMessageListener * or {@code null} if the defaults should be used. * @since 5.0 */ - @Nullable - protected QosSettings getResponseQosSettings() { + protected @Nullable QosSettings getResponseQosSettings() { return this.responseQosSettings; } @@ -405,8 +400,7 @@ public abstract class AbstractAdaptableMessageListener * @see #setDefaultResponseTopicName * @see #setDestinationResolver */ - @Nullable - protected Destination resolveDefaultResponseDestination(Session session) throws JMSException { + protected @Nullable Destination resolveDefaultResponseDestination(Session session) throws JMSException { if (this.defaultResponseDestination instanceof Destination destination) { return destination; } @@ -504,11 +498,9 @@ public abstract class AbstractAdaptableMessageListener private final jakarta.jms.Message message; - @Nullable - private Object payload; + private @Nullable Object payload; - @Nullable - private MessageHeaders headers; + private @Nullable MessageHeaders headers; public LazyResolutionMessage(jakarta.jms.Message message) { this.message = message; 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 0bd7175016..e0ce32085c 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 @@ -19,9 +19,9 @@ package org.springframework.jms.listener.adapter; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.jms.support.destination.DestinationResolver; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -87,8 +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) + public @Nullable Destination resolveDestination(DestinationResolver destinationResolver, Session session) throws JMSException { if (this.destination instanceof Destination dest) { diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessageListenerAdapter.java b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessageListenerAdapter.java index f30c2e4b8e..ca4b1aff05 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessageListenerAdapter.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessageListenerAdapter.java @@ -22,12 +22,12 @@ import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.jms.listener.SessionAwareMessageListener; import org.springframework.jms.listener.SubscriptionNameProvider; import org.springframework.jms.support.converter.MessageConverter; import org.springframework.jms.support.converter.SimpleMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MethodInvoker; import org.springframework.util.ObjectUtils; @@ -284,8 +284,7 @@ public class MessageListenerAdapter extends AbstractAdaptableMessageListener imp * @see #getListenerMethodName * @see #buildListenerArguments */ - @Nullable - protected Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException { + protected @Nullable Object invokeListenerMethod(String methodName, Object[] arguments) throws JMSException { try { MethodInvoker methodInvoker = new MethodInvoker(); methodInvoker.setTargetObject(getDelegate()); diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapter.java b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapter.java index 6518a5cd51..973abcba99 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapter.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessagingMessageListenerAdapter.java @@ -18,12 +18,12 @@ package org.springframework.jms.listener.adapter; import jakarta.jms.JMSException; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.jms.listener.SubscriptionNameProvider; import org.springframework.jms.support.JmsHeaderMapper; import org.springframework.jms.support.converter.MessageConversionException; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.core.AbstractMessageSendingTemplate; @@ -57,8 +57,7 @@ import org.springframework.util.Assert; public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageListener implements SubscriptionNameProvider { - @Nullable - private InvocableHandlerMethod handlerMethod; + private @Nullable InvocableHandlerMethod handlerMethod; /** @@ -103,8 +102,7 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis * Invoke the handler, wrapping any exception in a {@link ListenerExecutionFailedException} * with a dedicated error message. */ - @Nullable - private Object invokeHandler(jakarta.jms.Message jmsMessage, @Nullable Session session, Message message) { + private @Nullable Object invokeHandler(jakarta.jms.Message jmsMessage, @Nullable Session session, Message message) { InvocableHandlerMethod handlerMethod = getHandlerMethod(); try { return handlerMethod.invoke(message, jmsMessage, session); 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 57f5b02289..bb8b651007 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,9 +3,7 @@ * methods, converting messages to appropriate message content types * (such as String or byte array) that get passed into listener methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.listener.adapter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ec1d22184b..d6c7f1b541 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 @@ -19,10 +19,10 @@ package org.springframework.jms.listener.endpoint; import java.util.Map; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.jms.support.QosSettings; import org.springframework.jms.support.converter.MessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -55,29 +55,23 @@ public class JmsActivationSpecConfig { ); - @Nullable - private String destinationName; + private @Nullable String destinationName; private boolean pubSubDomain = false; - @Nullable - private Boolean replyPubSubDomain; + private @Nullable Boolean replyPubSubDomain; - @Nullable - private QosSettings replyQosSettings; + private @Nullable QosSettings replyQosSettings; private boolean subscriptionDurable = false; private boolean subscriptionShared = false; - @Nullable - private String subscriptionName; + private @Nullable String subscriptionName; - @Nullable - private String clientId; + private @Nullable String clientId; - @Nullable - private String messageSelector; + private @Nullable String messageSelector; private int acknowledgeMode = Session.AUTO_ACKNOWLEDGE; @@ -85,16 +79,14 @@ public class JmsActivationSpecConfig { private int prefetchSize = -1; - @Nullable - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; public void setDestinationName(@Nullable String destinationName) { this.destinationName = destinationName; } - @Nullable - public String getDestinationName() { + public @Nullable String getDestinationName() { return this.destinationName; } @@ -123,8 +115,7 @@ public class JmsActivationSpecConfig { this.replyQosSettings = replyQosSettings; } - @Nullable - public QosSettings getReplyQosSettings() { + public @Nullable QosSettings getReplyQosSettings() { return this.replyQosSettings; } @@ -154,8 +145,7 @@ public class JmsActivationSpecConfig { this.subscriptionName = subscriptionName; } - @Nullable - public String getSubscriptionName() { + public @Nullable String getSubscriptionName() { return this.subscriptionName; } @@ -164,8 +154,7 @@ public class JmsActivationSpecConfig { this.subscriptionDurable = (durableSubscriptionName != null); } - @Nullable - public String getDurableSubscriptionName() { + public @Nullable String getDurableSubscriptionName() { return (this.subscriptionDurable ? this.subscriptionName : null); } @@ -173,8 +162,7 @@ public class JmsActivationSpecConfig { this.clientId = clientId; } - @Nullable - public String getClientId() { + public @Nullable String getClientId() { return this.clientId; } @@ -182,8 +170,7 @@ public class JmsActivationSpecConfig { this.messageSelector = messageSelector; } - @Nullable - public String getMessageSelector() { + public @Nullable String getMessageSelector() { return this.messageSelector; } @@ -297,8 +284,7 @@ public class JmsActivationSpecConfig { /** * Return the {@link MessageConverter} to use, if any. */ - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { return this.messageConverter; } diff --git a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointFactory.java b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointFactory.java index 6a164236d7..7769ec8351 100644 --- a/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointFactory.java +++ b/spring-jms/src/main/java/org/springframework/jms/listener/endpoint/JmsMessageEndpointFactory.java @@ -20,9 +20,9 @@ import jakarta.jms.Message; import jakarta.jms.MessageListener; import jakarta.resource.ResourceException; import jakarta.resource.spi.UnavailableException; +import org.jspecify.annotations.Nullable; import org.springframework.jca.endpoint.AbstractMessageEndpointFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -49,8 +49,7 @@ import org.springframework.util.Assert; */ public class JmsMessageEndpointFactory extends AbstractMessageEndpointFactory { - @Nullable - private MessageListener messageListener; + private @Nullable MessageListener messageListener; /** 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 64e380f813..4dc7290ae4 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 @@ -18,6 +18,7 @@ package org.springframework.jms.listener.endpoint; import jakarta.jms.MessageListener; import jakarta.resource.ResourceException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanNameAware; import org.springframework.jca.endpoint.GenericMessageEndpointManager; @@ -25,7 +26,6 @@ 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 @@ -60,8 +60,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager private JmsActivationSpecFactory activationSpecFactory = new DefaultJmsActivationSpecFactory(); - @Nullable - private JmsActivationSpecConfig activationSpecConfig; + private @Nullable JmsActivationSpecConfig activationSpecConfig; /** @@ -146,8 +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() { + public @Nullable JmsActivationSpecConfig getActivationSpecConfig() { return this.activationSpecConfig; } @@ -191,8 +189,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager } @Override - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { JmsActivationSpecConfig config = getActivationSpecConfig(); if (config != null) { return config.getMessageConverter(); @@ -201,8 +198,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager } @Override - @Nullable - public DestinationResolver getDestinationResolver() { + public @Nullable DestinationResolver getDestinationResolver() { if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory standardFactory) { return standardFactory.getDestinationResolver(); } @@ -228,8 +224,7 @@ public class JmsMessageEndpointManager extends GenericMessageEndpointManager } @Override - @Nullable - public QosSettings getReplyQosSettings() { + public @Nullable QosSettings getReplyQosSettings() { JmsActivationSpecConfig config = getActivationSpecConfig(); if (config != null) { return config.getReplyQosSettings(); 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 81232764d5..62d312cc05 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 @@ -24,13 +24,13 @@ import jakarta.jms.Session; import jakarta.jms.Topic; import jakarta.resource.spi.ActivationSpec; import jakarta.resource.spi.ResourceAdapter; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; 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. @@ -52,14 +52,11 @@ import org.springframework.lang.Nullable; */ public class StandardJmsActivationSpecFactory implements JmsActivationSpecFactory { - @Nullable - private Class activationSpecClass; + private @Nullable Class activationSpecClass; - @Nullable - private Map defaultProperties; + private @Nullable Map defaultProperties; - @Nullable - private DestinationResolver destinationResolver; + private @Nullable DestinationResolver destinationResolver; /** @@ -98,8 +95,7 @@ public class StandardJmsActivationSpecFactory implements JmsActivationSpecFactor /** * Return the {@link DestinationResolver} to use for resolving destinations names. */ - @Nullable - public DestinationResolver getDestinationResolver() { + public @Nullable DestinationResolver getDestinationResolver() { return this.destinationResolver; } @@ -131,8 +127,7 @@ public class StandardJmsActivationSpecFactory implements JmsActivationSpecFactor * if not determinable * @see #setActivationSpecClass */ - @Nullable - protected Class determineActivationSpecClass(ResourceAdapter adapter) { + protected @Nullable 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 23a0e183cd..98a6278d91 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,9 +1,7 @@ /** * This package provides JCA-based endpoint management for JMS message listeners. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.listener.endpoint; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2652ddc6f1..c7b7c404f4 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,9 +3,7 @@ * It also offers the DefaultMessageListenerContainer and SimpleMessageListenerContainer * implementations, based on the plain JMS client API. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.listener; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 e114d09c01..5c68e46f66 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,9 +2,7 @@ * This package contains integration classes for JMS, * allowing for Spring-style JMS access. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java b/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java index 5145749e7f..f963c9aebf 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/JmsAccessor.java @@ -24,10 +24,10 @@ import jakarta.jms.JMSException; import jakarta.jms.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.jms.JmsException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -63,8 +63,7 @@ public abstract class JmsAccessor implements InitializingBean { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ConnectionFactory connectionFactory; + private @Nullable ConnectionFactory connectionFactory; private boolean sessionTransacted = false; @@ -82,8 +81,7 @@ public abstract class JmsAccessor implements InitializingBean { * Return the ConnectionFactory that this accessor uses for obtaining * JMS {@link Connection Connections}. */ - @Nullable - public ConnectionFactory getConnectionFactory() { + public @Nullable ConnectionFactory getConnectionFactory() { return this.connectionFactory; } diff --git a/spring-jms/src/main/java/org/springframework/jms/support/JmsMessageHeaderAccessor.java b/spring-jms/src/main/java/org/springframework/jms/support/JmsMessageHeaderAccessor.java index 3523c7808b..17534797b5 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/JmsMessageHeaderAccessor.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/JmsMessageHeaderAccessor.java @@ -20,8 +20,8 @@ import java.util.List; import java.util.Map; import jakarta.jms.Destination; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.support.NativeMessageHeaderAccessor; @@ -47,8 +47,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#CORRELATION_ID correlationId}. * @see JmsHeaders#CORRELATION_ID */ - @Nullable - public String getCorrelationId() { + public @Nullable String getCorrelationId() { return (String) getHeader(JmsHeaders.CORRELATION_ID); } @@ -56,8 +55,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#DESTINATION destination}. * @see JmsHeaders#DESTINATION */ - @Nullable - public Destination getDestination() { + public @Nullable Destination getDestination() { return (Destination) getHeader(JmsHeaders.DESTINATION); } @@ -65,8 +63,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#DELIVERY_MODE delivery mode}. * @see JmsHeaders#DELIVERY_MODE */ - @Nullable - public Integer getDeliveryMode() { + public @Nullable Integer getDeliveryMode() { return (Integer) getHeader(JmsHeaders.DELIVERY_MODE); } @@ -74,8 +71,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the message {@link JmsHeaders#EXPIRATION expiration}. * @see JmsHeaders#EXPIRATION */ - @Nullable - public Long getExpiration() { + public @Nullable Long getExpiration() { return (Long) getHeader(JmsHeaders.EXPIRATION); } @@ -83,8 +79,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#MESSAGE_ID message id}. * @see JmsHeaders#MESSAGE_ID */ - @Nullable - public String getMessageId() { + public @Nullable String getMessageId() { return (String) getHeader(JmsHeaders.MESSAGE_ID); } @@ -92,8 +87,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#PRIORITY priority}. * @see JmsHeaders#PRIORITY */ - @Nullable - public Integer getPriority() { + public @Nullable Integer getPriority() { return (Integer) getHeader(JmsHeaders.PRIORITY); } @@ -101,8 +95,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#REPLY_TO reply to}. * @see JmsHeaders#REPLY_TO */ - @Nullable - public Destination getReplyTo() { + public @Nullable Destination getReplyTo() { return (Destination) getHeader(JmsHeaders.REPLY_TO); } @@ -110,8 +103,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#REDELIVERED redelivered} flag. * @see JmsHeaders#REDELIVERED */ - @Nullable - public Boolean getRedelivered() { + public @Nullable Boolean getRedelivered() { return (Boolean) getHeader(JmsHeaders.REDELIVERED); } @@ -119,8 +111,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the {@link JmsHeaders#TYPE type}. * @see JmsHeaders#TYPE */ - @Nullable - public String getType() { + public @Nullable String getType() { return (String) getHeader(JmsHeaders.TYPE); } @@ -129,8 +120,7 @@ public class JmsMessageHeaderAccessor extends NativeMessageHeaderAccessor { * @see JmsHeaders#TIMESTAMP */ @Override - @Nullable - public Long getTimestamp() { + public @Nullable Long getTimestamp() { return (Long) getHeader(JmsHeaders.TIMESTAMP); } 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 b4815924fa..d5a88a3545 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 @@ -25,6 +25,7 @@ import jakarta.jms.QueueRequestor; import jakarta.jms.Session; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jms.InvalidClientIDException; import org.springframework.jms.InvalidDestinationException; @@ -39,7 +40,6 @@ 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; /** @@ -241,8 +241,7 @@ public abstract class JmsUtils { * @return the descriptive message String * @see jakarta.jms.JMSException#getLinkedException() */ - @Nullable - public static String buildExceptionMessage(JMSException ex) { + public static @Nullable String buildExceptionMessage(JMSException ex) { String message = ex.getMessage(); Exception linkedEx = ex.getLinkedException(); if (linkedEx != null) { diff --git a/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java b/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java index 39ee533489..1175665627 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/QosSettings.java @@ -17,8 +17,7 @@ package org.springframework.jms.support; import jakarta.jms.Message; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Gather the Quality-of-Service settings that can be used when sending a message. 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 50e1099a40..f45a140f1c 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 @@ -35,10 +35,10 @@ import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.Session; import jakarta.jms.TextMessage; +import org.jspecify.annotations.Nullable; 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; @@ -73,21 +73,17 @@ public class MappingJackson2MessageConverter implements SmartMessageConverter, B private MessageType targetType = MessageType.BYTES; - @Nullable - private String encoding; + private @Nullable String encoding; - @Nullable - private String encodingPropertyName; + private @Nullable String encodingPropertyName; - @Nullable - private String typeIdPropertyName; + private @Nullable String typeIdPropertyName; private Map> idClassMappings = new HashMap<>(); private final Map, String> classIdMappings = new HashMap<>(); - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; /** @@ -478,8 +474,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(@Nullable Object conversionHint) { + protected @Nullable Class getSerializationView(@Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter methodParam) { JsonView annotation = methodParam.getParameterAnnotation(JsonView.class); if (annotation == null) { diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/MarshallingMessageConverter.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/MarshallingMessageConverter.java index afea54c559..1bada096ff 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/MarshallingMessageConverter.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/MarshallingMessageConverter.java @@ -32,9 +32,9 @@ import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.Session; import jakarta.jms.TextMessage; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; @@ -52,11 +52,9 @@ import org.springframework.util.Assert; */ public class MarshallingMessageConverter implements MessageConverter, InitializingBean { - @Nullable - private Marshaller marshaller; + private @Nullable Marshaller marshaller; - @Nullable - private Unmarshaller unmarshaller; + private @Nullable Unmarshaller unmarshaller; private MessageType targetType = MessageType.BYTES; 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 e6ba699751..142a6e4be8 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 @@ -16,8 +16,9 @@ package org.springframework.jms.support.converter; +import org.jspecify.annotations.Nullable; + import org.springframework.jms.JmsException; -import org.springframework.lang.Nullable; /** * Thrown by {@link MessageConverter} implementations when the conversion diff --git a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java index 188ff23484..117ca437ec 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java @@ -20,11 +20,11 @@ import java.util.Map; import jakarta.jms.JMSException; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.jms.support.JmsHeaderMapper; import org.springframework.jms.support.SimpleJmsHeaderMapper; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.core.AbstractMessageSendingTemplate; 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 3a6468d78c..a2cc701b09 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 @@ -19,8 +19,7 @@ package org.springframework.jms.support.converter; import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.Session; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An extended {@link MessageConverter} SPI with conversion hint support. 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 53c46520b7..97a800b9b4 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,9 +2,7 @@ * Provides a MessageConverter abstraction to convert * between Java objects and JMS messages. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.support.converter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/BeanFactoryDestinationResolver.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/BeanFactoryDestinationResolver.java index 291e7a3d07..0bd7030193 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/BeanFactoryDestinationResolver.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/BeanFactoryDestinationResolver.java @@ -19,11 +19,11 @@ package org.springframework.jms.support.destination; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -38,8 +38,7 @@ import org.springframework.util.Assert; */ public class BeanFactoryDestinationResolver implements DestinationResolver, BeanFactoryAware { - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** 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 ce3e74f1cd..63faba4065 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 @@ -16,8 +16,9 @@ package org.springframework.jms.support.destination; +import org.jspecify.annotations.Nullable; + import org.springframework.jms.JmsException; -import org.springframework.lang.Nullable; /** * Thrown by a DestinationResolver when it cannot resolve a destination name. 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 ddc273729a..c7a8f178a2 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 @@ -19,8 +19,7 @@ package org.springframework.jms.support.destination; import jakarta.jms.Destination; import jakarta.jms.JMSException; import jakarta.jms.Session; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for resolving JMS destinations. diff --git a/spring-jms/src/main/java/org/springframework/jms/support/destination/DynamicDestinationResolver.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/DynamicDestinationResolver.java index 0a1d885f7e..331e6457ce 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/DynamicDestinationResolver.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/DynamicDestinationResolver.java @@ -21,8 +21,8 @@ import jakarta.jms.JMSException; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.Topic; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 6711e7030f..15fdc84e69 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 @@ -21,9 +21,9 @@ import jakarta.jms.JMSException; import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.springframework.jms.support.JmsAccessor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -126,8 +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 { + protected @Nullable 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/JndiDestinationResolver.java b/spring-jms/src/main/java/org/springframework/jms/support/destination/JndiDestinationResolver.java index b27d883a08..ae9b29e4b6 100644 --- a/spring-jms/src/main/java/org/springframework/jms/support/destination/JndiDestinationResolver.java +++ b/spring-jms/src/main/java/org/springframework/jms/support/destination/JndiDestinationResolver.java @@ -26,9 +26,9 @@ import jakarta.jms.JMSException; import jakarta.jms.Queue; import jakarta.jms.Session; import jakarta.jms.Topic; +import org.jspecify.annotations.Nullable; import org.springframework.jndi.JndiLocatorSupport; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** 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 91b3c3e502..b7b8c73afc 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,9 +1,7 @@ /** * Support classes for Spring's JMS framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.support.destination; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 3443300691..e85dac873e 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,9 +2,7 @@ * This package provides generic JMS support classes, * to be used by higher-level classes like JmsTemplate. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jms.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java b/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java index b158f8c346..b592219d2a 100644 --- a/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/annotation/AbstractJmsAnnotationDrivenTests.java @@ -19,6 +19,7 @@ package org.springframework.jms.annotation; import java.lang.reflect.Method; import jakarta.jms.JMSException; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; @@ -30,7 +31,6 @@ import org.springframework.jms.config.MethodJmsListenerEndpoint; import org.springframework.jms.config.SimpleJmsListenerEndpoint; import org.springframework.jms.listener.SimpleMessageListenerContainer; import org.springframework.jms.listener.adapter.MessagingMessageListenerAdapter; -import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.SendTo; import org.springframework.stereotype.Component; import org.springframework.util.ReflectionUtils; diff --git a/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java b/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java index 7ce7573658..18128bd1df 100644 --- a/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/config/MethodJmsListenerEndpointTests.java @@ -29,6 +29,7 @@ import jakarta.jms.ObjectMessage; import jakarta.jms.QueueSender; import jakarta.jms.Session; import jakarta.jms.TextMessage; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; @@ -47,7 +48,6 @@ import org.springframework.jms.support.JmsMessageHeaderAccessor; 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.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.converter.MessageConversionException; diff --git a/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java b/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java index 82f5f08918..bffebc7d69 100644 --- a/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/listener/SimpleMessageListenerContainerTests.java @@ -27,11 +27,11 @@ import jakarta.jms.Message; import jakarta.jms.MessageConsumer; import jakarta.jms.MessageListener; import jakarta.jms.Session; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.context.support.GenericApplicationContext; import org.springframework.jms.StubQueue; -import org.springframework.lang.Nullable; import org.springframework.util.ErrorHandler; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java b/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java index 3dee45d9b9..392060c755 100644 --- a/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java +++ b/spring-jms/src/test/java/org/springframework/jms/support/converter/MappingJackson2MessageConverterTests.java @@ -29,12 +29,12 @@ import jakarta.jms.BytesMessage; import jakarta.jms.JMSException; import jakarta.jms.Session; import jakarta.jms.TextMessage; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/MessageDeliveryException.java b/spring-messaging/src/main/java/org/springframework/messaging/MessageDeliveryException.java index f73fafb896..9a1ad8dcbe 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessageDeliveryException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessageDeliveryException.java @@ -16,7 +16,7 @@ package org.springframework.messaging; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception that indicates an error occurred during message delivery. 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 5d0f0d2c85..c7cdb761e7 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessageHeaders.java @@ -30,8 +30,8 @@ import java.util.UUID; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.AlternativeJdkIdGenerator; import org.springframework.util.CollectionUtils; import org.springframework.util.IdGenerator; @@ -112,8 +112,7 @@ public class MessageHeaders implements Map, Serializable { private static final IdGenerator defaultIdGenerator = new AlternativeJdkIdGenerator(); - @Nullable - private static volatile IdGenerator idGenerator; + private static volatile @Nullable IdGenerator idGenerator; @SuppressWarnings("serial") private final Map headers; @@ -183,30 +182,25 @@ public class MessageHeaders implements Map, Serializable { return (generator != null ? generator : defaultIdGenerator); } - @Nullable - public UUID getId() { + public @Nullable UUID getId() { return get(ID, UUID.class); } - @Nullable - public Long getTimestamp() { + public @Nullable Long getTimestamp() { return get(TIMESTAMP, Long.class); } - @Nullable - public Object getReplyChannel() { + public @Nullable Object getReplyChannel() { return get(REPLY_CHANNEL); } - @Nullable - public Object getErrorChannel() { + public @Nullable Object getErrorChannel() { return get(ERROR_CHANNEL); } @SuppressWarnings("unchecked") - @Nullable - public T get(Object key, Class type) { + public @Nullable T get(Object key, Class type) { Object value = this.headers.get(key); if (value == null) { return null; @@ -237,8 +231,7 @@ public class MessageHeaders implements Map, Serializable { } @Override - @Nullable - public Object get(Object key) { + public @Nullable Object get(Object key) { return this.headers.get(key); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/MessagingException.java b/spring-messaging/src/main/java/org/springframework/messaging/MessagingException.java index bd2f8d26af..05ed6d76e6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/MessagingException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/MessagingException.java @@ -16,8 +16,9 @@ package org.springframework.messaging; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * The base exception for any failures related to messaging. @@ -29,8 +30,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class MessagingException extends NestedRuntimeException { - @Nullable - private final Message failedMessage; + private final @Nullable Message failedMessage; public MessagingException(Message message) { @@ -64,8 +64,7 @@ public class MessagingException extends NestedRuntimeException { } - @Nullable - public Message getFailedMessage() { + public @Nullable Message getFailedMessage() { return this.failedMessage; } 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 1dc0ba7780..8bedc2814f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/PollableChannel.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/PollableChannel.java @@ -16,7 +16,7 @@ package org.springframework.messaging; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A {@link MessageChannel} from which messages may be actively received through polling. @@ -30,8 +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(); + @Nullable Message receive(); /** * Receive a message from this channel, blocking until either a message is available @@ -40,7 +39,6 @@ public interface PollableChannel extends MessageChannel { * @return the next available {@link Message} or {@code null} if the specified timeout * period elapses or the message receipt is interrupted */ - @Nullable - Message receive(long timeout); + @Nullable Message receive(long timeout); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractJsonMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractJsonMessageConverter.java index a73dccd77b..a837d6fc2f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractJsonMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/AbstractJsonMessageConverter.java @@ -28,7 +28,8 @@ import java.lang.reflect.Type; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.ClassUtils; @@ -62,8 +63,7 @@ public abstract class AbstractJsonMessageConverter extends AbstractMessageConver } @Override - @Nullable - protected Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { + protected @Nullable Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { try { Type resolvedType = getResolvedType(targetClass, conversionHint); Object payload = message.getPayload(); @@ -84,8 +84,7 @@ public abstract class AbstractJsonMessageConverter extends AbstractMessageConver } @Override - @Nullable - protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { + protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { try { Type resolvedType = getResolvedType(payload.getClass(), conversionHint); if (byte[].class == getSerializedPayloadClass()) { 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 60c88c0ea9..2c3249b024 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 @@ -25,10 +25,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; @@ -53,8 +53,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter private final List supportedMimeTypes = new ArrayList<>(4); - @Nullable - private ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver(); + private @Nullable ContentTypeResolver contentTypeResolver = new DefaultContentTypeResolver(); private boolean strictContentTypeMatch = false; @@ -116,8 +115,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * Return the {@link #setContentTypeResolver(ContentTypeResolver) configured} * {@code ContentTypeResolver}. */ - @Nullable - public ContentTypeResolver getContentTypeResolver() { + public @Nullable ContentTypeResolver getContentTypeResolver() { return this.contentTypeResolver; } @@ -169,14 +167,12 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter @Override - @Nullable - public final Object fromMessage(Message message, Class targetClass) { + public final @Nullable Object fromMessage(Message message, Class targetClass) { return fromMessage(message, targetClass, null); } @Override - @Nullable - public final Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint) { + public final @Nullable Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint) { if (!canConvertFrom(message, targetClass)) { return null; } @@ -184,14 +180,12 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter } @Override - @Nullable - public final Message toMessage(Object payload, @Nullable MessageHeaders headers) { + public final @Nullable Message toMessage(Object payload, @Nullable MessageHeaders headers) { return toMessage(payload, headers, null); } @Override - @Nullable - public final Message toMessage( + public final @Nullable Message toMessage( Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { if (!canConvertTo(payload, headers)) { @@ -249,8 +243,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter return false; } - @Nullable - protected MimeType getMimeType(@Nullable MessageHeaders headers) { + protected @Nullable MimeType getMimeType(@Nullable MessageHeaders headers) { return (this.contentTypeResolver != null ? this.contentTypeResolver.resolve(headers) : null); } @@ -264,8 +257,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * @param payload the payload being converted to a message * @return the content type, or {@code null} if not known */ - @Nullable - protected MimeType getDefaultContentType(Object payload) { + protected @Nullable MimeType getDefaultContentType(Object payload) { List mimeTypes = getSupportedMimeTypes(); return (!mimeTypes.isEmpty() ? mimeTypes.get(0) : null); } @@ -288,8 +280,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * perform the conversion * @since 4.2 */ - @Nullable - protected Object convertFromInternal( + protected @Nullable Object convertFromInternal( Message message, Class targetClass, @Nullable Object conversionHint) { return null; @@ -305,8 +296,7 @@ public abstract class AbstractMessageConverter implements SmartMessageConverter * cannot perform the conversion * @since 4.2 */ - @Nullable - protected Object convertToInternal( + protected @Nullable Object convertToInternal( Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { return null; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/ByteArrayMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/ByteArrayMessageConverter.java index 0a26c82f0d..8762b6cab4 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/ByteArrayMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/ByteArrayMessageConverter.java @@ -16,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.MimeTypeUtils; @@ -41,16 +42,14 @@ public class ByteArrayMessageConverter extends AbstractMessageConverter { } @Override - @Nullable - protected Object convertFromInternal( + protected @Nullable Object convertFromInternal( Message message, @Nullable Class targetClass, @Nullable Object conversionHint) { return message.getPayload(); } @Override - @Nullable - protected Object convertToInternal( + protected @Nullable Object convertToInternal( Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { return payload; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/CompositeMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/CompositeMessageConverter.java index 0c46db9234..cc803975dc 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/CompositeMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/CompositeMessageConverter.java @@ -20,7 +20,8 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -51,8 +52,7 @@ public class CompositeMessageConverter implements SmartMessageConverter { @Override - @Nullable - public Object fromMessage(Message message, Class targetClass) { + public @Nullable Object fromMessage(Message message, Class targetClass) { for (MessageConverter converter : getConverters()) { Object result = converter.fromMessage(message, targetClass); if (result != null) { @@ -63,8 +63,7 @@ public class CompositeMessageConverter implements SmartMessageConverter { } @Override - @Nullable - public Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint) { + public @Nullable Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint) { for (MessageConverter converter : getConverters()) { Object result = (converter instanceof SmartMessageConverter smartMessageConverter ? smartMessageConverter.fromMessage(message, targetClass, conversionHint) : @@ -77,8 +76,7 @@ public class CompositeMessageConverter implements SmartMessageConverter { } @Override - @Nullable - public Message toMessage(Object payload, @Nullable MessageHeaders headers) { + public @Nullable Message toMessage(Object payload, @Nullable MessageHeaders headers) { for (MessageConverter converter : getConverters()) { Message result = converter.toMessage(payload, headers); if (result != null) { @@ -89,8 +87,7 @@ public class CompositeMessageConverter implements SmartMessageConverter { } @Override - @Nullable - public Message toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { + public @Nullable Message toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { for (MessageConverter converter : getConverters()) { Message result = (converter instanceof SmartMessageConverter smartMessageConverter ? smartMessageConverter.toMessage(payload, headers, conversionHint) : 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 b116e8bdb8..61440abbe0 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,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessageHeaders; import org.springframework.util.InvalidMimeTypeException; import org.springframework.util.MimeType; @@ -37,7 +38,6 @@ public interface ContentTypeResolver { * @throws InvalidMimeTypeException if the content type is a String that cannot be parsed * @throws IllegalArgumentException if there is a content type but its type is unknown */ - @Nullable - MimeType resolve(@Nullable MessageHeaders headers) throws InvalidMimeTypeException; + @Nullable MimeType resolve(@Nullable MessageHeaders headers) throws InvalidMimeTypeException; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/DefaultContentTypeResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/DefaultContentTypeResolver.java index 8dca8058c2..77bba89461 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/DefaultContentTypeResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/DefaultContentTypeResolver.java @@ -16,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessageHeaders; import org.springframework.util.MimeType; @@ -32,8 +33,7 @@ import org.springframework.util.MimeType; */ public class DefaultContentTypeResolver implements ContentTypeResolver { - @Nullable - private MimeType defaultMimeType; + private @Nullable MimeType defaultMimeType; /** @@ -49,15 +49,13 @@ public class DefaultContentTypeResolver implements ContentTypeResolver { * Return the default MIME type to use if no * {@link MessageHeaders#CONTENT_TYPE} header is present. */ - @Nullable - public MimeType getDefaultMimeType() { + public @Nullable MimeType getDefaultMimeType() { return this.defaultMimeType; } @Override - @Nullable - public MimeType resolve(@Nullable MessageHeaders headers) { + public @Nullable MimeType resolve(@Nullable MessageHeaders headers) { if (headers == null || headers.get(MessageHeaders.CONTENT_TYPE) == null) { return this.defaultMimeType; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/GenericMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/GenericMessageConverter.java index fbe8165b98..1b55d55b53 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/GenericMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/GenericMessageConverter.java @@ -16,10 +16,11 @@ package org.springframework.messaging.converter; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionException; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -58,8 +59,7 @@ public class GenericMessageConverter extends SimpleMessageConverter { @Override - @Nullable - public Object fromMessage(Message message, Class targetClass) { + public @Nullable Object fromMessage(Message message, Class targetClass) { Object payload = message.getPayload(); if (this.conversionService.canConvert(payload.getClass(), targetClass)) { try { 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 d43e991870..56bd08feea 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 @@ -34,9 +34,9 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.MapperFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; +import org.jspecify.annotations.Nullable; 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; @@ -64,8 +64,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { private ObjectMapper objectMapper; - @Nullable - private Boolean prettyPrint; + private @Nullable Boolean prettyPrint; /** @@ -227,8 +226,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { } @Override - @Nullable - protected Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { + protected @Nullable Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { JavaType javaType = this.objectMapper.constructType(getResolvedType(targetClass, conversionHint)); Object payload = message.getPayload(); Class view = getSerializationView(conversionHint); @@ -260,8 +258,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { } @Override - @Nullable - protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, + protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { try { @@ -304,8 +301,7 @@ public class MappingJackson2MessageConverter extends AbstractMessageConverter { * @return the serialization view class, or {@code null} if none * @since 4.2 */ - @Nullable - protected Class getSerializationView(@Nullable Object conversionHint) { + protected @Nullable Class getSerializationView(@Nullable Object conversionHint) { if (conversionHint instanceof MethodParameter param) { JsonView annotation = (param.getParameterIndex() >= 0 ? param.getParameterAnnotation(JsonView.class) : param.getMethodAnnotation(JsonView.class)); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java index 0821559db6..92653d96ce 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/MarshallingMessageConverter.java @@ -27,8 +27,9 @@ import javax.xml.transform.Source; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.TypeMismatchException; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.oxm.Marshaller; @@ -51,11 +52,9 @@ import org.springframework.util.MimeType; */ public class MarshallingMessageConverter extends AbstractMessageConverter { - @Nullable - private Marshaller marshaller; + private @Nullable Marshaller marshaller; - @Nullable - private Unmarshaller unmarshaller; + private @Nullable Unmarshaller unmarshaller; /** @@ -102,8 +101,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter { /** * Return the configured Marshaller. */ - @Nullable - public Marshaller getMarshaller() { + public @Nullable Marshaller getMarshaller() { return this.marshaller; } @@ -117,8 +115,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter { /** * Return the configured unmarshaller. */ - @Nullable - public Unmarshaller getUnmarshaller() { + public @Nullable Unmarshaller getUnmarshaller() { return this.unmarshaller; } @@ -142,8 +139,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter { } @Override - @Nullable - protected Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { + protected @Nullable Object convertFromInternal(Message message, Class targetClass, @Nullable Object conversionHint) { Assert.state(this.unmarshaller != null, "Property 'unmarshaller' is required"); try { Source source = getSource(message.getPayload()); @@ -168,8 +164,7 @@ public class MarshallingMessageConverter extends AbstractMessageConverter { } @Override - @Nullable - protected Object convertToInternal(Object payload, @Nullable MessageHeaders headers, + protected @Nullable Object convertToInternal(Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { Assert.state(this.marshaller != null, "Property 'marshaller' is required"); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConversionException.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConversionException.java index 3a6922a2fc..68ab727325 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConversionException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/MessageConversionException.java @@ -16,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; 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 84d95e6d7d..3de08c007e 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,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -42,8 +43,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); + @Nullable Object fromMessage(Message message, Class targetClass); /** * Create a {@link Message} whose payload is the result of converting the given @@ -58,7 +58,6 @@ public interface MessageConverter { * @return the new message, or {@code null} if the converter does not support the * Object type or the target media type */ - @Nullable - Message toMessage(Object payload, @Nullable MessageHeaders headers); + @Nullable Message toMessage(Object payload, @Nullable MessageHeaders headers); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufJsonFormatMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufJsonFormatMessageConverter.java index 62fa2c6206..17f300fd2d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufJsonFormatMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufJsonFormatMessageConverter.java @@ -18,8 +18,7 @@ package org.springframework.messaging.converter; import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.util.JsonFormat; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Subclass of {@link ProtobufMessageConverter} for use with the official @@ -52,7 +51,7 @@ public class ProtobufJsonFormatMessageConverter extends ProtobufMessageConverter * JsonFormat.Printer}, and a default instance of {@link ExtensionRegistry}. */ public ProtobufJsonFormatMessageConverter( - @Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) { + JsonFormat.@Nullable Parser parser, JsonFormat.@Nullable Printer printer) { this(parser, printer, null); } @@ -62,8 +61,8 @@ public class ProtobufJsonFormatMessageConverter extends ProtobufMessageConverter * JsonFormat.Parser}, {@link com.google.protobuf.util.JsonFormat.Printer * JsonFormat.Printer}, and {@link ExtensionRegistry}. */ - public ProtobufJsonFormatMessageConverter(@Nullable JsonFormat.Parser parser, - @Nullable JsonFormat.Printer printer, @Nullable ExtensionRegistry extensionRegistry) { + public ProtobufJsonFormatMessageConverter(JsonFormat.@Nullable Parser parser, + JsonFormat.@Nullable Printer printer, @Nullable ExtensionRegistry extensionRegistry) { super(new ProtobufJavaUtilSupport(parser, printer), extensionRegistry); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java index bab066d23b..e3ae174697 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/ProtobufMessageConverter.java @@ -28,8 +28,8 @@ import java.util.Map; import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.Message; import com.google.protobuf.util.JsonFormat; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -75,8 +75,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter { final ExtensionRegistry extensionRegistry; - @Nullable - private final ProtobufFormatSupport protobufFormatSupport; + private final @Nullable ProtobufFormatSupport protobufFormatSupport; /** @@ -244,7 +243,7 @@ public class ProtobufMessageConverter extends AbstractMessageConverter { private final JsonFormat.Printer printer; - public ProtobufJavaUtilSupport(@Nullable JsonFormat.Parser parser, @Nullable JsonFormat.Printer printer) { + public ProtobufJavaUtilSupport(JsonFormat.@Nullable Parser parser, JsonFormat.@Nullable Printer printer) { this.parser = (parser != null ? parser : JsonFormat.parser()); this.printer = (printer != null ? printer : JsonFormat.printer()); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/converter/SimpleMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/SimpleMessageConverter.java index 9f2407300c..ba5fd5040c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/SimpleMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/SimpleMessageConverter.java @@ -16,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageBuilder; @@ -36,8 +37,7 @@ import org.springframework.util.ClassUtils; public class SimpleMessageConverter implements MessageConverter { @Override - @Nullable - public Object fromMessage(Message message, Class targetClass) { + public @Nullable Object fromMessage(Message message, Class targetClass) { Object payload = message.getPayload(); return (ClassUtils.isAssignableValue(targetClass, payload) ? payload : null); } 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 cba7ff9c2a..5120b1a6a2 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,7 +16,8 @@ package org.springframework.messaging.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -44,8 +45,7 @@ public interface SmartMessageConverter extends MessageConverter { * perform the conversion * @see #fromMessage(Message, Class) */ - @Nullable - Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint); + @Nullable Object fromMessage(Message message, Class targetClass, @Nullable Object conversionHint); /** * A variant of {@link #toMessage(Object, MessageHeaders)} which takes an extra @@ -59,7 +59,6 @@ public interface SmartMessageConverter extends MessageConverter { * Object type or the target media type * @see #toMessage(Object, MessageHeaders) */ - @Nullable - Message toMessage(Object payload, @Nullable MessageHeaders headers, @Nullable 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/StringMessageConverter.java b/spring-messaging/src/main/java/org/springframework/messaging/converter/StringMessageConverter.java index 9bcfcc93a4..85293e9baf 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/converter/StringMessageConverter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/converter/StringMessageConverter.java @@ -19,7 +19,8 @@ package org.springframework.messaging.converter; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -61,8 +62,7 @@ public class StringMessageConverter extends AbstractMessageConverter { } @Override - @Nullable - protected Object convertToInternal( + protected @Nullable Object convertToInternal( Object payload, @Nullable MessageHeaders headers, @Nullable Object conversionHint) { if (byte[].class == getSerializedPayloadClass()) { 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 c5dcb046af..3a76fc8b7a 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,9 +1,7 @@ /** * Provides support for message conversion. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.converter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractDestinationResolvingMessagingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractDestinationResolvingMessagingTemplate.java index d16dda9f56..3b29c98434 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractDestinationResolvingMessagingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractDestinationResolvingMessagingTemplate.java @@ -18,7 +18,8 @@ package org.springframework.messaging.core; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -42,8 +43,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A DestinationResolvingMessageReceivingOperations, DestinationResolvingMessageRequestReplyOperations { - @Nullable - private DestinationResolver destinationResolver; + private @Nullable DestinationResolver destinationResolver; /** @@ -60,8 +60,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A /** * Return the configured destination resolver. */ - @Nullable - public DestinationResolver getDestinationResolver() { + public @Nullable DestinationResolver getDestinationResolver() { return this.destinationResolver; } @@ -102,36 +101,31 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A } @Override - @Nullable - public Message receive(String destinationName) { + public @Nullable Message receive(String destinationName) { D destination = resolveDestination(destinationName); return super.receive(destination); } @Override - @Nullable - public T receiveAndConvert(String destinationName, Class targetClass) { + public @Nullable T receiveAndConvert(String destinationName, Class targetClass) { D destination = resolveDestination(destinationName); return super.receiveAndConvert(destination, targetClass); } @Override - @Nullable - public Message sendAndReceive(String destinationName, Message requestMessage) { + public @Nullable Message sendAndReceive(String destinationName, Message requestMessage) { D destination = resolveDestination(destinationName); return super.sendAndReceive(destination, requestMessage); } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, Class targetClass) { + public @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) { D destination = resolveDestination(destinationName); return super.convertSendAndReceive(destination, request, targetClass); } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, + public @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass) { D destination = resolveDestination(destinationName); @@ -139,8 +133,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, Class targetClass, + public @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) { D destination = resolveDestination(destinationName); @@ -148,8 +141,7 @@ public abstract class AbstractDestinationResolvingMessagingTemplate extends A } @Override - @Nullable - public T convertSendAndReceive(String destinationName, Object request, + public @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass, @Nullable MessagePostProcessor postProcessor) { 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 ab86900198..518faee934 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,7 +16,8 @@ package org.springframework.messaging.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; @@ -35,14 +36,12 @@ public abstract class AbstractMessageReceivingTemplate extends AbstractMessag implements MessageReceivingOperations { @Override - @Nullable - public Message receive() { + public @Nullable Message receive() { return doReceive(getRequiredDefaultDestination()); } @Override - @Nullable - public Message receive(D destination) { + public @Nullable Message receive(D destination) { return doReceive(destination); } @@ -52,19 +51,16 @@ 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); + protected abstract @Nullable Message doReceive(D destination); @Override - @Nullable - public T receiveAndConvert(Class targetClass) { + public @Nullable T receiveAndConvert(Class targetClass) { return receiveAndConvert(getRequiredDefaultDestination(), targetClass); } @Override - @Nullable - public T receiveAndConvert(D destination, Class targetClass) { + public @Nullable T receiveAndConvert(D destination, Class targetClass) { Message message = doReceive(destination); if (message != null) { return doConvert(message, targetClass); @@ -81,8 +77,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) { + protected @Nullable T doConvert(Message message, Class targetClass) { MessageConverter messageConverter = getMessageConverter(); T value = (T) messageConverter.fromMessage(message, targetClass); if (value == null) { 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 699dabe9e2..9e012166b7 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 @@ -20,8 +20,8 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessagingException; @@ -53,8 +53,7 @@ public abstract class AbstractMessageSendingTemplate implements MessageSendin protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private D defaultDestination; + private @Nullable D defaultDestination; private MessageConverter converter = new SimpleMessageConverter(); @@ -71,8 +70,7 @@ public abstract class AbstractMessageSendingTemplate implements MessageSendin /** * Return the configured default destination. */ - @Nullable - public D getDefaultDestination() { + public @Nullable D getDefaultDestination() { return this.defaultDestination; } @@ -194,8 +192,7 @@ 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) */ - @Nullable - protected Map processHeadersToSend(@Nullable Map headers) { + protected @Nullable Map processHeadersToSend(@Nullable Map headers) { return headers; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java index 2814e3512c..9911e7734e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/AbstractMessagingTemplate.java @@ -18,7 +18,8 @@ package org.springframework.messaging.core; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; /** @@ -35,52 +36,44 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv implements MessageRequestReplyOperations { @Override - @Nullable - public Message sendAndReceive(Message requestMessage) { + public @Nullable Message sendAndReceive(Message requestMessage) { return sendAndReceive(getRequiredDefaultDestination(), requestMessage); } @Override - @Nullable - public Message sendAndReceive(D destination, Message requestMessage) { + public @Nullable Message sendAndReceive(D destination, Message requestMessage) { return doSendAndReceive(destination, requestMessage); } - @Nullable - protected abstract Message doSendAndReceive(D destination, Message requestMessage); + protected abstract @Nullable Message doSendAndReceive(D destination, Message requestMessage); @Override - @Nullable - public T convertSendAndReceive(Object request, Class targetClass) { + public @Nullable T convertSendAndReceive(Object request, Class targetClass) { return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass); } @Override - @Nullable - public T convertSendAndReceive(D destination, Object request, Class targetClass) { + public @Nullable T convertSendAndReceive(D destination, Object request, Class targetClass) { return convertSendAndReceive(destination, request, null, targetClass); } @Override - @Nullable - public T convertSendAndReceive( + public @Nullable T convertSendAndReceive( D destination, Object request, @Nullable Map headers, Class targetClass) { return convertSendAndReceive(destination, request, headers, targetClass, null); } @Override - @Nullable - public T convertSendAndReceive( + public @Nullable T convertSendAndReceive( Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) { return convertSendAndReceive(getRequiredDefaultDestination(), request, targetClass, postProcessor); } @Override - @Nullable - public T convertSendAndReceive(D destination, Object request, Class targetClass, + public @Nullable T convertSendAndReceive(D destination, Object request, Class targetClass, @Nullable MessagePostProcessor postProcessor) { return convertSendAndReceive(destination, request, null, targetClass, postProcessor); @@ -88,8 +81,7 @@ public abstract class AbstractMessagingTemplate extends AbstractMessageReceiv @SuppressWarnings("unchecked") @Override - @Nullable - public T convertSendAndReceive(D destination, Object request, @Nullable Map headers, + public @Nullable T convertSendAndReceive(D destination, Object request, @Nullable Map headers, Class targetClass, @Nullable MessagePostProcessor postProcessor) { Message requestMessage = doConvert(request, headers, postProcessor); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/BeanFactoryMessageChannelDestinationResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/core/BeanFactoryMessageChannelDestinationResolver.java index 3ff3cd6826..3a189a9a49 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/BeanFactoryMessageChannelDestinationResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/BeanFactoryMessageChannelDestinationResolver.java @@ -16,10 +16,11 @@ package org.springframework.messaging.core; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; import org.springframework.messaging.MessageChannel; import org.springframework.util.Assert; @@ -34,8 +35,7 @@ import org.springframework.util.Assert; public class BeanFactoryMessageChannelDestinationResolver implements DestinationResolver, BeanFactoryAware { - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java b/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java index bf83792123..240cb82a8e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/CachingDestinationResolverProxy.java @@ -19,8 +19,9 @@ package org.springframework.messaging.core; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,8 +40,7 @@ public class CachingDestinationResolverProxy implements DestinationResolver resolvedDestinationCache = new ConcurrentHashMap<>(); - @Nullable - private DestinationResolver targetDestinationResolver; + private @Nullable DestinationResolver targetDestinationResolver; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolutionException.java b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolutionException.java index 282b4a2de8..17899462d6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolutionException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolutionException.java @@ -16,7 +16,8 @@ package org.springframework.messaging.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessagingException; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageReceivingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageReceivingOperations.java index b85f20622c..035b97dcba 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageReceivingOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageReceivingOperations.java @@ -16,7 +16,8 @@ package org.springframework.messaging.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -36,8 +37,7 @@ public interface DestinationResolvingMessageReceivingOperations extends Messa * Resolve the given destination name and receive a message from it. * @param destinationName the destination name to resolve */ - @Nullable - Message receive(String destinationName) throws MessagingException; + @Nullable Message receive(String destinationName) throws MessagingException; /** * Resolve the given destination name, receive a message from it, @@ -45,7 +45,6 @@ public interface DestinationResolvingMessageReceivingOperations extends Messa * @param destinationName the destination name to resolve * @param targetClass the target class for the converted payload */ - @Nullable - T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException; + @Nullable T receiveAndConvert(String destinationName, Class targetClass) throws MessagingException; } 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 16c3e4e4e1..f90dc2235d 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,7 +18,8 @@ package org.springframework.messaging.core; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -42,8 +43,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; + @Nullable Message sendAndReceive(String destinationName, Message requestMessage) throws MessagingException; /** * Resolve the given destination name, convert the payload request Object @@ -57,8 +57,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) + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass) throws MessagingException; /** @@ -74,8 +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, + @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass) throws MessagingException; /** @@ -92,8 +90,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, + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException; /** @@ -111,8 +108,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, @Nullable Map headers, + @Nullable T convertSendAndReceive(String destinationName, Object request, @Nullable Map headers, Class targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java index 6abe4dda58..4a40707d7e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/DestinationResolvingMessageSendingOperations.java @@ -18,7 +18,8 @@ package org.springframework.messaging.core; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java index 95952f4b0b..a6e82711b6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java @@ -21,11 +21,11 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -193,13 +193,11 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag } @Override - @Nullable - protected final Message doReceive(MessageChannel channel) { + protected final @Nullable Message doReceive(MessageChannel channel) { return doReceive(channel, this.receiveTimeout); } - @Nullable - protected final Message doReceive(MessageChannel channel, long timeout) { + protected final @Nullable Message doReceive(MessageChannel channel, long timeout) { Assert.notNull(channel, "MessageChannel is required"); if (!(channel instanceof PollableChannel pollableChannel)) { throw new IllegalStateException("A PollableChannel is required to receive messages"); @@ -215,8 +213,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag } @Override - @Nullable - protected final Message doSendAndReceive(MessageChannel channel, Message requestMessage) { + protected final @Nullable Message doSendAndReceive(MessageChannel channel, Message requestMessage) { Assert.notNull(channel, "'channel' is required"); Object originalReplyChannelHeader = requestMessage.getHeaders().getReplyChannel(); Object originalErrorChannelHeader = requestMessage.getHeaders().getErrorChannel(); @@ -259,8 +256,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag return (receiveTimeout != null ? receiveTimeout : this.receiveTimeout); } - @Nullable - private Long headerToLong(@Nullable Object headerValue) { + private @Nullable Long headerToLong(@Nullable Object headerValue) { if (headerValue instanceof Number number) { return number.longValue(); } @@ -284,8 +280,7 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag private final boolean throwExceptionOnLateReply; - @Nullable - private volatile Message replyMessage; + private volatile @Nullable Message replyMessage; private volatile boolean hasReceived; @@ -302,14 +297,12 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag } @Override - @Nullable - public Message receive() { + public @Nullable Message receive() { return this.receive(-1); } @Override - @Nullable - public Message receive(long timeout) { + public @Nullable Message receive(long timeout) { try { if (timeout < 0) { this.replyLatch.await(); 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 18a1062f2d..2079db56fd 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,7 +16,8 @@ package org.springframework.messaging.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -36,8 +37,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; + @Nullable Message receive() throws MessagingException; /** * Receive a message from the given destination. @@ -45,8 +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; + @Nullable Message receive(D destination) throws MessagingException; /** * Receive a message from a default destination and convert its payload to the @@ -55,8 +54,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; + @Nullable T receiveAndConvert(Class targetClass) throws MessagingException; /** * Receive a message from the given destination and convert its payload to the @@ -66,7 +64,6 @@ 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; + @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 249fa9c668..83882510dc 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,7 +18,8 @@ package org.springframework.messaging.core; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; @@ -39,8 +40,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; + @Nullable Message sendAndReceive(Message requestMessage) throws MessagingException; /** * Send a request message and receive the reply from the given destination. @@ -49,8 +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; + @Nullable Message sendAndReceive(D destination, Message requestMessage) throws MessagingException; /** * Convert the given request Object to serialized form, possibly using a @@ -62,8 +61,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; + @Nullable T convertSendAndReceive(Object request, Class targetClass) throws MessagingException; /** * Convert the given request Object to serialized form, possibly using a @@ -76,8 +74,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; + @Nullable T convertSendAndReceive(D destination, Object request, Class targetClass) throws MessagingException; /** * Convert the given request Object to serialized form, possibly using a @@ -91,8 +88,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( + @Nullable T convertSendAndReceive( D destination, Object request, @Nullable Map headers, Class targetClass) throws MessagingException; @@ -108,8 +104,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( + @Nullable T convertSendAndReceive( Object request, Class targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException; @@ -126,8 +121,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, + @Nullable T convertSendAndReceive(D destination, Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; /** @@ -143,8 +137,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( + @Nullable T convertSendAndReceive( D destination, Object request, @Nullable Map headers, Class targetClass, @Nullable MessagePostProcessor requestPostProcessor) throws MessagingException; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java index 93944974a0..f961d0dc79 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/core/MessageSendingOperations.java @@ -18,7 +18,8 @@ package org.springframework.messaging.core; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.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 ed87d0e45a..41eb9cd090 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,9 +1,7 @@ /** * Defines interfaces and implementation classes for messaging templates. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.core; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java index 1df91f7495..085ce64ac5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/AbstractMessageCondition.java @@ -19,7 +19,7 @@ package org.springframework.messaging.handler; import java.util.Collection; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Base class for {@code MessageCondition's} that pre-declares abstract methods diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/CompositeMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/CompositeMessageCondition.java index d9c908fb92..75f6f482d9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/CompositeMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/CompositeMessageCondition.java @@ -21,7 +21,8 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.util.Assert; @@ -80,8 +81,7 @@ public class CompositeMessageCondition implements MessageCondition message) { + public @Nullable CompositeMessageCondition getMatchingCondition(Message message) { List> result = new ArrayList<>(this.messageConditions.size()); for (MessageCondition condition : this.messageConditions) { MessageCondition matchingCondition = (MessageCondition) condition.getMatchingCondition(message); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java index bdb6e23dec..4035666940 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/DestinationPatternsMessageCondition.java @@ -25,7 +25,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.util.AntPathMatcher; import org.springframework.util.CollectionUtils; @@ -160,8 +161,7 @@ public class DestinationPatternsMessageCondition * or {@code null} either if a destination can not be extracted or there is no match */ @Override - @Nullable - public DestinationPatternsMessageCondition getMatchingCondition(Message message) { + public @Nullable DestinationPatternsMessageCondition getMatchingCondition(Message message) { Object destination = message.getHeaders().get(LOOKUP_DESTINATION_HEADER); if (destination == null) { return null; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java index 7dfd09c6f4..08ad08ea38 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java @@ -22,10 +22,10 @@ import java.util.stream.IntStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.core.annotation.AnnotatedMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -53,13 +53,11 @@ public class HandlerMethod extends AnnotatedMethod { private final Object bean; - @Nullable - private final BeanFactory beanFactory; + private final @Nullable BeanFactory beanFactory; private final Class beanType; - @Nullable - private HandlerMethod resolvedFromHandlerMethod; + private @Nullable HandlerMethod resolvedFromHandlerMethod; protected Log logger = defaultLogger; @@ -167,8 +165,7 @@ public class HandlerMethod extends AnnotatedMethod { * resolved via {@link #createWithResolvedBean()}. * @since 4.3 */ - @Nullable - public HandlerMethod getResolvedFromHandlerMethod() { + public @Nullable HandlerMethod getResolvedFromHandlerMethod() { return this.resolvedFromHandlerMethod; } @@ -215,7 +212,7 @@ public class HandlerMethod extends AnnotatedMethod { * beans, and others). Endpoint classes that require proxying should prefer * class-based proxy mechanisms. */ - protected void assertTargetBean(Method method, Object targetBean, Object[] args) { + protected void assertTargetBean(Method method, Object targetBean, @Nullable Object[] args) { Class methodDeclaringClass = method.getDeclaringClass(); Class targetBeanClass = targetBean.getClass(); if (!methodDeclaringClass.isAssignableFrom(targetBeanClass)) { @@ -227,7 +224,7 @@ public class HandlerMethod extends AnnotatedMethod { } } - protected String formatInvokeError(String text, Object[] args) { + protected String formatInvokeError(String text, @Nullable Object[] args) { String formattedArgs = IntStream.range(0, args.length) .mapToObj(i -> (args[i] != null ? "[" + i + "] [type=" + args[i].getClass().getName() + "] [value=" + args[i] + "]" : 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 e2547f08f7..9fb9b81e88 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,7 +16,8 @@ package org.springframework.messaging.handler; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; /** @@ -47,8 +48,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); + @Nullable T getMatchingCondition(Message message); /** * Compare this condition to another in the context of a specific message. diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/MessagingAdviceBean.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/MessagingAdviceBean.java index 21216f1bf6..9d5eb345b8 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/MessagingAdviceBean.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/MessagingAdviceBean.java @@ -16,8 +16,9 @@ package org.springframework.messaging.handler; +import org.jspecify.annotations.Nullable; + import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; /** * Represents a Spring-managed bean with cross-cutting functionality to be @@ -40,8 +41,7 @@ public interface MessagingAdviceBean extends Ordered { *

    If the bean type is a CGLIB-generated class, the original user-defined * class is returned. */ - @Nullable - Class getBeanType(); + @Nullable Class getBeanType(); /** * Return the advice bean instance, if necessary resolving a bean specified diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java index 94b592f067..a5ff0004ba 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/MessageMappingReflectiveProcessor.java @@ -22,12 +22,13 @@ import java.lang.reflect.Parameter; import java.lang.reflect.Type; import java.security.Principal; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.annotation.ReflectiveProcessor; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.support.MessageHeaderAccessor; @@ -114,8 +115,7 @@ public class MessageMappingReflectiveProcessor implements ReflectiveProcessor { this.bindingRegistrar.registerReflectionHints(hints, returnType.getGenericParameterType()); } - @Nullable - protected Type getMessageType(MethodParameter parameter) { + protected @Nullable Type getMessageType(MethodParameter parameter) { MethodParameter nestedParameter = parameter.nested(); return (nestedParameter.getNestedParameterType() == nestedParameter.getParameterType() ? null : nestedParameter.getNestedParameterType()); 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 3259288c04..07a9bff88d 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,9 +1,7 @@ /** * Annotations and support classes for handling messages. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.handler.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/AbstractNamedValueMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/AbstractNamedValueMethodArgumentResolver.java index 1a169e7294..22e8cb9d03 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/AbstractNamedValueMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/AbstractNamedValueMethodArgumentResolver.java @@ -19,6 +19,8 @@ package org.springframework.messaging.handler.annotation.reactive; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.beans.factory.config.BeanExpressionResolver; @@ -26,7 +28,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.TypeDescriptor; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.annotation.ValueConstants; import org.springframework.messaging.handler.invocation.reactive.SyncHandlerMethodArgumentResolver; @@ -55,11 +56,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa private final ConversionService conversionService; - @Nullable - private final ConfigurableBeanFactory configurableBeanFactory; + private final @Nullable ConfigurableBeanFactory configurableBeanFactory; - @Nullable - private final BeanExpressionContext expressionContext; + private final @Nullable BeanExpressionContext expressionContext; private final Map namedValueInfoCache = new ConcurrentHashMap<>(256); @@ -81,8 +80,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa @Override - @Nullable - public Object resolveArgumentValue(MethodParameter parameter, Message message) { + public @Nullable Object resolveArgumentValue(MethodParameter parameter, Message message) { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); @@ -167,8 +165,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa * Resolve the given annotation-specified value, * potentially containing placeholders and expressions. */ - @Nullable - private Object resolveEmbeddedValuesAndExpressions(String value) { + private @Nullable Object resolveEmbeddedValuesAndExpressions(String value) { if (this.configurableBeanFactory == null || this.expressionContext == null) { return value; } @@ -187,8 +184,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa * @param name the name of the value being resolved * @return the resolved argument. May be {@code null} */ - @Nullable - protected abstract Object resolveArgumentInternal(MethodParameter parameter, Message message, String name); + protected abstract @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message message, String name); /** * Invoked when a value is required, but {@link #resolveArgumentInternal} @@ -205,8 +201,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa * Specifically for booleans method parameters, use {@link Boolean#FALSE}. * Also raise an ISE for primitive types. */ - @Nullable - private Object handleNullValue(String name, @Nullable Object value, Class paramType) { + private @Nullable Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (paramType == boolean.class) { return Boolean.FALSE; @@ -231,8 +226,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements SyncHa private final boolean required; - @Nullable - private final String defaultValue; + private final @Nullable String defaultValue; protected NamedValueInfo(String name, boolean required, @Nullable String defaultValue) { this.name = name; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/DestinationVariableMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/DestinationVariableMethodArgumentResolver.java index 6cd3f07f08..367241fbc1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/DestinationVariableMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/DestinationVariableMethodArgumentResolver.java @@ -18,9 +18,10 @@ package org.springframework.messaging.handler.annotation.reactive; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.MessageHeaders; @@ -59,9 +60,8 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu } @Override - @Nullable @SuppressWarnings("unchecked") - protected Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) { + protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) { MessageHeaders headers = message.getHeaders(); Map vars = (Map) headers.get(DESTINATION_TEMPLATE_VARIABLES_HEADER); return vars != null ? vars.get(name) : null; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolver.java index 0c632ee931..35f752b11d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeaderMethodArgumentResolver.java @@ -21,11 +21,11 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -67,8 +67,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume } @Override - @Nullable - protected Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) { + protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) { Object headerValue = message.getHeaders().get(name); Object nativeHeaderValue = getNativeHeaderValue(message, name); @@ -84,8 +83,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume return (headerValue != null ? headerValue : nativeHeaderValue); } - @Nullable - private Object getNativeHeaderValue(Message message, String name) { + private @Nullable Object getNativeHeaderValue(Message message, String name) { Map> nativeHeaders = getNativeHeaders(message); if (name.startsWith("nativeHeaders.")) { name = name.substring("nativeHeaders.".length()); @@ -98,8 +96,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume } @SuppressWarnings("unchecked") - @Nullable - private Map> getNativeHeaders(Message message) { + private @Nullable Map> getNativeHeaders(Message message) { return (Map>) message.getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeadersMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeadersMethodArgumentResolver.java index 3912b97ce2..86cff18700 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeadersMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/HeadersMethodArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.messaging.handler.annotation.reactive; import java.lang.reflect.Method; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.handler.annotation.Headers; @@ -49,8 +50,7 @@ public class HeadersMethodArgumentResolver implements SyncHandlerMethodArgumentR } @Override - @Nullable - public Object resolveArgumentValue(MethodParameter parameter, Message message) { + public @Nullable Object resolveArgumentValue(MethodParameter parameter, Message message) { Class paramType = parameter.getParameterType(); if (Map.class.isAssignableFrom(paramType)) { return message.getHeaders(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java index 850fefbf17..6a910678fe 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/MessageMappingMessageHandler.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -39,7 +40,6 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.codec.Decoder; import org.springframework.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.CompositeMessageCondition; import org.springframework.messaging.handler.DestinationPatternsMessageCondition; @@ -86,16 +86,13 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler> decoders = new ArrayList<>(); - @Nullable - private Validator validator; + private @Nullable Validator validator; - @Nullable - private RouteMatcher routeMatcher; + private @Nullable RouteMatcher routeMatcher; private ConversionService conversionService = new DefaultFormattingConversionService(); - @Nullable - private StringValueResolver valueResolver; + private @Nullable StringValueResolver valueResolver; public MessageMappingMessageHandler() { @@ -130,8 +127,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler handlerType) { + protected @Nullable CompositeMessageCondition getMappingForMethod(Method method, Class handlerType) { CompositeMessageCondition methodCondition = getCondition(method); if (methodCondition != null) { CompositeMessageCondition typeCondition = getCondition(handlerType); @@ -289,8 +283,7 @@ public class MessageMappingMessageHandler extends AbstractMethodMessageHandler message) { + protected RouteMatcher.@Nullable Route getDestination(Message message) { return (RouteMatcher.Route) message.getHeaders() .get(DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER); } @Override - @Nullable - protected CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message message) { + protected @Nullable CompositeMessageCondition getMatchingMapping(CompositeMessageCondition mapping, Message message) { return mapping.getMatchingCondition(message); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java index 53004446d1..dbf352a148 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolver.java @@ -24,6 +24,7 @@ import java.util.function.Consumer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -37,7 +38,6 @@ import org.springframework.core.codec.Decoder; import org.springframework.core.codec.DecodingException; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.handler.annotation.Payload; @@ -79,8 +79,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol private final List> decoders; - @Nullable - private final Validator validator; + private final @Nullable Validator validator; private final ReactiveAdapterRegistry adapterRegistry; @@ -108,8 +107,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol /** * Return the configured validator, if any. */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return this.validator; } @@ -196,8 +194,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol * {@link MimeType} value or a String to parse to a {@link MimeType}. * @param message the input message */ - @Nullable - protected MimeType getMimeType(Message message) { + protected @Nullable MimeType getMimeType(Message message) { Object headerValue = message.getHeaders().get(MessageHeaders.CONTENT_TYPE); if (headerValue == null) { return null; @@ -279,8 +276,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol "Payload content is missing: " + param.getExecutable().toGenericString()); } - @Nullable - private Consumer getValidator(Message message, MethodParameter parameter) { + private @Nullable Consumer getValidator(Message message, MethodParameter parameter) { if (this.validator == null) { return null; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/package-info.java index cd1dcb8aba..923889f9d8 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/reactive/package-info.java @@ -2,9 +2,7 @@ * Support classes for working with annotated message-handling methods with * non-blocking, reactive contracts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.handler.annotation.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 fd17f5e1f7..2e8cab2909 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 @@ -19,6 +19,8 @@ package org.springframework.messaging.handler.annotation.support; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanExpressionContext; import org.springframework.beans.factory.config.BeanExpressionResolver; @@ -27,7 +29,6 @@ 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; @@ -57,11 +58,9 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle private final ConversionService conversionService; - @Nullable - private final ConfigurableBeanFactory configurableBeanFactory; + private final @Nullable ConfigurableBeanFactory configurableBeanFactory; - @Nullable - private final BeanExpressionContext expressionContext; + private final @Nullable BeanExpressionContext expressionContext; private final Map namedValueInfoCache = new ConcurrentHashMap<>(256); @@ -89,8 +88,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, Message message) throws Exception { + public @Nullable Object resolveArgument(MethodParameter parameter, Message message) throws Exception { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); MethodParameter nestedParameter = parameter.nestedIfOptional(); @@ -177,8 +175,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * Resolve the given annotation-specified value, * potentially containing placeholders and expressions. */ - @Nullable - private Object resolveEmbeddedValuesAndExpressions(String value) { + private @Nullable Object resolveEmbeddedValuesAndExpressions(String value) { if (this.configurableBeanFactory == null || this.expressionContext == null) { return value; } @@ -198,8 +195,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) + protected abstract @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) throws Exception; /** @@ -217,8 +213,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * Specifically for booleans method parameters, use {@link Boolean#FALSE}. * Also raise an ISE for primitive types. */ - @Nullable - private Object handleNullValue(String name, @Nullable Object value, Class paramType) { + private @Nullable Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (paramType == boolean.class) { return Boolean.FALSE; @@ -254,8 +249,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle private final boolean required; - @Nullable - private final String defaultValue; + private final @Nullable String defaultValue; protected NamedValueInfo(String name, boolean required, @Nullable String defaultValue) { this.name = name; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java index b1022ff357..4637549f67 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DefaultMessageHandlerMethodFactory.java @@ -20,13 +20,14 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + 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.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.messaging.converter.GenericMessageConverter; import org.springframework.messaging.converter.MessageConverter; import org.springframework.messaging.handler.invocation.HandlerMethodArgumentResolver; @@ -62,20 +63,16 @@ public class DefaultMessageHandlerMethodFactory private ConversionService conversionService = new DefaultFormattingConversionService(); - @Nullable - private MessageConverter messageConverter; + private @Nullable MessageConverter messageConverter; - @Nullable - private Validator validator; + private @Nullable Validator validator; - @Nullable - private List customArgumentResolvers; + private @Nullable List customArgumentResolvers; private final HandlerMethodArgumentResolverComposite argumentResolvers = new HandlerMethodArgumentResolverComposite(); - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java index ad80d5922d..7caab83952 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/DestinationVariableMethodArgumentResolver.java @@ -18,9 +18,10 @@ package org.springframework.messaging.handler.annotation.support; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.MessageHeaders; @@ -59,9 +60,8 @@ public class DestinationVariableMethodArgumentResolver extends AbstractNamedValu } @Override - @Nullable @SuppressWarnings("unchecked") - protected Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) { + protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) { MessageHeaders headers = message.getHeaders(); Map vars = (Map) headers.get(DESTINATION_TEMPLATE_VARIABLES_HEADER); return vars != null ? vars.get(name) : null; 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 e6b50f0586..e5b120ce55 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 @@ -21,11 +21,11 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -68,8 +68,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume } @Override - @Nullable - protected Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) + protected @Nullable Object resolveArgumentInternal(MethodParameter parameter, Message message, String name) throws Exception { Object headerValue = message.getHeaders().get(name); @@ -86,8 +85,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume return (headerValue != null ? headerValue : nativeHeaderValue); } - @Nullable - private Object getNativeHeaderValue(Message message, String name) { + private @Nullable Object getNativeHeaderValue(Message message, String name) { Map> nativeHeaders = getNativeHeaders(message); if (name.startsWith("nativeHeaders.")) { name = name.substring("nativeHeaders.".length()); @@ -100,8 +98,7 @@ public class HeaderMethodArgumentResolver extends AbstractNamedValueMethodArgume } @SuppressWarnings("unchecked") - @Nullable - private Map> getNativeHeaders(Message message) { + private @Nullable Map> getNativeHeaders(Message message) { return (Map>) message.getHeaders().get(NativeMessageHeaderAccessor.NATIVE_HEADERS); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java index 1981c1b254..b4d3cce6bd 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/HeadersMethodArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.messaging.handler.annotation.support; import java.lang.reflect.Method; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.handler.annotation.Headers; @@ -49,8 +50,7 @@ public class HeadersMethodArgumentResolver implements HandlerMethodArgumentResol } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, Message message) throws Exception { + public @Nullable Object resolveArgument(MethodParameter parameter, Message message) throws Exception { Class paramType = parameter.getParameterType(); if (Map.class.isAssignableFrom(paramType)) { return message.getHeaders(); 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 46f5c77884..4cac2c3a0e 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 @@ -18,9 +18,10 @@ package org.springframework.messaging.handler.annotation.support; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + 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; @@ -43,8 +44,7 @@ import org.springframework.util.StringUtils; */ public class MessageMethodArgumentResolver implements HandlerMethodArgumentResolver { - @Nullable - private final MessageConverter converter; + private final @Nullable MessageConverter converter; /** 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 9ab9da75ed..c581f86a69 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 @@ -16,8 +16,9 @@ package org.springframework.messaging.handler.annotation.support; +import org.jspecify.annotations.Nullable; + 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; @@ -34,8 +35,7 @@ import org.springframework.validation.ObjectError; @SuppressWarnings("serial") public class MethodArgumentNotValidException extends MethodArgumentResolutionException { - @Nullable - private final BindingResult bindingResult; + private final @Nullable BindingResult bindingResult; /** @@ -60,8 +60,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() { + public final @Nullable BindingResult getBindingResult() { return this.bindingResult; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolver.java index e38629fbee..b6bd7c14c8 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/PayloadMethodArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.messaging.handler.annotation.support; import java.lang.annotation.Annotation; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConversionException; import org.springframework.messaging.converter.MessageConverter; @@ -61,8 +62,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol private final MessageConverter converter; - @Nullable - private final Validator validator; + private final @Nullable Validator validator; private final boolean useDefaultResolution; @@ -111,8 +111,7 @@ public class PayloadMethodArgumentResolver implements HandlerMethodArgumentResol } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, Message message) throws Exception { + public @Nullable Object resolveArgument(MethodParameter parameter, Message message) throws Exception { Payload ann = parameter.getParameterAnnotation(Payload.class); if (ann != null && StringUtils.hasText(ann.expression())) { throw new IllegalStateException("@Payload SpEL expressions not supported by this resolver"); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/package-info.java index 494657e5c6..43dd5f21e7 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/annotation/support/package-info.java @@ -1,9 +1,7 @@ /** * Support classes for working with annotated message-handling methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.handler.annotation.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractAsyncReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractAsyncReturnValueHandler.java index 38801e420d..85279806e1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractAsyncReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/AbstractAsyncReturnValueHandler.java @@ -16,8 +16,9 @@ package org.springframework.messaging.handler.invocation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** 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 1c5b1593c8..dfd7ea3342 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 @@ -22,8 +22,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ExceptionDepthComparator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -98,8 +99,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(Throwable exception) { + public @Nullable Method resolveMethod(Throwable exception) { Method method = resolveMethodByExceptionType(exception.getClass()); if (method == null) { Throwable cause = exception.getCause(); @@ -118,8 +118,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) { + public @Nullable Method resolveMethodByExceptionType(Class exceptionType) { Method method = this.exceptionLookupCache.get(exceptionType); if (method == null) { method = getMappedMethod(exceptionType); @@ -132,8 +131,7 @@ public abstract class AbstractExceptionHandlerMethodResolver { * Return the {@link Method} mapped to the given exception type, or * {@link #NO_MATCHING_EXCEPTION_HANDLER_METHOD} if none. */ - @Nullable - private Method getMappedMethod(Class exceptionType) { + private @Nullable Method getMappedMethod(Class exceptionType) { List> matches = new ArrayList<>(); for (Class mappedException : this.mappedMethods.keySet()) { if (mappedException.isAssignableFrom(exceptionType)) { 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 c469fe0db2..99279d4827 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 @@ -34,13 +34,13 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; 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.MessageHandlingException; @@ -89,8 +89,7 @@ public abstract class AbstractMethodMessageHandler protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Log handlerMethodLogger; + private @Nullable Log handlerMethodLogger; private final List destinationPrefixes = new ArrayList<>(); @@ -105,8 +104,7 @@ public abstract class AbstractMethodMessageHandler private final HandlerMethodReturnValueHandlerComposite returnValueHandlers = new HandlerMethodReturnValueHandlerComposite(); - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; private final Map handlerMethods = new LinkedHashMap<>(64); @@ -225,8 +223,7 @@ public abstract class AbstractMethodMessageHandler this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -343,8 +340,7 @@ public abstract class AbstractMethodMessageHandler * @param handlerType the handler type, possibly a subtype 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); + protected abstract @Nullable T getMappingForMethod(Method method, Class handlerType); /** * Register a handler method and its unique mapping. @@ -399,8 +395,7 @@ public abstract class AbstractMethodMessageHandler * Return a logger to set on {@link HandlerMethodReturnValueHandlerComposite}. * @since 5.1 */ - @Nullable - protected Log getReturnValueHandlerLogger() { + protected @Nullable Log getReturnValueHandlerLogger() { return null; } @@ -408,8 +403,7 @@ public abstract class AbstractMethodMessageHandler * Return a logger to set on {@link InvocableHandlerMethod}. * @since 5.1 */ - @Nullable - protected Log getHandlerMethodLogger() { + protected @Nullable Log getHandlerMethodLogger() { return null; } @@ -458,8 +452,7 @@ public abstract class AbstractMethodMessageHandler headerAccessor.setImmutable(); } - @Nullable - protected abstract String getDestination(Message message); + protected abstract @Nullable String getDestination(Message message); /** * Check whether the given destination (of an incoming message) matches to @@ -469,8 +462,7 @@ public abstract class AbstractMethodMessageHandler *

    If there are no destination prefixes, return the destination as is. */ @SuppressWarnings("ForLoopReplaceableByForEach") - @Nullable - protected String getLookupDestination(@Nullable String destination) { + protected @Nullable String getLookupDestination(@Nullable String destination) { if (destination == null) { return null; } @@ -539,8 +531,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 abstract @Nullable T getMatchingMapping(T mapping, Message message); protected void handleNoMatch(Set ts, String lookupDestination, Message message) { logger.debug("No matching message handler methods."); @@ -628,8 +619,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) { + protected @Nullable 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 876329c2e2..cff9ff3fed 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 @@ -18,8 +18,9 @@ package org.springframework.messaging.handler.invocation; import java.util.concurrent.CompletableFuture; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * An extension of {@link HandlerMethodReturnValueHandler} for handling async, @@ -61,7 +62,6 @@ public interface AsyncHandlerMethodReturnValueHandler extends HandlerMethodRetur * no further handling will be performed * @since 6.0 */ - @Nullable - CompletableFuture toCompletableFuture(Object returnValue, MethodParameter returnType); + @Nullable CompletableFuture toCompletableFuture(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 4d1c17f95d..3a49369a18 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 @@ -16,8 +16,9 @@ package org.springframework.messaging.handler.invocation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -48,7 +49,6 @@ 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; + @Nullable Object resolveArgument(MethodParameter parameter, Message message) throws Exception; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java index 966fa70834..5b89bb8cda 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodArgumentResolverComposite.java @@ -22,8 +22,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -108,8 +109,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu * @throws IllegalArgumentException if no suitable argument resolver is found */ @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, Message message) throws Exception { + public @Nullable Object resolveArgument(MethodParameter parameter, Message message) throws Exception { HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); if (resolver == null) { throw new IllegalArgumentException("Unsupported parameter type [" + @@ -122,8 +122,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu * Find a registered {@link HandlerMethodArgumentResolver} that supports * the given method parameter. */ - @Nullable - private HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { + private @Nullable HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter); if (result == null) { for (HandlerMethodArgumentResolver resolver : this.argumentResolvers) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java index 3dca2443cc..ca768b7d7f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/HandlerMethodReturnValueHandler.java @@ -16,8 +16,9 @@ package org.springframework.messaging.handler.invocation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** 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 5e3ed7e3a8..d2b43df031 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 @@ -23,9 +23,9 @@ import java.util.concurrent.CompletableFuture; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -102,8 +102,7 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet } @SuppressWarnings("ForLoopReplaceableByForEach") - @Nullable - private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { + private @Nullable HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { if (handler.supportsReturnType(returnType)) { return handler; @@ -134,8 +133,7 @@ public class HandlerMethodReturnValueHandlerComposite implements AsyncHandlerMet } @Override - @Nullable - public CompletableFuture toCompletableFuture(Object returnValue, MethodParameter returnType) { + public @Nullable CompletableFuture toCompletableFuture(Object returnValue, MethodParameter returnType) { HandlerMethodReturnValueHandler handler = getReturnValueHandler(returnType); if (handler instanceof AsyncHandlerMethodReturnValueHandler asyncHandler) { return asyncHandler.toCompletableFuture(returnValue, 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 cc74ad6ed9..c3a6ce5609 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 @@ -21,11 +21,12 @@ import java.lang.reflect.Method; import java.lang.reflect.Type; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + 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.ObjectUtils; @@ -110,9 +111,8 @@ public class InvocableHandlerMethod extends HandlerMethod { * @see #getMethodArgumentValues * @see #doInvoke */ - @Nullable - public Object invoke(Message message, @Nullable Object... providedArgs) throws Exception { - Object[] args = getMethodArgumentValues(message, providedArgs); + public @Nullable Object invoke(Message message, @Nullable Object... providedArgs) throws Exception { + @Nullable Object[] args = getMethodArgumentValues(message, providedArgs); if (logger.isTraceEnabled()) { logger.trace("Arguments: " + Arrays.toString(args)); } @@ -125,13 +125,13 @@ public class InvocableHandlerMethod extends HandlerMethod { *

    The resulting array will be passed into {@link #doInvoke}. * @since 5.1.2 */ - protected Object[] getMethodArgumentValues(Message message, @Nullable Object... providedArgs) throws Exception { + protected @Nullable Object[] getMethodArgumentValues(Message message, @Nullable Object... providedArgs) throws Exception { MethodParameter[] parameters = getMethodParameters(); if (ObjectUtils.isEmpty(parameters)) { return EMPTY_ARGS; } - Object[] args = new Object[parameters.length]; + @Nullable Object[] args = new Object[parameters.length]; for (int i = 0; i < parameters.length; i++) { MethodParameter parameter = parameters[i]; parameter.initParameterNameDiscovery(this.parameterNameDiscoverer); @@ -163,8 +163,7 @@ public class InvocableHandlerMethod extends HandlerMethod { /** * Invoke the handler method with the given argument values. */ - @Nullable - protected Object doInvoke(Object... args) throws Exception { + protected @Nullable Object doInvoke(@Nullable Object... args) throws Exception { try { return getBridgedMethod().invoke(getBean(), args); } @@ -199,8 +198,7 @@ public class InvocableHandlerMethod extends HandlerMethod { private class AsyncResultMethodParameter extends AnnotatedMethodParameter { - @Nullable - private final Object returnValue; + private final @Nullable Object returnValue; private final ResolvableType returnType; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/MethodArgumentResolutionException.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/MethodArgumentResolutionException.java index 21a795a807..1e4f6e1e15 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/MethodArgumentResolutionException.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/MethodArgumentResolutionException.java @@ -16,8 +16,9 @@ package org.springframework.messaging.handler.invocation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ReactiveReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ReactiveReturnValueHandler.java index 18a5948f64..73cf3412db 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ReactiveReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/ReactiveReturnValueHandler.java @@ -18,12 +18,12 @@ package org.springframework.messaging.handler.invocation; import java.util.concurrent.CompletableFuture; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; /** * Support for single-value reactive types (like {@code Mono} or {@code Single}) @@ -58,8 +58,7 @@ public class ReactiveReturnValueHandler extends AbstractAsyncReturnValueHandler } @Override - @Nullable - public CompletableFuture toCompletableFuture(Object returnValue, MethodParameter returnType) { + public @Nullable CompletableFuture toCompletableFuture(Object returnValue, MethodParameter returnType) { ReactiveAdapter adapter = this.adapterRegistry.getAdapter(returnType.getParameterType(), returnValue); if (adapter != null) { return Mono.from(adapter.toPublisher(returnValue)).toFuture(); 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 eb05eec33d..1fa8315488 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,9 +1,7 @@ /** * Common infrastructure for invoking message handler methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.handler.invocation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java index bfb05d91ed..5d5d5198aa 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractEncoderMethodReturnValueHandler.java @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -36,7 +37,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessagingException; @@ -166,9 +166,8 @@ public abstract class AbstractEncoderMethodReturnValueHandler implements Handler } } - @Nullable @SuppressWarnings("unchecked") - private Encoder getEncoder(ResolvableType elementType, @Nullable MimeType mimeType) { + private @Nullable Encoder getEncoder(ResolvableType elementType, @Nullable MimeType mimeType) { for (Encoder encoder : getEncoders()) { if (encoder.canEncode(elementType, mimeType)) { return (Encoder) encoder; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java index c8731bfc49..145a1b214a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/AbstractMethodMessageHandler.java @@ -33,6 +33,7 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.BeanNameAware; @@ -41,7 +42,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.MethodIntrospector; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessagingException; import org.springframework.messaging.ReactiveMessageHandler; @@ -87,11 +87,9 @@ public abstract class AbstractMethodMessageHandler protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Predicate> handlerPredicate; + private @Nullable Predicate> handlerPredicate; - @Nullable - List handlers; + @Nullable List handlers; private ArgumentResolverConfigurer argumentResolverConfigurer = new ArgumentResolverConfigurer(); @@ -99,11 +97,9 @@ public abstract class AbstractMethodMessageHandler private final InvocableHelper invocableHelper = new InvocableHelper(this::createExceptionMethodResolverFor); - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private String beanName; + private @Nullable String beanName; private final Map handlerMethods = new ConcurrentHashMap<>(64); @@ -124,8 +120,7 @@ public abstract class AbstractMethodMessageHandler /** * Return the {@link #setHandlerPredicate configured} handler predicate. */ - @Nullable - public Predicate> getHandlerPredicate() { + public @Nullable Predicate> getHandlerPredicate() { return this.handlerPredicate; } @@ -193,8 +188,7 @@ public abstract class AbstractMethodMessageHandler this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -365,8 +359,7 @@ public abstract class AbstractMethodMessageHandler * @param handlerType the handler type, possibly a subtype 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); + protected abstract @Nullable T getMappingForMethod(Method method, Class handlerType); /** * Register a handler method and its unique mapping. @@ -461,8 +454,7 @@ public abstract class AbstractMethodMessageHandler return this.invocableHelper.handleMessage(handlerMethod, message); } - @Nullable - private Match getHandlerMethod(Message message) { + private @Nullable Match getHandlerMethod(Message message) { List> matches = new ArrayList<>(); RouteMatcher.Route destination = getDestination(message); @@ -502,8 +494,7 @@ public abstract class AbstractMethodMessageHandler * Extract the destination from the given message. * @see #getDirectLookupMappings(Object) */ - @Nullable - protected abstract RouteMatcher.Route getDestination(Message message); + protected abstract RouteMatcher.@Nullable Route getDestination(Message message); @SuppressWarnings("NullAway") private void addMatchesToCollection( @@ -524,8 +515,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 abstract @Nullable T getMatchingMapping(T mapping, Message message); /** * Return a comparator for sorting matching mappings. @@ -540,7 +530,7 @@ public abstract class AbstractMethodMessageHandler * @param destination the destination * @param message the message */ - protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message message) { + protected void handleNoMatch(RouteMatcher.@Nullable Route destination, Message message) { logger.debug("No handlers for destination '" + (destination != null ? destination.value() : "") + "'"); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/ChannelSendOperator.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/ChannelSendOperator.java index 0edef96cf2..2c77297a77 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/ChannelSendOperator.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/ChannelSendOperator.java @@ -18,6 +18,7 @@ package org.springframework.messaging.handler.invocation.reactive; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -30,7 +31,6 @@ import reactor.util.context.Context; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -68,9 +68,8 @@ class ChannelSendOperator extends Mono implements Scannable { @Override - @Nullable @SuppressWarnings("rawtypes") - public Object scanUnsafe(Attr key) { + public @Nullable Object scanUnsafe(Attr key) { if (key == Attr.PREFETCH) { return Integer.MAX_VALUE; } @@ -134,16 +133,13 @@ class ChannelSendOperator extends Mono implements Scannable { private final WriteCompletionBarrier writeCompletionBarrier; /* Upstream write source subscription */ - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; /** Cached data item before readyToWrite. */ - @Nullable - private T item; + private @Nullable T item; /** Cached error signal before readyToWrite. */ - @Nullable - private Throwable error; + private @Nullable Throwable error; /** Cached onComplete signal before readyToWrite. */ private boolean completed = false; @@ -155,8 +151,7 @@ class ChannelSendOperator extends Mono implements Scannable { private State state = State.NEW; /** The actual writeSubscriber from the HTTP server adapter. */ - @Nullable - private Subscriber writeSubscriber; + private @Nullable Subscriber writeSubscriber; WriteBarrier(CoreSubscriber completionSubscriber) { @@ -391,8 +386,7 @@ class ChannelSendOperator extends Mono implements Scannable { private final WriteBarrier writeBarrier; - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; public WriteCompletionBarrier(CoreSubscriber subscriber, WriteBarrier writeBarrier) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java index fc73bf63de..5ea4d42cde 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodArgumentResolverComposite.java @@ -24,10 +24,10 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -124,8 +124,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu * Find a registered {@link HandlerMethodArgumentResolver} that supports * the given method parameter. */ - @Nullable - public HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { + public @Nullable HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter); if (result == null) { for (HandlerMethodArgumentResolver methodArgumentResolver : this.argumentResolvers) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandler.java index 4d0efbdeb6..7628048e14 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandler.java @@ -16,10 +16,10 @@ package org.springframework.messaging.handler.invocation.reactive; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java index 724fc8b650..ebe91fee7e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/HandlerMethodReturnValueHandlerComposite.java @@ -22,10 +22,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -93,8 +93,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe } @SuppressWarnings("ForLoopReplaceableByForEach") - @Nullable - private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { + private @Nullable HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { if (handler.supportsReturnType(returnType)) { return handler; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java index ccb9c3c198..91a0cd9fe4 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/InvocableHelper.java @@ -25,11 +25,11 @@ import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.HandlerMethod; import org.springframework.messaging.handler.MessagingAdviceBean; @@ -146,8 +146,7 @@ class InvocableHelper { * @param ex the exception raised or signaled * @return a method to handle the exception, or {@code null} */ - @Nullable - public InvocableHandlerMethod initExceptionHandlerMethod(HandlerMethod handlerMethod, Throwable ex) { + public @Nullable InvocableHandlerMethod initExceptionHandlerMethod(HandlerMethod handlerMethod, Throwable ex) { if (logger.isDebugEnabled()) { logger.debug("Searching for methods to handle " + ex.getClass().getSimpleName()); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/SyncHandlerMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/SyncHandlerMethodArgumentResolver.java index e933104d5c..8a4f053697 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/SyncHandlerMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/SyncHandlerMethodArgumentResolver.java @@ -16,10 +16,10 @@ package org.springframework.messaging.handler.invocation.reactive; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -47,7 +47,6 @@ public interface SyncHandlerMethodArgumentResolver extends HandlerMethodArgument * @param message the currently processed message * @return the resolved value, if any */ - @Nullable - Object resolveArgumentValue(MethodParameter parameter, Message message); + @Nullable Object resolveArgumentValue(MethodParameter parameter, Message message); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/package-info.java index 27a85c242d..a4d42cb5fe 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/handler/invocation/reactive/package-info.java @@ -2,9 +2,7 @@ * Common infrastructure for invoking message handler methods with non-blocking, * and reactive contracts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.handler.invocation.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d4ae3f87b9..9ca6dcb809 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,9 +1,7 @@ /** * Basic abstractions for working with message handler methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.handler; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 875d7b5b72..2d31f80a4e 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,9 +1,7 @@ /** * Support for working with messaging APIs and protocols. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultMetadataExtractor.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultMetadataExtractor.java index 9db72199dd..d791cc8f5e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultMetadataExtractor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultMetadataExtractor.java @@ -32,13 +32,13 @@ import io.rsocket.metadata.RoutingMetadata; import io.rsocket.metadata.WellKnownMimeType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; import org.springframework.core.codec.Decoder; import org.springframework.core.io.buffer.NettyDataBuffer; import org.springframework.core.io.buffer.NettyDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequester.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequester.java index 43ea6d6f64..73117463fd 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequester.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequester.java @@ -23,6 +23,7 @@ import java.util.function.Consumer; import io.rsocket.Payload; import io.rsocket.RSocket; import io.rsocket.core.RSocketClient; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,7 +36,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MimeType; @@ -52,8 +52,7 @@ final class DefaultRSocketRequester implements RSocketRequester { private final RSocketClient rsocketClient; - @Nullable - private final RSocket rsocket; + private final @Nullable RSocket rsocket; private final MimeType dataMimeType; @@ -87,9 +86,8 @@ final class DefaultRSocketRequester implements RSocketRequester { return this.rsocketClient; } - @Nullable @Override - public RSocket rsocket() { + public @Nullable RSocket rsocket() { return this.rsocket; } @@ -132,11 +130,9 @@ final class DefaultRSocketRequester implements RSocketRequester { private final MetadataEncoder metadataEncoder = new MetadataEncoder(metadataMimeType(), strategies); - @Nullable - private Mono payloadMono; + private @Nullable Mono payloadMono; - @Nullable - private Flux payloadFlux; + private @Nullable Flux payloadFlux; public DefaultRequestSpec(String route, Object... vars) { @@ -178,8 +174,7 @@ final class DefaultRSocketRequester implements RSocketRequester { return this; } - @Nullable - private ReactiveAdapter getAdapter(Class aClass) { + private @Nullable ReactiveAdapter getAdapter(Class aClass) { return strategies.reactiveAdapterRegistry().getAdapter(aClass); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java index e3a045d7f2..fb2a63595c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketRequesterBuilder.java @@ -36,6 +36,7 @@ import io.rsocket.transport.ClientTransport; import io.rsocket.transport.netty.client.TcpClientTransport; import io.rsocket.transport.netty.client.WebsocketClientTransport; import io.rsocket.util.DefaultPayload; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -47,7 +48,6 @@ import org.springframework.core.codec.StringDecoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.NettyDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeType; @@ -69,26 +69,19 @@ final class DefaultRSocketRequesterBuilder implements RSocketRequester.Builder { private static final Payload EMPTY_SETUP_PAYLOAD = DefaultPayload.create(EMPTY_BYTE_ARRAY); - @Nullable - private MimeType dataMimeType; + private @Nullable MimeType dataMimeType; - @Nullable - private MimeType metadataMimeType; + private @Nullable MimeType metadataMimeType; - @Nullable - private Object setupData; + private @Nullable Object setupData; - @Nullable - private String setupRoute; + private @Nullable String setupRoute; - @Nullable - private Object[] setupRouteVars; + private Object @Nullable [] setupRouteVars; - @Nullable - private Map setupMetadata; + private @Nullable Map setupMetadata; - @Nullable - private RSocketStrategies strategies; + private @Nullable RSocketStrategies strategies; private final List> strategiesConfigurers = new ArrayList<>(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketStrategies.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketStrategies.java index ec6ceab06b..385d3036c3 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketStrategies.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/DefaultRSocketStrategies.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.function.Consumer; import io.netty.buffer.PooledByteBufAllocator; +import org.jspecify.annotations.Nullable; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.codec.ByteArrayDecoder; @@ -37,7 +38,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.codec.StringDecoder; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.NettyDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.RouteMatcher; import org.springframework.util.SimpleRouteMatcher; @@ -117,17 +117,13 @@ final class DefaultRSocketStrategies implements RSocketStrategies { private final List> decoders = new ArrayList<>(); - @Nullable - private RouteMatcher routeMatcher; + private @Nullable RouteMatcher routeMatcher; - @Nullable - private ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); + private @Nullable ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); - @Nullable - private DataBufferFactory bufferFactory; + private @Nullable DataBufferFactory bufferFactory; - @Nullable - private MetadataExtractor metadataExtractor; + private @Nullable MetadataExtractor metadataExtractor; private final List> metadataExtractors = new ArrayList<>(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java index 507745c7e1..5f153b3c39 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataEncoder.java @@ -27,6 +27,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.CompositeByteBuf; import io.rsocket.metadata.WellKnownMimeType; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.ReactiveAdapter; @@ -35,7 +36,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.NettyDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeType; @@ -63,8 +63,7 @@ final class MetadataEncoder { private final ByteBufAllocator allocator; - @Nullable - private String route; + private @Nullable String route; private final List metadataEntries = new ArrayList<>(4); @@ -155,7 +154,7 @@ final class MetadataEncoder { * Add route and/or metadata, both optional. */ public MetadataEncoder metadataAndOrRoute(@Nullable Map metadata, - @Nullable String route, @Nullable Object[] vars) { + @Nullable String route, Object @Nullable [] vars) { if (route != null) { this.route = expand(route, vars != null ? vars : new Object[0]); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataExtractorRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataExtractorRegistry.java index 667e02cd30..4856cf398c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataExtractorRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/MetadataExtractorRegistry.java @@ -19,8 +19,9 @@ package org.springframework.messaging.rsocket; import java.util.Map; import java.util.function.BiConsumer; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketRequester.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketRequester.java index 2c946d5c31..baac049c56 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketRequester.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketRequester.java @@ -29,6 +29,7 @@ import io.rsocket.loadbalance.LoadbalanceTarget; import io.rsocket.transport.ClientTransport; import io.rsocket.transport.netty.client.TcpClientTransport; import io.rsocket.transport.netty.client.WebsocketClientTransport; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.Disposable; import reactor.core.publisher.Flux; @@ -37,7 +38,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.codec.Decoder; -import org.springframework.lang.Nullable; import org.springframework.messaging.rsocket.annotation.support.RSocketMessageHandler; import org.springframework.util.MimeType; @@ -64,8 +64,7 @@ public interface RSocketRequester extends Disposable { * or via one of the (deprecated) connect methods on the * {@code RSocketRequester} builder, or otherwise return {@code null}. */ - @Nullable - RSocket rsocket(); + @Nullable RSocket rsocket(); /** * Return the data {@code MimeType} selected for the underlying RSocket diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketStrategies.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketStrategies.java index 8e8a43a10f..914deca8a1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketStrategies.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/RSocketStrategies.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.function.Consumer; import io.rsocket.Payload; +import org.jspecify.annotations.Nullable; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ResolvableType; @@ -28,7 +29,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.core.io.buffer.NettyDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.MimeType; import org.springframework.util.RouteMatcher; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/package-info.java index ed54c26543..272bc6591b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/package-info.java @@ -1,9 +1,7 @@ /** * Annotations and support classes for handling RSocket streams. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.rsocket.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/MessagingRSocket.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/MessagingRSocket.java index b7686c46f5..163fc0a651 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/MessagingRSocket.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/MessagingRSocket.java @@ -24,6 +24,7 @@ import io.rsocket.ConnectionSetupPayload; import io.rsocket.Payload; import io.rsocket.RSocket; import io.rsocket.frame.FrameType; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -31,7 +32,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.NettyDataBuffer; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.ReactiveMessageHandler; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageCondition.java index e8167a3f14..111a8f6b8e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageCondition.java @@ -24,8 +24,8 @@ import java.util.Map; import java.util.Set; import io.rsocket.frame.FrameType; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.AbstractMessageCondition; import org.springframework.util.Assert; @@ -117,8 +117,7 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition message) { + public static @Nullable FrameType getFrameType(Message message) { return (FrameType) message.getHeaders().get(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER); } @@ -134,8 +133,7 @@ public class RSocketFrameTypeMessageCondition extends AbstractMessageCondition message) { + public @Nullable RSocketFrameTypeMessageCondition getMatchingCondition(Message message) { FrameType actual = message.getHeaders().get(FRAME_TYPE_HEADER, FrameType.class); if (actual != null) { for (FrameType type : this.frameTypes) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketMessageHandler.java index d83119b1b7..a663a8b0d1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketMessageHandler.java @@ -28,6 +28,7 @@ import io.rsocket.RSocket; import io.rsocket.SocketAcceptor; import io.rsocket.frame.FrameType; import io.rsocket.metadata.WellKnownMimeType; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.BeanUtils; @@ -38,7 +39,6 @@ import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.codec.Decoder; import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.PooledDataBuffer; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.handler.CompositeMessageCondition; @@ -96,8 +96,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler { private RSocketStrategies strategies = RSocketStrategies.create(); - @Nullable - private MimeType defaultDataMimeType; + private @Nullable MimeType defaultDataMimeType; private MimeType defaultMetadataMimeType = MimeTypeUtils.parseMimeType( WellKnownMimeType.MESSAGE_RSOCKET_COMPOSITE_METADATA.getString()); @@ -256,8 +255,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler { * Return the configured * {@link #setDefaultDataMimeType defaultDataMimeType}, or {@code null}. */ - @Nullable - public MimeType getDefaultDataMimeType() { + public @Nullable MimeType getDefaultDataMimeType() { return this.defaultDataMimeType; } @@ -311,8 +309,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler { @Override - @Nullable - protected CompositeMessageCondition getCondition(AnnotatedElement element) { + protected @Nullable CompositeMessageCondition getCondition(AnnotatedElement element) { MessageMapping ann1 = AnnotatedElementUtils.findMergedAnnotation(element, MessageMapping.class); if (ann1 != null && ann1.value().length > 0) { return new CompositeMessageCondition( @@ -379,7 +376,7 @@ public class RSocketMessageHandler extends MessageMappingMessageHandler { } @Override - protected void handleNoMatch(@Nullable RouteMatcher.Route destination, Message message) { + protected void handleNoMatch(RouteMatcher.@Nullable Route destination, Message message) { FrameType frameType = RSocketFrameTypeMessageCondition.getFrameType(message); if (frameType == FrameType.SETUP || frameType == FrameType.METADATA_PUSH) { if (frameType == FrameType.SETUP && message.getPayload() instanceof PooledDataBuffer pooledDataBuffer) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketPayloadReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketPayloadReturnValueHandler.java index 78f8ce774b..dc86c82d7d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketPayloadReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/RSocketPayloadReturnValueHandler.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicReference; import io.rsocket.Payload; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -27,7 +28,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.invocation.reactive.AbstractEncoderMethodReturnValueHandler; import org.springframework.messaging.rsocket.PayloadUtils; @@ -75,9 +75,8 @@ public class RSocketPayloadReturnValueHandler extends AbstractEncoderMethodRetur return Mono.empty(); } - @Nullable @SuppressWarnings("unchecked") - private AtomicReference> getResponseReference(Message message) { + private @Nullable AtomicReference> getResponseReference(Message message) { Object headerValue = message.getHeaders().get(RESPONSE_HEADER); Assert.state(headerValue == null || headerValue instanceof AtomicReference, "Expected AtomicReference"); return (AtomicReference>) headerValue; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/package-info.java index 4c02159a3c..ee1caa3abe 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/annotation/support/package-info.java @@ -1,9 +1,7 @@ /** * Support classes for working with annotated RSocket stream handling methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.rsocket.annotation.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/package-info.java index 9cb5ed03ac..5d33cca2d6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/package-info.java @@ -1,9 +1,7 @@ /** * Support for the RSocket protocol. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.rsocket; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java index 99b00160da..a1c822c16a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/DestinationVariableArgumentResolver.java @@ -18,8 +18,9 @@ package org.springframework.messaging.rsocket.service; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.DestinationVariable; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/MetadataArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/MetadataArgumentResolver.java index 3e89f95bed..537fca1895 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/MetadataArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/MetadataArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.messaging.rsocket.service; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolver.java index b80c747bbd..bcb1404582 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolver.java @@ -16,11 +16,12 @@ package org.springframework.messaging.rsocket.service; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.Payload; import org.springframework.util.Assert; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessor.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessor.java index d9ed6be314..f80a6743ad 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessor.java @@ -19,6 +19,8 @@ package org.springframework.messaging.rsocket.service; import java.util.HashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopProxyUtils; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.ProxyHints; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.Search; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -46,9 +47,8 @@ import static org.springframework.core.annotation.MergedAnnotations.SearchStrate */ class RSocketExchangeBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { - @Nullable @Override - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); Set> exchangeInterfaces = new HashSet<>(); Search search = MergedAnnotations.search(TYPE_HIERARCHY); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketRequestValues.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketRequestValues.java index 4866b033f4..1666803f08 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketRequestValues.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketRequestValues.java @@ -22,10 +22,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.util.StringUtils; @@ -41,21 +41,17 @@ import org.springframework.util.StringUtils; */ public final class RSocketRequestValues { - @Nullable - private final String route; + private final @Nullable String route; private final Object[] routeVariables; private final Map metadata; - @Nullable - private final Object payloadValue; + private final @Nullable Object payloadValue; - @Nullable - private final Publisher payload; + private final @Nullable Publisher payload; - @Nullable - private final ParameterizedTypeReference payloadElementType; + private final @Nullable ParameterizedTypeReference payloadElementType; public RSocketRequestValues( @@ -76,8 +72,7 @@ public final class RSocketRequestValues { * Return the route value for * {@link org.springframework.messaging.rsocket.RSocketRequester#route(String, Object...) route}. */ - @Nullable - public String getRoute() { + public @Nullable String getRoute() { return this.route; } @@ -102,8 +97,7 @@ public final class RSocketRequestValues { *

    This is mutually exclusive with {@link #getPayload()}. * Only one of the two or neither is set. */ - @Nullable - public Object getPayloadValue() { + public @Nullable Object getPayloadValue() { return this.payloadValue; } @@ -112,16 +106,14 @@ public final class RSocketRequestValues { *

    This is mutually exclusive with {@link #getPayloadValue()}. * Only one of the two or neither is set. */ - @Nullable - public Publisher getPayload() { + public @Nullable Publisher getPayload() { return this.payload; } /** * Return the element type for a {@linkplain #getPayload() Publisher payload}. */ - @Nullable - public ParameterizedTypeReference getPayloadElementType() { + public @Nullable ParameterizedTypeReference getPayloadElementType() { return this.payloadElementType; } @@ -136,23 +128,17 @@ public final class RSocketRequestValues { */ public static final class Builder { - @Nullable - private String route; + private @Nullable String route; - @Nullable - private List routeVariables; + private @Nullable List routeVariables; - @Nullable - private MetadataHelper metadataHelper; + private @Nullable MetadataHelper metadataHelper; - @Nullable - private Object payloadValue; + private @Nullable Object payloadValue; - @Nullable - private Publisher payload; + private @Nullable Publisher payload; - @Nullable - private ParameterizedTypeReference payloadElementType; + private @Nullable ParameterizedTypeReference payloadElementType; Builder(@Nullable String route) { this.route = (StringUtils.hasText(route) ? route : null); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolver.java index a15b97e86b..a26f671f1b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.messaging.rsocket.service; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * Resolve an argument from an {@link RSocketExchange @RSocketExchange}-annotated diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java index 1b6c87f817..acc60e3cb7 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceMethod.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.Optional; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -34,7 +35,6 @@ import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.SynthesizingMethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.messaging.rsocket.RSocketStrategies; import org.springframework.util.Assert; @@ -59,8 +59,7 @@ final class RSocketServiceMethod { private final List argumentResolvers; - @Nullable - private final String route; + private final @Nullable String route; private final Function responseFunction; @@ -91,9 +90,8 @@ final class RSocketServiceMethod { return parameters; } - @Nullable @SuppressWarnings("NullAway") - private static String initRoute( + private static @Nullable String initRoute( Method method, Class containingClass, RSocketStrategies strategies, @Nullable StringValueResolver embeddedValueResolver) { @@ -217,8 +215,7 @@ final class RSocketServiceMethod { return this.method; } - @Nullable - public Object invoke(Object[] arguments) { + public @Nullable Object invoke(Object[] arguments) { RSocketRequestValues.Builder requestValues = RSocketRequestValues.builder(this.route); applyArguments(requestValues, arguments); return this.responseFunction.apply(requestValues.build()); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceProxyFactory.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceProxyFactory.java index bfab89ed57..3d449795c6 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceProxyFactory.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/RSocketServiceProxyFactory.java @@ -27,13 +27,13 @@ import java.util.stream.Collectors; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ReflectiveMethodInvocation; import org.springframework.core.MethodIntrospector; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.messaging.rsocket.RSocketRequester; import org.springframework.util.Assert; import org.springframework.util.StringValueResolver; @@ -54,13 +54,11 @@ public final class RSocketServiceProxyFactory { private final List argumentResolvers; - @Nullable - private final StringValueResolver embeddedValueResolver; + private final @Nullable StringValueResolver embeddedValueResolver; private final ReactiveAdapterRegistry reactiveAdapterRegistry; - @Nullable - private final Duration blockTimeout; + private final @Nullable Duration blockTimeout; private RSocketServiceProxyFactory( @@ -129,18 +127,15 @@ public final class RSocketServiceProxyFactory { */ public static final class Builder { - @Nullable - private RSocketRequester rsocketRequester; + private @Nullable RSocketRequester rsocketRequester; private final List customArgumentResolvers = new ArrayList<>(); - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); - @Nullable - private Duration blockTimeout; + private @Nullable Duration blockTimeout; private Builder() { } @@ -247,8 +242,7 @@ public final class RSocketServiceProxyFactory { } @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); RSocketServiceMethod serviceMethod = this.serviceMethods.get(method); if (serviceMethod != null) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/package-info.java index 65c6ba8c22..e9dcd84d49 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/rsocket/service/package-info.java @@ -3,9 +3,7 @@ * with a proxy factory backed by an * {@link org.springframework.messaging.rsocket.RSocketRequester}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.rsocket.service; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 8946b6db20..7970fb17c4 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 @@ -19,8 +19,8 @@ package org.springframework.messaging.simp; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; @@ -71,8 +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) { + public @Nullable 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 6474d56afc..8acde11942 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 @@ -16,8 +16,9 @@ package org.springframework.messaging.simp; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -66,8 +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() { + public static @Nullable SimpAttributes getAttributes() { return attributesHolder.get(); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java index 015db5c8dc..dde426e0d5 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageHeaderAccessor.java @@ -21,7 +21,8 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.support.IdTimestampMessageHeaderInitializer; import org.springframework.messaging.support.MessageHeaderAccessor; @@ -85,8 +86,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { public static final String IGNORE_ERROR = "simpIgnoreError"; - @Nullable - private Consumer userCallback; + private @Nullable Consumer userCallback; /** @@ -125,8 +125,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { } } - @Nullable - public SimpMessageType getMessageType() { + public @Nullable SimpMessageType getMessageType() { return (SimpMessageType) getHeader(MESSAGE_TYPE_HEADER); } @@ -134,8 +133,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { setHeader(DESTINATION_HEADER, destination); } - @Nullable - public String getDestination() { + public @Nullable String getDestination() { return (String) getHeader(DESTINATION_HEADER); } @@ -143,8 +141,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { setHeader(SUBSCRIPTION_ID_HEADER, subscriptionId); } - @Nullable - public String getSubscriptionId() { + public @Nullable String getSubscriptionId() { return (String) getHeader(SUBSCRIPTION_ID_HEADER); } @@ -155,8 +152,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { /** * Return the id of the current session. */ - @Nullable - public String getSessionId() { + public @Nullable String getSessionId() { return (String) getHeader(SESSION_ID_HEADER); } @@ -171,8 +167,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { * Return the attributes associated with the current session. */ @SuppressWarnings("unchecked") - @Nullable - public Map getSessionAttributes() { + public @Nullable Map getSessionAttributes() { return (Map) getHeader(SESSION_ATTRIBUTES); } @@ -186,8 +181,7 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { /** * Return the user associated with the current session. */ - @Nullable - public Principal getUser() { + public @Nullable Principal getUser() { return (Principal) getHeader(USER_HEADER); } @@ -279,39 +273,32 @@ public class SimpMessageHeaderAccessor extends NativeMessageHeaderAccessor { return new SimpMessageHeaderAccessor(message); } - @Nullable - public static SimpMessageType getMessageType(Map headers) { + public static @Nullable SimpMessageType getMessageType(Map headers) { return (SimpMessageType) headers.get(MESSAGE_TYPE_HEADER); } - @Nullable - public static String getDestination(Map headers) { + public static @Nullable String getDestination(Map headers) { return (String) headers.get(DESTINATION_HEADER); } - @Nullable - public static String getSubscriptionId(Map headers) { + public static @Nullable String getSubscriptionId(Map headers) { return (String) headers.get(SUBSCRIPTION_ID_HEADER); } - @Nullable - public static String getSessionId(Map headers) { + public static @Nullable String getSessionId(Map headers) { return (String) headers.get(SESSION_ID_HEADER); } @SuppressWarnings("unchecked") - @Nullable - public static Map getSessionAttributes(Map headers) { + public static @Nullable Map getSessionAttributes(Map headers) { return (Map) headers.get(SESSION_ATTRIBUTES); } - @Nullable - public static Principal getUser(Map headers) { + public static @Nullable Principal getUser(Map headers) { return (Principal) headers.get(USER_HEADER); } - @Nullable - public static long[] getHeartbeat(Map headers) { + public static long @Nullable [] getHeartbeat(Map headers) { return (long[]) headers.get(HEART_BEAT_HEADER); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java index 4523714ecc..9131c291ad 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageMappingInfo.java @@ -16,7 +16,8 @@ package org.springframework.messaging.simp; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.handler.CompositeMessageCondition; import org.springframework.messaging.handler.DestinationPatternsMessageCondition; @@ -64,8 +65,7 @@ public class SimpMessageMappingInfo implements MessageCondition message) { + public @Nullable SimpMessageMappingInfo getMatchingCondition(Message message) { CompositeMessageCondition condition = this.delegate.getMatchingCondition(message); return condition != null ? new SimpMessageMappingInfo(condition) : null; } 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 e1cac48b59..11583e5139 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,7 +18,8 @@ package org.springframework.messaging.simp; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessagingException; import org.springframework.messaging.core.MessagePostProcessor; import org.springframework.messaging.core.MessageSendingOperations; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageTypeMessageCondition.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageTypeMessageCondition.java index 522cd82fc7..e8bfa31458 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageTypeMessageCondition.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessageTypeMessageCondition.java @@ -20,7 +20,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.handler.AbstractMessageCondition; import org.springframework.util.Assert; @@ -74,8 +75,7 @@ public class SimpMessageTypeMessageCondition extends AbstractMessageCondition message) { + public @Nullable SimpMessageTypeMessageCondition getMatchingCondition(Message message) { SimpMessageType actual = SimpMessageHeaderAccessor.getMessageType(message.getHeaders()); return (actual != null && actual.equals(this.messageType) ? this : null); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java index fdd5f357a7..89c7f64a6b 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/SimpMessagingTemplate.java @@ -18,7 +18,8 @@ package org.springframework.messaging.simp; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -53,8 +54,7 @@ public class SimpMessagingTemplate extends AbstractMessageSendingTemplate message){ + public @Nullable Object resolveArgument(MethodParameter parameter, Message message){ Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders()); return parameter.isOptional() ? Optional.ofNullable(user) : user; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java index 44bc35404c..042265f3a9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SendToMethodReturnValueHandler.java @@ -21,10 +21,11 @@ import java.security.Principal; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -70,8 +71,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH private final PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("{", "}", null, null, false); - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; public SendToMethodReturnValueHandler(SimpMessageSendingOperations messagingTemplate, boolean annotationRequired) { @@ -129,8 +129,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -208,8 +207,7 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH new DestinationHelper(headers, m1, m2) : new DestinationHelper(headers, c1, c2)); } - @Nullable - protected String getUserName(Message message, MessageHeaders headers) { + protected @Nullable String getUserName(Message message, MessageHeaders headers) { Principal principal = SimpMessageHeaderAccessor.getUser(headers); if (principal != null) { return (principal instanceof DestinationUserNameProvider provider ? @@ -260,11 +258,9 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH private final PlaceholderResolver placeholderResolver; - @Nullable - private final SendTo sendTo; + private final @Nullable SendTo sendTo; - @Nullable - private final SendToUser sendToUser; + private final @Nullable SendToUser sendToUser; public DestinationHelper(MessageHeaders headers, @Nullable SendToUser sendToUser, @Nullable SendTo sendTo) { @@ -280,13 +276,11 @@ public class SendToMethodReturnValueHandler implements HandlerMethodReturnValueH return (Map) headers.getOrDefault(name, Collections.emptyMap()); } - @Nullable - public SendTo getSendTo() { + public @Nullable SendTo getSendTo() { return this.sendTo; } - @Nullable - public SendToUser getSendToUser() { + public @Nullable SendToUser getSendToUser() { return this.sendToUser; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java index caefa70ac4..fd974e5994 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandler.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.Set; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.ApplicationContext; @@ -35,7 +36,6 @@ import org.springframework.context.SmartLifecycle; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.convert.ConversionService; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; @@ -111,17 +111,13 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan private boolean slashPathSeparator = true; - @Nullable - private Validator validator; + private @Nullable Validator validator; - @Nullable - private StringValueResolver valueResolver; + private @Nullable StringValueResolver valueResolver; - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; - @Nullable - private Integer phase; + private @Nullable Integer phase; private volatile boolean running; @@ -167,8 +163,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan super.setDestinationPrefixes(appendSlashes(prefixes)); } - @Nullable - private static Collection appendSlashes(@Nullable Collection prefixes) { + private static @Nullable Collection appendSlashes(@Nullable Collection prefixes) { if (CollectionUtils.isEmpty(prefixes)) { return prefixes; } @@ -237,8 +232,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan /** * Return the configured Validator instance. */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return this.validator; } @@ -269,8 +263,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -396,8 +389,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan } @Override - @Nullable - protected SimpMessageMappingInfo getMappingForMethod(Method method, Class handlerType) { + protected @Nullable SimpMessageMappingInfo getMappingForMethod(Method method, Class handlerType) { MessageMapping messageAnn = AnnotatedElementUtils.findMergedAnnotation(method, MessageMapping.class); if (messageAnn != null) { MessageMapping typeAnn = AnnotatedElementUtils.findMergedAnnotation(handlerType, MessageMapping.class); @@ -469,14 +461,12 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan } @Override - @Nullable - protected String getDestination(Message message) { + protected @Nullable String getDestination(Message message) { return SimpMessageHeaderAccessor.getDestination(message.getHeaders()); } @Override - @Nullable - protected String getLookupDestination(@Nullable String destination) { + protected @Nullable String getLookupDestination(@Nullable String destination) { if (destination == null) { return null; } @@ -497,8 +487,7 @@ public class SimpAnnotationMethodMessageHandler extends AbstractMethodMessageHan } @Override - @Nullable - protected SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo mapping, Message message) { + protected @Nullable SimpMessageMappingInfo getMatchingMapping(SimpMessageMappingInfo mapping, Message message) { return mapping.getMatchingCondition(message); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java index 8ff4d521a2..f6d316ec81 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/SubscriptionMethodReturnValueHandler.java @@ -17,9 +17,9 @@ package org.springframework.messaging.simp.annotation.support; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.core.AbstractMessageSendingTemplate; @@ -63,8 +63,7 @@ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturn private final MessageSendingOperations messagingTemplate; - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; /** @@ -90,8 +89,7 @@ public class SubscriptionMethodReturnValueHandler implements HandlerMethodReturn /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } 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 bc4b50f166..c5810b2e55 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,9 +2,7 @@ * Support classes for handling messages from simple messaging protocols * (like STOMP). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.simp.annotation.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java index 7c17734e06..7ddf02c825 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/AbstractBrokerMessageHandler.java @@ -22,11 +22,11 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Predicate; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.SmartLifecycle; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -59,13 +59,11 @@ public abstract class AbstractBrokerMessageHandler private final Collection destinationPrefixes; - @Nullable - private Predicate userDestinationPredicate; + private @Nullable Predicate userDestinationPredicate; private boolean preservePublishOrder = false; - @Nullable - private ApplicationEventPublisher eventPublisher; + private @Nullable ApplicationEventPublisher eventPublisher; private final AtomicBoolean brokerAvailable = new AtomicBoolean(); @@ -75,8 +73,7 @@ public abstract class AbstractBrokerMessageHandler private boolean autoStartup = true; - @Nullable - private Integer phase; + private @Nullable Integer phase; private volatile boolean running; @@ -186,8 +183,7 @@ public abstract class AbstractBrokerMessageHandler this.eventPublisher = publisher; } - @Nullable - public ApplicationEventPublisher getApplicationEventPublisher() { + public @Nullable ApplicationEventPublisher getApplicationEventPublisher() { return this.eventPublisher; } 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 078ed325a7..76798f769a 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 @@ -28,6 +28,8 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiConsumer; +import org.jspecify.annotations.Nullable; + import org.springframework.expression.EvaluationContext; import org.springframework.expression.Expression; import org.springframework.expression.ExpressionParser; @@ -36,7 +38,6 @@ import org.springframework.expression.TypedValue; import org.springframework.expression.spel.SpelEvaluationException; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.SimpleEvaluationContext; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; @@ -80,8 +81,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { private int cacheLimit = DEFAULT_CACHE_LIMIT; - @Nullable - private String selectorHeaderName; + private @Nullable String selectorHeaderName; private volatile boolean selectorHeaderInUse; @@ -148,8 +148,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { * @since 4.2 * @see #setSelectorHeaderName(String) */ - @Nullable - public String getSelectorHeaderName() { + public @Nullable String getSelectorHeaderName() { return this.selectorHeaderName; } @@ -165,8 +164,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { this.destinationCache.updateAfterNewSubscription(sessionId, subscription); } - @Nullable - private Expression getSelectorExpression(MessageHeaders headers) { + private @Nullable Expression getSelectorExpression(MessageHeaders headers) { if (getSelectorHeaderName() == null) { return null; } @@ -395,8 +393,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { private final ConcurrentMap sessions = new ConcurrentHashMap<>(); - @Nullable - public SessionInfo getSession(String sessionId) { + public @Nullable SessionInfo getSession(String sessionId) { return this.sessions.get(sessionId); } @@ -410,8 +407,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { info.addSubscription(subscription); } - @Nullable - public SessionInfo removeSubscriptions(String sessionId) { + public @Nullable SessionInfo removeSubscriptions(String sessionId) { return this.sessions.remove(sessionId); } } @@ -428,8 +424,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { return this.subscriptionMap.values(); } - @Nullable - public Subscription getSubscription(String subscriptionId) { + public @Nullable Subscription getSubscription(String subscriptionId) { return this.subscriptionMap.get(subscriptionId); } @@ -437,8 +432,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { this.subscriptionMap.putIfAbsent(subscription.getId(), subscription); } - @Nullable - public Subscription removeSubscription(String subscriptionId) { + public @Nullable Subscription removeSubscription(String subscriptionId) { return this.subscriptionMap.remove(subscriptionId); } } @@ -454,8 +448,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { private final boolean isPattern; - @Nullable - private final Expression selector; + private final @Nullable Expression selector; public Subscription(String id, String destination, boolean isPattern, @Nullable Expression selector) { Assert.notNull(id, "Subscription id must not be null"); @@ -478,8 +471,7 @@ public class DefaultSubscriptionRegistry extends AbstractSubscriptionRegistry { return this.isPattern; } - @Nullable - public Expression getSelector() { + public @Nullable Expression getSelector() { return this.selector; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java index 5d26ccbea7..0d20c2c71c 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/OrderedMessageChannelDecorator.java @@ -22,8 +22,8 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -172,8 +172,7 @@ public class OrderedMessageChannelDecorator implements MessageChannel { /** * Obtain the task to release the next message, if found. */ - @Nullable - public static Runnable getNextMessageTask(Message message) { + public static @Nullable Runnable getNextMessageTask(Message message) { return (Runnable) message.getHeaders().get(OrderedMessageChannelDecorator.NEXT_MESSAGE_TASK_HEADER); } @@ -185,8 +184,7 @@ public class OrderedMessageChannelDecorator implements MessageChannel { private final Message message; - @Nullable - private final AtomicInteger handledCount; + private final @Nullable AtomicInteger handledCount; private PostHandleTask(Message message) { this.message = message; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java index 80bcfe99e4..bd1703c89e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/broker/SimpleBrokerMessageHandler.java @@ -24,7 +24,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ScheduledFuture; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -54,31 +55,24 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { private static final byte[] EMPTY_PAYLOAD = new byte[0]; - @Nullable - private PathMatcher pathMatcher; + private @Nullable PathMatcher pathMatcher; - @Nullable - private Integer cacheLimit; + private @Nullable Integer cacheLimit; - @Nullable - private String selectorHeaderName; + private @Nullable String selectorHeaderName; - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; - @Nullable - private long[] heartbeatValue; + private long @Nullable [] heartbeatValue; - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; private SubscriptionRegistry subscriptionRegistry; private final Map sessions = new ConcurrentHashMap<>(); - @Nullable - private ScheduledFuture heartbeatFuture; + private @Nullable ScheduledFuture heartbeatFuture; /** @@ -212,8 +206,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { * Return the configured TaskScheduler. * @since 4.2 */ - @Nullable - public TaskScheduler getTaskScheduler() { + public @Nullable TaskScheduler getTaskScheduler() { return this.taskScheduler; } @@ -226,7 +219,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { * (in milliseconds). * @since 4.2 */ - public void setHeartbeatValue(@Nullable long[] heartbeat) { + public void setHeartbeatValue(long @Nullable [] heartbeat) { if (heartbeat != null && (heartbeat.length != 2 || heartbeat[0] < 0 || heartbeat[1] < 0)) { throw new IllegalArgumentException("Invalid heart-beat: " + Arrays.toString(heartbeat)); } @@ -237,8 +230,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { * The configured value for the heart-beat settings. * @since 4.2 */ - @Nullable - public long[] getHeartbeatValue() { + public long @Nullable [] getHeartbeatValue() { return this.heartbeatValue; } @@ -256,8 +248,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { * Return the configured header initializer. * @since 4.1 */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -444,8 +435,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { private final String sessionId; - @Nullable - private final Principal user; + private final @Nullable Principal user; private final MessageChannel clientOutboundChannel; @@ -459,7 +449,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { public SessionInfo(String sessionId, @Nullable Principal user, MessageChannel outboundChannel, - @Nullable long[] clientHeartbeat, @Nullable long[] serverHeartbeat) { + long @Nullable [] clientHeartbeat, long @Nullable [] serverHeartbeat) { this.sessionId = sessionId; this.user = user; @@ -481,8 +471,7 @@ public class SimpleBrokerMessageHandler extends AbstractBrokerMessageHandler { return this.sessionId; } - @Nullable - public Principal getUser() { + public @Nullable Principal getUser() { return this.user; } 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 afc2f7016c..3059a03c42 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.messaging.simp.broker; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java index 37c2d3b400..194bc027f9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractBrokerRegistration.java @@ -21,7 +21,8 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler; @@ -49,7 +50,7 @@ public abstract class AbstractBrokerRegistration { * @param destinationPrefixes the destination prefixes */ public AbstractBrokerRegistration(SubscribableChannel clientInboundChannel, - MessageChannel clientOutboundChannel, @Nullable String[] destinationPrefixes) { + MessageChannel clientOutboundChannel, String @Nullable [] destinationPrefixes) { Assert.notNull(clientInboundChannel, "'clientInboundChannel' must not be null"); Assert.notNull(clientOutboundChannel, "'clientOutboundChannel' must not be null"); 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 9c505329dc..b55bda3dc0 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 @@ -24,13 +24,14 @@ import java.util.Map; import java.util.concurrent.Executor; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; import org.springframework.context.event.SmartApplicationListener; -import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.converter.ByteArrayMessageConverter; import org.springframework.messaging.converter.CompositeMessageConverter; @@ -121,20 +122,15 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC } - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private ChannelRegistration clientInboundChannelRegistration; + private @Nullable ChannelRegistration clientInboundChannelRegistration; - @Nullable - private ChannelRegistration clientOutboundChannelRegistration; + private @Nullable ChannelRegistration clientOutboundChannelRegistration; - @Nullable - private MessageBrokerRegistry brokerRegistry; + private @Nullable MessageBrokerRegistry brokerRegistry; - @Nullable - private Integer phase; + private @Nullable Integer phase; /** @@ -149,8 +145,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -324,8 +319,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC * Provide access to the configured PatchMatcher for access from other * configuration classes. */ - @Nullable - public final PathMatcher getPathMatcher( + public final @Nullable PathMatcher getPathMatcher( AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel) { return getBrokerRegistry(clientInboundChannel, clientOutboundChannel).getPathMatcher(); @@ -385,8 +379,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC } @Bean - @Nullable - public AbstractBrokerMessageHandler simpleBrokerMessageHandler( + public @Nullable AbstractBrokerMessageHandler simpleBrokerMessageHandler( AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver) { @@ -414,8 +407,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC } @Bean - @Nullable - public AbstractBrokerMessageHandler stompBrokerRelayMessageHandler( + public @Nullable AbstractBrokerMessageHandler stompBrokerRelayMessageHandler( AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationMessageHandler userDestinationMessageHandler, @Nullable MessageHandler userRegistryMessageHandler, UserDestinationResolver userDestinationResolver) { @@ -458,8 +450,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC } @Bean - @Nullable - public MessageHandler userRegistryMessageHandler( + public @Nullable MessageHandler userRegistryMessageHandler( AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpUserRegistry userRegistry, SimpMessagingTemplate brokerMessagingTemplate, @Qualifier("messageBrokerTaskScheduler") TaskScheduler scheduler) { @@ -618,8 +609,7 @@ public abstract class AbstractMessageBrokerConfiguration implements ApplicationC * Override this method to provide a custom {@link Validator}. * @since 4.0.1 */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return null; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java index ad8649587a..f6d63f0e9e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/ChannelRegistration.java @@ -23,7 +23,8 @@ import java.util.concurrent.Executor; import java.util.function.Consumer; import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.support.ChannelInterceptor; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; @@ -37,11 +38,9 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; */ public class ChannelRegistration { - @Nullable - private TaskExecutorRegistration registration; + private @Nullable TaskExecutorRegistration registration; - @Nullable - private Executor executor; + private @Nullable Executor executor; private final List interceptors = new ArrayList<>(); 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 45caca7de7..a2892b4a56 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,8 +19,9 @@ package org.springframework.messaging.simp.config; import java.util.Arrays; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.context.event.SmartApplicationListener; -import org.springframework.lang.Nullable; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler; @@ -41,28 +42,21 @@ public class MessageBrokerRegistry { private final MessageChannel clientOutboundChannel; - @Nullable - private SimpleBrokerRegistration simpleBrokerRegistration; + private @Nullable SimpleBrokerRegistration simpleBrokerRegistration; - @Nullable - private StompBrokerRelayRegistration brokerRelayRegistration; + private @Nullable StompBrokerRelayRegistration brokerRelayRegistration; private final ChannelRegistration brokerChannelRegistration = new ChannelRegistration(); - @Nullable - private String[] applicationDestinationPrefixes; + private String @Nullable [] applicationDestinationPrefixes; - @Nullable - private String userDestinationPrefix; + private @Nullable String userDestinationPrefix; - @Nullable - private Integer userRegistryOrder; + private @Nullable Integer userRegistryOrder; - @Nullable - private PathMatcher pathMatcher; + private @Nullable PathMatcher pathMatcher; - @Nullable - private Integer cacheLimit; + private @Nullable Integer cacheLimit; private boolean preservePublishOrder; @@ -111,14 +105,12 @@ public class MessageBrokerRegistry { return this.brokerChannelRegistration; } - @Nullable - protected String getUserDestinationBroadcast() { + protected @Nullable String getUserDestinationBroadcast() { return (this.brokerRelayRegistration != null ? this.brokerRelayRegistration.getUserDestinationBroadcast() : null); } - @Nullable - protected String getUserRegistryBroadcast() { + protected @Nullable String getUserRegistryBroadcast() { return (this.brokerRelayRegistration != null ? this.brokerRelayRegistration.getUserRegistryBroadcast() : null); } @@ -138,8 +130,7 @@ public class MessageBrokerRegistry { return this; } - @Nullable - protected Collection getApplicationDestinationPrefixes() { + protected @Nullable Collection getApplicationDestinationPrefixes() { return (this.applicationDestinationPrefixes != null ? Arrays.asList(this.applicationDestinationPrefixes) : null); } @@ -161,8 +152,7 @@ public class MessageBrokerRegistry { return this; } - @Nullable - protected String getUserDestinationPrefix() { + protected @Nullable String getUserDestinationPrefix() { return this.userDestinationPrefix; } @@ -177,8 +167,7 @@ public class MessageBrokerRegistry { this.userRegistryOrder = order; } - @Nullable - protected Integer getUserRegistryOrder() { + protected @Nullable Integer getUserRegistryOrder() { return this.userRegistryOrder; } @@ -204,8 +193,7 @@ public class MessageBrokerRegistry { return this; } - @Nullable - protected PathMatcher getPathMatcher() { + protected @Nullable PathMatcher getPathMatcher() { return this.pathMatcher; } @@ -236,8 +224,7 @@ public class MessageBrokerRegistry { return this; } - @Nullable - protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) { + protected @Nullable SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerChannel) { if (this.simpleBrokerRegistration == null && this.brokerRelayRegistration == null) { enableSimpleBroker(); } @@ -251,8 +238,7 @@ public class MessageBrokerRegistry { return null; } - @Nullable - protected StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) { + protected @Nullable StompBrokerRelayMessageHandler getStompBrokerRelay(SubscribableChannel brokerChannel) { if (this.brokerRelayRegistration != null) { StompBrokerRelayMessageHandler relay = this.brokerRelayRegistration.getMessageHandler(brokerChannel); relay.setPreservePublishOrder(this.preservePublishOrder); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java index 628914a9d7..99b14b5ad1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/SimpleBrokerRegistration.java @@ -16,7 +16,8 @@ package org.springframework.messaging.simp.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler; @@ -31,14 +32,11 @@ import org.springframework.scheduling.TaskScheduler; */ public class SimpleBrokerRegistration extends AbstractBrokerRegistration { - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; - @Nullable - private long[] heartbeat; + private long @Nullable [] heartbeat; - @Nullable - private String selectorHeaderName; + private @Nullable String selectorHeaderName; /** diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java index 417a4dcab5..333651492f 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/StompBrokerRelayRegistration.java @@ -16,7 +16,8 @@ package org.springframework.messaging.simp.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessageChannel; import org.springframework.messaging.SubscribableChannel; import org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler; @@ -44,28 +45,21 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { private String systemPasscode = "guest"; - @Nullable - private Long systemHeartbeatSendInterval; + private @Nullable Long systemHeartbeatSendInterval; - @Nullable - private Long systemHeartbeatReceiveInterval; + private @Nullable Long systemHeartbeatReceiveInterval; - @Nullable - private String virtualHost; + private @Nullable String virtualHost; - @Nullable - private TcpOperations tcpClient; + private @Nullable TcpOperations tcpClient; - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; private boolean autoStartup = true; - @Nullable - private String userDestinationBroadcast; + private @Nullable String userDestinationBroadcast; - @Nullable - private String userRegistryBroadcast; + private @Nullable String userRegistryBroadcast; /** @@ -235,8 +229,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { return this; } - @Nullable - protected String getUserDestinationBroadcast() { + protected @Nullable String getUserDestinationBroadcast() { return this.userDestinationBroadcast; } @@ -254,8 +247,7 @@ public class StompBrokerRelayRegistration extends AbstractBrokerRegistration { return this; } - @Nullable - protected String getUserRegistryBroadcast() { + protected @Nullable String getUserRegistryBroadcast() { return this.userRegistryBroadcast; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java index f9cfdb07ad..89141906fe 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/TaskExecutorRegistration.java @@ -16,7 +16,8 @@ package org.springframework.messaging.simp.config; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.util.Assert; @@ -33,17 +34,13 @@ public class TaskExecutorRegistration { private final ThreadPoolTaskExecutor taskExecutor; - @Nullable - private Integer corePoolSize; + private @Nullable Integer corePoolSize; - @Nullable - private Integer maxPoolSize; + private @Nullable Integer maxPoolSize; - @Nullable - private Integer keepAliveSeconds; + private @Nullable Integer keepAliveSeconds; - @Nullable - private Integer queueCapacity; + private @Nullable Integer queueCapacity; /** 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 09947fad0c..21b960eb75 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,9 +1,7 @@ /** * Configuration support for WebSocket messaging using higher level messaging protocols. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.simp.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2907d6c332..c6b727907e 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,9 +1,7 @@ /** * Generic support for Simple Messaging Protocols including protocols such as STOMP. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.simp; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/BufferingStompDecoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/BufferingStompDecoder.java index b7c9e1e322..ad57a7a265 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/BufferingStompDecoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/BufferingStompDecoder.java @@ -22,7 +22,8 @@ import java.util.List; import java.util.Queue; import java.util.concurrent.LinkedBlockingQueue; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; @@ -52,8 +53,7 @@ public class BufferingStompDecoder { private final Queue chunks = new LinkedBlockingQueue<>(); - @Nullable - private volatile Integer expectedContentLength; + private volatile @Nullable Integer expectedContentLength; /** @@ -163,8 +163,7 @@ public class BufferingStompDecoder { /** * Get the expected content length of the currently buffered, incomplete STOMP frame. */ - @Nullable - public Integer getExpectedContentLength() { + public @Nullable Integer getExpectedContentLength() { return this.expectedContentLength; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java index 3ecbe0a799..84b549aaa4 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/DefaultStompSession.java @@ -30,9 +30,9 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.converter.MessageConversionException; @@ -87,19 +87,16 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { private MessageConverter converter = new SimpleMessageConverter(); - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; private long receiptTimeLimit = TimeUnit.SECONDS.toMillis(15); private volatile boolean autoReceiptEnabled; - @Nullable - private volatile TcpConnection connection; + private volatile @Nullable TcpConnection connection; - @Nullable - private volatile String version; + private volatile @Nullable String version; private final AtomicInteger subscriptionIndex = new AtomicInteger(); @@ -179,8 +176,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { /** * Return the configured TaskScheduler to use for receipt tracking. */ - @Nullable - public TaskScheduler getTaskScheduler() { + public @Nullable TaskScheduler getTaskScheduler() { return this.taskScheduler; } @@ -240,8 +236,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { return receiptable; } - @Nullable - private String checkOrAddReceipt(StompHeaders headers) { + private @Nullable String checkOrAddReceipt(StompHeaders headers) { String receiptId = headers.getReceipt(); if (isAutoReceiptEnabled() && receiptId == null) { receiptId = String.valueOf(DefaultStompSession.this.receiptIndex.getAndIncrement()); @@ -540,21 +535,17 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { private class ReceiptHandler implements Receiptable { - @Nullable - private final String receiptId; + private final @Nullable String receiptId; private final List> receiptCallbacks = new ArrayList<>(2); private final List receiptLostCallbacks = new ArrayList<>(2); - @Nullable - private ScheduledFuture future; + private @Nullable ScheduledFuture future; - @Nullable - private Boolean result; + private @Nullable Boolean result; - @Nullable - private StompHeaders receiptHeaders; + private @Nullable StompHeaders receiptHeaders; public ReceiptHandler(@Nullable String receiptId) { this.receiptId = receiptId; @@ -571,8 +562,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { } @Override - @Nullable - public String getReceiptId() { + public @Nullable String getReceiptId() { return this.receiptId; } @@ -671,8 +661,7 @@ public class DefaultStompSession implements ConnectionHandlingStompSession { } @Override - @Nullable - public String getSubscriptionId() { + public @Nullable String getSubscriptionId() { return this.headers.getId(); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java index e321e19f66..8548c41a27 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClient.java @@ -18,7 +18,8 @@ package org.springframework.messaging.simp.stomp; import java.util.concurrent.CompletableFuture; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.tcp.TcpOperations; import org.springframework.messaging.tcp.reactor.ReactorNetty2TcpClient; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index 811157d51a..f8a1daaed9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -26,7 +26,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageDeliveryException; @@ -137,21 +138,17 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler private final Map systemSubscriptions = new HashMap<>(4); - @Nullable - private String virtualHost; + private @Nullable String virtualHost; - @Nullable - private TcpOperations tcpClient; + private @Nullable TcpOperations tcpClient; - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; private final DefaultStats stats = new DefaultStats(); private final Map connectionHandlers = new ConcurrentHashMap<>(); - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; /** @@ -349,8 +346,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler /** * Return the configured virtual host value. */ - @Nullable - public String getVirtualHost() { + public @Nullable String getVirtualHost() { return this.virtualHost; } @@ -371,8 +367,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler * invoked and this method is invoked before the handler is started and * hence a default implementation initialized). */ - @Nullable - public TcpOperations getTcpClient() { + public @Nullable TcpOperations getTcpClient() { return this.tcpClient; } @@ -389,8 +384,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -429,8 +423,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler this.taskScheduler = taskScheduler; } - @Nullable - public TaskScheduler getTaskScheduler() { + public @Nullable TaskScheduler getTaskScheduler() { return this.taskScheduler; } @@ -644,15 +637,13 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler private final MessageChannel outboundChannel; - @Nullable - private volatile TcpConnection tcpConnection; + private volatile @Nullable TcpConnection tcpConnection; private volatile boolean isStompConnected; private long clientSendInterval; - @Nullable - private final AtomicInteger clientSendMessageCount; + private final @Nullable AtomicInteger clientSendMessageCount; private long clientSendMessageTimestamp; @@ -691,8 +682,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler return this.connectHeaders; } - @Nullable - protected TcpConnection getTcpConnection() { + protected @Nullable TcpConnection getTcpConnection() { return this.tcpConnection; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java index 03df60b746..f699ea41bc 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompClientSupport.java @@ -19,7 +19,8 @@ package org.springframework.messaging.simp.stomp; import java.util.Arrays; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.converter.MessageConverter; import org.springframework.messaging.converter.SimpleMessageConverter; import org.springframework.scheduling.TaskScheduler; @@ -44,8 +45,7 @@ public abstract class StompClientSupport { private MessageConverter messageConverter = new SimpleMessageConverter(); - @Nullable - private TaskScheduler taskScheduler; + private @Nullable TaskScheduler taskScheduler; private long[] defaultHeartbeat = new long[] {10000, 10000}; @@ -85,8 +85,7 @@ public abstract class StompClientSupport { /** * The configured TaskScheduler. */ - @Nullable - public TaskScheduler getTaskScheduler() { + public @Nullable TaskScheduler getTaskScheduler() { return this.taskScheduler; } 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 442c4301ac..f3a2c80057 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 @@ -23,8 +23,8 @@ import java.util.ArrayList; import java.util.List; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.support.MessageBuilder; @@ -53,8 +53,7 @@ public class StompDecoder { private static final Log logger = SimpLogging.forLogName(StompDecoder.class); - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; /** @@ -68,8 +67,7 @@ public class StompDecoder { /** * Return the configured {@code MessageHeaderInitializer}, if any. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -129,9 +127,8 @@ public class StompDecoder { /** * Decode a single STOMP frame from the given {@code byteBuffer} into a {@link Message}. */ - @Nullable @SuppressWarnings("NullAway") - private Message decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap headers) { + private @Nullable Message decodeMessage(ByteBuffer byteBuffer, @Nullable MultiValueMap headers) { Message decodedMessage = null; skipEol(byteBuffer); byteBuffer.mark(); @@ -302,8 +299,7 @@ public class StompDecoder { return sb.toString(); } - @Nullable - private byte[] readPayload(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) { + private byte @Nullable [] readPayload(ByteBuffer byteBuffer, StompHeaderAccessor headerAccessor) { Integer contentLength; try { contentLength = headerAccessor.getContentLength(); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java index 8d9da03c42..29b7e0e2d2 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompEncoder.java @@ -26,8 +26,8 @@ import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.simp.SimpLogging; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; 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 a0a9448e10..037e305fbf 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,7 +18,7 @@ package org.springframework.messaging.simp.stomp; import java.lang.reflect.Type; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Contract to handle a STOMP frame. 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 44fec8110a..6320d9f3a3 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 @@ -26,7 +26,8 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.atomic.AtomicLong; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageType; @@ -185,8 +186,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { // Redeclared for visibility within simp.stomp @Override - @Nullable - protected Map> getNativeHeaders() { + protected @Nullable Map> getNativeHeaders() { return super.getNativeHeaders(); } @@ -228,8 +228,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { /** * Return the STOMP command, or {@code null} if not yet set. */ - @Nullable - public StompCommand getCommand() { + public @Nullable StompCommand getCommand() { return (StompCommand) getHeader(COMMAND_HEADER); } @@ -261,8 +260,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_HOST_HEADER, host); } - @Nullable - public String getHost() { + public @Nullable String getHost() { return getFirstNativeHeader(STOMP_HOST_HEADER); } @@ -300,8 +298,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { } } - @Nullable - public Integer getContentLength() { + public @Nullable Integer getContentLength() { String header = getFirstNativeHeader(STOMP_CONTENT_LENGTH_HEADER); return (header != null ? Integer.valueOf(header) : null); } @@ -318,8 +315,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_ACK_HEADER, ack); } - @Nullable - public String getAck() { + public @Nullable String getAck() { return getFirstNativeHeader(STOMP_ACK_HEADER); } @@ -327,8 +323,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_NACK_HEADER, nack); } - @Nullable - public String getNack() { + public @Nullable String getNack() { return getFirstNativeHeader(STOMP_NACK_HEADER); } @@ -336,8 +331,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_LOGIN_HEADER, login); } - @Nullable - public String getLogin() { + public @Nullable String getLogin() { return getFirstNativeHeader(STOMP_LOGIN_HEADER); } @@ -357,8 +351,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { /** * Return the passcode header value, or {@code null} if not set. */ - @Nullable - public String getPasscode() { + public @Nullable String getPasscode() { StompPasscode credentials = (StompPasscode) getHeader(CREDENTIALS_HEADER); return (credentials != null ? credentials.passcode : null); } @@ -367,8 +360,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_RECEIPT_ID_HEADER, receiptId); } - @Nullable - public String getReceiptId() { + public @Nullable String getReceiptId() { return getFirstNativeHeader(STOMP_RECEIPT_ID_HEADER); } @@ -376,13 +368,11 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_RECEIPT_HEADER, receiptId); } - @Nullable - public String getReceipt() { + public @Nullable String getReceipt() { return getFirstNativeHeader(STOMP_RECEIPT_HEADER); } - @Nullable - public String getMessage() { + public @Nullable String getMessage() { return getFirstNativeHeader(STOMP_MESSAGE_HEADER); } @@ -390,8 +380,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_MESSAGE_HEADER, content); } - @Nullable - public String getMessageId() { + public @Nullable String getMessageId() { return getFirstNativeHeader(STOMP_MESSAGE_ID_HEADER); } @@ -399,8 +388,7 @@ public class StompHeaderAccessor extends SimpMessageHeaderAccessor { setNativeHeader(STOMP_MESSAGE_ID_HEADER, id); } - @Nullable - public String getVersion() { + public @Nullable String getVersion() { return getFirstNativeHeader(STOMP_VERSION_HEADER); } @@ -526,22 +514,19 @@ 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) { + public static @Nullable StompCommand getCommand(Map headers) { return (StompCommand) headers.get(COMMAND_HEADER); } /** * Return the passcode header value, or {@code null} if not set. */ - @Nullable - public static String getPasscode(Map headers) { + public static @Nullable String getPasscode(Map headers) { StompPasscode credentials = (StompPasscode) headers.get(CREDENTIALS_HEADER); return (credentials != null ? credentials.passcode : null); } - @Nullable - public static Integer getContentLength(Map> nativeHeaders) { + public static @Nullable Integer getContentLength(Map> nativeHeaders) { List values = nativeHeaders.get(STOMP_CONTENT_LENGTH_HEADER); return (!CollectionUtils.isEmpty(values) ? Integer.valueOf(values.get(0)) : null); } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java index ef253caa57..f023946fb1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompHeaders.java @@ -26,7 +26,8 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -146,8 +147,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Return the content-type header value. */ - @Nullable - public MimeType getContentType() { + public @Nullable MimeType getContentType() { String value = getFirst(CONTENT_TYPE); return (StringUtils.hasLength(value) ? MimeTypeUtils.parseMimeType(value) : null); } @@ -179,8 +179,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the receipt header. */ - @Nullable - public String getReceipt() { + public @Nullable String getReceipt() { return getFirst(RECEIPT); } @@ -195,8 +194,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the host header. */ - @Nullable - public String getHost() { + public @Nullable String getHost() { return getFirst(HOST); } @@ -205,7 +203,7 @@ public class StompHeaders implements MultiValueMap, Serializable * Applies to the CONNECT frame. * @since 5.0.7 */ - public void setAcceptVersion(@Nullable String... acceptVersions) { + public void setAcceptVersion(String @Nullable ... acceptVersions) { if (ObjectUtils.isEmpty(acceptVersions)) { set(ACCEPT_VERSION, null); return; @@ -220,8 +218,7 @@ public class StompHeaders implements MultiValueMap, Serializable * Get the accept-version header. * @since 5.0.7 */ - @Nullable - public String[] getAcceptVersion() { + public String @Nullable [] getAcceptVersion() { String value = getFirst(ACCEPT_VERSION); return value != null ? StringUtils.commaDelimitedListToStringArray(value) : null; } @@ -237,8 +234,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the login header. */ - @Nullable - public String getLogin() { + public @Nullable String getLogin() { return getFirst(LOGIN); } @@ -253,8 +249,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the passcode header. */ - @Nullable - public String getPasscode() { + public @Nullable String getPasscode() { return getFirst(PASSCODE); } @@ -262,7 +257,7 @@ public class StompHeaders implements MultiValueMap, Serializable * Set the heartbeat header. * Applies to the CONNECT and CONNECTED frames. */ - public void setHeartbeat(@Nullable long[] heartbeat) { + public void setHeartbeat(long @Nullable [] heartbeat) { if (heartbeat == null || heartbeat.length != 2) { throw new IllegalArgumentException("Heart-beat array must be of length 2, not " + (heartbeat != null ? heartbeat.length : "null")); @@ -277,9 +272,8 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the heartbeat header. */ - @Nullable @SuppressWarnings("NullAway") - public long[] getHeartbeat() { + public long @Nullable [] getHeartbeat() { String rawValue = getFirst(HEARTBEAT); int pos = (rawValue != null ? rawValue.indexOf(',') : -1); if (pos == -1) { @@ -309,8 +303,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the session header. */ - @Nullable - public String getSession() { + public @Nullable String getSession() { return getFirst(SESSION); } @@ -326,8 +319,7 @@ public class StompHeaders implements MultiValueMap, Serializable * Get the server header. * Applies to the CONNECTED frame. */ - @Nullable - public String getServer() { + public @Nullable String getServer() { return getFirst(SERVER); } @@ -342,8 +334,7 @@ public class StompHeaders implements MultiValueMap, Serializable * Get the destination header. * Applies to the SEND, SUBSCRIBE, and MESSAGE frames. */ - @Nullable - public String getDestination() { + public @Nullable String getDestination() { return getFirst(DESTINATION); } @@ -358,8 +349,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the id header. */ - @Nullable - public String getId() { + public @Nullable String getId() { return getFirst(ID); } @@ -374,8 +364,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the ack header. */ - @Nullable - public String getAck() { + public @Nullable String getAck() { return getFirst(ACK); } @@ -390,8 +379,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the subscription header. */ - @Nullable - public String getSubscription() { + public @Nullable String getSubscription() { return getFirst(SUBSCRIPTION); } @@ -406,8 +394,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the message-id header. */ - @Nullable - public String getMessageId() { + public @Nullable String getMessageId() { return getFirst(MESSAGE_ID); } @@ -422,8 +409,7 @@ public class StompHeaders implements MultiValueMap, Serializable /** * Get the receipt header. */ - @Nullable - public String getReceiptId() { + public @Nullable String getReceiptId() { return getFirst(RECEIPT_ID); } @@ -433,8 +419,7 @@ public class StompHeaders implements MultiValueMap, Serializable * @return the first header value, or {@code null} if none */ @Override - @Nullable - public String getFirst(String headerName) { + public @Nullable String getFirst(String headerName) { List headerValues = this.headers.get(headerName); return headerValues != null ? headerValues.get(0) : null; } @@ -515,8 +500,7 @@ public class StompHeaders implements MultiValueMap, Serializable } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { return this.headers.get(key); } 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 94875b6d0a..1af02d99ed 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 @@ -18,7 +18,7 @@ package org.springframework.messaging.simp.stomp; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represents a STOMP session with operations to send messages, @@ -136,8 +136,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(); + @Nullable String getReceiptId(); /** * Task to invoke when a receipt is received. @@ -173,8 +172,7 @@ public interface StompSession { /** * Return the id for the subscription. */ - @Nullable - String getSubscriptionId(); + @Nullable String getSubscriptionId(); /** * Return the headers used on the SUBSCRIBE frame. diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandler.java index c55b8b26f5..aefd083cce 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandler.java @@ -16,7 +16,7 @@ package org.springframework.messaging.simp.stomp; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A contract for client STOMP session lifecycle events including a callback diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandlerAdapter.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandlerAdapter.java index 2d57f14574..cc0b13afb9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandlerAdapter.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompSessionHandlerAdapter.java @@ -18,7 +18,7 @@ package org.springframework.messaging.simp.stomp; import java.lang.reflect.Type; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract adapter class for {@link StompSessionHandler} with mostly empty 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 6b42fa754c..d4b398bc07 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,9 +1,7 @@ /** * Generic support for simple messaging protocols (like STOMP). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.simp.stomp; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 822864ae09..f059866110 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 @@ -22,8 +22,8 @@ import java.util.HashSet; import java.util.Set; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpLogging; @@ -124,8 +124,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { @Override - @Nullable - public UserDestinationResult resolveDestination(Message message) { + public @Nullable UserDestinationResult resolveDestination(Message message) { ParseResult parseResult = parse(message); if (parseResult == null) { return null; @@ -145,8 +144,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { return new UserDestinationResult(sourceDest, targetSet, subscribeDest, user, sessionIds); } - @Nullable - private ParseResult parse(Message message) { + private @Nullable ParseResult parse(Message message) { MessageHeaders headers = message.getHeaders(); String sourceDestination = SimpMessageHeaderAccessor.getDestination(headers); if (sourceDestination == null || !checkDestination(sourceDestination, this.prefix)) { @@ -163,8 +161,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { return null; } - @Nullable - private ParseResult parseSubscriptionMessage(Message message, String sourceDestination) { + private @Nullable ParseResult parseSubscriptionMessage(Message message, String sourceDestination) { MessageHeaders headers = message.getHeaders(); String sessionId = SimpMessageHeaderAccessor.getSessionId(headers); if (sessionId == null) { @@ -243,8 +240,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { * @return a target destination, or {@code null} if none */ @SuppressWarnings("unused") - @Nullable - protected String getTargetDestination(String sourceDestination, String actualDestination, + protected @Nullable String getTargetDestination(String sourceDestination, String actualDestination, String sessionId, @Nullable String user) { return actualDestination + "-user" + sessionId; @@ -269,8 +265,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { private final Set sessionIds; - @Nullable - private final String user; + private final @Nullable String user; public ParseResult(String sourceDest, String actualDest, String subscribeDest, Set sessionIds, @Nullable String user) { @@ -313,8 +308,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver { /** * The name of the user associated with the session. */ - @Nullable - public String getUser() { + public @Nullable String getUser() { return this.user; } } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java index 14d4c21df4..f041968b52 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/MultiServerUserRegistry.java @@ -28,10 +28,11 @@ import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; import org.springframework.context.event.SmartApplicationListener; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.converter.MessageConverter; import org.springframework.util.Assert; @@ -117,8 +118,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati // SimpUserRegistry methods @Override - @Nullable - public SimpUser getUser(String userName) { + public @Nullable SimpUser getUser(String userName) { // Prefer remote registries due to cross-server SessionLookup for (UserRegistrySnapshot registry : this.remoteRegistries.values()) { SimpUser user = registry.getUserMap().get(userName); @@ -279,8 +279,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati private final Set sessions; // Cross-server session lookup (for example, user connected to multiple servers) - @Nullable - private SessionLookup sessionLookup; + private @Nullable SessionLookup sessionLookup; /** * Default constructor for JSON deserialization. @@ -312,9 +311,8 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati return this.name; } - @Nullable @Override - public Principal getPrincipal() { + public @Nullable Principal getPrincipal() { return null; } @@ -327,8 +325,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati } @Override - @Nullable - public SimpSession getSession(String sessionId) { + public @Nullable SimpSession getSession(String sessionId) { if (this.sessionLookup != null) { return this.sessionLookup.findSessions(getName()).get(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 bcd0d67392..677d467d5b 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 @@ -19,7 +19,7 @@ package org.springframework.messaging.simp.user; import java.security.Principal; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represents a connected user. @@ -40,8 +40,7 @@ public interface SimpUser { * server in a multi-server user registry scenario. * @since 5.3 */ - @Nullable - Principal getPrincipal(); + @Nullable Principal getPrincipal(); /** * Whether the user has any sessions. @@ -53,8 +52,7 @@ public interface SimpUser { * @param sessionId the session id * @return the matching session, or {@code null} if none found */ - @Nullable - SimpSession getSession(String sessionId); + @Nullable SimpSession getSession(String sessionId); /** * Return the sessions for the user. 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 9847104d31..ded0e4d221 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,7 +18,7 @@ package org.springframework.messaging.simp.user; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A registry of currently connected users. @@ -33,8 +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); + @Nullable SimpUser getUser(String userName); /** * Return a snapshot of all connected users. 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 9c8d24faab..ddd4226a60 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 @@ -24,9 +24,9 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.context.SmartLifecycle; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -69,16 +69,13 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec private final SendHelper sendHelper; - @Nullable - private BroadcastHandler broadcastHandler; + private @Nullable BroadcastHandler broadcastHandler; - @Nullable - private MessageHeaderInitializer headerInitializer; + private @Nullable MessageHeaderInitializer headerInitializer; private volatile boolean running; - @Nullable - private Integer phase; + private @Nullable Integer phase; private final Object lifecycleMonitor = new Object(); @@ -127,8 +124,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec /** * Return the configured destination for unresolved messages. */ - @Nullable - public String getBroadcastDestination() { + public @Nullable String getBroadcastDestination() { return (this.broadcastHandler != null ? this.broadcastHandler.getBroadcastDestination() : null); } @@ -152,8 +148,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -262,8 +257,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec private final MessageSendingOperations messagingTemplate; - @Nullable - private final Map> orderedMessagingTemplates; + private final @Nullable Map> orderedMessagingTemplates; SendHelper(MessageChannel clientInboundChannel, MessageChannel brokerChannel) { this.brokerChannel = brokerChannel; @@ -334,8 +328,7 @@ public class UserDestinationMessageHandler implements MessageHandler, SmartLifec return this.broadcastDestination; } - @Nullable - public Message preHandle(Message message) throws MessagingException { + public @Nullable Message preHandle(Message message) throws MessagingException { String destination = SimpMessageHeaderAccessor.getDestination(message.getHeaders()); if (!getBroadcastDestination().equals(destination)) { return message; 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 95e5e44808..1efb0315a6 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,7 +16,8 @@ package org.springframework.messaging.simp.user; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; /** @@ -45,7 +46,6 @@ 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); + @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 aa74978e1f..c47607bac9 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 @@ -19,7 +19,8 @@ package org.springframework.messaging.simp.user; import java.util.Collections; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -38,8 +39,7 @@ public class UserDestinationResult { private final String subscribeDestination; - @Nullable - private final String user; + private final @Nullable String user; private final Set sessionIds; @@ -106,16 +106,14 @@ 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() { + public @Nullable String getUser() { return this.user; } /** * Return the session id for the targetDestination. */ - @Nullable - public Set getSessionIds() { + public @Nullable Set getSessionIds() { return this.sessionIds; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java index eb55f0110e..4696e3049d 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/user/UserRegistryMessageHandler.java @@ -20,8 +20,9 @@ import java.time.Duration; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationListener; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; import org.springframework.messaging.MessagingException; @@ -55,8 +56,7 @@ public class UserRegistryMessageHandler implements MessageHandler, ApplicationLi private final UserRegistryTask schedulerTask = new UserRegistryTask(); - @Nullable - private volatile ScheduledFuture scheduledFuture; + private volatile @Nullable ScheduledFuture scheduledFuture; private long registryExpirationPeriod = TimeUnit.SECONDS.toMillis(20); 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 bd59b706f1..95d5b632c1 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,9 +6,7 @@ *

    Also included is {@link org.springframework.messaging.simp.user.SimpUserRegistry} * for keeping track of connected user sessions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.simp.user; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c729f871f3..2405bcdf0e 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 @@ -20,8 +20,8 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.messaging.MessageHeaders; import org.springframework.util.StringUtils; @@ -90,8 +90,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) { + protected @Nullable V getHeaderIfAvailable(Map headers, String name, Class type) { Object value = headers.get(name); if (value == null) { return 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 d1d209e8af..6c097e5814 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 @@ -22,9 +22,9 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -174,8 +174,7 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep private int receiveInterceptorIndex = -1; - @Nullable - public Message applyPreSend(Message message, MessageChannel channel) { + public @Nullable Message applyPreSend(Message message, MessageChannel channel) { Message messageToUse = message; for (ChannelInterceptor interceptor : interceptors) { Message resolvedMessage = interceptor.preSend(messageToUse, channel); @@ -224,8 +223,7 @@ public abstract class AbstractMessageChannel implements MessageChannel, Intercep return true; } - @Nullable - public Message applyPostReceive(Message message, MessageChannel channel) { + public @Nullable Message applyPostReceive(Message message, MessageChannel channel) { Message messageToUse = message; for (ChannelInterceptor interceptor : interceptors) { messageToUse = interceptor.postReceive(messageToUse, 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 4dd9dbd7c2..b83c54e369 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,7 +16,8 @@ package org.springframework.messaging.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -39,8 +40,7 @@ public interface ChannelInterceptor { * If this method returns {@code null} then the actual * send invocation will not occur. */ - @Nullable - default Message preSend(Message message, MessageChannel channel) { + default @Nullable Message preSend(Message message, MessageChannel channel) { return message; } @@ -77,8 +77,7 @@ public interface ChannelInterceptor { * necessary; {@code null} aborts further interceptor invocations. * This only applies to PollableChannels. */ - @Nullable - default Message postReceive(Message message, MessageChannel channel) { + default @Nullable Message postReceive(Message message, MessageChannel channel) { return message; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/ErrorMessage.java b/spring-messaging/src/main/java/org/springframework/messaging/support/ErrorMessage.java index e097701169..d0b31f6adc 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/ErrorMessage.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/ErrorMessage.java @@ -18,7 +18,8 @@ package org.springframework.messaging.support; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; @@ -45,9 +46,8 @@ public class ErrorMessage extends GenericMessage { private static final long serialVersionUID = -5470210965279837728L; - @Nullable @SuppressWarnings("serial") - private final Message originalMessage; + private final @Nullable Message originalMessage; /** @@ -129,8 +129,7 @@ public class ErrorMessage extends GenericMessage { * where the ErrorMessage was created. * @since 5.0 */ - @Nullable - public Message getOriginalMessage() { + public @Nullable Message getOriginalMessage() { return this.originalMessage; } 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 ef34ae90ec..57d92d29be 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,7 +16,8 @@ package org.springframework.messaging.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; @@ -46,8 +47,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 - default Message beforeHandle(Message message, MessageChannel channel, MessageHandler handler) { + default @Nullable Message beforeHandle(Message message, MessageChannel channel, MessageHandler handler) { return message; } 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 1d8b56531d..8875e6ba9f 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 @@ -21,7 +21,8 @@ import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.RejectedExecutionException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageDeliveryException; import org.springframework.messaging.MessageHandler; @@ -37,8 +38,7 @@ import org.springframework.messaging.SubscribableChannel; */ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel { - @Nullable - private final Executor executor; + private final @Nullable Executor executor; private final List executorInterceptors = new ArrayList<>(4); @@ -62,8 +62,7 @@ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel { } - @Nullable - public Executor getExecutor() { + public @Nullable Executor getExecutor() { return this.executor; } @@ -168,8 +167,7 @@ public class ExecutorSubscribableChannel extends AbstractSubscribableChannel { } } - @Nullable - private Message applyBeforeHandle(Message message) { + private @Nullable Message applyBeforeHandle(Message message) { Message messageToUse = message; for (ExecutorChannelInterceptor interceptor : executorInterceptors) { messageToUse = interceptor.beforeHandle(messageToUse, ExecutorSubscribableChannel.this, this.messageHandler); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java b/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java index 72b06f560a..263f166022 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/support/GenericMessage.java @@ -19,7 +19,8 @@ package org.springframework.messaging.support; import java.io.Serializable; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; 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 cbd338cda8..9c05c25d24 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 @@ -16,7 +16,8 @@ package org.springframework.messaging.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.MessageHeaders; import org.springframework.util.IdGenerator; @@ -32,8 +33,7 @@ public class IdTimestampMessageHeaderInitializer implements MessageHeaderInitial private static final IdGenerator ID_VALUE_NONE_GENERATOR = () -> MessageHeaders.ID_VALUE_NONE; - @Nullable - private IdGenerator idGenerator; + private @Nullable IdGenerator idGenerator; private boolean enableTimestamp; @@ -52,8 +52,7 @@ public class IdTimestampMessageHeaderInitializer implements MessageHeaderInitial /** * Return the configured {@code IdGenerator}, if any. */ - @Nullable - public IdGenerator getIdGenerator() { + public @Nullable 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 028bbbc524..73cd088c75 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,7 +18,8 @@ package org.springframework.messaging.support; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -41,8 +42,7 @@ public final class MessageBuilder { private final T payload; - @Nullable - private final Message providedMessage; + private final @Nullable Message providedMessage; private MessageHeaderAccessor headerAccessor; 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 ab39f57211..dff4c9ced0 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 @@ -26,7 +26,8 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; @@ -120,8 +121,7 @@ public class MessageHeaderAccessor { private boolean enableTimestamp = false; - @Nullable - private IdGenerator idGenerator; + private @Nullable IdGenerator idGenerator; private MessageHeaderAccessor(@Nullable MessageHeaders headers) { this.headers = new MutableMessageHeaders(headers); @@ -299,8 +299,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) { + public @Nullable Object getHeader(String headerName) { return this.headers.get(headerName); } @@ -433,8 +432,7 @@ public class MessageHeaderAccessor { // Specific header accessors - @Nullable - public UUID getId() { + public @Nullable UUID getId() { Object value = getHeader(MessageHeaders.ID); if (value == null) { return null; @@ -442,8 +440,7 @@ public class MessageHeaderAccessor { return (value instanceof UUID uuid ? uuid : UUID.fromString(value.toString())); } - @Nullable - public Long getTimestamp() { + public @Nullable Long getTimestamp() { Object value = getHeader(MessageHeaders.TIMESTAMP); if (value == null) { return null; @@ -455,8 +452,7 @@ public class MessageHeaderAccessor { setHeader(MessageHeaders.CONTENT_TYPE, contentType); } - @Nullable - public MimeType getContentType() { + public @Nullable MimeType getContentType() { Object value = getHeader(MessageHeaders.CONTENT_TYPE); if (value == null) { return null; @@ -478,8 +474,7 @@ public class MessageHeaderAccessor { setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel); } - @Nullable - public Object getReplyChannel() { + public @Nullable Object getReplyChannel() { return getHeader(MessageHeaders.REPLY_CHANNEL); } @@ -491,8 +486,7 @@ public class MessageHeaderAccessor { setHeader(MessageHeaders.ERROR_CHANNEL, errorChannel); } - @Nullable - public Object getErrorChannel() { + public @Nullable Object getErrorChannel() { return getHeader(MessageHeaders.ERROR_CHANNEL); } @@ -586,8 +580,7 @@ public class MessageHeaderAccessor { * @return an accessor instance of the specified type, or {@code null} if none * @since 5.1.19 */ - @Nullable - public static MessageHeaderAccessor getAccessor(Message message) { + public static @Nullable MessageHeaderAccessor getAccessor(Message message) { return getAccessor(message.getHeaders(), null); } @@ -602,8 +595,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, @Nullable Class requiredType) { + public static @Nullable T getAccessor(Message message, @Nullable Class requiredType) { return getAccessor(message.getHeaders(), requiredType); } @@ -617,8 +609,7 @@ public class MessageHeaderAccessor { * @since 4.1 */ @SuppressWarnings("unchecked") - @Nullable - public static T getAccessor( + public static @Nullable T getAccessor( MessageHeaders messageHeaders, @Nullable Class requiredType) { if (messageHeaders instanceof MutableMessageHeaders mutableHeaders) { 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 aafc1dcca4..e8ab4c9888 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,7 +21,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.messaging.Message; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -87,8 +88,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * Subclasses can use this method to access the "native" headers sub-map. */ @SuppressWarnings("unchecked") - @Nullable - protected Map> getNativeHeaders() { + protected @Nullable Map> getNativeHeaders() { return (Map>) getHeader(NATIVE_HEADERS); } @@ -158,8 +158,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * @param headerName the name of the header * @return the associated values, or {@code null} if none */ - @Nullable - public List getNativeHeader(String headerName) { + public @Nullable List getNativeHeader(String headerName) { Map> map = getNativeHeaders(); return (map != null ? map.get(headerName) : null); } @@ -169,8 +168,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * @param headerName the name of the header * @return the associated value, or {@code null} if none */ - @Nullable - public String getFirstNativeHeader(String headerName) { + public @Nullable String getFirstNativeHeader(String headerName) { Map> map = getNativeHeaders(); if (map != null) { List values = map.get(headerName); @@ -272,8 +270,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * @param headerName the name of the header * @return the associated values, or {@code null} if the header was not present */ - @Nullable - public List removeNativeHeader(String headerName) { + public @Nullable List removeNativeHeader(String headerName) { Assert.state(isMutable(), "Already immutable"); Map> nativeHeaders = getNativeHeaders(); if (CollectionUtils.isEmpty(nativeHeaders)) { @@ -291,8 +288,7 @@ public class NativeMessageHeaderAccessor extends MessageHeaderAccessor { * @return the associated value, or {@code null} if none */ @SuppressWarnings("unchecked") - @Nullable - public static String getFirstNativeHeader(String headerName, Map headers) { + public static @Nullable String getFirstNativeHeader(String headerName, Map headers) { Map> map = (Map>) headers.get(NATIVE_HEADERS); if (map != null) { List values = map.get(headerName); 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 b2213f6a16..cdc809c879 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,9 +4,7 @@ * message headers, as well as various {@link org.springframework.messaging.MessageChannel} * implementations and channel interceptor support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 572866d399..eebbc41975 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,7 +16,7 @@ package org.springframework.messaging.tcp; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A contract to determine the frequency of reconnect attempts after connection failure. @@ -32,7 +32,6 @@ 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); + @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 2b940f2170..8eb670ba00 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,9 +6,7 @@ * as well as sending messages via * {@link org.springframework.messaging.tcp.TcpConnection TcpConnection}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.tcp; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNetty2TcpClient.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNetty2TcpClient.java index 624201cdcb..f8cace98ef 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNetty2TcpClient.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNetty2TcpClient.java @@ -31,6 +31,7 @@ import io.netty5.handler.codec.ByteToMessageDecoder; import io.netty5.util.concurrent.ImmediateEventExecutor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; @@ -44,7 +45,6 @@ import reactor.netty5.resources.LoopResources; import reactor.netty5.tcp.TcpClient; import reactor.util.retry.Retry; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.tcp.ReconnectStrategy; import org.springframework.messaging.tcp.TcpConnection; @@ -70,14 +70,11 @@ public class ReactorNetty2TcpClient

    implements TcpOperations

    { private final TcpMessageCodec

    codec; - @Nullable - private final ChannelGroup channelGroup; + private final @Nullable ChannelGroup channelGroup; - @Nullable - private final LoopResources loopResources; + private final @Nullable LoopResources loopResources; - @Nullable - private final ConnectionProvider poolResources; + private final @Nullable ConnectionProvider poolResources; private final Scheduler scheduler = Schedulers.newParallel("tcp-client-scheduler"); diff --git a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java index 35ff79fc78..106496a3f9 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/tcp/reactor/ReactorNettyTcpClient.java @@ -31,6 +31,7 @@ import io.netty.handler.codec.ByteToMessageDecoder; import io.netty.util.concurrent.ImmediateEventExecutor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; @@ -45,7 +46,6 @@ import reactor.netty.resources.LoopResources; import reactor.netty.tcp.TcpClient; import reactor.util.retry.Retry; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.tcp.ReconnectStrategy; import org.springframework.messaging.tcp.TcpConnection; @@ -70,14 +70,11 @@ public class ReactorNettyTcpClient

    implements TcpOperations

    { private final ReactorNettyCodec

    codec; - @Nullable - private final ChannelGroup channelGroup; + private final @Nullable ChannelGroup channelGroup; - @Nullable - private final LoopResources loopResources; + private final @Nullable LoopResources loopResources; - @Nullable - private final ConnectionProvider poolResources; + private final @Nullable ConnectionProvider poolResources; private final Scheduler scheduler = Schedulers.newParallel("tcp-client-scheduler"); 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 0fbf6c5be7..976a3d45c0 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,9 +1,7 @@ /** * Contains support for TCP messaging based on Reactor. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.tcp.reactor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/converter/MessageConverterTests.java b/spring-messaging/src/test/java/org/springframework/messaging/converter/MessageConverterTests.java index 320fd1adc1..adce141d90 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/converter/MessageConverterTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/converter/MessageConverterTests.java @@ -19,9 +19,9 @@ package org.springframework.messaging.converter; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/MessagingPredicates.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/MessagingPredicates.java index 1c3c826fb0..8287461489 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/MessagingPredicates.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/MessagingPredicates.java @@ -18,8 +18,9 @@ package org.springframework.messaging.handler.annotation; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * Predicates for messaging annotations. @@ -55,8 +56,7 @@ public class MessagingPredicates { public static class DestinationVariablePredicate implements Predicate { - @Nullable - private String value; + private @Nullable String value; public DestinationVariablePredicate value(@Nullable String name) { @@ -79,14 +79,11 @@ public class MessagingPredicates { public static class HeaderPredicate implements Predicate { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private Boolean required; + private @Nullable Boolean required; - @Nullable - private String defaultValue; + private @Nullable String defaultValue; public HeaderPredicate name(@Nullable String name) { diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolverTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolverTests.java index da36141e30..b63e3bf9dd 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolverTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/annotation/reactive/PayloadMethodArgumentResolverTests.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -35,7 +36,6 @@ import org.springframework.core.codec.Decoder; import org.springframework.core.codec.StringDecoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DefaultDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.handler.annotation.Payload; @@ -160,8 +160,7 @@ class PayloadMethodArgumentResolverTests { @SuppressWarnings("unchecked") - @Nullable - private T resolveValue(MethodParameter param, Publisher content, Validator validator) { + private @Nullable T resolveValue(MethodParameter param, Publisher content, Validator validator) { Message message = new GenericMessage<>(content, Collections.singletonMap(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.TEXT_PLAIN)); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethodTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethodTests.java index cdd1fcb27a..06b9fa5322 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethodTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/InvocableHandlerMethodTests.java @@ -18,10 +18,10 @@ package org.springframework.messaging.handler.invocation; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import static org.assertj.core.api.Assertions.assertThat; @@ -154,8 +154,7 @@ class InvocableHandlerMethodTests { .withMessageContaining("Illegal argument"); } - @Nullable - private Object invoke(Object handler, Method method, Object... providedArgs) throws Exception { + private @Nullable Object invoke(Object handler, Method method, Object... providedArgs) throws Exception { InvocableHandlerMethod handlerMethod = new InvocableHandlerMethod(handler, method); handlerMethod.setMessageMethodArgumentResolvers(this.resolvers); return handlerMethod.invoke(this.message, providedArgs); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java index 31df4ee8cc..47fc6b28a7 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/ResolvableMethod.java @@ -32,6 +32,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cglib.core.SpringNamingPolicy; import org.springframework.cglib.proxy.Callback; @@ -47,7 +48,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; 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.Assert; @@ -613,12 +613,10 @@ public class ResolvableMethod { private static class MethodInvocationInterceptor implements MethodInterceptor, InvocationHandler { - @Nullable - private Method invokedMethod; + private @Nullable Method invokedMethod; @Override - @Nullable - public Object intercept(Object object, Method method, @Nullable Object[] args, @Nullable MethodProxy proxy) { + public @Nullable Object intercept(Object object, Method method, Object @Nullable [] args, @Nullable MethodProxy proxy) { if (ReflectionUtils.isObjectMethod(method)) { return ReflectionUtils.invokeMethod(method, object, args); } @@ -629,13 +627,11 @@ public class ResolvableMethod { } @Override - @Nullable - public Object invoke(Object proxy, Method method, @Nullable Object[] args) { + public @Nullable Object invoke(Object proxy, Method method, Object @Nullable [] args) { return intercept(proxy, method, args, null); } - @Nullable - Method getInvokedMethod() { + @Nullable Method getInvokedMethod() { return this.invokedMethod; } } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/StubArgumentResolver.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/StubArgumentResolver.java index fb8e7db1bf..a2010c4446 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/StubArgumentResolver.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/StubArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.messaging.handler.invocation; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -32,8 +33,7 @@ public class StubArgumentResolver implements HandlerMethodArgumentResolver { private final Class valueType; - @Nullable - private final Object value; + private final @Nullable Object value; private List resolvedParameters = new ArrayList<>(); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/EncoderMethodReturnValueHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/EncoderMethodReturnValueHandlerTests.java index d07b83aed6..21c0fab5e5 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/EncoderMethodReturnValueHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/EncoderMethodReturnValueHandlerTests.java @@ -19,6 +19,7 @@ package org.springframework.messaging.handler.invocation.reactive; import java.util.Collections; import io.reactivex.rxjava3.core.Completable; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -27,7 +28,6 @@ import reactor.test.StepVerifier; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.codec.CharSequenceEncoder; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/InvocableHandlerMethodTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/InvocableHandlerMethodTests.java index 67eb668c3b..1413e76e3d 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/InvocableHandlerMethodTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/InvocableHandlerMethodTests.java @@ -22,12 +22,12 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; 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.messaging.handler.invocation.ResolvableMethod; @@ -161,8 +161,7 @@ class InvocableHandlerMethodTests { } - @Nullable - private Object invokeAndBlock(Object handler, Method method, Object... providedArgs) { + private @Nullable Object invokeAndBlock(Object handler, Method method, Object... providedArgs) { return invoke(handler, method, providedArgs).block(Duration.ofSeconds(5)); } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/MethodMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/MethodMessageHandlerTests.java index f48f5ce592..6078e83ff4 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/MethodMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/MethodMessageHandlerTests.java @@ -25,13 +25,13 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.context.support.StaticApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.handler.DestinationPatternsMessageCondition; import org.springframework.messaging.handler.HandlerMethod; @@ -218,8 +218,7 @@ class MethodMessageHandlerTests { return Collections.singletonList(this.returnValueHandler); } - @Nullable - public Object getLastReturnValue() { + public @Nullable Object getLastReturnValue() { return this.returnValueHandler.getLastReturnValue(); } @@ -238,8 +237,7 @@ class MethodMessageHandlerTests { } @Override - @Nullable - protected RouteMatcher.Route getDestination(Message message) { + protected RouteMatcher.@Nullable Route getDestination(Message message) { return (RouteMatcher.Route) message.getHeaders().get( DestinationPatternsMessageCondition.LOOKUP_DESTINATION_HEADER); } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java index c5b5b9ecf0..12fe1000f2 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/StubArgumentResolver.java @@ -19,10 +19,10 @@ package org.springframework.messaging.handler.invocation.reactive; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -34,8 +34,7 @@ public class StubArgumentResolver implements HandlerMethodArgumentResolver { private final Class valueType; - @Nullable - private final Object value; + private final @Nullable Object value; private List resolvedParameters = new ArrayList<>(); diff --git a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java index 22ea181370..ba83bc7f44 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/handler/invocation/reactive/TestReturnValueHandler.java @@ -16,11 +16,11 @@ package org.springframework.messaging.handler.invocation.reactive; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; /** @@ -29,12 +29,10 @@ import org.springframework.messaging.Message; */ public class TestReturnValueHandler implements HandlerMethodReturnValueHandler { - @Nullable - private Object lastReturnValue; + private @Nullable Object lastReturnValue; - @Nullable - public Object getLastReturnValue() { + public @Nullable Object getLastReturnValue() { return this.lastReturnValue; } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultMetadataExtractorTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultMetadataExtractorTests.java index 9de9f9627a..baf908d569 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultMetadataExtractorTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/DefaultMetadataExtractorTests.java @@ -24,6 +24,7 @@ import java.util.Map; import io.netty.buffer.PooledByteBufAllocator; import io.rsocket.Payload; import io.rsocket.metadata.WellKnownMimeType; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,7 +36,6 @@ import org.springframework.core.codec.StringDecoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/TestRSocket.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/TestRSocket.java index 15580a3026..17332a4084 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/TestRSocket.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/TestRSocket.java @@ -18,12 +18,11 @@ package org.springframework.messaging.rsocket; import io.rsocket.Payload; import io.rsocket.RSocket; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; - /** * {@link RSocket} that saves the name of the invoked method and the input payload(s). */ @@ -33,11 +32,11 @@ public class TestRSocket implements RSocket { private Flux payloadFluxToReturn = Flux.empty(); - @Nullable private volatile String savedMethodName; + private volatile @Nullable String savedMethodName; - @Nullable private volatile Payload savedPayload; + private volatile @Nullable Payload savedPayload; - @Nullable private volatile Flux savedPayloadFlux; + private volatile @Nullable Flux savedPayloadFlux; public void setPayloadMonoToReturn(Mono payloadMonoToReturn) { @@ -48,18 +47,15 @@ public class TestRSocket implements RSocket { this.payloadFluxToReturn = payloadFluxToReturn; } - @Nullable - public String getSavedMethodName() { + public @Nullable String getSavedMethodName() { return this.savedMethodName; } - @Nullable - public Payload getSavedPayload() { + public @Nullable Payload getSavedPayload() { return this.savedPayload; } - @Nullable - public Flux getSavedPayloadFlux() { + public @Nullable Flux getSavedPayloadFlux() { return this.savedPayloadFlux; } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageConditionTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageConditionTests.java index 209c2fadfc..f23fd0ae35 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageConditionTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/annotation/support/RSocketFrameTypeMessageConditionTests.java @@ -19,9 +19,9 @@ package org.springframework.messaging.rsocket.annotation.support; import java.util.Arrays; import io.rsocket.frame.FrameType; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.support.MessageBuilder; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolverTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolverTests.java index f1f5ac9527..037bf93552 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolverTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/PayloadArgumentResolverTests.java @@ -18,6 +18,7 @@ package org.springframework.messaging.rsocket.service; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Single; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -25,7 +26,6 @@ import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.Payload; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessorTests.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessorTests.java index ef1fe46c77..107e16b251 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessorTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketExchangeBeanRegistrationAotProcessorTests.java @@ -16,6 +16,7 @@ package org.springframework.messaging.rsocket.service; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.SpringProxy; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.DecoratingProxy; -import org.springframework.lang.Nullable; import org.springframework.messaging.handler.annotation.Payload; import static org.assertj.core.api.Assertions.assertThat; @@ -70,8 +70,7 @@ class RSocketExchangeBeanRegistrationAotProcessorTests { } } - @Nullable - private static BeanRegistrationAotContribution createContribution(Class beanClass) { + private static @Nullable BeanRegistrationAotContribution createContribution(Class beanClass) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass)); return new RSocketExchangeBeanRegistrationAotProcessor() diff --git a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolverTestSupport.java b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolverTestSupport.java index 7b534dcca8..6b7b5b5c3e 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolverTestSupport.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/rsocket/service/RSocketServiceArgumentResolverTestSupport.java @@ -18,8 +18,9 @@ package org.springframework.messaging.rsocket.service; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -28,13 +29,11 @@ import org.springframework.util.ClassUtils; */ public abstract class RSocketServiceArgumentResolverTestSupport { - @Nullable - private RSocketServiceArgumentResolver resolver; + private @Nullable RSocketServiceArgumentResolver resolver; private final RSocketRequestValues.Builder requestValuesBuilder = RSocketRequestValues.builder(null); - @Nullable - private RSocketRequestValues requestValues; + private @Nullable RSocketRequestValues requestValues; protected RSocketServiceArgumentResolverTestSupport() { diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java index 7421a10d3c..6369215aa8 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/annotation/support/SimpAnnotationMethodMessageHandlerTests.java @@ -25,6 +25,7 @@ import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -37,7 +38,6 @@ import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import org.springframework.context.support.StaticApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java index 3445bb0a32..e8ad5acb25 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/config/MessageBrokerConfigurationTests.java @@ -24,6 +24,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; @@ -32,7 +33,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHandler; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClientTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClientTests.java index 65d54e3616..36648bea3f 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClientTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/ReactorNettyTcpStompClientTests.java @@ -29,12 +29,12 @@ import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.TransportConnector; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInfo; -import org.springframework.lang.Nullable; import org.springframework.messaging.converter.StringMessageConverter; import org.springframework.messaging.simp.stomp.StompSession.Subscription; import org.springframework.messaging.tcp.reactor.ReactorNetty2TcpClient; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/SplittingStompEncoderTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/SplittingStompEncoderTests.java index a5d2640671..e127c17685 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/SplittingStompEncoderTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/SplittingStompEncoderTests.java @@ -20,10 +20,9 @@ import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; - import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSession.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSession.java index 133116e989..a0926df294 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSession.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSession.java @@ -19,7 +19,7 @@ package org.springframework.messaging.simp.user; import java.util.HashSet; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Rossen Stoyanchev diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java index bad87cf42c..5dc420936b 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpSubscription.java @@ -18,7 +18,8 @@ package org.springframework.messaging.simp.user; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpUser.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpUser.java index 548d820646..736568ac9d 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpUser.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/TestSimpUser.java @@ -22,7 +22,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Rossen Stoyanchev @@ -44,9 +44,8 @@ public class TestSimpUser implements SimpUser { return name; } - @Nullable @Override - public Principal getPrincipal() { + public @Nullable Principal getPrincipal() { return null; } diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java index e1ec61dd89..0f2548f879 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/user/UserDestinationMessageHandlerTests.java @@ -18,12 +18,12 @@ package org.springframework.messaging.simp.user; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; import org.springframework.core.testfixture.security.TestPrincipal; -import org.springframework.lang.Nullable; import org.springframework.messaging.Message; import org.springframework.messaging.StubMessageChannel; import org.springframework.messaging.SubscribableChannel; diff --git a/spring-orm/src/main/java/org/springframework/orm/ObjectOptimisticLockingFailureException.java b/spring-orm/src/main/java/org/springframework/orm/ObjectOptimisticLockingFailureException.java index 0799a5033e..8fc038ed6b 100644 --- a/spring-orm/src/main/java/org/springframework/orm/ObjectOptimisticLockingFailureException.java +++ b/spring-orm/src/main/java/org/springframework/orm/ObjectOptimisticLockingFailureException.java @@ -16,8 +16,9 @@ package org.springframework.orm; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.OptimisticLockingFailureException; -import org.springframework.lang.Nullable; /** * Exception thrown on an optimistic locking violation for a mapped object. @@ -29,11 +30,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ObjectOptimisticLockingFailureException extends OptimisticLockingFailureException { - @Nullable - private final Object persistentClass; + private final @Nullable Object persistentClass; - @Nullable - private final Object identifier; + private final @Nullable Object identifier; /** @@ -135,8 +134,7 @@ public class ObjectOptimisticLockingFailureException extends OptimisticLockingFa * Return the persistent class of the object for which the locking failed. * If no Class was specified, this method returns null. */ - @Nullable - public Class getPersistentClass() { + public @Nullable Class getPersistentClass() { return (this.persistentClass instanceof Class clazz ? clazz : null); } @@ -144,8 +142,7 @@ public class ObjectOptimisticLockingFailureException extends OptimisticLockingFa * Return the name of the persistent class of the object for which the locking failed. * Will work for both Class objects and String names. */ - @Nullable - public String getPersistentClassName() { + public @Nullable String getPersistentClassName() { if (this.persistentClass instanceof Class clazz) { return clazz.getName(); } @@ -155,8 +152,7 @@ public class ObjectOptimisticLockingFailureException extends OptimisticLockingFa /** * Return the identifier of the object for which the locking failed. */ - @Nullable - public Object getIdentifier() { + public @Nullable Object getIdentifier() { return this.identifier; } diff --git a/spring-orm/src/main/java/org/springframework/orm/ObjectRetrievalFailureException.java b/spring-orm/src/main/java/org/springframework/orm/ObjectRetrievalFailureException.java index 54536f5d57..7a359a7ca6 100644 --- a/spring-orm/src/main/java/org/springframework/orm/ObjectRetrievalFailureException.java +++ b/spring-orm/src/main/java/org/springframework/orm/ObjectRetrievalFailureException.java @@ -16,8 +16,9 @@ package org.springframework.orm; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataRetrievalFailureException; -import org.springframework.lang.Nullable; /** * Exception thrown if a mapped object could not be retrieved via its identifier. @@ -29,11 +30,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ObjectRetrievalFailureException extends DataRetrievalFailureException { - @Nullable - private final Object persistentClass; + private final @Nullable Object persistentClass; - @Nullable - private final Object identifier; + private final @Nullable Object identifier; /** @@ -109,8 +108,7 @@ public class ObjectRetrievalFailureException extends DataRetrievalFailureExcepti * Return the persistent class of the object that was not found. * If no Class was specified, this method returns null. */ - @Nullable - public Class getPersistentClass() { + public @Nullable Class getPersistentClass() { return (this.persistentClass instanceof Class clazz ? clazz : null); } @@ -118,8 +116,7 @@ public class ObjectRetrievalFailureException extends DataRetrievalFailureExcepti * Return the name of the persistent class of the object that was not found. * Will work for both Class objects and String names. */ - @Nullable - public String getPersistentClassName() { + public @Nullable String getPersistentClassName() { if (this.persistentClass instanceof Class clazz) { return clazz.getName(); } @@ -129,8 +126,7 @@ public class ObjectRetrievalFailureException extends DataRetrievalFailureExcepti /** * Return the identifier of the object that was not found. */ - @Nullable - public Object getIdentifier() { + public @Nullable Object getIdentifier() { return this.identifier; } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/ConfigurableJtaPlatform.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/ConfigurableJtaPlatform.java index 38265a6f1f..084adf9fed 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/ConfigurableJtaPlatform.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/ConfigurableJtaPlatform.java @@ -25,8 +25,8 @@ import jakarta.transaction.TransactionSynchronizationRegistry; import jakarta.transaction.UserTransaction; import org.hibernate.TransactionException; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.jta.UserTransactionAdapter; import org.springframework.util.Assert; @@ -44,8 +44,7 @@ class ConfigurableJtaPlatform implements JtaPlatform { private final UserTransaction userTransaction; - @Nullable - private final TransactionSynchronizationRegistry transactionSynchronizationRegistry; + private final @Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry; /** diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java index fc247d49f5..dcc9978498 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateExceptionTranslator.java @@ -19,11 +19,11 @@ package org.springframework.orm.hibernate5; import jakarta.persistence.PersistenceException; import org.hibernate.HibernateException; import org.hibernate.JDBCException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessException; import org.springframework.dao.support.PersistenceExceptionTranslator; import org.springframework.jdbc.support.SQLExceptionTranslator; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryUtils; /** @@ -45,8 +45,7 @@ import org.springframework.orm.jpa.EntityManagerFactoryUtils; */ public class HibernateExceptionTranslator implements PersistenceExceptionTranslator { - @Nullable - private SQLExceptionTranslator jdbcExceptionTranslator; + private @Nullable SQLExceptionTranslator jdbcExceptionTranslator; /** @@ -66,8 +65,7 @@ public class HibernateExceptionTranslator implements PersistenceExceptionTransla @Override - @Nullable - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof HibernateException hibernateEx) { return convertHibernateAccessException(hibernateEx); } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateJdbcException.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateJdbcException.java index 3e3674502c..fad5469844 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateJdbcException.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateJdbcException.java @@ -19,9 +19,9 @@ package org.springframework.orm.hibernate5; import java.sql.SQLException; import org.hibernate.JDBCException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.UncategorizedDataAccessException; -import org.springframework.lang.Nullable; /** * Hibernate-specific subclass of UncategorizedDataAccessException, @@ -50,9 +50,8 @@ public class HibernateJdbcException extends UncategorizedDataAccessException { /** * Return the SQL that led to the problem. */ - @Nullable @SuppressWarnings("NullAway") - public String getSql() { + public @Nullable String getSql() { return ((JDBCException) getCause()).getSQL(); } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateQueryException.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateQueryException.java index 1122c91a24..68fa2a3e63 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateQueryException.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateQueryException.java @@ -17,9 +17,9 @@ package org.springframework.orm.hibernate5; import org.hibernate.QueryException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessResourceUsageException; -import org.springframework.lang.Nullable; /** * Hibernate-specific subclass of InvalidDataAccessResourceUsageException, @@ -39,9 +39,8 @@ public class HibernateQueryException extends InvalidDataAccessResourceUsageExcep /** * Return the HQL query string that was invalid. */ - @Nullable @SuppressWarnings("NullAway") - public String getQueryString() { + public @Nullable String getQueryString() { return ((QueryException) getCause()).getQueryString(); } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateSystemException.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateSystemException.java index 5831fa0ba4..fba045573d 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateSystemException.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/HibernateSystemException.java @@ -17,9 +17,9 @@ package org.springframework.orm.hibernate5; import org.hibernate.HibernateException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.UncategorizedDataAccessException; -import org.springframework.lang.Nullable; /** * Hibernate-specific subclass of UncategorizedDataAccessException, 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 13c707d701..798ddbbad3 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 @@ -32,6 +32,7 @@ import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.engine.spi.SessionImplementor; import org.hibernate.resource.transaction.spi.TransactionStatus; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; @@ -43,7 +44,6 @@ 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; @@ -114,11 +114,9 @@ import org.springframework.util.Assert; public class HibernateTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, BeanFactoryAware, InitializingBean { - @Nullable - private SessionFactory sessionFactory; + private @Nullable SessionFactory sessionFactory; - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; private boolean autodetectDataSource = true; @@ -128,18 +126,15 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana private boolean hibernateManagedSession = false; - @Nullable - private Consumer sessionInitializer; + private @Nullable Consumer sessionInitializer; - @Nullable - private Object entityInterceptor; + private @Nullable Object entityInterceptor; /** * Just needed for entityInterceptorBeanName. * @see #setEntityInterceptorBeanName */ - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** @@ -170,8 +165,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana /** * Return the SessionFactory that this instance should manage transactions for. */ - @Nullable - public SessionFactory getSessionFactory() { + public @Nullable SessionFactory getSessionFactory() { return this.sessionFactory; } @@ -231,8 +225,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana /** * Return the JDBC DataSource that this instance manages transactions for. */ - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { return this.dataSource; } @@ -363,8 +356,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana * @see #setEntityInterceptorBeanName * @see #setBeanFactory */ - @Nullable - public Interceptor getEntityInterceptor() throws IllegalStateException, BeansException { + public @Nullable Interceptor getEntityInterceptor() throws IllegalStateException, BeansException { if (this.entityInterceptor instanceof Interceptor interceptor) { return interceptor; } @@ -799,8 +791,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana */ private class HibernateTransactionObject extends JdbcTransactionObjectSupport { - @Nullable - private SessionHolder sessionHolder; + private @Nullable SessionHolder sessionHolder; private boolean newSessionHolder; @@ -808,8 +799,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana private boolean needsConnectionReset; - @Nullable - private Integer previousHoldability; + private @Nullable Integer previousHoldability; public void setSession(Session session) { this.sessionHolder = new SessionHolder(session); @@ -858,8 +848,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana this.previousHoldability = previousHoldability; } - @Nullable - public Integer getPreviousHoldability() { + public @Nullable Integer getPreviousHoldability() { return this.previousHoldability; } @@ -911,8 +900,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana private final SessionHolder sessionHolder; - @Nullable - private final ConnectionHolder connectionHolder; + private final @Nullable ConnectionHolder connectionHolder; private SuspendedResourcesHolder(SessionHolder sessionHolder, @Nullable ConnectionHolder conHolder) { this.sessionHolder = sessionHolder; @@ -923,8 +911,7 @@ public class HibernateTransactionManager extends AbstractPlatformTransactionMana return this.sessionHolder; } - @Nullable - private ConnectionHolder getConnectionHolder() { + private @Nullable ConnectionHolder getConnectionHolder() { return this.connectionHolder; } } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java index f0ee7c9f91..c810de1a15 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/LocalSessionFactoryBean.java @@ -34,6 +34,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.integrator.spi.Integrator; import org.hibernate.service.ServiceRegistry; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -52,7 +53,6 @@ import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternUtils; import org.springframework.core.task.AsyncTaskExecutor; import org.springframework.core.type.filter.TypeFilter; -import org.springframework.lang.Nullable; /** * {@link FactoryBean} that creates a Hibernate {@link SessionFactory}. This is the usual @@ -84,85 +84,59 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator implements FactoryBean, ResourceLoaderAware, BeanFactoryAware, InitializingBean, SmartInitializingSingleton, DisposableBean { - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; - @Nullable - private Resource[] configLocations; + private Resource @Nullable [] configLocations; - @Nullable - private String[] mappingResources; + private String @Nullable [] mappingResources; - @Nullable - private Resource[] mappingLocations; + private Resource @Nullable [] mappingLocations; - @Nullable - private Resource[] cacheableMappingLocations; + private Resource @Nullable [] cacheableMappingLocations; - @Nullable - private Resource[] mappingJarLocations; + private Resource @Nullable [] mappingJarLocations; - @Nullable - private Resource[] mappingDirectoryLocations; + private Resource @Nullable [] mappingDirectoryLocations; - @Nullable - private Interceptor entityInterceptor; + private @Nullable Interceptor entityInterceptor; - @Nullable - private ImplicitNamingStrategy implicitNamingStrategy; + private @Nullable ImplicitNamingStrategy implicitNamingStrategy; - @Nullable - private PhysicalNamingStrategy physicalNamingStrategy; + private @Nullable PhysicalNamingStrategy physicalNamingStrategy; - @Nullable - private Object jtaTransactionManager; + private @Nullable Object jtaTransactionManager; - @Nullable - private RegionFactory cacheRegionFactory; + private @Nullable RegionFactory cacheRegionFactory; - @Nullable - private MultiTenantConnectionProvider multiTenantConnectionProvider; + private @Nullable MultiTenantConnectionProvider multiTenantConnectionProvider; - @Nullable - private CurrentTenantIdentifierResolver currentTenantIdentifierResolver; + private @Nullable CurrentTenantIdentifierResolver currentTenantIdentifierResolver; - @Nullable - private Properties hibernateProperties; + private @Nullable Properties hibernateProperties; - @Nullable - private TypeFilter[] entityTypeFilters; + private TypeFilter @Nullable [] entityTypeFilters; - @Nullable - private Class[] annotatedClasses; + private Class @Nullable [] annotatedClasses; - @Nullable - private String[] annotatedPackages; + private String @Nullable [] annotatedPackages; - @Nullable - private String[] packagesToScan; + private String @Nullable [] packagesToScan; - @Nullable - private AsyncTaskExecutor bootstrapExecutor; + private @Nullable AsyncTaskExecutor bootstrapExecutor; - @Nullable - private Integrator[] hibernateIntegrators; + private Integrator @Nullable [] hibernateIntegrators; private boolean metadataSourcesAccessed = false; - @Nullable - private MetadataSources metadataSources; + private @Nullable MetadataSources metadataSources; - @Nullable - private ResourcePatternResolver resourcePatternResolver; + private @Nullable ResourcePatternResolver resourcePatternResolver; - @Nullable - private ConfigurableListableBeanFactory beanFactory; + private @Nullable ConfigurableListableBeanFactory beanFactory; - @Nullable - private Configuration configuration; + private @Nullable Configuration configuration; - @Nullable - private SessionFactory sessionFactory; + private @Nullable SessionFactory sessionFactory; /** @@ -643,8 +617,7 @@ public class LocalSessionFactoryBean extends HibernateExceptionTranslator @Override - @Nullable - public SessionFactory getObject() { + public @Nullable SessionFactory getObject() { return this.sessionFactory; } 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 ad92e4b960..004466170e 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 @@ -49,6 +49,7 @@ import org.hibernate.context.spi.CurrentTenantIdentifierResolver; import org.hibernate.engine.jdbc.connections.spi.MultiTenantConnectionProvider; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.InfrastructureProxy; @@ -65,7 +66,6 @@ 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; @@ -120,8 +120,7 @@ public class LocalSessionFactoryBuilder extends Configuration { private final ResourcePatternResolver resourcePatternResolver; - @Nullable - private TypeFilter[] entityTypeFilters = DEFAULT_ENTITY_TYPE_FILTERS; + private @Nullable TypeFilter[] entityTypeFilters = DEFAULT_ENTITY_TYPE_FILTERS; /** 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 a528397628..92f126a54a 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 @@ -51,6 +51,7 @@ import org.hibernate.exception.JDBCConnectionException; import org.hibernate.exception.LockAcquisitionException; import org.hibernate.exception.SQLGrammarException; import org.hibernate.service.UnknownServiceException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.DataAccessException; @@ -62,7 +63,6 @@ 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; /** * Helper class featuring methods for Hibernate Session handling. @@ -146,8 +146,7 @@ public abstract class SessionFactoryUtils { * @return the DataSource, or {@code null} if none found * @see ConnectionProvider */ - @Nullable - public static DataSource getDataSource(SessionFactory sessionFactory) { + public static @Nullable DataSource getDataSource(SessionFactory sessionFactory) { Map props = sessionFactory.getProperties(); if (props != null) { Object dataSourceValue = props.get(Environment.JAKARTA_NON_JTA_DATASOURCE); diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionHolder.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionHolder.java index 261035a45d..90ea49d2a8 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionHolder.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SessionHolder.java @@ -19,8 +19,8 @@ package org.springframework.orm.hibernate5; import org.hibernate.FlushMode; import org.hibernate.Session; import org.hibernate.Transaction; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerHolder; /** @@ -38,11 +38,9 @@ import org.springframework.orm.jpa.EntityManagerHolder; */ public class SessionHolder extends EntityManagerHolder { - @Nullable - private Transaction transaction; + private @Nullable Transaction transaction; - @Nullable - private FlushMode previousFlushMode; + private @Nullable FlushMode previousFlushMode; public SessionHolder(Session session) { @@ -59,8 +57,7 @@ public class SessionHolder extends EntityManagerHolder { setTransactionActive(transaction != null); } - @Nullable - public Transaction getTransaction() { + public @Nullable Transaction getTransaction() { return this.transaction; } @@ -68,8 +65,7 @@ public class SessionHolder extends EntityManagerHolder { this.previousFlushMode = previousFlushMode; } - @Nullable - public FlushMode getPreviousFlushMode() { + public @Nullable FlushMode getPreviousFlushMode() { return this.previousFlushMode; } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringBeanContainer.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringBeanContainer.java index f4c0b4149f..727d05d22c 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringBeanContainer.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringBeanContainer.java @@ -25,12 +25,12 @@ import org.hibernate.resource.beans.container.spi.BeanContainer; import org.hibernate.resource.beans.container.spi.ContainedBean; import org.hibernate.resource.beans.spi.BeanInstanceProducer; import org.hibernate.type.spi.TypeBootstrapContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -243,8 +243,7 @@ public final class SpringBeanContainer implements BeanContainer { private final B beanInstance; - @Nullable - private Consumer destructionCallback; + private @Nullable Consumer destructionCallback; public SpringContainedBean(B beanInstance) { this.beanInstance = beanInstance; diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java index 72f93fd7b6..e444a8326f 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringFlushSynchronization.java @@ -17,8 +17,8 @@ package org.springframework.orm.hibernate5; import org.hibernate.Session; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronization; /** diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java index ea814641ca..d57ca19422 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/SpringSessionContext.java @@ -26,8 +26,8 @@ import org.hibernate.Session; import org.hibernate.context.spi.CurrentSessionContext; import org.hibernate.engine.spi.SessionFactoryImplementor; import org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -48,11 +48,9 @@ public class SpringSessionContext implements CurrentSessionContext { private final SessionFactoryImplementor sessionFactory; - @Nullable - private TransactionManager transactionManager; + private @Nullable TransactionManager transactionManager; - @Nullable - private CurrentSessionContext jtaSessionContext; + private @Nullable CurrentSessionContext jtaSessionContext; /** 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 0ee67d0774..7b8f451af2 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,9 +10,7 @@ * *

    This package supports Hibernate 5.x only. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.orm.hibernate5; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/AsyncRequestInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/AsyncRequestInterceptor.java index 14edcf2802..9a55409225 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/AsyncRequestInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/AsyncRequestInterceptor.java @@ -21,8 +21,8 @@ import java.util.concurrent.Callable; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.hibernate.SessionFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.orm.hibernate5.SessionFactoryUtils; import org.springframework.orm.hibernate5.SessionHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInViewInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInViewInterceptor.java index dade7e24c8..49a24fcaae 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInViewInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInViewInterceptor.java @@ -22,10 +22,10 @@ import org.hibernate.FlushMode; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; import org.springframework.orm.hibernate5.SessionFactoryUtils; import org.springframework.orm.hibernate5.SessionHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -80,8 +80,7 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private SessionFactory sessionFactory; + private @Nullable SessionFactory sessionFactory; /** @@ -94,8 +93,7 @@ public class OpenSessionInViewInterceptor implements AsyncWebRequestInterceptor /** * Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. */ - @Nullable - public SessionFactory getSessionFactory() { + public @Nullable SessionFactory getSessionFactory() { return this.sessionFactory; } diff --git a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInterceptor.java index a2016e8314..267243c4c8 100644 --- a/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/hibernate5/support/OpenSessionInterceptor.java @@ -22,10 +22,10 @@ import org.hibernate.FlushMode; import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.SessionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; import org.springframework.orm.hibernate5.SessionFactoryUtils; import org.springframework.orm.hibernate5.SessionHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -50,8 +50,7 @@ import org.springframework.util.Assert; */ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBean { - @Nullable - private SessionFactory sessionFactory; + private @Nullable SessionFactory sessionFactory; /** @@ -64,8 +63,7 @@ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBe /** * Return the Hibernate SessionFactory that should be used to create Hibernate Sessions. */ - @Nullable - public SessionFactory getSessionFactory() { + public @Nullable SessionFactory getSessionFactory() { return this.sessionFactory; } @@ -78,8 +76,7 @@ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBe @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { SessionFactory sf = getSessionFactory(); Assert.state(sf != null, "No SessionFactory set"); 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 8eb9429629..c6a1cbfd08 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,9 +1,7 @@ /** * Classes supporting the {@code org.springframework.orm.hibernate5} package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.orm.hibernate5.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 94c88ec65f..d645fa1e0f 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 @@ -45,6 +45,7 @@ import jakarta.persistence.spi.PersistenceProvider; import jakarta.persistence.spi.PersistenceUnitInfo; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanClassLoaderAware; @@ -58,7 +59,6 @@ import org.springframework.beans.factory.SmartInitializingSingleton; 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; @@ -98,51 +98,38 @@ public abstract class AbstractEntityManagerFactoryBean implements /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private PersistenceProvider persistenceProvider; + private @Nullable PersistenceProvider persistenceProvider; - @Nullable - private String persistenceUnitName; + private @Nullable String persistenceUnitName; private final Map jpaPropertyMap = new HashMap<>(); - @Nullable - private Class entityManagerFactoryInterface; + private @Nullable Class entityManagerFactoryInterface; - @Nullable - private Class entityManagerInterface; + private @Nullable Class entityManagerInterface; - @Nullable - private JpaDialect jpaDialect; + private @Nullable JpaDialect jpaDialect; - @Nullable - private JpaVendorAdapter jpaVendorAdapter; + private @Nullable JpaVendorAdapter jpaVendorAdapter; - @Nullable - private Consumer entityManagerInitializer; + private @Nullable Consumer entityManagerInitializer; - @Nullable - private AsyncTaskExecutor bootstrapExecutor; + private @Nullable AsyncTaskExecutor bootstrapExecutor; private ClassLoader beanClassLoader = getClass().getClassLoader(); - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private String beanName; + private @Nullable String beanName; /** Raw EntityManagerFactory as returned by the PersistenceProvider. */ - @Nullable - private EntityManagerFactory nativeEntityManagerFactory; + private @Nullable EntityManagerFactory nativeEntityManagerFactory; /** Future for lazily initializing raw target EntityManagerFactory. */ - @Nullable - private Future nativeEntityManagerFactoryFuture; + private @Nullable Future nativeEntityManagerFactoryFuture; /** Exposed client-level EntityManagerFactory proxy. */ - @Nullable - private EntityManagerFactory entityManagerFactory; + private @Nullable EntityManagerFactory entityManagerFactory; /** @@ -172,8 +159,7 @@ public abstract class AbstractEntityManagerFactoryBean implements } @Override - @Nullable - public PersistenceProvider getPersistenceProvider() { + public @Nullable PersistenceProvider getPersistenceProvider() { return this.persistenceProvider; } @@ -189,8 +175,7 @@ public abstract class AbstractEntityManagerFactoryBean implements } @Override - @Nullable - public String getPersistenceUnitName() { + public @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -255,8 +240,7 @@ public abstract class AbstractEntityManagerFactoryBean implements } @Override - @Nullable - public Class getEntityManagerInterface() { + public @Nullable Class getEntityManagerInterface() { return this.entityManagerInterface; } @@ -272,8 +256,7 @@ public abstract class AbstractEntityManagerFactoryBean implements } @Override - @Nullable - public JpaDialect getJpaDialect() { + public @Nullable JpaDialect getJpaDialect() { return this.jpaDialect; } @@ -291,8 +274,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * Return the JpaVendorAdapter implementation for this EntityManagerFactory, * or {@code null} if not known. */ - @Nullable - public JpaVendorAdapter getJpaVendorAdapter() { + public @Nullable JpaVendorAdapter getJpaVendorAdapter() { return this.jpaVendorAdapter; } @@ -332,8 +314,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * Return the asynchronous executor for background bootstrapping, if any. * @since 4.3 */ - @Nullable - public AsyncTaskExecutor getBootstrapExecutor() { + public @Nullable AsyncTaskExecutor getBootstrapExecutor() { return this.bootstrapExecutor; } @@ -492,7 +473,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * Delegate an incoming invocation from the proxy, dispatching to EntityManagerFactoryInfo * or the native EntityManagerFactory accordingly. */ - Object invokeProxyMethod(Method method, @Nullable Object[] args) throws Throwable { + Object invokeProxyMethod(Method method, Object @Nullable [] args) throws Throwable { if (method.getDeclaringClass().isAssignableFrom(EntityManagerFactoryInfo.class)) { return method.invoke(this, args); } @@ -554,8 +535,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible */ @Override - @Nullable - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) { JpaDialect jpaDialect = getJpaDialect(); return (jpaDialect != null ? jpaDialect.translateExceptionIfPossible(ex) : EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex)); @@ -618,14 +598,12 @@ public abstract class AbstractEntityManagerFactoryBean implements } @Override - @Nullable - public PersistenceUnitInfo getPersistenceUnitInfo() { + public @Nullable PersistenceUnitInfo getPersistenceUnitInfo() { return null; } @Override - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { return null; } @@ -634,8 +612,7 @@ public abstract class AbstractEntityManagerFactoryBean implements * Return the singleton EntityManagerFactory. */ @Override - @Nullable - public EntityManagerFactory getObject() { + public @Nullable EntityManagerFactory getObject() { return this.entityManagerFactory; } @@ -719,8 +696,7 @@ public abstract class AbstractEntityManagerFactoryBean implements } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { switch (method.getName()) { case "equals" -> { // Only consider equal when proxies are identical. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java index f562fa03e2..0aca79d5ca 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/DefaultJpaDialect.java @@ -21,10 +21,10 @@ import java.sql.SQLException; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.datasource.ConnectionHandle; -import org.springframework.lang.Nullable; import org.springframework.transaction.InvalidIsolationLevelException; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -56,8 +56,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable { * @see #cleanupTransaction */ @Override - @Nullable - public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) + public @Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException { if (definition.getIsolationLevel() != TransactionDefinition.ISOLATION_DEFAULT) { @@ -70,8 +69,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable { } @Override - @Nullable - public Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name) + public @Nullable Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name) throws PersistenceException { return null; @@ -91,8 +89,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable { * indicating that no JDBC Connection can be provided. */ @Override - @Nullable - public ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) + public @Nullable ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) throws PersistenceException, SQLException { return null; @@ -121,8 +118,7 @@ public class DefaultJpaDialect implements JpaDialect, Serializable { * @see EntityManagerFactoryUtils#convertJpaAccessExceptionIfPossible */ @Override - @Nullable - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) { return EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(ex); } 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 32bb7fdd60..f034fcaf2e 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 @@ -24,12 +24,12 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -46,11 +46,9 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware { /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private EntityManagerFactory entityManagerFactory; + private @Nullable EntityManagerFactory entityManagerFactory; - @Nullable - private String persistenceUnitName; + private @Nullable String persistenceUnitName; private final Map jpaPropertyMap = new HashMap<>(); @@ -69,8 +67,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware { * Return the JPA EntityManagerFactory that should be used to create * EntityManagers. */ - @Nullable - public EntityManagerFactory getEntityManagerFactory() { + public @Nullable EntityManagerFactory getEntityManagerFactory() { return this.entityManagerFactory; } @@ -101,8 +98,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() { + public @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -176,8 +172,7 @@ public abstract class EntityManagerFactoryAccessor implements BeanFactoryAware { * @see EntityManagerFactoryUtils#getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory) * @see EntityManagerFactoryUtils#getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory, java.util.Map) */ - @Nullable - protected EntityManager getTransactionalEntityManager() throws IllegalStateException{ + protected @Nullable EntityManager getTransactionalEntityManager() throws IllegalStateException{ EntityManagerFactory emf = obtainEntityManagerFactory(); return EntityManagerFactoryUtils.getTransactionalEntityManager(emf, getJpaPropertyMap()); } 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 cdb9dda3ce..8d8d649c0c 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 @@ -24,8 +24,7 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.spi.PersistenceProvider; import jakarta.persistence.spi.PersistenceUnitInfo; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Metadata interface for a Spring-managed JPA {@link EntityManagerFactory}. @@ -46,8 +45,7 @@ public interface EntityManagerFactoryInfo { * or {@code null} if the standard JPA provider autodetection process * was used to configure the EntityManagerFactory */ - @Nullable - PersistenceProvider getPersistenceProvider(); + @Nullable PersistenceProvider getPersistenceProvider(); /** * Return the PersistenceUnitInfo used to create this @@ -56,8 +54,7 @@ public interface EntityManagerFactoryInfo { * or {@code null} if the in-container contract was not used to * configure the EntityManagerFactory */ - @Nullable - PersistenceUnitInfo getPersistenceUnitInfo(); + @Nullable PersistenceUnitInfo getPersistenceUnitInfo(); /** * Return the name of the persistence unit used to create this @@ -68,16 +65,14 @@ public interface EntityManagerFactoryInfo { * @see #getPersistenceUnitInfo() * @see jakarta.persistence.spi.PersistenceUnitInfo#getPersistenceUnitName() */ - @Nullable - String getPersistenceUnitName(); + @Nullable String getPersistenceUnitName(); /** * Return the JDBC DataSource that this EntityManagerFactory * obtains its JDBC Connections from. * @return the JDBC DataSource, or {@code null} if not known */ - @Nullable - DataSource getDataSource(); + @Nullable DataSource getDataSource(); /** * Return the (potentially vendor-specific) EntityManager interface @@ -86,15 +81,13 @@ public interface EntityManagerFactoryInfo { * to happen: either based on a target {@code EntityManager} instance * or simply defaulting to {@code jakarta.persistence.EntityManager}. */ - @Nullable - Class getEntityManagerInterface(); + @Nullable Class getEntityManagerInterface(); /** * Return the vendor-specific JpaDialect implementation for this * EntityManagerFactory, or {@code null} if not known. */ - @Nullable - JpaDialect getJpaDialect(); + @Nullable JpaDialect getJpaDialect(); /** * Return the ClassLoader that the application's beans are loaded with. 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 b9f38e313b..9f194f526b 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 @@ -34,6 +34,7 @@ import jakarta.persistence.SynchronizationType; import jakarta.persistence.TransactionRequiredException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.ListableBeanFactory; @@ -48,7 +49,6 @@ 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; @@ -130,8 +130,7 @@ public abstract class EntityManagerFactoryUtils { * @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained * @see JpaTransactionManager */ - @Nullable - public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf) + public static @Nullable EntityManager getTransactionalEntityManager(EntityManagerFactory emf) throws DataAccessResourceFailureException { return getTransactionalEntityManager(emf, null); @@ -148,8 +147,7 @@ public abstract class EntityManagerFactoryUtils { * @throws DataAccessResourceFailureException if the EntityManager couldn't be obtained * @see JpaTransactionManager */ - @Nullable - public static EntityManager getTransactionalEntityManager(EntityManagerFactory emf, @Nullable Map properties) + public static @Nullable EntityManager getTransactionalEntityManager(EntityManagerFactory emf, @Nullable Map properties) throws DataAccessResourceFailureException { try { return doGetTransactionalEntityManager(emf, properties, true); @@ -171,8 +169,7 @@ public abstract class EntityManagerFactoryUtils { * @see #getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory) * @see JpaTransactionManager */ - @Nullable - public static EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map properties) + public static @Nullable EntityManager doGetTransactionalEntityManager(EntityManagerFactory emf, Map properties) throws PersistenceException { return doGetTransactionalEntityManager(emf, properties, true); @@ -192,8 +189,7 @@ public abstract class EntityManagerFactoryUtils { * @see #getTransactionalEntityManager(jakarta.persistence.EntityManagerFactory) * @see JpaTransactionManager */ - @Nullable - public static EntityManager doGetTransactionalEntityManager( + public static @Nullable EntityManager doGetTransactionalEntityManager( EntityManagerFactory emf, @Nullable Map properties, boolean synchronizedWithTransaction) throws PersistenceException { @@ -300,8 +296,7 @@ public abstract class EntityManagerFactoryUtils { * (to be passed into cleanupTransaction) * @see JpaDialect#prepareTransaction */ - @Nullable - private static Object prepareTransaction(EntityManager em, EntityManagerFactory emf) { + private static @Nullable Object prepareTransaction(EntityManager em, EntityManagerFactory emf) { if (emf instanceof EntityManagerFactoryInfo emfInfo) { JpaDialect jpaDialect = emfInfo.getJpaDialect(); if (jpaDialect != null) { @@ -360,8 +355,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) { + public static @Nullable DataAccessException convertJpaAccessExceptionIfPossible(RuntimeException ex) { // Following the JPA specification, a persistence provider can also // throw these two exceptions, besides PersistenceException. if (ex instanceof IllegalStateException) { @@ -441,11 +435,9 @@ public abstract class EntityManagerFactoryUtils { extends ResourceHolderSynchronization implements Ordered { - @Nullable - private final Object transactionData; + private final @Nullable Object transactionData; - @Nullable - private final JpaDialect jpaDialect; + private final @Nullable JpaDialect jpaDialect; private final boolean newEntityManager; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerHolder.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerHolder.java index cc72652674..1c5c09df64 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerHolder.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerHolder.java @@ -17,8 +17,8 @@ package org.springframework.orm.jpa; import jakarta.persistence.EntityManager; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.SavepointManager; import org.springframework.transaction.support.ResourceHolderSupport; import org.springframework.util.Assert; @@ -40,13 +40,11 @@ import org.springframework.util.Assert; */ public class EntityManagerHolder extends ResourceHolderSupport { - @Nullable - private final EntityManager entityManager; + private final @Nullable EntityManager entityManager; private boolean transactionActive; - @Nullable - private SavepointManager savepointManager; + private @Nullable SavepointManager savepointManager; public EntityManagerHolder(@Nullable EntityManager entityManager) { @@ -71,8 +69,7 @@ public class EntityManagerHolder extends ResourceHolderSupport { this.savepointManager = savepointManager; } - @Nullable - protected SavepointManager getSavepointManager() { + protected @Nullable SavepointManager getSavepointManager() { return this.savepointManager; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java index 72891dffdc..3ed7953dc7 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/EntityManagerRuntimeHints.java @@ -18,11 +18,12 @@ package org.springframework.orm.jpa; import java.util.Collections; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** 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 3d31c1f755..9e7716a5a1 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 @@ -33,11 +33,11 @@ import jakarta.persistence.spi.PersistenceUnitInfo; import jakarta.persistence.spi.PersistenceUnitTransactionType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -261,8 +261,7 @@ public abstract class ExtendedEntityManagerCreator { private final EntityManager target; - @Nullable - private final PersistenceExceptionTranslator exceptionTranslator; + private final @Nullable PersistenceExceptionTranslator exceptionTranslator; private final boolean jta; @@ -293,8 +292,7 @@ public abstract class ExtendedEntityManagerCreator { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on EntityManager interface coming in... switch (method.getName()) { @@ -439,8 +437,7 @@ public abstract class ExtendedEntityManagerCreator { private final EntityManager entityManager; - @Nullable - private final PersistenceExceptionTranslator exceptionTranslator; + private final @Nullable PersistenceExceptionTranslator exceptionTranslator; public volatile boolean closeOnCompletion; 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 61eaa9bef2..cbccef3da2 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 @@ -20,10 +20,10 @@ import java.sql.SQLException; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceException; +import org.jspecify.annotations.Nullable; 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; @@ -80,8 +80,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @see jakarta.persistence.EntityTransaction#begin * @see org.springframework.jdbc.datasource.DataSourceUtils#prepareConnectionForTransaction */ - @Nullable - Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) + @Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException; /** @@ -103,8 +102,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @throws jakarta.persistence.PersistenceException if thrown by JPA methods * @see #cleanupTransaction */ - @Nullable - Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name) + @Nullable Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullable String name) throws PersistenceException; /** @@ -150,8 +148,7 @@ public interface JpaDialect extends PersistenceExceptionTranslator { * @see org.springframework.jdbc.datasource.SimpleConnectionHandle * @see JpaTransactionManager#setDataSource */ - @Nullable - ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean readOnly) + @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 168938c70b..9b8d020f87 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 @@ -28,6 +28,7 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.EntityTransaction; import jakarta.persistence.PersistenceException; import jakarta.persistence.RollbackException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; @@ -40,7 +41,6 @@ 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; @@ -117,21 +117,17 @@ import org.springframework.util.CollectionUtils; public class JpaTransactionManager extends AbstractPlatformTransactionManager implements ResourceTransactionManager, BeanFactoryAware, InitializingBean { - @Nullable - private EntityManagerFactory entityManagerFactory; + private @Nullable EntityManagerFactory entityManagerFactory; - @Nullable - private String persistenceUnitName; + private @Nullable String persistenceUnitName; private final Map jpaPropertyMap = new HashMap<>(); - @Nullable - private DataSource dataSource; + private @Nullable DataSource dataSource; private JpaDialect jpaDialect = new DefaultJpaDialect(); - @Nullable - private Consumer entityManagerInitializer; + private @Nullable Consumer entityManagerInitializer; /** @@ -168,8 +164,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager /** * Return the EntityManagerFactory that this instance should manage transactions for. */ - @Nullable - public EntityManagerFactory getEntityManagerFactory() { + public @Nullable EntityManagerFactory getEntityManagerFactory() { return this.entityManagerFactory; } @@ -200,8 +195,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager /** * Return the name of the persistence unit to manage transactions for, if any. */ - @Nullable - public String getPersistenceUnitName() { + public @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -276,8 +270,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JDBC DataSource that this instance manages transactions for. */ - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { return this.dataSource; } @@ -665,13 +658,11 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager */ private class JpaTransactionObject extends JdbcTransactionObjectSupport { - @Nullable - private EntityManagerHolder entityManagerHolder; + private @Nullable EntityManagerHolder entityManagerHolder; private boolean newEntityManagerHolder; - @Nullable - private Object transactionData; + private @Nullable Object transactionData; public void setEntityManagerHolder( @Nullable EntityManagerHolder entityManagerHolder, boolean newEntityManagerHolder) { @@ -705,8 +696,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager } } - @Nullable - public Object getTransactionData() { + public @Nullable Object getTransactionData() { return this.transactionData; } @@ -808,8 +798,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager private final EntityManagerHolder entityManagerHolder; - @Nullable - private final ConnectionHolder connectionHolder; + private final @Nullable ConnectionHolder connectionHolder; private SuspendedResourcesHolder(EntityManagerHolder emHolder, @Nullable ConnectionHolder conHolder) { this.entityManagerHolder = emHolder; @@ -820,8 +809,7 @@ public class JpaTransactionManager extends AbstractPlatformTransactionManager return this.entityManagerHolder; } - @Nullable - private ConnectionHolder getConnectionHolder() { + private @Nullable ConnectionHolder getConnectionHolder() { return this.connectionHolder; } } 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 d55a6b614b..1120ad1137 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 @@ -23,8 +23,7 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.spi.PersistenceProvider; import jakarta.persistence.spi.PersistenceUnitInfo; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * SPI interface that allows to plug in vendor-specific behavior @@ -49,8 +48,7 @@ public interface JpaVendorAdapter { * excluding provider classes from temporary class overriding. * @since 2.5.2 */ - @Nullable - default String getPersistenceProviderRootPackage() { + default @Nullable String getPersistenceProviderRootPackage() { return null; } @@ -99,8 +97,7 @@ public interface JpaVendorAdapter { * Return the vendor-specific JpaDialect implementation for this * provider, or {@code null} if there is none. */ - @Nullable - default JpaDialect getJpaDialect() { + default @Nullable JpaDialect getJpaDialect() { return null; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java index bc66db3acf..ad9e00a4b3 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.java @@ -24,6 +24,7 @@ import jakarta.persistence.SharedCacheMode; import jakarta.persistence.ValidationMode; import jakarta.persistence.spi.PersistenceProvider; import jakarta.persistence.spi.PersistenceUnitInfo; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.context.ResourceLoaderAware; @@ -31,7 +32,6 @@ import org.springframework.context.weaving.LoadTimeWeaverAware; import org.springframework.core.io.ResourceLoader; import org.springframework.instrument.classloading.LoadTimeWeaver; import org.springframework.jdbc.datasource.lookup.SingleDataSourceLookup; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager; import org.springframework.orm.jpa.persistenceunit.ManagedClassNameFilter; import org.springframework.orm.jpa.persistenceunit.PersistenceManagedTypes; @@ -89,13 +89,11 @@ import org.springframework.util.ClassUtils; public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManagerFactoryBean implements ResourceLoaderAware, LoadTimeWeaverAware { - @Nullable - private PersistenceUnitManager persistenceUnitManager; + private @Nullable PersistenceUnitManager persistenceUnitManager; private final DefaultPersistenceUnitManager internalPersistenceUnitManager = new DefaultPersistenceUnitManager(); - @Nullable - private PersistenceUnitInfo persistenceUnitInfo; + private @Nullable PersistenceUnitInfo persistenceUnitInfo; /** @@ -426,14 +424,12 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage @Override - @Nullable - public PersistenceUnitInfo getPersistenceUnitInfo() { + public @Nullable PersistenceUnitInfo getPersistenceUnitInfo() { return this.persistenceUnitInfo; } @Override - @Nullable - public String getPersistenceUnitName() { + public @Nullable String getPersistenceUnitName() { if (this.persistenceUnitInfo != null) { return this.persistenceUnitInfo.getPersistenceUnitName(); } @@ -441,8 +437,7 @@ public class LocalContainerEntityManagerFactoryBean extends AbstractEntityManage } @Override - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { if (this.persistenceUnitInfo != null) { return (this.persistenceUnitInfo.getJtaDataSource() != null ? this.persistenceUnitInfo.getJtaDataSource() : diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java index 88b3d1128f..31e204c21d 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/LocalEntityManagerFactoryBean.java @@ -22,8 +22,7 @@ import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.Persistence; import jakarta.persistence.PersistenceException; import jakarta.persistence.spi.PersistenceProvider; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link org.springframework.beans.factory.FactoryBean} that creates a JPA @@ -91,8 +90,7 @@ public class LocalEntityManagerFactoryBean extends AbstractEntityManagerFactoryB * @see #getJpaPropertyMap() */ @Override - @Nullable - public DataSource getDataSource() { + public @Nullable DataSource getDataSource() { return (DataSource) getJpaPropertyMap().get(DATASOURCE_PROPERTY); } 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 9dfb8c7d0e..d3ae81bc32 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 @@ -35,8 +35,8 @@ import jakarta.persistence.StoredProcedureQuery; import jakarta.persistence.TransactionRequiredException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -190,13 +190,11 @@ public abstract class SharedEntityManagerCreator { private final EntityManagerFactory targetFactory; - @Nullable - private final Map properties; + private final @Nullable Map properties; private final boolean synchronizedWithTransaction; - @Nullable - private transient volatile ClassLoader proxyClassLoader; + private transient volatile @Nullable ClassLoader proxyClassLoader; public SharedEntityManagerInvocationHandler( EntityManagerFactory target, @Nullable Map properties, boolean synchronizedWithTransaction) { @@ -217,8 +215,7 @@ public abstract class SharedEntityManagerCreator { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { // Invocation on EntityManager interface coming in... switch (method.getName()) { @@ -362,11 +359,9 @@ public abstract class SharedEntityManagerCreator { private final Query target; - @Nullable - private EntityManager entityManager; + private @Nullable EntityManager entityManager; - @Nullable - private Map outputParameters; + private @Nullable Map outputParameters; public DeferredQueryInvocationHandler(Query target, EntityManager entityManager) { this.target = target; 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 ae73e43ba2..1bb8358803 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.orm.jpa; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 0654e12c3d..529504237a 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 @@ -22,8 +22,8 @@ import java.security.ProtectionDomain; import jakarta.persistence.spi.ClassTransformer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -53,8 +53,7 @@ class ClassFileTransformerAdapter implements ClassFileTransformer { @Override - @Nullable - public byte[] transform( + public byte @Nullable [] 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 058f5e9184..f1c0b17110 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 @@ -33,6 +33,7 @@ import jakarta.persistence.ValidationMode; import jakarta.persistence.spi.PersistenceUnitInfo; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ResourceLoaderAware; @@ -47,7 +48,6 @@ 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.ObjectUtils; import org.springframework.util.ResourceUtils; @@ -104,43 +104,31 @@ public class DefaultPersistenceUnitManager private String[] persistenceXmlLocations = new String[] {DEFAULT_PERSISTENCE_XML_LOCATION}; - @Nullable - private String defaultPersistenceUnitRootLocation = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION; + private @Nullable String defaultPersistenceUnitRootLocation = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_ROOT_LOCATION; - @Nullable - private String defaultPersistenceUnitName = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME; + private @Nullable String defaultPersistenceUnitName = ORIGINAL_DEFAULT_PERSISTENCE_UNIT_NAME; - @Nullable - private PersistenceManagedTypes managedTypes; + private @Nullable PersistenceManagedTypes managedTypes; - @Nullable - private String[] packagesToScan; + private String @Nullable [] packagesToScan; - @Nullable - private ManagedClassNameFilter managedClassNameFilter; + private @Nullable ManagedClassNameFilter managedClassNameFilter; - @Nullable - private String[] mappingResources; + private String @Nullable [] mappingResources; - @Nullable - private SharedCacheMode sharedCacheMode; + private @Nullable SharedCacheMode sharedCacheMode; - @Nullable - private ValidationMode validationMode; + private @Nullable ValidationMode validationMode; private DataSourceLookup dataSourceLookup = new JndiDataSourceLookup(); - @Nullable - private DataSource defaultDataSource; + private @Nullable DataSource defaultDataSource; - @Nullable - private DataSource defaultJtaDataSource; + private @Nullable DataSource defaultJtaDataSource; - @Nullable - private PersistenceUnitPostProcessor[] persistenceUnitPostProcessors; + private PersistenceUnitPostProcessor @Nullable [] persistenceUnitPostProcessors; - @Nullable - private LoadTimeWeaver loadTimeWeaver; + private @Nullable LoadTimeWeaver loadTimeWeaver; private ResourcePatternResolver resourcePatternResolver = new PathMatchingResourcePatternResolver(); @@ -329,8 +317,7 @@ public class DefaultPersistenceUnitManager * persistence provider, resolving data source names in {@code persistence.xml} * against Spring-managed DataSource instances. */ - @Nullable - public DataSourceLookup getDataSourceLookup() { + public @Nullable DataSourceLookup getDataSourceLookup() { return this.dataSourceLookup; } @@ -351,8 +338,7 @@ public class DefaultPersistenceUnitManager * Return the JDBC DataSource that the JPA persistence provider is supposed to use * for accessing the database if none has been specified in {@code persistence.xml}. */ - @Nullable - public DataSource getDefaultDataSource() { + public @Nullable DataSource getDefaultDataSource() { return this.defaultDataSource; } @@ -373,8 +359,7 @@ public class DefaultPersistenceUnitManager * Return the JTA-aware DataSource that the JPA persistence provider is supposed to use * for accessing the database if none has been specified in {@code persistence.xml}. */ - @Nullable - public DataSource getDefaultJtaDataSource() { + public @Nullable DataSource getDefaultJtaDataSource() { return this.defaultJtaDataSource; } @@ -384,7 +369,7 @@ public class DefaultPersistenceUnitManager *

    Such post-processors can, for example, register further entity classes and * jar files, in addition to the metadata read from {@code persistence.xml}. */ - public void setPersistenceUnitPostProcessors(@Nullable PersistenceUnitPostProcessor... postProcessors) { + public void setPersistenceUnitPostProcessors(PersistenceUnitPostProcessor @Nullable ... postProcessors) { this.persistenceUnitPostProcessors = postProcessors; } @@ -392,8 +377,7 @@ public class DefaultPersistenceUnitManager * Return the PersistenceUnitPostProcessors to be applied to each * PersistenceUnitInfo that has been parsed by this manager. */ - @Nullable - public PersistenceUnitPostProcessor[] getPersistenceUnitPostProcessors() { + public PersistenceUnitPostProcessor @Nullable [] getPersistenceUnitPostProcessors() { return this.persistenceUnitPostProcessors; } @@ -424,8 +408,7 @@ public class DefaultPersistenceUnitManager * Return the Spring LoadTimeWeaver to use for class instrumentation according * to the JPA class transformer contract. */ - @Nullable - public LoadTimeWeaver getLoadTimeWeaver() { + public @Nullable LoadTimeWeaver getLoadTimeWeaver() { return this.loadTimeWeaver; } @@ -594,8 +577,7 @@ public class DefaultPersistenceUnitManager * @return the persistence unit root URL to pass to the JPA PersistenceProvider * @see #setDefaultPersistenceUnitRootLocation */ - @Nullable - private URL determineDefaultPersistenceUnitRootUrl() { + private @Nullable URL determineDefaultPersistenceUnitRootUrl() { if (this.defaultPersistenceUnitRootLocation == null) { return null; } @@ -618,8 +600,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() { + private @Nullable Resource getOrmXmlForDefaultPersistenceUnit() { Resource ormXml = this.resourcePatternResolver.getResource( this.defaultPersistenceUnitRootLocation + DEFAULT_ORM_XML_RESOURCE); if (ormXml.exists()) { @@ -647,8 +628,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) { + protected final @Nullable 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/MutablePersistenceUnitInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java index 2393c67fae..c8691065a1 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/MutablePersistenceUnitInfo.java @@ -27,8 +27,8 @@ import jakarta.persistence.SharedCacheMode; import jakarta.persistence.ValidationMode; import jakarta.persistence.spi.ClassTransformer; import jakarta.persistence.spi.PersistenceUnitTransactionType; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -48,27 +48,21 @@ import org.springframework.util.ClassUtils; @SuppressWarnings("removal") public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { - @Nullable - private String persistenceUnitName; + private @Nullable String persistenceUnitName; - @Nullable - private String persistenceProviderClassName; + private @Nullable String persistenceProviderClassName; - @Nullable - private PersistenceUnitTransactionType transactionType; + private @Nullable PersistenceUnitTransactionType transactionType; - @Nullable - private DataSource nonJtaDataSource; + private @Nullable DataSource nonJtaDataSource; - @Nullable - private DataSource jtaDataSource; + private @Nullable DataSource jtaDataSource; private final List mappingFileNames = new ArrayList<>(); private final List jarFileUrls = new ArrayList<>(); - @Nullable - private URL persistenceUnitRootUrl; + private @Nullable URL persistenceUnitRootUrl; private final List managedClassNames = new ArrayList<>(); @@ -84,8 +78,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { private String persistenceXMLSchemaVersion = "2.0"; - @Nullable - private String persistenceProviderPackageName; + private @Nullable String persistenceProviderPackageName; public void setPersistenceUnitName(@Nullable String persistenceUnitName) { @@ -93,8 +86,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { } @Override - @Nullable - public String getPersistenceUnitName() { + public @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -103,8 +95,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { } @Override - @Nullable - public String getPersistenceProviderClassName() { + public @Nullable String getPersistenceProviderClassName() { return this.persistenceProviderClassName; } @@ -128,8 +119,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { } @Override - @Nullable - public DataSource getJtaDataSource() { + public @Nullable DataSource getJtaDataSource() { return this.jtaDataSource; } @@ -138,8 +128,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { } @Override - @Nullable - public DataSource getNonJtaDataSource() { + public @Nullable DataSource getNonJtaDataSource() { return this.nonJtaDataSource; } @@ -166,8 +155,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { } @Override - @Nullable - public URL getPersistenceUnitRootUrl() { + public @Nullable URL getPersistenceUnitRootUrl() { return this.persistenceUnitRootUrl; } @@ -258,8 +246,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { this.persistenceProviderPackageName = persistenceProviderPackageName; } - @Nullable - public String getPersistenceProviderPackageName() { + public @Nullable String getPersistenceProviderPackageName() { return this.persistenceProviderPackageName; } @@ -269,8 +256,7 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { * @see org.springframework.util.ClassUtils#getDefaultClassLoader() */ @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -291,14 +277,12 @@ public class MutablePersistenceUnitInfo implements SmartPersistenceUnitInfo { } @Override - @Nullable - public String getScopeAnnotationName() { + public @Nullable String getScopeAnnotationName() { return null; } @Override - @Nullable - public List getQualifierAnnotationNames() { + public @Nullable List getQualifierAnnotationNames() { return null; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypes.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypes.java index 738b14294f..4c953dcef4 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypes.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypes.java @@ -20,8 +20,8 @@ import java.net.URL; import java.util.List; import jakarta.persistence.spi.PersistenceUnitInfo; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -54,8 +54,7 @@ public interface PersistenceManagedTypes { * @return the persistence unit root url * @see PersistenceUnitInfo#getPersistenceUnitRootUrl() */ - @Nullable - URL getPersistenceUnitRootUrl(); + @Nullable URL getPersistenceUnitRootUrl(); /** * Create an instance using the specified managed class names. diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java index 89800bdae4..3af979ec7e 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesBeanRegistrationAotProcessor.java @@ -33,6 +33,7 @@ import jakarta.persistence.PostUpdate; import jakarta.persistence.PrePersist; import jakarta.persistence.PreRemove; import jakarta.persistence.PreUpdate; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.GeneratedMethod; import org.springframework.aot.generate.GenerationContext; @@ -50,7 +51,6 @@ import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.ParameterizedTypeName; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -71,9 +71,8 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr private static final boolean jpaPresent = ClassUtils.isPresent("jakarta.persistence.Entity", PersistenceManagedTypesBeanRegistrationAotProcessor.class.getClassLoader()); - @Nullable @Override - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { if (jpaPresent) { if (PersistenceManagedTypes.class.isAssignableFrom(registeredBean.getBeanClass())) { return BeanRegistrationAotContribution.withCustomCodeFragments(codeFragments -> @@ -230,8 +229,7 @@ class PersistenceManagedTypesBeanRegistrationAotProcessor implements BeanRegistr } } - @Nullable - private static Class loadClass(String className, @Nullable ClassLoader classLoader) { + private static @Nullable Class loadClass(String className, @Nullable ClassLoader classLoader) { try { return (Class) ClassUtils.forName(className, classLoader); } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesScanner.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesScanner.java index a76b1a4b58..fef854dee3 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesScanner.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/PersistenceManagedTypesScanner.java @@ -29,6 +29,7 @@ import jakarta.persistence.Embeddable; import jakarta.persistence.Entity; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PersistenceException; +import org.jspecify.annotations.Nullable; import org.springframework.context.index.CandidateComponentsIndex; import org.springframework.context.index.CandidateComponentsIndexLoader; @@ -43,7 +44,6 @@ 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.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.ResourceUtils; @@ -77,8 +77,7 @@ public final class PersistenceManagedTypesScanner { private final ResourcePatternResolver resourcePatternResolver; - @Nullable - private final CandidateComponentsIndex componentsIndex; + private final @Nullable CandidateComponentsIndex componentsIndex; private final ManagedClassNameFilter managedClassNameFilter; @@ -192,8 +191,7 @@ public final class PersistenceManagedTypesScanner { private final List managedPackages = new ArrayList<>(); - @Nullable - private URL persistenceUnitRootUrl; + private @Nullable URL persistenceUnitRootUrl; PersistenceManagedTypes toJpaManagedTypes() { return new SimplePersistenceManagedTypes(this.managedClassNames, 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 22f6d057a1..069420cab0 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 @@ -31,6 +31,7 @@ import jakarta.persistence.ValidationMode; import jakarta.persistence.spi.PersistenceUnitTransactionType; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.ErrorHandler; @@ -39,7 +40,6 @@ 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; @@ -331,8 +331,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 { + static @Nullable URL determinePersistenceUnitRootUrl(Resource resource) throws IOException { URL originalURL = resource.getURL(); // If we get an archive, simply return the jar URL (section 6.2 from the JPA spec) diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SimplePersistenceManagedTypes.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SimplePersistenceManagedTypes.java index 6a9b54642c..e569925333 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SimplePersistenceManagedTypes.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SimplePersistenceManagedTypes.java @@ -19,7 +19,7 @@ package org.springframework.orm.jpa.persistenceunit; import java.net.URL; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A simple {@link PersistenceManagedTypes} implementation that holds the list @@ -34,8 +34,7 @@ class SimplePersistenceManagedTypes implements PersistenceManagedTypes { private final List managedPackages; - @Nullable - private final URL persistenceUnitRootUrl; + private final @Nullable URL persistenceUnitRootUrl; SimplePersistenceManagedTypes(List managedClassNames, List managedPackages, @@ -60,8 +59,7 @@ class SimplePersistenceManagedTypes implements PersistenceManagedTypes { } @Override - @Nullable - public URL getPersistenceUnitRootUrl() { + public @Nullable URL getPersistenceUnitRootUrl() { return this.persistenceUnitRootUrl; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java index e188d4c4ce..3dabc98075 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/persistenceunit/SpringPersistenceUnitInfo.java @@ -18,11 +18,11 @@ package org.springframework.orm.jpa.persistenceunit; import jakarta.persistence.spi.ClassTransformer; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.DecoratingClassLoader; import org.springframework.instrument.classloading.LoadTimeWeaver; import org.springframework.instrument.classloading.SimpleThrowawayClassLoader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -39,11 +39,9 @@ import org.springframework.util.Assert; */ class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo { - @Nullable - private LoadTimeWeaver loadTimeWeaver; + private @Nullable LoadTimeWeaver loadTimeWeaver; - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; /** @@ -70,8 +68,7 @@ class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo { * if specified. */ @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return this.classLoader; } 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 e27e279a1c..d3f6e6a543 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,9 +1,7 @@ /** * Internal support for managing JPA persistence units. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.orm.jpa.persistenceunit; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java index 3bee08ed14..db6be53668 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/AsyncRequestInterceptor.java @@ -21,8 +21,8 @@ import java.util.concurrent.Callable; import jakarta.persistence.EntityManagerFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryUtils; import org.springframework.orm.jpa.EntityManagerHolder; import org.springframework.transaction.support.TransactionSynchronizationManager; 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 4b18540054..a3ace5665a 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 @@ -25,9 +25,9 @@ import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; 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; @@ -75,14 +75,11 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter { public static final String DEFAULT_ENTITY_MANAGER_FACTORY_BEAN_NAME = "entityManagerFactory"; - @Nullable - private String entityManagerFactoryBeanName; + private @Nullable String entityManagerFactoryBeanName; - @Nullable - private String persistenceUnitName; + private @Nullable String persistenceUnitName; - @Nullable - private volatile EntityManagerFactory entityManagerFactory; + private volatile @Nullable EntityManagerFactory entityManagerFactory; /** @@ -101,8 +98,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter { * Return the bean name of the EntityManagerFactory to fetch from Spring's * root application context. */ - @Nullable - protected String getEntityManagerFactoryBeanName() { + protected @Nullable String getEntityManagerFactoryBeanName() { return this.entityManagerFactoryBeanName; } @@ -123,8 +119,7 @@ public class OpenEntityManagerInViewFilter extends OncePerRequestFilter { /** * Return the name of the persistence unit to access the EntityManagerFactory for, if any. */ - @Nullable - protected String getPersistenceUnitName() { + protected @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewInterceptor.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewInterceptor.java index e6cc8f14fe..9d1f4349a4 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewInterceptor.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/OpenEntityManagerInViewInterceptor.java @@ -19,10 +19,10 @@ package org.springframework.orm.jpa.support; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.PersistenceException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessResourceFailureException; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryAccessor; import org.springframework.orm.jpa.EntityManagerFactoryUtils; import org.springframework.orm.jpa.EntityManagerHolder; 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 f5e17433c6..e163fdde9c 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 @@ -38,6 +38,7 @@ import jakarta.persistence.PersistenceContextType; import jakarta.persistence.PersistenceProperty; import jakarta.persistence.PersistenceUnit; import jakarta.persistence.SynchronizationType; +import org.jspecify.annotations.Nullable; import org.springframework.aot.generate.GeneratedClass; import org.springframework.aot.generate.GeneratedMethod; @@ -73,7 +74,6 @@ import org.springframework.javapoet.CodeBlock; import org.springframework.javapoet.MethodSpec; 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; @@ -191,26 +191,21 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar DestructionAwareBeanPostProcessor, MergedBeanDefinitionPostProcessor, BeanRegistrationAotProcessor, PriorityOrdered, BeanFactoryAware, Serializable { - @Nullable - private Object jndiEnvironment; + private @Nullable Object jndiEnvironment; private boolean resourceRef = true; - @Nullable - private transient Map persistenceUnits; + private transient @Nullable Map persistenceUnits; - @Nullable - private transient Map persistenceContexts; + private transient @Nullable Map persistenceContexts; - @Nullable - private transient Map extendedPersistenceContexts; + private transient @Nullable Map extendedPersistenceContexts; private transient String defaultPersistenceUnitName = ""; private int order = Ordered.LOWEST_PRECEDENCE - 4; - @Nullable - private transient ListableBeanFactory beanFactory; + private transient @Nullable ListableBeanFactory beanFactory; private final transient Map injectionMetadataCache = new ConcurrentHashMap<>(256); @@ -359,8 +354,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar } @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); String beanName = registeredBean.getBeanName(); RootBeanDefinition beanDefinition = registeredBean.getMergedBeanDefinition(); @@ -479,8 +473,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar * or {@code null} if none found * @see #setPersistenceUnits */ - @Nullable - protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) { + protected @Nullable EntityManagerFactory getPersistenceUnit(@Nullable String unitName) { if (this.persistenceUnits != null) { String unitNameForLookup = (unitName != null ? unitName : ""); if (unitNameForLookup.isEmpty()) { @@ -511,8 +504,7 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar * @see #setPersistenceContexts * @see #setExtendedPersistenceContexts */ - @Nullable - protected EntityManager getPersistenceContext(@Nullable String unitName, boolean extended) { + protected @Nullable EntityManager getPersistenceContext(@Nullable String unitName, boolean extended) { Map contexts = (extended ? this.extendedPersistenceContexts : this.persistenceContexts); if (contexts != null) { String unitNameForLookup = (unitName != null ? unitName : ""); @@ -648,13 +640,11 @@ public class PersistenceAnnotationBeanPostProcessor implements InstantiationAwar private final String unitName; - @Nullable - private PersistenceContextType type; + private @Nullable PersistenceContextType type; private boolean synchronizedWithTransaction = false; - @Nullable - private Properties properties; + private @Nullable Properties properties; public PersistenceElement(Member member, AnnotatedElement ae, @Nullable PropertyDescriptor pd) { super(member, pd); diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java b/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java index 0b460b0000..61b7a7d0de 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/support/SharedEntityManagerBean.java @@ -18,10 +18,10 @@ package org.springframework.orm.jpa.support; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.EntityManagerFactoryAccessor; import org.springframework.orm.jpa.EntityManagerFactoryInfo; import org.springframework.orm.jpa.SharedEntityManagerCreator; @@ -52,13 +52,11 @@ import org.springframework.util.Assert; public class SharedEntityManagerBean extends EntityManagerFactoryAccessor implements FactoryBean, InitializingBean { - @Nullable - private Class entityManagerInterface; + private @Nullable Class entityManagerInterface; private boolean synchronizedWithTransaction = true; - @Nullable - private EntityManager shared; + private @Nullable EntityManager shared; /** @@ -108,8 +106,7 @@ public class SharedEntityManagerBean extends EntityManagerFactoryAccessor @Override - @Nullable - public EntityManager getObject() { + public @Nullable EntityManager getObject() { return this.shared; } 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 b2b1b32ba4..f848643165 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,9 +1,7 @@ /** * Classes supporting the {@code org.springframework.orm.jpa} package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.orm.jpa.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/AbstractJpaVendorAdapter.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/AbstractJpaVendorAdapter.java index f79bb3f5d8..88713bbed6 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/AbstractJpaVendorAdapter.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/AbstractJpaVendorAdapter.java @@ -22,8 +22,8 @@ import java.util.Map; import jakarta.persistence.EntityManager; import jakarta.persistence.EntityManagerFactory; import jakarta.persistence.spi.PersistenceUnitInfo; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.JpaDialect; import org.springframework.orm.jpa.JpaVendorAdapter; @@ -39,8 +39,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter { private Database database = Database.DEFAULT; - @Nullable - private String databasePlatform; + private @Nullable String databasePlatform; private boolean generateDdl = false; @@ -77,8 +76,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter { /** * Return the name of the target database to operate on. */ - @Nullable - protected String getDatabasePlatform() { + protected @Nullable String getDatabasePlatform() { return this.databasePlatform; } @@ -125,8 +123,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter { @Override - @Nullable - public String getPersistenceProviderRootPackage() { + public @Nullable String getPersistenceProviderRootPackage() { return null; } @@ -141,8 +138,7 @@ public abstract class AbstractJpaVendorAdapter implements JpaVendorAdapter { } @Override - @Nullable - public JpaDialect getJpaDialect() { + public @Nullable JpaDialect getJpaDialect() { return null; } diff --git a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java index 5b313816d1..b8f2ee89d5 100644 --- a/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java +++ b/spring-orm/src/main/java/org/springframework/orm/jpa/vendor/EclipseLinkJpaDialect.java @@ -25,9 +25,9 @@ import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceException; import org.eclipse.persistence.sessions.DatabaseLogin; import org.eclipse.persistence.sessions.UnitOfWork; +import org.jspecify.annotations.Nullable; import org.springframework.jdbc.datasource.ConnectionHandle; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.DefaultJpaDialect; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -96,8 +96,7 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect { @Override - @Nullable - public Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) + public @Nullable Object beginTransaction(EntityManager entityManager, TransactionDefinition definition) throws PersistenceException, SQLException, TransactionException { int currentIsolationLevel = definition.getIsolationLevel(); @@ -172,8 +171,7 @@ public class EclipseLinkJpaDialect extends DefaultJpaDialect { private final EntityManager entityManager; - @Nullable - private Connection connection; + private @Nullable Connection connection; public EclipseLinkConnectionHandle(EntityManager entityManager) { this.entityManager = entityManager; 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 4cbe6c71d7..84cfaac3e5 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 @@ -25,8 +25,7 @@ import jakarta.persistence.spi.PersistenceProvider; import org.eclipse.persistence.config.PersistenceUnitProperties; import org.eclipse.persistence.config.TargetDatabase; import org.eclipse.persistence.jpa.JpaEntityManager; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Eclipse @@ -91,8 +90,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) { + protected @Nullable String determineTargetDatabaseName(Database database) { return switch (database) { case DB2 -> TargetDatabase.DB2; case DERBY -> TargetDatabase.Derby; 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 12a9d75c97..cc62cde226 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 @@ -47,6 +47,7 @@ import org.hibernate.exception.DataException; import org.hibernate.exception.JDBCConnectionException; import org.hibernate.exception.LockAcquisitionException; import org.hibernate.exception.SQLGrammarException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.DataAccessException; @@ -61,7 +62,6 @@ import org.springframework.jdbc.datasource.ConnectionHandle; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.support.SQLExceptionSubclassTranslator; import org.springframework.jdbc.support.SQLExceptionTranslator; -import org.springframework.lang.Nullable; import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.orm.ObjectRetrievalFailureException; import org.springframework.orm.jpa.DefaultJpaDialect; @@ -89,11 +89,9 @@ public class HibernateJpaDialect extends DefaultJpaDialect { boolean prepareConnection = true; - @Nullable - private SQLExceptionTranslator jdbcExceptionTranslator; + private @Nullable SQLExceptionTranslator jdbcExceptionTranslator; - @Nullable - private SQLExceptionTranslator transactionExceptionTranslator = new SQLExceptionSubclassTranslator(); + private @Nullable SQLExceptionTranslator transactionExceptionTranslator = new SQLExceptionSubclassTranslator(); /** @@ -198,8 +196,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { return new SessionTransactionData(session, previousFlushMode, false, null, readOnly); } - @Nullable - protected FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException { + protected @Nullable FlushMode prepareFlushMode(Session session, boolean readOnly) throws PersistenceException { FlushMode flushMode = session.getHibernateFlushMode(); if (readOnly) { // We should suppress flushing for a read-only transaction. @@ -235,8 +232,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { } @Override - @Nullable - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof HibernateException hibernateEx) { return convertHibernateAccessException(hibernateEx); } @@ -345,8 +341,7 @@ public class HibernateJpaDialect extends DefaultJpaDialect { return entityManager.unwrap(SessionImplementor.class); } - @Nullable - protected Object getIdentifier(HibernateException hibEx) { + protected @Nullable Object getIdentifier(HibernateException hibEx) { try { // getIdentifier declares Serializable return value on 5.x but Object on 6.x // -> not binary compatible, let's invoke it reflectively for the time being @@ -362,13 +357,11 @@ public class HibernateJpaDialect extends DefaultJpaDialect { private final SessionImplementor session; - @Nullable - private final FlushMode previousFlushMode; + private final @Nullable FlushMode previousFlushMode; private final boolean needsConnectionReset; - @Nullable - private final Integer previousIsolationLevel; + private final @Nullable Integer previousIsolationLevel; private final boolean 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 5204428944..b8561cd345 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 @@ -37,8 +37,7 @@ import org.hibernate.dialect.PostgreSQLDialect; import org.hibernate.dialect.SQLServerDialect; import org.hibernate.dialect.SybaseDialect; import org.hibernate.resource.jdbc.spi.PhysicalConnectionHandlingMode; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@link org.springframework.orm.jpa.JpaVendorAdapter} implementation for Hibernate. @@ -177,8 +176,7 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { * @return the Hibernate database dialect class, or {@code null} if none found * @see #determineDatabaseDialectName */ - @Nullable - protected Class determineDatabaseDialectClass(Database database) { + protected @Nullable Class determineDatabaseDialectClass(Database database) { return switch (database) { case DB2 -> DB2Dialect.class; case H2 -> H2Dialect.class; @@ -201,8 +199,7 @@ public class HibernateJpaVendorAdapter extends AbstractJpaVendorAdapter { * @since 7.0 * @see #determineDatabaseDialectClass */ - @Nullable - protected String determineDatabaseDialectName(Database database) { + protected @Nullable String determineDatabaseDialectName(Database database) { return switch (database) { case DERBY -> "org.hibernate.community.dialect.DerbyDialect"; default -> null; 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 b14f429ab9..10fb63e595 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,9 +1,7 @@ /** * Support classes for adapting to specific JPA vendors. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.orm.jpa.vendor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2b6a01a34f..33e510e6a7 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,9 +2,7 @@ * Root package for Spring's O/R Mapping integration classes. * Contains generic DataAccessExceptions related to O/R Mapping. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.orm; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java index cb31b8bf01..78dc137844 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessorAotContributionTests.java @@ -29,6 +29,7 @@ import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceProperty; import jakarta.persistence.PersistenceUnit; import org.assertj.core.api.InstanceOfAssertFactories; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,7 +44,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.test.tools.CompileWithForkedClassLoader; import org.springframework.core.test.tools.Compiled; import org.springframework.core.test.tools.TestCompiler; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; @@ -215,8 +215,7 @@ class PersistenceAnnotationBeanPostProcessorAotContributionTests { .compile(compiled -> result.accept(new Invoker(compiled), compiled)); } - @Nullable - private BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + private @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { PersistenceAnnotationBeanPostProcessor postProcessor = new PersistenceAnnotationBeanPostProcessor(); return postProcessor.processAheadOfTime(registeredBean); } diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceContextTransactionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceContextTransactionTests.java index 877863a66e..36c91e0bc7 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceContextTransactionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceContextTransactionTests.java @@ -22,11 +22,11 @@ import jakarta.persistence.EntityTransaction; import jakarta.persistence.PersistenceContext; import jakarta.persistence.PersistenceContextType; import jakarta.persistence.SynchronizationType; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.JpaTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionSynchronizationManager; diff --git a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java index ade307a3b3..327da6edea 100644 --- a/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java +++ b/spring-orm/src/test/java/org/springframework/orm/jpa/support/PersistenceInjectionTests.java @@ -31,6 +31,7 @@ import jakarta.persistence.PersistenceContextType; import jakarta.persistence.PersistenceProperty; import jakarta.persistence.PersistenceUnit; import org.hibernate.Session; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.FactoryBean; @@ -40,7 +41,6 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.context.testfixture.SimpleMapScope; import org.springframework.context.testfixture.jndi.ExpectedLookupTemplate; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import org.springframework.orm.jpa.AbstractEntityManagerFactoryBeanTests; import org.springframework.orm.jpa.DefaultJpaDialect; import org.springframework.orm.jpa.EntityManagerFactoryInfo; 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 9907718e49..800e594cde 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,9 +1,7 @@ /** * Provides an namespace handler for the Spring Object/XML namespace. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.oxm.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java index b989541fd3..7bf0a5ee23 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java @@ -25,6 +25,7 @@ import jakarta.xml.bind.annotation.XmlRegistry; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlSeeAlso; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; import org.springframework.core.io.support.PathMatchingResourcePatternResolver; @@ -34,7 +35,6 @@ 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.oxm.UncategorizedMappingException; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java index efddba0045..120e959264 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/jaxb/Jaxb2Marshaller.java @@ -77,6 +77,7 @@ import jakarta.xml.bind.attachment.AttachmentMarshaller; import jakarta.xml.bind.attachment.AttachmentUnmarshaller; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.ls.LSResourceResolver; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; @@ -87,7 +88,6 @@ import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.oxm.GenericMarshaller; import org.springframework.oxm.GenericUnmarshaller; import org.springframework.oxm.MarshallingFailureException; @@ -142,43 +142,31 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private String contextPath; + private @Nullable String contextPath; - @Nullable - private Class[] classesToBeBound; + private Class @Nullable [] classesToBeBound; - @Nullable - private String[] packagesToScan; + private String @Nullable [] packagesToScan; - @Nullable - private Map jaxbContextProperties; + private @Nullable Map jaxbContextProperties; - @Nullable - private Map marshallerProperties; + private @Nullable Map marshallerProperties; - @Nullable - private Map unmarshallerProperties; + private @Nullable Map unmarshallerProperties; - @Nullable - private Marshaller.Listener marshallerListener; + private Marshaller.@Nullable Listener marshallerListener; - @Nullable - private Unmarshaller.Listener unmarshallerListener; + private Unmarshaller.@Nullable Listener unmarshallerListener; - @Nullable - private ValidationEventHandler validationEventHandler; + private @Nullable ValidationEventHandler validationEventHandler; - @Nullable - private XmlAdapter[] adapters; + private XmlAdapter @Nullable [] adapters; - @Nullable - private Resource[] schemaResources; + private Resource @Nullable [] schemaResources; private String schemaLanguage = XMLConstants.W3C_XML_SCHEMA_NS_URI; - @Nullable - private LSResourceResolver schemaResourceResolver; + private @Nullable LSResourceResolver schemaResourceResolver; private boolean lazyInit = false; @@ -188,29 +176,23 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi private boolean checkForXmlRootElement = true; - @Nullable - private Class mappedClass; + private @Nullable Class mappedClass; - @Nullable - private ClassLoader beanClassLoader; + private @Nullable ClassLoader beanClassLoader; private final Lock jaxbContextLock = new ReentrantLock(); - @Nullable - private volatile JAXBContext jaxbContext; + private volatile @Nullable JAXBContext jaxbContext; - @Nullable - private Schema schema; + private @Nullable Schema schema; private boolean supportDtd = false; private boolean processExternalEntities = false; - @Nullable - private volatile SAXParserFactory schemaParserFactory; + private volatile @Nullable SAXParserFactory schemaParserFactory; - @Nullable - private volatile SAXParserFactory sourceParserFactory; + private volatile @Nullable SAXParserFactory sourceParserFactory; /** @@ -234,8 +216,7 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi /** * Return the JAXB context path. */ - @Nullable - public String getContextPath() { + public @Nullable String getContextPath() { return this.contextPath; } @@ -244,15 +225,14 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi *

    Setting either this property, {@link #setContextPath "contextPath"} * or {@link #setPackagesToScan "packagesToScan"} is required. */ - public void setClassesToBeBound(@Nullable Class... classesToBeBound) { + public void setClassesToBeBound(Class @Nullable ... classesToBeBound) { this.classesToBeBound = classesToBeBound; } /** * Return the list of Java classes to be recognized by a newly created JAXBContext. */ - @Nullable - public Class[] getClassesToBeBound() { + public Class @Nullable [] getClassesToBeBound() { return this.classesToBeBound; } @@ -263,15 +243,14 @@ public class Jaxb2Marshaller implements MimeMarshaller, MimeUnmarshaller, Generi *

    Setting either this property, {@link #setContextPath "contextPath"} or * {@link #setClassesToBeBound "classesToBeBound"} is required. */ - public void setPackagesToScan(@Nullable String... packagesToScan) { + public void setPackagesToScan(String @Nullable ... packagesToScan) { this.packagesToScan = packagesToScan; } /** * Return the packages to search for JAXB2 annotations. */ - @Nullable - public String[] getPackagesToScan() { + public String @Nullable [] getPackagesToScan() { return this.packagesToScan; } 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 8a630106f4..e9d62635a6 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,9 +2,7 @@ * Package providing integration of JAXB * with Spring's O/X Mapping support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.oxm.jaxb; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 11f24456d0..9aa2b230da 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 @@ -17,8 +17,7 @@ package org.springframework.oxm.mime; import jakarta.activation.DataHandler; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Represents a container for MIME attachments @@ -58,7 +57,6 @@ public interface MimeContainer { * @param contentId the content id * @return the attachment, as a data handler */ - @Nullable - DataHandler getAttachment(String contentId); + @Nullable DataHandler getAttachment(String contentId); } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeMarshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeMarshaller.java index f22ab1632e..ad72e5eb14 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeMarshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeMarshaller.java @@ -20,7 +20,8 @@ import java.io.IOException; import javax.xml.transform.Result; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.oxm.Marshaller; import org.springframework.oxm.XmlMappingException; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeUnmarshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeUnmarshaller.java index e45a3c3514..2479d62ec3 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeUnmarshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/mime/MimeUnmarshaller.java @@ -20,7 +20,8 @@ import java.io.IOException; import javax.xml.transform.Source; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.oxm.Unmarshaller; import org.springframework.oxm.XmlMappingException; 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 b62881733d..180b9402d0 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,9 +1,7 @@ /** * Contains (un)marshallers optimized to store binary data in MIME attachments. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.oxm.mime; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a9774649b7..09cff99872 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,9 +3,7 @@ * Contains generic Marshaller and Unmarshaller interfaces, * and XmlMappingExceptions related to O/X Mapping */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.oxm; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a3925acb50..df150cc5ed 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 @@ -44,6 +44,7 @@ import javax.xml.transform.stream.StreamSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; @@ -53,7 +54,6 @@ 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; @@ -82,11 +82,9 @@ public abstract class AbstractMarshaller implements Marshaller, Unmarshaller { private boolean processExternalEntities = false; - @Nullable - private volatile DocumentBuilderFactory documentBuilderFactory; + private volatile @Nullable DocumentBuilderFactory documentBuilderFactory; - @Nullable - private volatile SAXParserFactory saxParserFactory; + private volatile @Nullable SAXParserFactory saxParserFactory; /** @@ -220,8 +218,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() { + protected @Nullable String getDefaultEncoding() { return null; } diff --git a/spring-oxm/src/main/java/org/springframework/oxm/support/MarshallingSource.java b/spring-oxm/src/main/java/org/springframework/oxm/support/MarshallingSource.java index e2b7882485..45f65624cb 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/support/MarshallingSource.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/support/MarshallingSource.java @@ -22,6 +22,7 @@ import javax.xml.transform.Source; import javax.xml.transform.sax.SAXResult; import javax.xml.transform.sax.SAXSource; +import org.jspecify.annotations.Nullable; import org.xml.sax.ContentHandler; import org.xml.sax.DTDHandler; import org.xml.sax.EntityResolver; @@ -33,7 +34,6 @@ import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.ext.LexicalHandler; -import org.springframework.lang.Nullable; import org.springframework.oxm.Marshaller; import org.springframework.util.Assert; @@ -109,20 +109,15 @@ public class MarshallingSource extends SAXSource { private final Object content; - @Nullable - private DTDHandler dtdHandler; + private @Nullable DTDHandler dtdHandler; - @Nullable - private ContentHandler contentHandler; + private @Nullable ContentHandler contentHandler; - @Nullable - private EntityResolver entityResolver; + private @Nullable EntityResolver entityResolver; - @Nullable - private ErrorHandler errorHandler; + private @Nullable ErrorHandler errorHandler; - @Nullable - private LexicalHandler lexicalHandler; + private @Nullable LexicalHandler lexicalHandler; private MarshallingXMLReader(Marshaller marshaller, Object content) { Assert.notNull(marshaller, "'marshaller' must not be null"); @@ -137,8 +132,7 @@ public class MarshallingSource extends SAXSource { } @Override - @Nullable - public ContentHandler getContentHandler() { + public @Nullable ContentHandler getContentHandler() { return this.contentHandler; } @@ -148,8 +142,7 @@ public class MarshallingSource extends SAXSource { } @Override - @Nullable - public DTDHandler getDTDHandler() { + public @Nullable DTDHandler getDTDHandler() { return this.dtdHandler; } @@ -159,8 +152,7 @@ public class MarshallingSource extends SAXSource { } @Override - @Nullable - public EntityResolver getEntityResolver() { + public @Nullable EntityResolver getEntityResolver() { return this.entityResolver; } @@ -170,13 +162,11 @@ public class MarshallingSource extends SAXSource { } @Override - @Nullable - public ErrorHandler getErrorHandler() { + public @Nullable ErrorHandler getErrorHandler() { return this.errorHandler; } - @Nullable - protected LexicalHandler getLexicalHandler() { + protected @Nullable LexicalHandler getLexicalHandler() { return this.lexicalHandler; } @@ -191,8 +181,7 @@ public class MarshallingSource extends SAXSource { } @Override - @Nullable - public Object getProperty(String name) throws SAXNotRecognizedException { + public @Nullable Object getProperty(String name) throws SAXNotRecognizedException { if ("http://xml.org/sax/properties/lexical-handler".equals(name)) { return this.lexicalHandler; } 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 b2e14d5248..73c63b5372 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 @@ -18,10 +18,10 @@ package org.springframework.oxm.support; import java.io.IOException; +import org.jspecify.annotations.Nullable; import org.xml.sax.InputSource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Convenient utility methods for dealing with SAX. @@ -51,8 +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) { + private static @Nullable 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 e421943a51..fab4ceb1c0 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,9 +4,7 @@ * with TrAX, MarshallingView for use within Spring Web MVC, and the * MarshallingMessageConverter for use within Spring's JMS support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.oxm.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java b/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java index a727bf1c2e..91a7bd47b8 100644 --- a/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java +++ b/spring-oxm/src/main/java/org/springframework/oxm/xstream/XStreamMarshaller.java @@ -66,6 +66,7 @@ import com.thoughtworks.xstream.mapper.Mapper; import com.thoughtworks.xstream.mapper.MapperWrapper; import com.thoughtworks.xstream.security.ForbiddenClassException; import com.thoughtworks.xstream.security.TypePermission; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -76,7 +77,6 @@ import org.xml.sax.ext.LexicalHandler; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.oxm.MarshallingFailureException; import org.springframework.oxm.UncategorizedMappingException; import org.springframework.oxm.UnmarshallingFailureException; @@ -130,60 +130,43 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo public static final String DEFAULT_ENCODING = "UTF-8"; - @Nullable - private ReflectionProvider reflectionProvider; + private @Nullable ReflectionProvider reflectionProvider; - @Nullable - private HierarchicalStreamDriver streamDriver; + private @Nullable HierarchicalStreamDriver streamDriver; - @Nullable - private HierarchicalStreamDriver defaultDriver; + private @Nullable HierarchicalStreamDriver defaultDriver; - @Nullable - private Mapper mapper; + private @Nullable Mapper mapper; - @Nullable - private Class[] mapperWrappers; + private Class @Nullable [] mapperWrappers; private ConverterLookup converterLookup = new DefaultConverterLookup(); private ConverterRegistry converterRegistry = (ConverterRegistry) this.converterLookup; - @Nullable - private ConverterMatcher[] converters; + private ConverterMatcher @Nullable [] converters; - @Nullable - private TypePermission[] typePermissions; + private TypePermission @Nullable [] typePermissions; - @Nullable - private MarshallingStrategy marshallingStrategy; + private @Nullable MarshallingStrategy marshallingStrategy; - @Nullable - private Integer mode; + private @Nullable Integer mode; - @Nullable - private Map aliases; + private @Nullable Map aliases; - @Nullable - private Map aliasesByType; + private @Nullable Map aliasesByType; - @Nullable - private Map fieldAliases; + private @Nullable Map fieldAliases; - @Nullable - private Class[] useAttributeForTypes; + private Class @Nullable [] useAttributeForTypes; - @Nullable - private Map useAttributeFor; + private @Nullable Map useAttributeFor; - @Nullable - private Map, String> implicitCollections; + private @Nullable Map, String> implicitCollections; - @Nullable - private Map, String> omittedFields; + private @Nullable Map, String> omittedFields; - @Nullable - private Class[] annotatedClasses; + private Class @Nullable [] annotatedClasses; private boolean autodetectAnnotations; @@ -191,11 +174,9 @@ public class XStreamMarshaller extends AbstractMarshaller implements BeanClassLo private NameCoder nameCoder = new XmlFriendlyNameCoder(); - @Nullable - private Class[] supportedClasses; + private Class @Nullable [] supportedClasses; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private final SingletonSupplier xstream = SingletonSupplier.of(this::buildXStream); 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 c01a9cbd10..220ef5d73d 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,9 +2,7 @@ * Package providing integration of XStream * with Spring's O/X Mapping support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.oxm.xstream; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/BadSqlGrammarException.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/BadSqlGrammarException.java index 84effd5a8f..17a38a9e3c 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/BadSqlGrammarException.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/BadSqlGrammarException.java @@ -17,9 +17,9 @@ package org.springframework.r2dbc; import io.r2dbc.spi.R2dbcException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessResourceUsageException; -import org.springframework.lang.Nullable; /** * Exception thrown when SQL specified is invalid. Such exceptions always have a @@ -53,8 +53,7 @@ public class BadSqlGrammarException extends InvalidDataAccessResourceUsageExcept /** * Return the wrapped {@link R2dbcException}. */ - @Nullable - public R2dbcException getR2dbcException() { + public @Nullable R2dbcException getR2dbcException() { return (R2dbcException) getCause(); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/UncategorizedR2dbcException.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/UncategorizedR2dbcException.java index 3c0b6acfa7..43fb1f5c35 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/UncategorizedR2dbcException.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/UncategorizedR2dbcException.java @@ -17,9 +17,9 @@ package org.springframework.r2dbc; import io.r2dbc.spi.R2dbcException; +import org.jspecify.annotations.Nullable; import org.springframework.dao.UncategorizedDataAccessException; -import org.springframework.lang.Nullable; /** * Exception thrown when we can't classify a {@link R2dbcException} into @@ -32,8 +32,7 @@ import org.springframework.lang.Nullable; public class UncategorizedR2dbcException extends UncategorizedDataAccessException { /** SQL that led to the problem. */ - @Nullable - private final String sql; + private final @Nullable String sql; /** @@ -51,16 +50,14 @@ public class UncategorizedR2dbcException extends UncategorizedDataAccessExceptio /** * Return the wrapped {@link R2dbcException}. */ - @Nullable - public R2dbcException getR2dbcException() { + public @Nullable R2dbcException getR2dbcException() { return (R2dbcException) getCause(); } /** * Return the SQL that led to the problem (if known). */ - @Nullable - public String getSql() { + public @Nullable String getSql() { return this.sql; } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java index 847dd93b72..81a4819c2e 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java @@ -31,6 +31,7 @@ import io.r2dbc.spi.R2dbcTimeoutException; import io.r2dbc.spi.R2dbcTransientException; import io.r2dbc.spi.R2dbcTransientResourceException; import io.r2dbc.spi.Wrapped; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.Ordered; @@ -43,7 +44,6 @@ import org.springframework.dao.PermissionDeniedDataAccessException; import org.springframework.dao.PessimisticLockingFailureException; import org.springframework.dao.QueryTimeoutException; import org.springframework.dao.TransientDataAccessResourceException; -import org.springframework.lang.Nullable; import org.springframework.r2dbc.BadSqlGrammarException; import org.springframework.r2dbc.UncategorizedR2dbcException; import org.springframework.transaction.NoTransactionException; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionHolder.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionHolder.java index dd1b9c36c7..7f5b1a45ee 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionHolder.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionHolder.java @@ -18,8 +18,8 @@ package org.springframework.r2dbc.connection; import io.r2dbc.spi.Connection; import io.r2dbc.spi.ConnectionFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.ResourceHolderSupport; import org.springframework.util.Assert; @@ -48,8 +48,7 @@ public class ConnectionHolder extends ResourceHolderSupport { static final String SAVEPOINT_NAME_PREFIX = "SAVEPOINT_"; - @Nullable - private Connection currentConnection; + private @Nullable Connection currentConnection; private boolean transactionActive; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java index d7dd814f6e..32c9b9299b 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java @@ -24,10 +24,10 @@ import io.r2dbc.spi.IsolationLevel; import io.r2dbc.spi.Option; import io.r2dbc.spi.R2dbcException; import io.r2dbc.spi.Result; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.reactive.AbstractReactiveTransactionManager; @@ -83,8 +83,7 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class R2dbcTransactionManager extends AbstractReactiveTransactionManager implements InitializingBean { - @Nullable - private ConnectionFactory connectionFactory; + private @Nullable ConnectionFactory connectionFactory; private boolean enforceReadOnly = false; @@ -123,8 +122,7 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager /** * Return the R2DBC {@link ConnectionFactory} that this instance manages transactions for. */ - @Nullable - public ConnectionFactory getConnectionFactory() { + public @Nullable ConnectionFactory getConnectionFactory() { return this.connectionFactory; } @@ -415,8 +413,7 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager * should remain {@link TransactionDefinition#ISOLATION_DEFAULT default}. * @see TransactionDefinition#getIsolationLevel() */ - @Nullable - protected IsolationLevel resolveIsolationLevel(int isolationLevel) { + protected @Nullable IsolationLevel resolveIsolationLevel(int isolationLevel) { return switch (isolationLevel) { case TransactionDefinition.ISOLATION_READ_COMMITTED -> IsolationLevel.READ_COMMITTED; case TransactionDefinition.ISOLATION_READ_UNCOMMITTED -> IsolationLevel.READ_UNCOMMITTED; @@ -448,13 +445,11 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager @SuppressWarnings("unchecked") @Override - @Nullable - public T getAttribute(Option option) { + public @Nullable T getAttribute(Option option) { return (T) doGetValue(option); } - @Nullable - private Object doGetValue(Option option) { + private @Nullable Object doGetValue(Option option) { if (io.r2dbc.spi.TransactionDefinition.ISOLATION_LEVEL.equals(option)) { return this.isolationLevel; } @@ -491,15 +486,13 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager */ private static class ConnectionFactoryTransactionObject { - @Nullable - private ConnectionHolder connectionHolder; + private @Nullable ConnectionHolder connectionHolder; private boolean newConnectionHolder; private boolean mustRestoreAutoCommit; - @Nullable - private String savepointName; + private @Nullable String savepointName; void setConnectionHolder(@Nullable ConnectionHolder connectionHolder, boolean newConnectionHolder) { setConnectionHolder(connectionHolder); diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java index 65e9786f8b..c31a9a309d 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/SingleConnectionFactory.java @@ -27,11 +27,11 @@ import io.r2dbc.spi.ConnectionFactories; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryMetadata; import io.r2dbc.spi.Wrapped; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.beans.factory.DisposableBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,15 +70,13 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory private boolean suppressClose; /** Override auto-commit state?. */ - @Nullable - private Boolean autoCommit; + private @Nullable Boolean autoCommit; /** Wrapped Connection. */ private final AtomicReference target = new AtomicReference<>(); /** Proxy Connection. */ - @Nullable - private Connection connection; + private @Nullable Connection connection; private final Mono connectionEmitter; @@ -164,8 +162,7 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory * be overridden. * @return the "autoCommit" value, or {@code null} if none to be applied */ - @Nullable - protected Boolean getAutoCommitValue() { + protected @Nullable Boolean getAutoCommitValue() { return this.autoCommit; } @@ -251,8 +248,7 @@ public class SingleConnectionFactory extends DelegatingConnectionFactory } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return switch (method.getName()) { // Only consider equal when proxies are identical. case "equals" -> proxy == args[0]; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java index c9d47089e8..7ff8ecc150 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/TransactionAwareConnectionFactoryProxy.java @@ -24,9 +24,9 @@ import java.lang.reflect.Proxy; import io.r2dbc.spi.Connection; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.Wrapped; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** @@ -129,8 +129,7 @@ public class TransactionAwareConnectionFactoryProxy extends DelegatingConnection } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (ReflectionUtils.isObjectMethod(method)) { if (ReflectionUtils.isToStringMethod(method)) { return proxyToString(proxy); diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializer.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializer.java index bfd89a9596..9aabcf8a9d 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializer.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ConnectionFactoryInitializer.java @@ -17,10 +17,10 @@ package org.springframework.r2dbc.connection.init; import io.r2dbc.spi.ConnectionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -36,14 +36,11 @@ import org.springframework.util.Assert; */ public class ConnectionFactoryInitializer implements InitializingBean, DisposableBean { - @Nullable - private ConnectionFactory connectionFactory; + private @Nullable ConnectionFactory connectionFactory; - @Nullable - private DatabasePopulator databasePopulator; + private @Nullable DatabasePopulator databasePopulator; - @Nullable - private DatabasePopulator databaseCleaner; + private @Nullable DatabasePopulator databaseCleaner; private boolean enabled = true; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java index 86dc2f4fcf..3f7d2b188c 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ResourceDatabasePopulator.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; import io.r2dbc.spi.Connection; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -29,7 +30,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.core.io.support.EncodedResource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -59,8 +59,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator { List scripts = new ArrayList<>(); - @Nullable - private Charset sqlScriptEncoding; + private @Nullable Charset sqlScriptEncoding; private String separator = ScriptUtils.DEFAULT_STATEMENT_SEPARATOR; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptException.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptException.java index 17491c476a..8e8b0e97a9 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptException.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptException.java @@ -16,8 +16,9 @@ package org.springframework.r2dbc.connection.init; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Root of the hierarchy of data access exceptions that are related to processing diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptParseException.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptParseException.java index 1b9d6883a9..aba165b5eb 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptParseException.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptParseException.java @@ -16,8 +16,9 @@ package org.springframework.r2dbc.connection.init; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.support.EncodedResource; -import org.springframework.lang.Nullable; /** * Thrown by {@link ScriptUtils} if an SQL script cannot be properly parsed. diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java index 8bf20593e2..abe4465397 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/ScriptUtils.java @@ -29,6 +29,7 @@ import io.r2dbc.spi.Connection; import io.r2dbc.spi.Result; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.core.io.support.EncodedResource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/package-info.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/package-info.java index e28bcfa442..9e01277a12 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/package-info.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/init/package-info.java @@ -1,9 +1,7 @@ /** * Provides extensible support for initializing databases through scripts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.r2dbc.connection.init; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java index 900197f5c0..c219d5fdb8 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/AbstractRoutingConnectionFactory.java @@ -21,10 +21,10 @@ import java.util.Map; import io.r2dbc.spi.Connection; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryMetadata; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -54,21 +54,17 @@ public abstract class AbstractRoutingConnectionFactory implements ConnectionFact private static final Object FALLBACK_MARKER = new Object(); - @Nullable - private Map targetConnectionFactories; + private @Nullable Map targetConnectionFactories; - @Nullable - private Object defaultTargetConnectionFactory; + private @Nullable Object defaultTargetConnectionFactory; private boolean lenientFallback = true; private ConnectionFactoryLookup connectionFactoryLookup = new MapConnectionFactoryLookup(); - @Nullable - private Map resolvedConnectionFactories; + private @Nullable Map resolvedConnectionFactories; - @Nullable - private ConnectionFactory resolvedDefaultConnectionFactory; + private @Nullable ConnectionFactory resolvedDefaultConnectionFactory; /** diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookup.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookup.java index 5359fec112..96f48d4a09 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookup.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/BeanFactoryConnectionFactoryLookup.java @@ -17,11 +17,11 @@ package org.springframework.r2dbc.connection.lookup; import io.r2dbc.spi.ConnectionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,8 +37,7 @@ import org.springframework.util.Assert; */ public class BeanFactoryConnectionFactoryLookup implements ConnectionFactoryLookup, BeanFactoryAware { - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; /** diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/package-info.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/package-info.java index cd99f59886..499e6c13c9 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/package-info.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/lookup/package-info.java @@ -1,9 +1,7 @@ /** * Provides a strategy for looking up R2DBC ConnectionFactories by name. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.r2dbc.connection.lookup; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/package-info.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/package-info.java index 5da1a594ea..dbeb5f8bcd 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/package-info.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/package-info.java @@ -3,9 +3,7 @@ * a ReactiveTransactionManager for a single ConnectionFactory, * and various simple ConnectionFactory implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.r2dbc.connection; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java index fbae6633ad..d3b7f00478 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/BeanPropertyRowMapper.java @@ -29,13 +29,13 @@ import io.r2dbc.spi.Readable; import io.r2dbc.spi.ReadableMetadata; import io.r2dbc.spi.Row; import io.r2dbc.spi.RowMetadata; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanWrapperImpl; import org.springframework.beans.TypeConverter; import org.springframework.core.convert.ConversionService; import org.springframework.core.convert.support.DefaultConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -235,8 +235,7 @@ public class BeanPropertyRowMapper implements Function { * @see Readable#get(int, Class) * @see Readable#get(int) */ - @Nullable - protected Object getItemValue(Readable readable, int itemIndex, Class paramType) { + protected @Nullable Object getItemValue(Readable readable, int itemIndex, Class paramType) { try { return readable.get(itemIndex, paramType); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ColumnMapRowMapper.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ColumnMapRowMapper.java index 5382452bd0..0c060e3fe3 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ColumnMapRowMapper.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ColumnMapRowMapper.java @@ -23,8 +23,8 @@ import java.util.function.BiFunction; import io.r2dbc.spi.ColumnMetadata; import io.r2dbc.spi.Row; import io.r2dbc.spi.RowMetadata; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedCaseInsensitiveMap; /** @@ -95,8 +95,7 @@ public class ColumnMapRowMapper implements BiFunction remainderByName, + private @Nullable Parameter getParameter(Map remainderByName, Map remainderByIndex, List parameterNames, String parameterName) { if (this.byName.containsKey(parameterName)) { @@ -530,8 +527,7 @@ final class DefaultDatabaseClient implements DatabaseClient { } @Override - @Nullable - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + public @Nullable Object invoke(Object proxy, Method method, Object[] args) throws Throwable { return switch (method.getName()) { // Only consider equal when proxies are identical. case "equals" -> proxy == args[0]; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClientBuilder.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClientBuilder.java index c8811043ae..a93ffb3bc8 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClientBuilder.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClientBuilder.java @@ -20,8 +20,8 @@ import java.util.function.Consumer; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.Statement; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.r2dbc.core.binding.BindMarkersFactory; import org.springframework.r2dbc.core.binding.BindMarkersFactoryResolver; import org.springframework.util.Assert; @@ -34,11 +34,9 @@ import org.springframework.util.Assert; */ class DefaultDatabaseClientBuilder implements DatabaseClient.Builder { - @Nullable - private BindMarkersFactory bindMarkers; + private @Nullable BindMarkersFactory bindMarkers; - @Nullable - private ConnectionFactory connectionFactory; + private @Nullable ConnectionFactory connectionFactory; private ExecuteFunction executeFunction = Statement::execute; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DelegateConnectionFunction.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DelegateConnectionFunction.java index a25bddd7f6..1be2d1cf10 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DelegateConnectionFunction.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DelegateConnectionFunction.java @@ -19,8 +19,7 @@ package org.springframework.r2dbc.core; import java.util.function.Function; import io.r2dbc.spi.Connection; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A {@link ConnectionFunction} that delegates to a {@code SqlProvider} and a plain @@ -48,9 +47,8 @@ final class DelegateConnectionFunction implements ConnectionFunction { return this.function.apply(t); } - @Nullable @Override - public String getSql() { + public @Nullable String getSql() { return this.sql.getSql(); } } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java index f6696e8d9c..680213cb09 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java @@ -26,9 +26,9 @@ import java.util.Set; import java.util.TreeMap; import io.r2dbc.spi.Parameter; +import org.jspecify.annotations.Nullable; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; import org.springframework.r2dbc.core.binding.BindMarker; import org.springframework.r2dbc.core.binding.BindMarkers; import org.springframework.r2dbc.core.binding.BindMarkersFactory; @@ -460,8 +460,7 @@ abstract class NamedParameterUtils { return param; } - @Nullable - List getMarker(String name) { + @Nullable List getMarker(String name) { return this.references.get(name); } @@ -566,8 +565,7 @@ abstract class NamedParameterUtils { } } - @Nullable - List getBindMarkers(String identifier) { + @Nullable List getBindMarkers(String identifier) { List parameters = this.parameters.getMarker(identifier); if (parameters == null) { return null; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java index 7d0d482fac..b5b892d1de 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java @@ -16,7 +16,8 @@ package org.springframework.r2dbc.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -32,8 +33,7 @@ import org.springframework.util.ObjectUtils; @Deprecated(since = "6.0") public final class Parameter { - @Nullable - private final Object value; + private final @Nullable Object value; private final Class type; @@ -79,8 +79,7 @@ public final class Parameter { * Return the column value (can be {@code null}). * @see #hasValue() */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ResultFunction.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ResultFunction.java index 1204eac5df..1dbdb45b88 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ResultFunction.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/ResultFunction.java @@ -22,9 +22,9 @@ import java.util.function.Supplier; import io.r2dbc.spi.Connection; import io.r2dbc.spi.Result; import io.r2dbc.spi.Statement; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -46,8 +46,7 @@ final class ResultFunction implements ConnectionFunction> { final StatementFilterFunction filterFunction; final ExecuteFunction executeFunction; - @Nullable - String resolvedSql = null; + @Nullable String resolvedSql = null; ResultFunction(Supplier sqlSupplier, BiFunction statementFunction, StatementFilterFunction filterFunction, ExecuteFunction executeFunction) { this.sqlSupplier = sqlSupplier; @@ -66,9 +65,8 @@ final class ResultFunction implements ConnectionFunction> { .cast(Result.class).checkpoint("SQL \"" + sql + "\" [DatabaseClient]"); } - @Nullable @Override - public String getSql() { + public @Nullable String getSql() { return this.resolvedSql; } } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/SqlProvider.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/SqlProvider.java index a46c98af84..3b8c84d270 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/SqlProvider.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/SqlProvider.java @@ -16,7 +16,7 @@ package org.springframework.r2dbc.core; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that can provide SQL strings. @@ -35,7 +35,6 @@ public interface SqlProvider { * typically the SQL used for creating statements. * @return the SQL string, or {@code null} if not available */ - @Nullable - String getSql(); + @Nullable String getSql(); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolver.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolver.java index c658352846..8a4ff087c8 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolver.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/BindMarkersFactoryResolver.java @@ -22,10 +22,10 @@ import java.util.Map; import io.r2dbc.spi.ConnectionFactory; import io.r2dbc.spi.ConnectionFactoryMetadata; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.support.SpringFactoriesLoader; import org.springframework.dao.NonTransientDataAccessException; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedCaseInsensitiveMap; /** @@ -83,8 +83,7 @@ public final class BindMarkersFactoryResolver { * @return the {@link BindMarkersFactory} if the {@link BindMarkerFactoryProvider} * can provide a bind marker factory object, otherwise {@code null} */ - @Nullable - BindMarkersFactory getBindMarkers(ConnectionFactory connectionFactory); + @Nullable BindMarkersFactory getBindMarkers(ConnectionFactory connectionFactory); } @@ -129,8 +128,7 @@ public final class BindMarkersFactoryResolver { @Override - @Nullable - public BindMarkersFactory getBindMarkers(ConnectionFactory connectionFactory) { + public @Nullable BindMarkersFactory getBindMarkers(ConnectionFactory connectionFactory) { ConnectionFactoryMetadata metadata = connectionFactory.getMetadata(); BindMarkersFactory r2dbcDialect = BUILTIN.get(metadata.getName()); if (r2dbcDialect != null) { diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/Bindings.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/Bindings.java index a0a6eacc73..445a46df22 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/Bindings.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/Bindings.java @@ -26,9 +26,9 @@ import java.util.Spliterator; import java.util.function.Consumer; import io.r2dbc.spi.Statement; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -178,8 +178,7 @@ public class Bindings implements Iterable { * @return the value of this binding * (can be {@code null} if this is a {@code NULL} binding) */ - @Nullable - public abstract Object getValue(); + public abstract @Nullable Object getValue(); /** * Apply the binding to a {@link BindTarget}. @@ -207,8 +206,7 @@ public class Bindings implements Iterable { } @Override - @NonNull - public Object getValue() { + public @NonNull Object getValue() { return this.value; } @@ -237,8 +235,7 @@ public class Bindings implements Iterable { } @Override - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return null; } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/package-info.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/package-info.java index e95acdc21d..36ea3a6875 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/package-info.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/binding/package-info.java @@ -1,9 +1,7 @@ /** * Classes providing an abstraction over SQL bind markers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.r2dbc.core.binding; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/package-info.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/package-info.java index a85478547b..78aa55e025 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/package-info.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/package-info.java @@ -1,9 +1,7 @@ /** * Core domain types around DatabaseClient. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.r2dbc.core; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/package-info.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/package-info.java index c892eec7f3..dc32fb6397 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/package-info.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/package-info.java @@ -13,9 +13,7 @@ * dependencies into application code. * */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.r2dbc; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java index 93f9a65d97..fd2a22c52d 100644 --- a/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java +++ b/spring-r2dbc/src/test/java/org/springframework/r2dbc/core/DefaultDatabaseClientTests.java @@ -29,6 +29,7 @@ import io.r2dbc.spi.test.MockColumnMetadata; import io.r2dbc.spi.test.MockResult; import io.r2dbc.spi.test.MockRow; import io.r2dbc.spi.test.MockRowMetadata; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.InOrder; @@ -43,7 +44,6 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.dao.IncorrectResultSizeDataAccessException; -import org.springframework.lang.Nullable; import org.springframework.r2dbc.core.binding.BindMarkersFactory; import org.springframework.r2dbc.core.binding.BindTarget; @@ -488,7 +488,7 @@ class DefaultDatabaseClientTests { * Mocks a {@link Result} with a single column "name" and a single row if a non-null * row is provided. */ - private MockResult mockSingleColumnResult(@Nullable MockRow.Builder row) { + private MockResult mockSingleColumnResult(MockRow.@Nullable Builder row) { MockResult.Builder resultBuilder = MockResult.builder(); if (row != null) { MockRowMetadata metadata = MockRowMetadata.builder().columnMetadata( 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 964c7688bc..0fa7e3a27a 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,9 +7,7 @@ *

    These mocks are useful for developing out-of-container * unit tests for code that depends on environment-specific properties. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.env; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java index 10736fe4f0..42222f4493 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/client/MockClientHttpRequest.java @@ -21,10 +21,11 @@ import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + 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.mock.http.MockHttpOutputMessage; import org.springframework.util.Assert; import org.springframework.web.util.UriComponentsBuilder; @@ -43,13 +44,11 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie private URI uri; - @Nullable - private ClientHttpResponse clientHttpResponse; + private @Nullable ClientHttpResponse clientHttpResponse; private boolean executed = false; - @Nullable - Map attributes; + @Nullable Map attributes; /** 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 3feddab586..8809f4d608 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,9 +3,7 @@ * This package contains {@code MockClientHttpRequest} and * {@code MockClientHttpResponse}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.http.client; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 36f5a5bb39..1bba824062 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,9 +1,7 @@ /** * Mock implementations of reactive HTTP client contracts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.http.client.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 18bda66888..df2c8eaefe 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,9 +3,7 @@ * This package contains {@code MockHttpInputMessage} and * {@code MockHttpOutputMessage}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.http; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java index 1b9d39b50b..e9ca3ee6d1 100644 --- a/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/http/server/reactive/MockServerHttpRequest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -38,7 +39,6 @@ import org.springframework.http.HttpRange; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.AbstractServerHttpRequest; import org.springframework.http.server.reactive.SslInfo; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MimeType; @@ -56,14 +56,11 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { private final MultiValueMap cookies; - @Nullable - private final InetSocketAddress localAddress; + private final @Nullable InetSocketAddress localAddress; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; - @Nullable - private final SslInfo sslInfo; + private final @Nullable SslInfo sslInfo; private final Flux body; @@ -82,20 +79,17 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return this.localAddress; } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.remoteAddress; } @Override - @Nullable - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { return this.sslInfo; } @@ -415,8 +409,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { private final URI url; - @Nullable - private String contextPath; + private @Nullable String contextPath; private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance(); @@ -424,14 +417,11 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { private final MultiValueMap cookies = new LinkedMultiValueMap<>(); - @Nullable - private InetSocketAddress remoteAddress; + private @Nullable InetSocketAddress remoteAddress; - @Nullable - private InetSocketAddress localAddress; + private @Nullable InetSocketAddress localAddress; - @Nullable - private SslInfo sslInfo; + private @Nullable SslInfo sslInfo; DefaultBodyBuilder(HttpMethod method, URI url) { this.method = method; 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 b989b2d96b..599c9d115f 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,9 +1,7 @@ /** * Mock implementations of reactive HTTP server contracts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.http.server.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a0a739765e..25249a7d93 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 @@ -21,7 +21,8 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; /** @@ -63,13 +64,11 @@ class HeaderValueHolder { return this.values.stream().map(Object::toString).toList(); } - @Nullable - Object getValue() { + @Nullable Object getValue() { return (!this.values.isEmpty() ? this.values.get(0) : null); } - @Nullable - String getStringValue() { + @Nullable String getStringValue() { return (!this.values.isEmpty() ? String.valueOf(this.values.get(0)) : null); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockAsyncContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockAsyncContext.java index 982d4e3b26..20761a496e 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockAsyncContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockAsyncContext.java @@ -29,9 +29,9 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.util.WebUtils; @@ -45,13 +45,11 @@ public class MockAsyncContext implements AsyncContext { private final HttpServletRequest request; - @Nullable - private final HttpServletResponse response; + private final @Nullable HttpServletResponse response; private final List listeners = new ArrayList<>(); - @Nullable - private String dispatchedPath; + private @Nullable String dispatchedPath; private long timeout = 10 * 1000L; @@ -82,8 +80,7 @@ public class MockAsyncContext implements AsyncContext { } @Override - @Nullable - public ServletResponse getResponse() { + public @Nullable ServletResponse getResponse() { return this.response; } @@ -110,8 +107,7 @@ public class MockAsyncContext implements AsyncContext { } } - @Nullable - public String getDispatchedPath() { + public @Nullable String getDispatchedPath() { return this.dispatchedPath; } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java b/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java index 81a905150e..6bc5923cd8 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockBodyContent.java @@ -24,8 +24,7 @@ import java.io.Writer; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.JspWriter; import jakarta.servlet.jsp.tagext.BodyContent; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of the {@link jakarta.servlet.jsp.tagext.BodyContent} class. diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java b/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java index c7ec34d088..4e08336dd6 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockCookie.java @@ -21,9 +21,9 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import jakarta.servlet.http.Cookie; +import org.jspecify.annotations.Nullable; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -54,8 +54,7 @@ public class MockCookie extends Cookie { private static final String EXPIRES = "Expires"; - @Nullable - private ZonedDateTime expires; + private @Nullable ZonedDateTime expires; /** @@ -81,8 +80,7 @@ public class MockCookie extends Cookie { * @return the "Expires" attribute for this cookie, or {@code null} if not set * @since 5.1.11 */ - @Nullable - public ZonedDateTime getExpires() { + public @Nullable ZonedDateTime getExpires() { return this.expires; } @@ -101,8 +99,7 @@ public class MockCookie extends Cookie { * Get the "SameSite" attribute for this cookie. * @return the "SameSite" attribute for this cookie, or {@code null} if not set */ - @Nullable - public String getSameSite() { + public @Nullable String getSameSite() { return getAttribute(SAME_SITE); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java index 2a48a42e5e..3d666d56d0 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterChain.java @@ -28,8 +28,8 @@ import jakarta.servlet.Servlet; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -50,16 +50,13 @@ import org.springframework.util.ObjectUtils; */ public class MockFilterChain implements FilterChain { - @Nullable - private ServletRequest request; + private @Nullable ServletRequest request; - @Nullable - private ServletResponse response; + private @Nullable ServletResponse response; private final List filters; - @Nullable - private Iterator iterator; + private @Nullable Iterator iterator; /** @@ -100,16 +97,14 @@ public class MockFilterChain implements FilterChain { /** * Return the request that {@link #doFilter} has been called with. */ - @Nullable - public ServletRequest getRequest() { + public @Nullable ServletRequest getRequest() { return this.request; } /** * Return the response that {@link #doFilter} has been called with. */ - @Nullable - public ServletResponse getResponse() { + public @Nullable ServletResponse getResponse() { return this.response; } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java index 5557276184..c6904bce4d 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterConfig.java @@ -23,8 +23,8 @@ import java.util.Map; import jakarta.servlet.FilterConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -97,8 +97,7 @@ public class MockFilterConfig implements FilterConfig { } @Override - @Nullable - public String getInitParameter(String name) { + public @Nullable String getInitParameter(String name) { Assert.notNull(name, "Parameter name must not be null"); return this.initParameters.get(name); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockFilterRegistration.java b/spring-test/src/main/java/org/springframework/mock/web/MockFilterRegistration.java index b73c4bfb4d..3edbe35746 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockFilterRegistration.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockFilterRegistration.java @@ -29,8 +29,7 @@ import java.util.Set; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterRegistration; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of {@link FilterRegistration}. @@ -68,9 +67,8 @@ public class MockFilterRegistration implements FilterRegistration.Dynamic { return this.name; } - @Nullable @Override - public String getClassName() { + public @Nullable String getClassName() { return this.className; } @@ -79,9 +77,8 @@ public class MockFilterRegistration implements FilterRegistration.Dynamic { return (this.initParameters.putIfAbsent(name, value) != null); } - @Nullable @Override - public String getInitParameter(String name) { + public @Nullable String getInitParameter(String name) { return this.initParameters.get(name); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletMapping.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletMapping.java index 17615a3bdc..50d854c520 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletMapping.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpServletMapping.java @@ -18,8 +18,7 @@ package org.springframework.mock.web; import jakarta.servlet.http.HttpServletMapping; import jakarta.servlet.http.MappingMatch; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of {@link HttpServletMapping}. @@ -39,8 +38,7 @@ public class MockHttpServletMapping implements HttpServletMapping { private final String servletName; - @Nullable - private final MappingMatch mappingMatch; + private final @Nullable MappingMatch mappingMatch; public MockHttpServletMapping( @@ -69,8 +67,7 @@ public class MockHttpServletMapping implements HttpServletMapping { } @Override - @Nullable - public MappingMatch getMappingMatch() { + public @Nullable MappingMatch getMappingMatch() { return this.mappingMatch; } 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 bb1b861fdd..8f2500c89e 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 @@ -62,10 +62,10 @@ import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpUpgradeHandler; import jakarta.servlet.http.MappingMatch; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; 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; @@ -170,20 +170,15 @@ public class MockHttpServletRequest implements HttpServletRequest { private final Map attributes = new LinkedHashMap<>(); - @Nullable - private String characterEncoding; + private @Nullable String characterEncoding; - @Nullable - private byte[] content; + private byte @Nullable [] content; - @Nullable - private String contentType; + private @Nullable String contentType; - @Nullable - private ServletInputStream inputStream; + private @Nullable ServletInputStream inputStream; - @Nullable - private BufferedReader reader; + private @Nullable BufferedReader reader; private final Map parameters = new LinkedHashMap<>(16); @@ -216,8 +211,7 @@ public class MockHttpServletRequest implements HttpServletRequest { private boolean asyncSupported = false; - @Nullable - private MockAsyncContext asyncContext; + private @Nullable MockAsyncContext asyncContext; private DispatcherType dispatcherType = DispatcherType.REQUEST; @@ -226,46 +220,35 @@ public class MockHttpServletRequest implements HttpServletRequest { // HttpServletRequest properties // --------------------------------------------------------------------- - @Nullable - private String authType; + private @Nullable String authType; - @Nullable - private Cookie[] cookies; + private Cookie @Nullable [] cookies; private final Map headers = new LinkedCaseInsensitiveMap<>(); - @Nullable - private String method; + private @Nullable String method; - @Nullable - private String pathInfo; + private @Nullable String pathInfo; private String contextPath = ""; - @Nullable - private String queryString; + private @Nullable String queryString; - @Nullable - private String remoteUser; + private @Nullable String remoteUser; private final Set userRoles = new HashSet<>(); - @Nullable - private Principal userPrincipal; + private @Nullable Principal userPrincipal; - @Nullable - private String requestedSessionId; + private @Nullable String requestedSessionId; - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; - @Nullable - private String requestURI; + private @Nullable String requestURI; private String servletPath = ""; - @Nullable - private HttpSession session; + private @Nullable HttpSession session; private boolean requestedSessionIdValid = true; @@ -275,8 +258,7 @@ public class MockHttpServletRequest implements HttpServletRequest { private final MultiValueMap parts = new LinkedMultiValueMap<>(); - @Nullable - private HttpServletMapping httpServletMapping; + private @Nullable HttpServletMapping httpServletMapping; // --------------------------------------------------------------------- @@ -385,8 +367,7 @@ public class MockHttpServletRequest implements HttpServletRequest { // --------------------------------------------------------------------- @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { checkActive(); return this.attributes.get(name); } @@ -398,8 +379,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getCharacterEncoding() { + public @Nullable String getCharacterEncoding() { return this.characterEncoding; } @@ -429,7 +409,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #getContentAsByteArray() * @see #getContentAsString() */ - public void setContent(@Nullable byte[] content) { + public void setContent(byte @Nullable [] content) { this.content = content; this.inputStream = null; this.reader = null; @@ -442,8 +422,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setContent(byte[]) * @see #getContentAsString() */ - @Nullable - public byte[] getContentAsByteArray() { + public byte @Nullable [] getContentAsByteArray() { return this.content; } @@ -458,8 +437,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setCharacterEncoding(String) * @see #getContentAsByteArray() */ - @Nullable - public String getContentAsString() throws IllegalStateException, UnsupportedEncodingException { + public @Nullable String getContentAsString() throws IllegalStateException, UnsupportedEncodingException { Assert.state(this.characterEncoding != null, "Cannot get content as a String for a null character encoding. " + "Consider setting the characterEncoding in the request."); @@ -502,8 +480,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -628,8 +605,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getParameter(String name) { + public @Nullable String getParameter(String name) { Assert.notNull(name, "Parameter name must not be null"); String[] arr = this.parameters.get(name); return (arr != null && arr.length > 0 ? arr[0] : null); @@ -641,8 +617,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String[] getParameterValues(String name) { + public String @Nullable [] getParameterValues(String name) { Assert.notNull(name, "Parameter name must not be null"); return this.parameters.get(name); } @@ -965,8 +940,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public AsyncContext getAsyncContext() { + public @Nullable AsyncContext getAsyncContext() { return this.asyncContext; } @@ -1021,12 +995,11 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getAuthType() { + public @Nullable String getAuthType() { return this.authType; } - public void setCookies(@Nullable Cookie... cookies) { + public void setCookies(Cookie @Nullable ... cookies) { this.cookies = (ObjectUtils.isEmpty(cookies) ? null : cookies); if (this.cookies == null) { removeHeader(HttpHeaders.COOKIE); @@ -1043,8 +1016,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public Cookie[] getCookies() { + public Cookie @Nullable [] getCookies() { return this.cookies; } @@ -1166,8 +1138,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { HeaderValueHolder header = this.headers.get(name); return (header != null ? header.getStringValue() : null); } @@ -1207,8 +1178,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getMethod() { + public @Nullable String getMethod() { return this.method; } @@ -1217,14 +1187,12 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getPathInfo() { + public @Nullable String getPathInfo() { return this.pathInfo; } @Override - @Nullable - public String getPathTranslated() { + public @Nullable String getPathTranslated() { return (this.pathInfo != null ? this.servletContext.getRealPath(this.pathInfo) : null); } @@ -1242,8 +1210,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getQueryString() { + public @Nullable String getQueryString() { return this.queryString; } @@ -1252,8 +1219,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getRemoteUser() { + public @Nullable String getRemoteUser() { return this.remoteUser; } @@ -1273,8 +1239,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public Principal getUserPrincipal() { + public @Nullable Principal getUserPrincipal() { return this.userPrincipal; } @@ -1283,8 +1248,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getRequestedSessionId() { + public @Nullable String getRequestedSessionId() { return this.requestedSessionId; } @@ -1301,8 +1265,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * Return the original URI template used to prepare the request, if any. * @since 6.2 */ - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } @@ -1311,8 +1274,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getRequestURI() { + public @Nullable String getRequestURI() { return this.requestURI; } @@ -1351,8 +1313,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public HttpSession getSession(boolean create) { + public @Nullable HttpSession getSession(boolean create) { checkActive(); // Reset session if invalidated. if (this.session instanceof MockHttpSession mockSession && mockSession.isInvalid()) { @@ -1366,8 +1327,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public HttpSession getSession() { + public @Nullable HttpSession getSession() { return getSession(true); } @@ -1435,8 +1395,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public Part getPart(String name) throws IOException, ServletException { + public @Nullable Part getPart(String name) throws IOException, ServletException { return this.parts.getFirst(name); } @@ -1466,8 +1425,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * This helps {@link org.springframework.web.util.ServletRequestPathUtils} * to take into account the Servlet path when parsing the requestURI. */ - @Nullable - private MappingMatch determineMappingMatch() { + private @Nullable MappingMatch determineMappingMatch() { if (StringUtils.hasText(this.requestURI) && StringUtils.hasText(this.servletPath)) { String path = UrlPathHelper.defaultInstance.getRequestUri(this); String prefix = this.contextPath + this.servletPath; 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 18df83dbf6..feed71a5e0 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 @@ -43,10 +43,10 @@ import java.util.TimeZone; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; 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; @@ -99,13 +99,11 @@ public class MockHttpServletResponse implements HttpServletResponse { private final ServletOutputStream outputStream = new ResponseServletOutputStream(this.content); - @Nullable - private PrintWriter writer; + private @Nullable PrintWriter writer; private long contentLength = 0; - @Nullable - private String contentType; + private @Nullable String contentType; private int bufferSize = 4096; @@ -124,16 +122,14 @@ public class MockHttpServletResponse implements HttpServletResponse { private int status = HttpServletResponse.SC_OK; - @Nullable - private String errorMessage; + private @Nullable String errorMessage; //--------------------------------------------------------------------- // Properties for MockRequestDispatcher //--------------------------------------------------------------------- - @Nullable - private String forwardedUrl; + private @Nullable String forwardedUrl; private final List includedUrls = new ArrayList<>(); @@ -372,8 +368,7 @@ public class MockHttpServletResponse implements HttpServletResponse { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -510,8 +505,7 @@ public class MockHttpServletResponse implements HttpServletResponse { return this.cookies.toArray(new Cookie[0]); } - @Nullable - public Cookie getCookie(String name) { + public @Nullable Cookie getCookie(String name) { Assert.notNull(name, "Cookie name must not be null"); for (Cookie cookie : this.cookies) { if (name.equals(cookie.getName())) { @@ -546,8 +540,7 @@ public class MockHttpServletResponse implements HttpServletResponse { * @see HttpServletResponse#getHeader(String) */ @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { HeaderValueHolder header = this.headers.get(name); return (header != null ? header.getStringValue() : null); } @@ -577,8 +570,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) { + public @Nullable Object getHeaderValue(String name) { HeaderValueHolder header = this.headers.get(name); return (header != null ? header.getValue() : null); } @@ -649,8 +641,7 @@ public class MockHttpServletResponse implements HttpServletResponse { setCommitted(true); } - @Nullable - public String getRedirectedUrl() { + public @Nullable String getRedirectedUrl() { return getHeader(HttpHeaders.LOCATION); } @@ -807,8 +798,7 @@ public class MockHttpServletResponse implements HttpServletResponse { /** * Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}. */ - @Nullable - public String getErrorMessage() { + public @Nullable String getErrorMessage() { return this.errorMessage; } @@ -821,8 +811,7 @@ public class MockHttpServletResponse implements HttpServletResponse { this.forwardedUrl = forwardedUrl; } - @Nullable - public String getForwardedUrl() { + public @Nullable String getForwardedUrl() { return this.forwardedUrl; } @@ -833,8 +822,7 @@ public class MockHttpServletResponse implements HttpServletResponse { } } - @Nullable - public String getIncludedUrl() { + public @Nullable String getIncludedUrl() { int count = this.includedUrls.size(); Assert.state(count <= 1, () -> "More than 1 URL included - check getIncludedUrls instead: " + this.includedUrls); diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java index 1881d802bc..e8d4e25eb9 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockHttpSession.java @@ -29,8 +29,8 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSessionBindingEvent; import jakarta.servlet.http.HttpSessionBindingListener; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -147,8 +147,7 @@ public class MockHttpSession implements HttpSession { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { assertIsValid(); Assert.notNull(name, "Attribute name must not be null"); return this.attributes.get(name); diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java b/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java index ab0c4ec51c..272a680210 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockJspWriter.java @@ -22,8 +22,7 @@ import java.io.Writer; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.JspWriter; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of the {@link jakarta.servlet.jsp.JspWriter} class. @@ -36,8 +35,7 @@ public class MockJspWriter extends JspWriter { private final HttpServletResponse response; - @Nullable - private PrintWriter targetWriter; + private @Nullable PrintWriter targetWriter; /** diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java index 781ab7a6e4..cc4834d49a 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockMultipartFile.java @@ -21,8 +21,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.web.multipart.MultipartFile; @@ -45,8 +46,7 @@ public class MockMultipartFile implements MultipartFile { private final String originalFilename; - @Nullable - private final String contentType; + private final @Nullable String contentType; private final byte[] content; @@ -56,7 +56,7 @@ public class MockMultipartFile implements MultipartFile { * @param name the name of the file * @param content the content of the file */ - public MockMultipartFile(String name, @Nullable byte[] content) { + public MockMultipartFile(String name, byte @Nullable [] content) { this(name, "", null, content); } @@ -78,7 +78,7 @@ public class MockMultipartFile implements MultipartFile { * @param content the content of the file */ public MockMultipartFile( - String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) { + String name, @Nullable String originalFilename, @Nullable String contentType, byte @Nullable [] content) { Assert.hasLength(name, "Name must not be empty"); this.name = name; @@ -109,14 +109,12 @@ public class MockMultipartFile implements MultipartFile { } @Override - @NonNull - public String getOriginalFilename() { + public @NonNull String getOriginalFilename() { return this.originalFilename; } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } 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 41411d366c..ce07775fe6 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 @@ -28,10 +28,10 @@ import java.util.Objects; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; 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; @@ -96,8 +96,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl } @Override - @Nullable - public MultipartFile getFile(String name) { + public @Nullable MultipartFile getFile(String name) { return this.multipartFiles.getFirst(name); } @@ -118,8 +117,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl } @Override - @Nullable - public String getMultipartContentType(String paramOrFileName) { + public @Nullable String getMultipartContentType(String paramOrFileName) { MultipartFile file = getFile(paramOrFileName); if (file != null) { return file.getContentType(); @@ -156,8 +154,7 @@ public class MockMultipartHttpServletRequest extends MockHttpServletRequest impl } @Override - @Nullable - public HttpHeaders getMultipartHeaders(String paramOrFileName) { + public @Nullable HttpHeaders getMultipartHeaders(String paramOrFileName) { MultipartFile file = getFile(paramOrFileName); if (file != null) { HttpHeaders headers = new HttpHeaders(); diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java b/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java index 99f430ebb3..5a65442701 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockPageContext.java @@ -36,8 +36,8 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.jsp.JspWriter; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -63,8 +63,7 @@ public class MockPageContext extends PageContext { private final Map attributes = new LinkedHashMap<>(); - @Nullable - private JspWriter out; + private @Nullable JspWriter out; /** @@ -163,15 +162,13 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); return this.attributes.get(name); } @Override - @Nullable - public Object getAttribute(String name, int scope) { + public @Nullable Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); return switch (scope) { case PAGE_SCOPE -> getAttribute(name); @@ -186,8 +183,7 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public Object findAttribute(String name) { + public @Nullable Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); @@ -268,8 +264,7 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public ELContext getELContext() { + public @Nullable ELContext getELContext() { return null; } @@ -294,8 +289,7 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public Exception getException() { + public @Nullable Exception getException() { return null; } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockPart.java b/spring-test/src/main/java/org/springframework/mock/web/MockPart.java index 1ffe741b7a..82b679b4b2 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockPart.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockPart.java @@ -23,10 +23,10 @@ import java.util.Collection; import java.util.Collections; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,8 +42,7 @@ public class MockPart implements Part { private final String name; - @Nullable - private final String filename; + private final @Nullable String filename; private final byte[] content; @@ -54,7 +53,7 @@ public class MockPart implements Part { * Constructor for a part with a name and content only. * @see #getHeaders() */ - public MockPart(String name, @Nullable byte[] content) { + public MockPart(String name, byte @Nullable [] content) { this(name, null, content); } @@ -62,7 +61,7 @@ public class MockPart implements Part { * Constructor for a part with a name, filename, and content. * @see #getHeaders() */ - public MockPart(String name, @Nullable String filename, @Nullable byte[] content) { + public MockPart(String name, @Nullable String filename, byte @Nullable [] content) { this(name, filename, content, null); } @@ -71,7 +70,7 @@ public class MockPart implements Part { * @since 6.1.2 * @see #getHeaders() */ - public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) { + public MockPart(String name, @Nullable String filename, byte @Nullable [] content, @Nullable MediaType contentType) { Assert.hasLength(name, "'name' must not be empty"); this.name = name; this.filename = filename; @@ -87,14 +86,12 @@ public class MockPart implements Part { } @Override - @Nullable - public String getSubmittedFileName() { + public @Nullable String getSubmittedFileName() { return this.filename; } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { MediaType contentType = this.headers.getContentType(); return (contentType != null ? contentType.toString() : null); } @@ -120,8 +117,7 @@ public class MockPart implements Part { } @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { return this.headers.getFirst(name); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java b/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java index 9c75c2916a..47b1e2df91 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockServletConfig.java @@ -23,8 +23,8 @@ import java.util.Map; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -93,8 +93,7 @@ public class MockServletConfig implements ServletConfig { } @Override - @Nullable - public String getInitParameter(String name) { + public @Nullable String getInitParameter(String name) { Assert.notNull(name, "Parameter name must not be null"); return this.initParameters.get(name); } 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 38e7dae2ba..a37917abd4 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 @@ -43,13 +43,13 @@ import jakarta.servlet.SessionTrackingMode; import jakarta.servlet.descriptor.JspConfigDescriptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.DefaultResourceLoader; 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.CollectionUtils; @@ -132,18 +132,15 @@ public class MockServletContext implements ServletContext { private final Set declaredRoles = new LinkedHashSet<>(); - @Nullable - private Set sessionTrackingModes; + private @Nullable Set sessionTrackingModes; private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig(); private int sessionTimeout; - @Nullable - private String requestCharacterEncoding; + private @Nullable String requestCharacterEncoding; - @Nullable - private String responseCharacterEncoding; + private @Nullable String responseCharacterEncoding; private final Map filterRegistrations = new LinkedHashMap<>(); @@ -226,8 +223,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public ServletContext getContext(String contextPath) { + public @Nullable ServletContext getContext(String contextPath) { if (this.contextPath.equals(contextPath)) { return this; } @@ -271,8 +267,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public String getMimeType(String filePath) { + public @Nullable String getMimeType(String filePath) { String extension = StringUtils.getFilenameExtension(filePath); if (this.mimeTypes.containsKey(extension)) { return this.mimeTypes.get(extension).toString(); @@ -295,8 +290,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public Set getResourcePaths(String path) { + public @Nullable Set getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); String resourceLocation = getResourceLocation(actualPath); Resource resource = null; @@ -327,8 +321,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public URL getResource(String path) throws MalformedURLException { + public @Nullable URL getResource(String path) throws MalformedURLException { String resourceLocation = getResourceLocation(path); Resource resource = null; try { @@ -351,8 +344,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public InputStream getResourceAsStream(String path) { + public @Nullable InputStream getResourceAsStream(String path) { String resourceLocation = getResourceLocation(path); Resource resource = null; try { @@ -379,8 +371,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public RequestDispatcher getNamedDispatcher(String path) { + public @Nullable RequestDispatcher getNamedDispatcher(String path) { return this.namedRequestDispatchers.get(path); } @@ -446,8 +437,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public String getRealPath(String path) { + public @Nullable String getRealPath(String path) { String resourceLocation = getResourceLocation(path); Resource resource = null; try { @@ -469,8 +459,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public String getInitParameter(String name) { + public @Nullable String getInitParameter(String name) { Assert.notNull(name, "Parameter name must not be null"); return this.initParameters.get(name); } @@ -496,8 +485,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); return this.attributes.get(name); } @@ -534,8 +522,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -590,8 +577,7 @@ public class MockServletContext implements ServletContext { } @Override // on Servlet 4.0 - @Nullable - public String getRequestCharacterEncoding() { + public @Nullable String getRequestCharacterEncoding() { return this.requestCharacterEncoding; } @@ -601,8 +587,7 @@ public class MockServletContext implements ServletContext { } @Override // on Servlet 4.0 - @Nullable - public String getResponseCharacterEncoding() { + public @Nullable String getResponseCharacterEncoding() { return this.responseCharacterEncoding; } @@ -615,8 +600,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public FilterRegistration getFilterRegistration(String filterName) { + public @Nullable FilterRegistration getFilterRegistration(String filterName) { return this.filterRegistrations.get(filterName); } @@ -665,8 +649,7 @@ public class MockServletContext implements ServletContext { * @see jakarta.servlet.ServletContext#getServletRegistration(java.lang.String) */ @Override - @Nullable - public ServletRegistration getServletRegistration(String servletName) { + public @Nullable ServletRegistration getServletRegistration(String servletName) { return null; } diff --git a/spring-test/src/main/java/org/springframework/mock/web/MockSessionCookieConfig.java b/spring-test/src/main/java/org/springframework/mock/web/MockSessionCookieConfig.java index 28c80b522b..30bcf6fce7 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/MockSessionCookieConfig.java +++ b/spring-test/src/main/java/org/springframework/mock/web/MockSessionCookieConfig.java @@ -21,8 +21,7 @@ import java.util.LinkedHashMap; import java.util.Map; import jakarta.servlet.SessionCookieConfig; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of the {@link jakarta.servlet.SessionCookieConfig} interface. @@ -33,17 +32,13 @@ import org.springframework.lang.Nullable; */ public class MockSessionCookieConfig implements SessionCookieConfig { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String domain; + private @Nullable String domain; - @Nullable - private String path; + private @Nullable String path; - @Nullable - private String comment; + private @Nullable String comment; private boolean httpOnly; @@ -60,8 +55,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -71,8 +65,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getDomain() { + public @Nullable String getDomain() { return this.domain; } @@ -82,8 +75,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.path; } @@ -95,8 +87,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { @SuppressWarnings("removal") @Override - @Nullable - public String getComment() { + public @Nullable String getComment() { return this.comment; } @@ -136,8 +127,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getAttribute(String name) { + public @Nullable String getAttribute(String name) { return this.attributes.get(name); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java b/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java index d0ca4ed482..2c4158ebff 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java +++ b/spring-test/src/main/java/org/springframework/mock/web/PassThroughFilterChain.java @@ -24,8 +24,8 @@ import jakarta.servlet.Servlet; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,14 +42,11 @@ import org.springframework.util.Assert; */ public class PassThroughFilterChain implements FilterChain { - @Nullable - private Filter filter; + private @Nullable Filter filter; - @Nullable - private FilterChain nextFilterChain; + private @Nullable FilterChain nextFilterChain; - @Nullable - private Servlet servlet; + private @Nullable Servlet servlet; /** 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 7a01244ba4..4673927f82 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 @@ -4,9 +4,7 @@ * *

    Useful for testing web contexts and controllers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.web; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java b/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java index 5461e40304..32bd66ad93 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java +++ b/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/MockServerRequest.java @@ -31,6 +31,7 @@ import java.util.OptionalLong; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -44,7 +45,6 @@ import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.RequestPath; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -76,8 +76,7 @@ public final class MockServerRequest implements ServerRequest { private final MultiValueMap cookies; - @Nullable - private final Object body; + private final @Nullable Object body; private final Map attributes; @@ -85,22 +84,17 @@ public final class MockServerRequest implements ServerRequest { private final Map pathVariables; - @Nullable - private final WebSession session; + private final @Nullable WebSession session; - @Nullable - private final Principal principal; + private final @Nullable Principal principal; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; - @Nullable - private final InetSocketAddress localAddress; + private final @Nullable InetSocketAddress localAddress; private final List> messageReaders; - @Nullable - private final ServerWebExchange exchange; + private final @Nullable ServerWebExchange exchange; private MockServerRequest(HttpMethod method, URI uri, String contextPath, MockHeaders headers, @@ -345,8 +339,7 @@ public final class MockServerRequest implements ServerRequest { private MultiValueMap cookies = new LinkedMultiValueMap<>(); - @Nullable - private Object body; + private @Nullable Object body; private Map attributes = new ConcurrentHashMap<>(); @@ -354,22 +347,17 @@ public final class MockServerRequest implements ServerRequest { private Map pathVariables = new LinkedHashMap<>(); - @Nullable - private WebSession session; + private @Nullable WebSession session; - @Nullable - private Principal principal; + private @Nullable Principal principal; - @Nullable - private InetSocketAddress remoteAddress; + private @Nullable InetSocketAddress remoteAddress; - @Nullable - private InetSocketAddress localAddress; + private @Nullable InetSocketAddress localAddress; private List> messageReaders = HandlerStrategies.withDefaults().messageReaders(); - @Nullable - private ServerWebExchange exchange; + private @Nullable ServerWebExchange exchange; @Override public Builder method(HttpMethod method) { @@ -569,8 +557,7 @@ public final class MockServerRequest implements ServerRequest { } @Override - @Nullable - public InetSocketAddress host() { + public @Nullable InetSocketAddress host() { return delegate().getHost(); } diff --git a/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/package-info.java b/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/package-info.java index 91fe074184..41100d28ee 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/web/reactive/function/server/package-info.java @@ -4,9 +4,7 @@ *

    Useful for testing router and handler functions. * */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.web.reactive.function.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/mock/web/server/MockServerWebExchange.java b/spring-test/src/main/java/org/springframework/mock/web/server/MockServerWebExchange.java index e2cf0fae8f..19d1f78305 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/server/MockServerWebExchange.java +++ b/spring-test/src/main/java/org/springframework/mock/web/server/MockServerWebExchange.java @@ -16,10 +16,10 @@ package org.springframework.mock.web.server; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; import org.springframework.mock.http.server.reactive.MockServerHttpResponse; import org.springframework.web.server.WebSession; @@ -98,8 +98,7 @@ public final class MockServerWebExchange extends DefaultServerWebExchange { private final MockServerHttpRequest request; - @Nullable - private WebSessionManager sessionManager; + private @Nullable WebSessionManager sessionManager; public Builder(MockServerHttpRequest request) { this.request = request; diff --git a/spring-test/src/main/java/org/springframework/mock/web/server/MockWebSession.java b/spring-test/src/main/java/org/springframework/mock/web/server/MockWebSession.java index 0a13b853ee..e8d795c6db 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/server/MockWebSession.java +++ b/spring-test/src/main/java/org/springframework/mock/web/server/MockWebSession.java @@ -21,9 +21,9 @@ import java.time.Duration; import java.time.Instant; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.WebSession; import org.springframework.web.server.session.InMemoryWebSessionStore; diff --git a/spring-test/src/main/java/org/springframework/mock/web/server/package-info.java b/spring-test/src/main/java/org/springframework/mock/web/server/package-info.java index 66a15310ee..e290525c8d 100644 --- a/spring-test/src/main/java/org/springframework/mock/web/server/package-info.java +++ b/spring-test/src/main/java/org/springframework/mock/web/server/package-info.java @@ -1,9 +1,7 @@ /** * Mock implementations of Spring's reactive server web API abstractions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.mock.web.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d6ce0a75ea..4121bcfeae 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,7 +16,7 @@ package org.springframework.test.annotation; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** *

    @@ -49,7 +49,6 @@ 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); + @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 26957c49f2..ed2e5e08ad 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 @@ -20,10 +20,10 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; 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 0e93e33cbd..84e981518d 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,9 +1,7 @@ /** * Support classes for annotation-driven tests. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/ApplicationContextFailureProcessor.java b/spring-test/src/main/java/org/springframework/test/context/ApplicationContextFailureProcessor.java index 2b22556d9a..4fc8214fb9 100644 --- a/spring-test/src/main/java/org/springframework/test/context/ApplicationContextFailureProcessor.java +++ b/spring-test/src/main/java/org/springframework/test/context/ApplicationContextFailureProcessor.java @@ -16,8 +16,9 @@ package org.springframework.test.context; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; -import org.springframework.lang.Nullable; /** * Strategy for components that process failures related to application contexts 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 5a35391eaf..8af79ed50f 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 @@ -23,10 +23,10 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.core.log.LogMessage; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContextAnnotationUtils.AnnotationDescriptor; import org.springframework.util.ClassUtils; @@ -168,8 +168,7 @@ public abstract class BootstrapUtils { } } - @Nullable - private static Class resolveExplicitTestContextBootstrapper(Class testClass) { + private static @Nullable Class resolveExplicitTestContextBootstrapper(Class testClass) { Set annotations = new LinkedHashSet<>(); AnnotationDescriptor descriptor = TestContextAnnotationUtils.findAnnotationDescriptor(testClass, BootstrapWith.class); 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 9e5def712c..276a23620b 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 @@ -16,9 +16,10 @@ package org.springframework.test.context; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.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 73643729ef..4d0e4f013a 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 @@ -20,13 +20,13 @@ import java.util.Arrays; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; 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; @@ -63,8 +63,7 @@ public class ContextConfigurationAttributes { private final boolean inheritInitializers; - @Nullable - private final String name; + private final @Nullable String name; private final Class contextLoaderClass; @@ -305,8 +304,7 @@ public class ContextConfigurationAttributes { * @since 3.2.2 * @see ContextConfiguration#name() */ - @Nullable - public String getName() { + public @Nullable 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 e8b35ff2c5..3541667950 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,7 +18,7 @@ package org.springframework.test.context; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Factory for creating {@link ContextCustomizer ContextCustomizers}. @@ -56,7 +56,6 @@ public interface ContextCustomizerFactory { * @return a {@link ContextCustomizer} or {@code null} if no customizer should * be used */ - @Nullable - ContextCustomizer createContextCustomizer(Class testClass, List configAttributes); + @Nullable ContextCustomizer createContextCustomizer(Class testClass, List configAttributes); } diff --git a/spring-test/src/main/java/org/springframework/test/context/DefaultMethodInvoker.java b/spring-test/src/main/java/org/springframework/test/context/DefaultMethodInvoker.java index a0f96ed47e..b625678759 100644 --- a/spring-test/src/main/java/org/springframework/test/context/DefaultMethodInvoker.java +++ b/spring-test/src/main/java/org/springframework/test/context/DefaultMethodInvoker.java @@ -21,8 +21,8 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -40,8 +40,7 @@ final class DefaultMethodInvoker implements MethodInvoker { @Override - @Nullable - public Object invoke(Method method, @Nullable Object target) throws Exception { + public @Nullable Object invoke(Method method, @Nullable Object target) throws Exception { Assert.notNull(method, "Method must not be null"); try { 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 26837b83f5..4815180f7e 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 @@ -23,13 +23,14 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.io.support.PropertySourceDescriptor; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; 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; @@ -102,11 +103,9 @@ public class MergedContextConfiguration implements Serializable { private final ContextLoader contextLoader; - @Nullable - private final CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate; + private final @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate; - @Nullable - private final MergedContextConfiguration parent; + private final @Nullable MergedContextConfiguration parent; /** @@ -118,8 +117,8 @@ public class MergedContextConfiguration implements Serializable { * @param activeProfiles the merged active bean definition profiles * @param contextLoader the resolved {@code ContextLoader} */ - public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, - @Nullable String[] activeProfiles, ContextLoader contextLoader) { + public MergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, + String @Nullable [] activeProfiles, ContextLoader contextLoader) { this(testClass, locations, classes, null, activeProfiles, contextLoader); } @@ -134,9 +133,9 @@ public class MergedContextConfiguration implements Serializable { * @param activeProfiles the merged active bean definition profiles * @param contextLoader the resolved {@code ContextLoader} */ - public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public MergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, ContextLoader contextLoader) { + String @Nullable [] activeProfiles, ContextLoader contextLoader) { this(testClass, locations, classes, contextInitializerClasses, activeProfiles, contextLoader, null, null); } @@ -155,9 +154,9 @@ public class MergedContextConfiguration implements Serializable { * @param parent the parent configuration or {@code null} if there is no parent * @since 3.2.2 */ - public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public MergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, ContextLoader contextLoader, + String @Nullable [] activeProfiles, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { @@ -204,10 +203,10 @@ public class MergedContextConfiguration implements Serializable { * {@link #MergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)} */ @Deprecated(since = "6.1") - public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public MergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, - @Nullable String[] propertySourceProperties, ContextLoader contextLoader, + String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, + String @Nullable [] propertySourceProperties, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { @@ -244,10 +243,10 @@ public class MergedContextConfiguration implements Serializable { * {@link #MergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)} */ @Deprecated(since = "6.1") - public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public MergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, - @Nullable String[] propertySourceProperties, @Nullable Set contextCustomizers, + String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, + String @Nullable [] propertySourceProperties, @Nullable Set contextCustomizers, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { @@ -280,10 +279,10 @@ public class MergedContextConfiguration implements Serializable { * @param parent the parent configuration or {@code null} if there is no parent * @since 6.1 */ - public MergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public MergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, List propertySourceDescriptors, - @Nullable String[] propertySourceProperties, @Nullable Set contextCustomizers, + String @Nullable [] activeProfiles, List propertySourceDescriptors, + String @Nullable [] propertySourceProperties, @Nullable Set contextCustomizers, ContextLoader contextLoader, @Nullable CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { @@ -443,8 +442,7 @@ public class MergedContextConfiguration implements Serializable { * @since 3.2.2 * @see #getParentApplicationContext() */ - @Nullable - public MergedContextConfiguration getParent() { + public @Nullable MergedContextConfiguration getParent() { return this.parent; } @@ -457,8 +455,7 @@ public class MergedContextConfiguration implements Serializable { * @since 3.2.2 * @see #getParent() */ - @Nullable - public ApplicationContext getParentApplicationContext() { + public @Nullable ApplicationContext getParentApplicationContext() { if (this.parent == null) { return null; } @@ -575,11 +572,11 @@ public class MergedContextConfiguration implements Serializable { } - protected static String[] processStrings(@Nullable String[] array) { + protected static String[] processStrings(String @Nullable [] array) { return (array != null ? array : EMPTY_STRING_ARRAY); } - private static Class[] processClasses(@Nullable Class[] classes) { + private static Class[] processClasses(Class @Nullable [] classes) { return (classes != null ? classes : EMPTY_CLASS_ARRAY); } @@ -597,7 +594,7 @@ public class MergedContextConfiguration implements Serializable { Collections.unmodifiableSet(contextCustomizers) : EMPTY_CONTEXT_CUSTOMIZERS); } - private static String[] processActiveProfiles(@Nullable String[] activeProfiles) { + private static String[] processActiveProfiles(String @Nullable [] activeProfiles) { if (activeProfiles == null) { return EMPTY_STRING_ARRAY; } diff --git a/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java b/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java index 247351e3b8..ea88c655d9 100644 --- a/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java +++ b/spring-test/src/main/java/org/springframework/test/context/MethodInvoker.java @@ -18,7 +18,7 @@ package org.springframework.test.context; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@code MethodInvoker} defines a generic API for invoking a {@link Method} @@ -66,7 +66,6 @@ public interface MethodInvoker { * @return the value returned from the method invocation, potentially {@code null} * @throws Exception if any error occurs */ - @Nullable - Object invoke(Method method, @Nullable Object target) throws Exception; + @Nullable Object invoke(Method method, @Nullable Object target) throws Exception; } diff --git a/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java index d7102667e0..e4d9568ba0 100644 --- a/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/NestedTestConfiguration.java @@ -26,8 +26,7 @@ import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@code @NestedTestConfiguration} is an annotation that can be applied to a test @@ -161,8 +160,7 @@ public @interface NestedTestConfiguration { * @return the corresponding enum constant or {@code null} if not found * @see EnclosingConfiguration#valueOf(String) */ - @Nullable - public static EnclosingConfiguration from(@Nullable String name) { + public static @Nullable EnclosingConfiguration from(@Nullable String name) { if (name == null) { return null; } diff --git a/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java b/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java index d140bc2695..142c62e2ca 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestConstructor.java @@ -26,8 +26,7 @@ import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@code @TestConstructor} is an annotation that can be applied to a test class @@ -151,8 +150,7 @@ public @interface TestConstructor { * @since 5.3 * @see AutowireMode#valueOf(String) */ - @Nullable - public static AutowireMode from(@Nullable String name) { + public static @Nullable AutowireMode from(@Nullable String name) { if (name == 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 3e6d5109c1..b8234f3fe1 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 @@ -20,10 +20,11 @@ import java.io.Serializable; import java.lang.reflect.Method; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationEvent; import org.springframework.core.AttributeAccessor; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; /** @@ -125,8 +126,7 @@ public interface TestContext extends AttributeAccessor, Serializable { * @return the exception that was thrown, or {@code null} if no exception was thrown * @see #updateState(Object, Method, Throwable) */ - @Nullable - Throwable getTestException(); + @Nullable Throwable getTestException(); /** * Call this method to signal that the {@linkplain ApplicationContext application diff --git a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java index 6053c11572..0f562d0c7a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/TestContextAnnotationUtils.java @@ -22,6 +22,8 @@ import java.util.HashSet; import java.util.Set; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; @@ -34,7 +36,6 @@ import org.springframework.core.annotation.RepeatableContainers; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.NestedTestConfiguration.EnclosingConfiguration; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -78,8 +79,7 @@ public abstract class TestContextAnnotationUtils { private static final ConcurrentLruCache, EnclosingConfiguration> cachedEnclosingConfigurationModes = new ConcurrentLruCache<>(32, TestContextAnnotationUtils::lookUpEnclosingConfiguration); - @Nullable - private static volatile EnclosingConfiguration defaultEnclosingConfigurationMode; + private static volatile @Nullable EnclosingConfiguration defaultEnclosingConfigurationMode; /** @@ -123,13 +123,11 @@ public abstract class TestContextAnnotationUtils { * @see #findAnnotationDescriptor(Class, Class) * @see #searchEnclosingClass(Class) */ - @Nullable - public static T findMergedAnnotation(Class clazz, Class annotationType) { + public static @Nullable T findMergedAnnotation(Class clazz, Class annotationType) { return findMergedAnnotation(clazz, annotationType, TestContextAnnotationUtils::searchEnclosingClass); } - @Nullable - private static T findMergedAnnotation(Class clazz, Class annotationType, + private static @Nullable T findMergedAnnotation(Class clazz, Class annotationType, Predicate> searchEnclosingClass) { return MergedAnnotations.search(SearchStrategy.TYPE_HIERARCHY) @@ -215,8 +213,7 @@ public abstract class TestContextAnnotationUtils { * otherwise {@code null} * @see #findAnnotationDescriptorForTypes(Class, Class...) */ - @Nullable - public static AnnotationDescriptor findAnnotationDescriptor( + public static @Nullable AnnotationDescriptor findAnnotationDescriptor( Class clazz, Class annotationType) { Assert.notNull(annotationType, "Annotation type must not be null"); @@ -236,8 +233,7 @@ public abstract class TestContextAnnotationUtils { * @return the corresponding annotation descriptor if the annotation was found; * otherwise {@code null} */ - @Nullable - private static AnnotationDescriptor findAnnotationDescriptor( + private static @Nullable AnnotationDescriptor findAnnotationDescriptor( @Nullable Class clazz, Class annotationType, Predicate> searchEnclosingClass, Set visited) { @@ -322,8 +318,7 @@ public abstract class TestContextAnnotationUtils { * @see #findAnnotationDescriptor(Class, Class) */ @SuppressWarnings("unchecked") - @Nullable - public static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes( + public static @Nullable UntypedAnnotationDescriptor findAnnotationDescriptorForTypes( Class clazz, Class... annotationTypes) { assertNonEmptyAnnotationTypeArray(annotationTypes, "The list of annotation types must not be empty"); @@ -340,8 +335,7 @@ public abstract class TestContextAnnotationUtils { * @return the corresponding annotation descriptor if one of the annotations * was found; otherwise {@code null} */ - @Nullable - private static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(@Nullable Class clazz, + private static @Nullable UntypedAnnotationDescriptor findAnnotationDescriptorForTypes(@Nullable Class clazz, Class[] annotationTypes, Set visited) { if (clazz == null || Object.class == clazz) { @@ -556,8 +550,7 @@ public abstract class TestContextAnnotationUtils { * @return the next corresponding annotation descriptor if the annotation * was found; otherwise {@code null} */ - @Nullable - public AnnotationDescriptor next() { + public @Nullable AnnotationDescriptor next() { // Declared on a superclass? AnnotationDescriptor descriptor = findAnnotationDescriptor(getRootDeclaringClass().getSuperclass(), getAnnotationType()); @@ -635,8 +628,7 @@ public abstract class TestContextAnnotationUtils { * @see AnnotationDescriptor#next() */ @Override - @Nullable - public UntypedAnnotationDescriptor next() { + public @Nullable UntypedAnnotationDescriptor next() { // Declared on a superclass? UntypedAnnotationDescriptor descriptor = findAnnotationDescriptorForTypes(getRootDeclaringClass().getSuperclass(), this.annotationTypes); 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 48a6079f94..b25c882605 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,8 +25,8 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils; diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributes.java b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributes.java index cfb243b491..497707c748 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributes.java @@ -16,8 +16,9 @@ package org.springframework.test.context.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; -import org.springframework.lang.Nullable; /** * Holder for metadata specific to ahead-of-time (AOT) support in the Spring @@ -117,8 +118,7 @@ public interface AotTestAttributes { * @see #getBoolean(String) * @see #setAttribute(String, String) */ - @Nullable - String getString(String name); + @Nullable String getString(String name); /** * Retrieve the attribute value for the given name as a {@code boolean}. diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributesFactory.java b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributesFactory.java index 1414083bd6..27c6ce61cf 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributesFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestAttributesFactory.java @@ -19,8 +19,9 @@ package org.springframework.test.context.aot; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; -import org.springframework.lang.Nullable; /** * Factory for {@link AotTestAttributes}. @@ -30,8 +31,7 @@ import org.springframework.lang.Nullable; */ final class AotTestAttributesFactory { - @Nullable - private static volatile Map attributes; + private static volatile @Nullable Map attributes; private AotTestAttributesFactory() { diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializers.java b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializers.java index 15b95e18ec..b035569800 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializers.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializers.java @@ -19,10 +19,11 @@ package org.springframework.test.context.aot; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; /** * {@code AotTestContextInitializers} provides mappings from test classes to @@ -76,8 +77,7 @@ public class AotTestContextInitializers { * @see #isSupportedTestClass(Class) * @see #getContextInitializerClass(Class) */ - @Nullable - public ApplicationContextInitializer getContextInitializer(Class testClass) { + public @Nullable ApplicationContextInitializer getContextInitializer(Class testClass) { Supplier> supplier = this.contextInitializers.get(testClass.getName()); return (supplier != null ? supplier.get() : null); @@ -91,8 +91,7 @@ public class AotTestContextInitializers { * @see #isSupportedTestClass(Class) * @see #getContextInitializer(Class) */ - @Nullable - public Class> getContextInitializerClass(Class testClass) { + public @Nullable Class> getContextInitializerClass(Class testClass) { return this.contextInitializerClasses.get(testClass.getName()); } diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializersFactory.java b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializersFactory.java index e130258a8e..1b742c50ae 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializersFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/AotTestContextInitializersFactory.java @@ -19,10 +19,11 @@ package org.springframework.test.context.aot; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; /** * Factory for {@link AotTestContextInitializers}. @@ -32,11 +33,9 @@ import org.springframework.lang.Nullable; */ final class AotTestContextInitializersFactory { - @Nullable - private static volatile Map>> contextInitializers; + private static volatile @Nullable Map>> contextInitializers; - @Nullable - private static volatile Map>> contextInitializerClasses; + private static volatile @Nullable Map>> contextInitializerClasses; private AotTestContextInitializersFactory() { diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/DefaultAotTestAttributes.java b/spring-test/src/main/java/org/springframework/test/context/aot/DefaultAotTestAttributes.java index 966485d5b5..d3f663b018 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/DefaultAotTestAttributes.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/DefaultAotTestAttributes.java @@ -18,8 +18,9 @@ package org.springframework.test.context.aot; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.AotDetector; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -54,8 +55,7 @@ class DefaultAotTestAttributes implements AotTestAttributes { } @Override - @Nullable - public String getString(String name) { + public @Nullable String getString(String name) { return this.attributes.get(name); } diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java index 65e630927a..3e2e63935d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/TestContextGenerationContext.java @@ -16,11 +16,12 @@ package org.springframework.test.context.aot; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.ClassNameGenerator; import org.springframework.aot.generate.DefaultGenerationContext; import org.springframework.aot.generate.GeneratedFiles; import org.springframework.aot.hint.RuntimeHints; -import org.springframework.lang.Nullable; /** * Extension of {@link DefaultGenerationContext} with a custom implementation of @@ -31,8 +32,7 @@ import org.springframework.lang.Nullable; */ class TestContextGenerationContext extends DefaultGenerationContext { - @Nullable - private final String featureName; + private final @Nullable String featureName; /** diff --git a/spring-test/src/main/java/org/springframework/test/context/aot/package-info.java b/spring-test/src/main/java/org/springframework/test/context/aot/package-info.java index d673bff93e..7339dd9e83 100644 --- a/spring-test/src/main/java/org/springframework/test/context/aot/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/aot/package-info.java @@ -1,9 +1,7 @@ /** * Ahead-of-time (AOT) support for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.aot; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java index 4d1f0f0d85..2c815c812c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideBeanFactoryPostProcessor.java @@ -22,6 +22,8 @@ import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryUtils; @@ -39,7 +41,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.aot.AbstractAotProcessor; import org.springframework.core.Ordered; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -293,8 +294,7 @@ class BeanOverrideBeanFactoryPostProcessor implements BeanFactoryPostProcessor, this.beanOverrideRegistry.registerBeanOverrideHandler(handler, beanName); } - @Nullable - private String getBeanNameForType(ConfigurableListableBeanFactory beanFactory, BeanOverrideHandler handler, + private @Nullable String getBeanNameForType(ConfigurableListableBeanFactory beanFactory, BeanOverrideHandler handler, boolean requireExistingBean) { Field field = handler.getField(); @@ -368,8 +368,7 @@ class BeanOverrideBeanFactoryPostProcessor implements BeanFactoryPostProcessor, * @return the name of the primary candidate, or {@code null} if none found * @see org.springframework.beans.factory.support.DefaultListableBeanFactory#determinePrimaryCandidate(Map, Class) */ - @Nullable - private static String determinePrimaryCandidate( + private static @Nullable String determinePrimaryCandidate( ConfigurableListableBeanFactory beanFactory, Set candidateBeanNames, Class beanType) { if (candidateBeanNames.isEmpty()) { diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java index e5d66ba8b0..0cd739a4a5 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactory.java @@ -20,7 +20,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizerFactory; import org.springframework.test.context.TestContextAnnotationUtils; @@ -39,8 +40,7 @@ import org.springframework.util.Assert; class BeanOverrideContextCustomizerFactory implements ContextCustomizerFactory { @Override - @Nullable - public BeanOverrideContextCustomizer createContextCustomizer(Class testClass, + public @Nullable BeanOverrideContextCustomizer createContextCustomizer(Class testClass, List configAttributes) { Set handlers = new LinkedHashSet<>(); diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java index b110813920..71858560d3 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/BeanOverrideHandler.java @@ -28,6 +28,8 @@ import java.util.Objects; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.SingletonBeanRegistry; @@ -35,7 +37,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -76,8 +77,7 @@ public abstract class BeanOverrideHandler { private final ResolvableType beanType; - @Nullable - private final String beanName; + private final @Nullable String beanName; private final BeanOverrideStrategy strategy; @@ -145,8 +145,7 @@ public abstract class BeanOverrideHandler { * Get the bean name to override, or {@code null} to look for a single * matching bean of type {@link #getBeanType()}. */ - @Nullable - public final String getBeanName() { + public final @Nullable String getBeanName() { return this.beanName; } diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java index 20df24ea88..ead7bf9f6e 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideHandler.java @@ -21,10 +21,11 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Objects; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.ResolvableType; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.BeanOverrideHandler; import org.springframework.test.context.bean.override.BeanOverrideStrategy; import org.springframework.util.ReflectionUtils; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/package-info.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/package-info.java index 59256e3fe6..cf410d0482 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/convention/package-info.java @@ -3,9 +3,7 @@ * in the test class. This allows defining a custom instance for the bean * straight from the test class. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.bean.override.convention; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/AbstractMockitoBeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/AbstractMockitoBeanOverrideHandler.java index 3e7b39275f..90550736ff 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/AbstractMockitoBeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/AbstractMockitoBeanOverrideHandler.java @@ -18,10 +18,11 @@ package org.springframework.test.context.bean.override.mockito; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.SingletonBeanRegistry; import org.springframework.core.ResolvableType; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.BeanOverrideHandler; import org.springframework.test.context.bean.override.BeanOverrideStrategy; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandler.java index 64ddd2f1b0..26e9d66c43 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideHandler.java @@ -23,6 +23,7 @@ import java.util.LinkedHashSet; import java.util.Objects; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.mockito.Answers; import org.mockito.MockSettings; import org.mockito.Mockito; @@ -30,7 +31,6 @@ import org.mockito.Mockito; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.ResolvableType; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.BeanOverrideHandler; import org.springframework.test.context.bean.override.BeanOverrideStrategy; import org.springframework.util.Assert; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoResetTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoResetTestExecutionListener.java index f4556a2619..094440ccc6 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoResetTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoResetTestExecutionListener.java @@ -22,6 +22,7 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.mockito.Mockito; import org.springframework.beans.factory.BeanFactory; @@ -32,7 +33,6 @@ import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContext; import org.springframework.test.context.support.AbstractTestExecutionListener; import org.springframework.util.ClassUtils; @@ -69,8 +69,7 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList * @see #mockitoPresent * @see #isEnabled() */ - @Nullable - private static volatile Boolean mockitoInitialized; + private static volatile @Nullable Boolean mockitoInitialized; /** @@ -126,8 +125,7 @@ public class MockitoResetTestExecutionListener extends AbstractTestExecutionList } } - @Nullable - private static Object getBean(ConfigurableListableBeanFactory beanFactory, String beanName) { + private static @Nullable Object getBean(ConfigurableListableBeanFactory beanFactory, String beanName) { try { if (isStandardBeanOrSingletonFactoryBean(beanFactory, beanName)) { return beanFactory.getBean(beanName); diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandler.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandler.java index ce929171e9..6f2bd2fdb8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandler.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/MockitoSpyBeanOverrideHandler.java @@ -19,6 +19,7 @@ package org.springframework.test.context.bean.override.mockito; import java.lang.reflect.Field; import java.lang.reflect.Proxy; +import org.jspecify.annotations.Nullable; import org.mockito.AdditionalAnswers; import org.mockito.MockSettings; import org.mockito.Mockito; @@ -27,7 +28,6 @@ import org.mockito.listeners.VerificationStartedListener; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.BeanOverrideHandler; import org.springframework.test.context.bean.override.BeanOverrideStrategy; import org.springframework.util.Assert; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/package-info.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/package-info.java index 15330b2b51..1d4c16cd8e 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/mockito/package-info.java @@ -1,9 +1,7 @@ /** * Bean overriding mechanism based on Mockito mocking and spying. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.bean.override.mockito; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/bean/override/package-info.java b/spring-test/src/main/java/org/springframework/test/context/bean/override/package-info.java index 4969d011ca..4b5ab0a176 100644 --- a/spring-test/src/main/java/org/springframework/test/context/bean/override/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/bean/override/package-info.java @@ -1,9 +1,7 @@ /** * Support case-by-case Bean overriding in Spring tests. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.bean.override; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/AotMergedContextConfiguration.java b/spring-test/src/main/java/org/springframework/test/context/cache/AotMergedContextConfiguration.java index 8ee9943623..712230d662 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/AotMergedContextConfiguration.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/AotMergedContextConfiguration.java @@ -18,11 +18,12 @@ package org.springframework.test.context.cache; import java.util.Collections; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.CacheAwareContextLoaderDelegate; import org.springframework.test.context.MergedContextConfiguration; 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 7d64249ce6..f4f4a6fe19 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 @@ -16,8 +16,9 @@ package org.springframework.test.context.cache; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; import org.springframework.test.context.MergedContextConfiguration; @@ -95,8 +96,7 @@ public interface ContextCache { * if not found in the cache * @see #remove */ - @Nullable - ApplicationContext get(MergedContextConfiguration key); + @Nullable ApplicationContext get(MergedContextConfiguration key); /** * Explicitly add an {@code ApplicationContext} instance to the cache diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java index c9601be992..be0bd587a7 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultCacheAwareContextLoaderDelegate.java @@ -20,13 +20,13 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.AotDetector; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.GenericApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; import org.springframework.test.context.ApplicationContextFailureProcessor; import org.springframework.test.context.CacheAwareContextLoaderDelegate; diff --git a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java index 99342ec496..6821dd8ff7 100644 --- a/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java +++ b/spring-test/src/main/java/org/springframework/test/context/cache/DefaultContextCache.java @@ -28,11 +28,11 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.util.Assert; @@ -121,8 +121,7 @@ public class DefaultContextCache implements ContextCache { } @Override - @Nullable - public ApplicationContext get(MergedContextConfiguration key) { + public @Nullable ApplicationContext get(MergedContextConfiguration key) { Assert.notNull(key, "Key must not be null"); ApplicationContext context = this.contextMap.get(key); if (context == null) { 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 e015cbf758..ef6e1811eb 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,9 +1,7 @@ /** * Support for context caching within the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.cache; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java b/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java index 91c4a9a8b2..c98be07fc8 100644 --- a/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java +++ b/spring-test/src/main/java/org/springframework/test/context/event/ApplicationEventsHolder.java @@ -16,7 +16,8 @@ package org.springframework.test.context.event; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -57,8 +58,7 @@ public abstract class ApplicationEventsHolder { * Get the {@link ApplicationEvents} for the current thread. * @return the current {@code ApplicationEvents}, or {@code null} if not registered */ - @Nullable - public static ApplicationEvents getApplicationEvents() { + public static @Nullable ApplicationEvents getApplicationEvents() { return applicationEvents.get(); } diff --git a/spring-test/src/main/java/org/springframework/test/context/event/annotation/package-info.java b/spring-test/src/main/java/org/springframework/test/context/event/annotation/package-info.java index f2a580e6ae..99f39ac1d3 100644 --- a/spring-test/src/main/java/org/springframework/test/context/event/annotation/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/event/annotation/package-info.java @@ -1,9 +1,7 @@ /** * Test execution event annotations for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.event.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/event/package-info.java b/spring-test/src/main/java/org/springframework/test/context/event/package-info.java index 1cee0ad6be..2ae253aae4 100644 --- a/spring-test/src/main/java/org/springframework/test/context/event/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/event/package-info.java @@ -1,9 +1,7 @@ /** * Test event support classes for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.event; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/hint/TestContextRuntimeHints.java b/spring-test/src/main/java/org/springframework/test/context/hint/TestContextRuntimeHints.java index db1ec27977..54329ee89d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/hint/TestContextRuntimeHints.java +++ b/spring-test/src/main/java/org/springframework/test/context/hint/TestContextRuntimeHints.java @@ -20,13 +20,14 @@ import java.lang.annotation.Annotation; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.ReflectionHints; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** diff --git a/spring-test/src/main/java/org/springframework/test/context/hint/package-info.java b/spring-test/src/main/java/org/springframework/test/context/hint/package-info.java index 1043d98cea..c441130bd0 100644 --- a/spring-test/src/main/java/org/springframework/test/context/hint/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/hint/package-info.java @@ -2,9 +2,7 @@ * Support for registering hints for reflection and resources in the * Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.hint; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java index 3e49b71b39..bda7712318 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/MergedSqlConfig.java @@ -19,13 +19,14 @@ package org.springframework.test.context.jdbc; import java.lang.reflect.Array; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; import org.springframework.core.style.ToStringCreator; import org.springframework.jdbc.datasource.init.ScriptUtils; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContextAnnotationUtils; import org.springframework.test.context.jdbc.SqlConfig.ErrorMode; import org.springframework.test.context.jdbc.SqlConfig.TransactionMode; diff --git a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java index 0b0534dd04..f3131669a7 100644 --- a/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/jdbc/SqlScriptsTestExecutionListener.java @@ -26,6 +26,7 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aot.hint.RuntimeHints; import org.springframework.context.ApplicationContext; @@ -35,7 +36,6 @@ import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContext; import org.springframework.test.context.TestContextAnnotationUtils; import org.springframework.test.context.aot.AotTestExecutionListener; @@ -238,16 +238,14 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen /** * Get the {@code @SqlMergeMode} annotation declared on the supplied class. */ - @Nullable - private SqlMergeMode getSqlMergeModeFor(Class clazz) { + private @Nullable SqlMergeMode getSqlMergeModeFor(Class clazz) { return TestContextAnnotationUtils.findMergedAnnotation(clazz, SqlMergeMode.class); } /** * Get the {@code @SqlMergeMode} annotation declared on the supplied method. */ - @Nullable - private SqlMergeMode getSqlMergeModeFor(Method method) { + private @Nullable SqlMergeMode getSqlMergeModeFor(Method method) { return AnnotatedElementUtils.findMergedAnnotation(method, SqlMergeMode.class); } @@ -386,8 +384,7 @@ public class SqlScriptsTestExecutionListener extends AbstractTestExecutionListen .equals(TransactionSynchronizationUtils.unwrapResourceIfNecessary(ds2)); } - @Nullable - private DataSource getDataSourceFromTransactionManager(PlatformTransactionManager transactionManager) { + private @Nullable DataSource getDataSourceFromTransactionManager(PlatformTransactionManager transactionManager) { try { Method getDataSourceMethod = transactionManager.getClass().getMethod("getDataSource"); Object obj = ReflectionUtils.invokeMethod(getDataSourceMethod, transactionManager); 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 fe01ea1dc5..f5158c3309 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,9 +2,7 @@ * JDBC support classes for the Spring TestContext Framework, * including support for declarative SQL script execution via {@code @Sql}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.jdbc; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java index 5e66aa58f4..af497e57ec 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java @@ -24,6 +24,7 @@ import java.lang.reflect.Parameter; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; @@ -50,7 +51,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.RepeatableContainers; -import org.springframework.lang.Nullable; import org.springframework.test.context.MethodInvoker; import org.springframework.test.context.TestConstructor; import org.springframework.test.context.TestContextAnnotationUtils; @@ -330,8 +330,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes * @see ParameterResolutionDelegate#resolveDependency */ @Override - @Nullable - public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { + public @Nullable Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Class testClass = extensionContext.getRequiredTestClass(); 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 c9c4800b6a..44c237362a 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,9 +2,7 @@ * Core support for integrating the Spring TestContext Framework * with the JUnit Jupiter extension model in JUnit 5. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.junit.jupiter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 2f48593acb..5fd141c9a5 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,9 +2,7 @@ * Web support for integrating the Spring TestContext Framework * with the JUnit Jupiter extension model in JUnit 5. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.junit.jupiter.web; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java index 9c39288080..05e1861d01 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractJUnit4SpringContextTests.java @@ -18,11 +18,11 @@ package org.springframework.test.context.junit4; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.junit.runner.RunWith; 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; @@ -75,8 +75,7 @@ public abstract class AbstractJUnit4SpringContextTests implements ApplicationCon * The {@link ApplicationContext} that was injected into this test instance * via {@link #setApplicationContext(ApplicationContext)}. */ - @Nullable - protected ApplicationContext applicationContext; + protected @Nullable ApplicationContext applicationContext; /** diff --git a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java index 24e3738254..c8970a9151 100644 --- a/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/junit4/AbstractTransactionalJUnit4SpringContextTests.java @@ -18,13 +18,14 @@ package org.springframework.test.context.junit4; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.jdbc.JdbcTestUtils; @@ -87,8 +88,7 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst */ protected final JdbcTemplate jdbcTemplate = new JdbcTemplate(); - @Nullable - private String sqlScriptEncoding; + private @Nullable String sqlScriptEncoding; /** 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 d06106d746..e98b57e665 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 @@ -22,6 +22,7 @@ import java.util.concurrent.TimeUnit; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.junit.Ignore; import org.junit.Test; import org.junit.internal.runners.model.ReflectiveCallable; @@ -35,7 +36,6 @@ 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; @@ -346,8 +346,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) { + protected @Nullable 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 b4b5883467..4013649cea 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,9 +2,7 @@ * Support classes for integrating the Spring TestContext Framework * with JUnit 4.12 or higher. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.junit4; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d1d981d2fb..0d4dfecd90 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,9 +1,7 @@ /** * Custom JUnit 4 {@code Rules} used in the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.junit4.rules; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d9162ae0d4..293dcd0eef 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 @@ -19,11 +19,11 @@ package org.springframework.test.context.junit4.statements; import java.lang.annotation.Annotation; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; 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; @@ -46,8 +46,7 @@ public class ProfileValueChecker extends Statement { private final Class testClass; - @Nullable - private final Method testMethod; + private final @Nullable Method testMethod; /** 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 50b9815c18..6733a69c4c 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,9 +1,7 @@ /** * Custom JUnit 4 {@code Statements} used in the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.junit4.statements; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java index 18bf72b672..889f3ba3fd 100644 --- a/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/observation/MicrometerObservationRegistryTestExecutionListener.java @@ -22,10 +22,10 @@ import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContext; import org.springframework.core.Conventions; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContext; import org.springframework.test.context.support.AbstractTestExecutionListener; import org.springframework.util.ReflectionUtils; @@ -68,8 +68,7 @@ class MicrometerObservationRegistryTestExecutionListener extends AbstractTestExe static final String OBSERVATION_THREAD_LOCAL_ACCESSOR_CLASS_NAME = "io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor"; - @Nullable - private static final String ERROR_MESSAGE; + private static final @Nullable String ERROR_MESSAGE; static { // Trigger eager resolution of Micrometer Observation types to ensure that diff --git a/spring-test/src/main/java/org/springframework/test/context/observation/package-info.java b/spring-test/src/main/java/org/springframework/test/context/observation/package-info.java index fecd9bf754..9a43008f56 100644 --- a/spring-test/src/main/java/org/springframework/test/context/observation/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/context/observation/package-info.java @@ -1,9 +1,7 @@ /** * Observation support classes for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.observation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 af3710b4b2..e5bf853860 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,9 +11,7 @@ * and caching, dependency injection of test fixtures, and transactional test * management with default rollback semantics. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 084d6ae7ff..1133531593 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 @@ -20,10 +20,10 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; 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 df48cd626f..5a11d1cff0 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 @@ -26,11 +26,11 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanInstantiationException; import org.springframework.beans.BeanUtils; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.Nullable; import org.springframework.test.context.BootstrapContext; import org.springframework.test.context.CacheAwareContextLoaderDelegate; import org.springframework.test.context.ContextConfiguration; @@ -79,8 +79,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot private final Log logger = LogFactory.getLog(getClass()); - @Nullable - private BootstrapContext bootstrapContext; + private @Nullable BootstrapContext bootstrapContext; @Override @@ -533,8 +532,7 @@ public abstract class AbstractTestContextBootstrapper implements TestContextBoot * @throws IllegalArgumentException if supplied configuration attributes are * {@code null} or empty */ - @Nullable - protected Class resolveExplicitContextLoaderClass( + protected @Nullable Class resolveExplicitContextLoaderClass( List configAttributesList) { Assert.notNull(configAttributesList, "ContextConfigurationAttributes list must not be null"); diff --git a/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java index a531d0c447..3a692987de 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/AnnotationConfigContextLoaderUtils.java @@ -22,10 +22,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.test.context.SmartContextLoader; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java b/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java index 03b6a25827..ae9fac01eb 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DefaultTestContext.java @@ -21,12 +21,13 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.DirtiesContext.HierarchyMode; import org.springframework.test.context.CacheAwareContextLoaderDelegate; import org.springframework.test.context.MergedContextConfiguration; @@ -56,14 +57,11 @@ public class DefaultTestContext implements TestContext { private final Class testClass; - @Nullable - private volatile Object testInstance; + private volatile @Nullable Object testInstance; - @Nullable - private volatile Method testMethod; + private volatile @Nullable Method testMethod; - @Nullable - private volatile Throwable testException; + private volatile @Nullable Throwable testException; private volatile MethodInvoker methodInvoker = MethodInvoker.DEFAULT_INVOKER; @@ -174,8 +172,7 @@ public class DefaultTestContext implements TestContext { } @Override - @Nullable - public final Throwable getTestException() { + public final @Nullable Throwable getTestException() { return this.testException; } @@ -211,8 +208,7 @@ public class DefaultTestContext implements TestContext { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { Assert.notNull(name, "Name must not be null"); return this.attributes.get(name); } @@ -229,8 +225,7 @@ public class DefaultTestContext implements TestContext { } @Override - @Nullable - public Object removeAttribute(String name) { + public @Nullable Object removeAttribute(String name) { Assert.notNull(name, "Name must not be null"); return this.attributes.remove(name); } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java index bc70c36066..57254fd054 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizer.java @@ -20,13 +20,14 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.lang.Nullable; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.test.context.MergedContextConfiguration; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java index ddd11ffe6a..fae55eadc5 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertiesContextCustomizerFactory.java @@ -22,9 +22,10 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodIntrospector; import org.springframework.core.annotation.MergedAnnotations; -import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizerFactory; import org.springframework.test.context.DynamicPropertySource; @@ -45,8 +46,7 @@ import org.springframework.test.context.TestContextAnnotationUtils; class DynamicPropertiesContextCustomizerFactory implements ContextCustomizerFactory { @Override - @Nullable - public DynamicPropertiesContextCustomizer createContextCustomizer(Class testClass, + public @Nullable DynamicPropertiesContextCustomizer createContextCustomizer(Class testClass, List configAttributes) { Set methods = new LinkedHashSet<>(); diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer.java index 3f24c6dd8a..5946f0590c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicPropertyRegistrarBeanInitializer.java @@ -18,6 +18,7 @@ package org.springframework.test.context.support; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactoryInitializer; import org.springframework.beans.factory.BeanFactoryUtils; @@ -25,7 +26,6 @@ import org.springframework.beans.factory.ListableBeanFactory; import org.springframework.context.EnvironmentAware; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.Environment; -import org.springframework.lang.Nullable; import org.springframework.test.context.DynamicPropertyRegistrar; import org.springframework.test.context.DynamicPropertyRegistry; @@ -49,8 +49,7 @@ public class DynamicPropertyRegistrarBeanInitializer implements BeanFactoryIniti "org.springframework.test.context.support.internalDynamicPropertyRegistrarBeanInitializer"; - @Nullable - private ConfigurableEnvironment environment; + private @Nullable ConfigurableEnvironment environment; @Override diff --git a/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java b/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java index bbe560152e..2a5470bdf2 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/DynamicValuesPropertySource.java @@ -21,11 +21,12 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.env.MapPropertySource; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource; -import org.springframework.lang.Nullable; import org.springframework.test.context.DynamicPropertyRegistry; import org.springframework.util.Assert; import org.springframework.util.function.SupplierUtils; @@ -60,8 +61,7 @@ class DynamicValuesPropertySource extends MapPropertySource { @Override - @Nullable - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { return SupplierUtils.resolve(super.getProperty(name)); } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java b/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java index ba76d8f191..0501c9e30a 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/MergedTestPropertySources.java @@ -19,11 +19,12 @@ package org.springframework.test.context.support; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.support.PropertySourceDescriptor; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestPropertySource; import org.springframework.util.Assert; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/PropertyProvider.java b/spring-test/src/main/java/org/springframework/test/context/support/PropertyProvider.java index 564ed078a9..a1d6367d8d 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/PropertyProvider.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/PropertyProvider.java @@ -16,7 +16,7 @@ package org.springframework.test.context.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy for providing named properties — for example, for looking up @@ -35,7 +35,6 @@ public interface PropertyProvider { * @param name the name of the property to retrieve * @return the value of the property or {@code null} if not found */ - @Nullable - String get(String name); + @Nullable String get(String name); } diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java index 37ddd68470..cbf8bdd060 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestConstructorUtils.java @@ -23,11 +23,11 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.SpringProperties; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestConstructor; import org.springframework.test.context.TestConstructor.AutowireMode; import org.springframework.test.context.TestContextAnnotationUtils; 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 c3a43e594d..df41b907af 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 @@ -22,6 +22,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.io.ClassPathResource; @@ -31,7 +32,6 @@ import org.springframework.core.log.LogMessage; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.util.TestContextResourceUtils; import org.springframework.util.Assert; diff --git a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java index 700f38acd8..b8f0369138 100644 --- a/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java +++ b/spring-test/src/main/java/org/springframework/test/context/support/TestPropertySourceUtils.java @@ -29,6 +29,7 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.context.ConfigurableApplicationContext; @@ -49,7 +50,6 @@ import org.springframework.core.io.support.PropertySourceDescriptor; import org.springframework.core.io.support.PropertySourceFactory; import org.springframework.core.io.support.ResourcePatternResolver; import org.springframework.core.io.support.ResourcePatternUtils; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContextAnnotationUtils; import org.springframework.test.context.TestPropertySource; import org.springframework.util.Assert; @@ -116,8 +116,7 @@ public abstract class TestPropertySourceUtils { return new MergedTestPropertySources(mergeLocations(attributesList), mergeProperties(attributesList)); } - @Nullable - private static TestPropertySourceAttributes mergeTestPropertySourceAttributes( + private static @Nullable TestPropertySourceAttributes mergeTestPropertySourceAttributes( List aggregatedAttributesList) { TestPropertySourceAttributes mergedAttributes = null; @@ -460,8 +459,7 @@ public abstract class TestPropertySourceUtils { private final LinkedHashMap map = new LinkedHashMap<>(); @Override - @Nullable - public Object put(Object key, Object value) { + public @Nullable Object put(Object key, Object value) { if (key instanceof String str) { return this.map.put(str, value); } 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 66f278fde8..227ccd0446 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,9 +1,7 @@ /** * Support classes for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c328f59a96..606932c048 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 @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.testng.IHookCallBack; import org.testng.IHookable; import org.testng.ITestResult; @@ -31,7 +32,6 @@ import org.testng.annotations.BeforeMethod; 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; @@ -69,13 +69,11 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App * The {@link ApplicationContext} that was injected into this test instance * via {@link #setApplicationContext(ApplicationContext)}. */ - @Nullable - protected ApplicationContext applicationContext; + protected @Nullable ApplicationContext applicationContext; private final TestContextManager testContextManager; - @Nullable - private Throwable testException; + private @Nullable Throwable testException; /** @@ -198,8 +196,7 @@ public abstract class AbstractTestNGSpringContextTests implements IHookable, App } - @Nullable - private Throwable getTestResultException(ITestResult testResult) { + private @Nullable Throwable getTestResultException(ITestResult testResult) { Throwable testResultException = testResult.getThrowable(); if (testResultException instanceof InvocationTargetException) { testResultException = testResultException.getCause(); diff --git a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java index d26ec301d0..ba01dec09c 100644 --- a/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java +++ b/spring-test/src/main/java/org/springframework/test/context/testng/AbstractTransactionalTestNGSpringContextTests.java @@ -18,13 +18,14 @@ package org.springframework.test.context.testng; import javax.sql.DataSource; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.core.io.Resource; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator; -import org.springframework.lang.Nullable; import org.springframework.test.jdbc.JdbcTestUtils; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.annotation.Transactional; @@ -70,8 +71,7 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst */ protected final JdbcTemplate jdbcTemplate = new JdbcTemplate(); - @Nullable - private String sqlScriptEncoding; + private @Nullable String sqlScriptEncoding; /** 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 a3ffed50e1..fedbcb4ced 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,9 +2,7 @@ * Support classes for integrating the Spring TestContext Framework * with TestNG. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.testng; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 01c55a1535..ac7349637d 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 @@ -22,12 +22,12 @@ import javax.sql.DataSource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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.TransactionManager; @@ -88,8 +88,7 @@ public abstract class TestContextTransactionUtils { * @throws BeansException if an error occurs while retrieving an explicitly * named {@code DataSource} */ - @Nullable - public static DataSource retrieveDataSource(TestContext testContext, @Nullable String name) { + public static @Nullable DataSource retrieveDataSource(TestContext testContext, @Nullable String name) { Assert.notNull(testContext, "TestContext must not be null"); BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory(); @@ -160,8 +159,7 @@ public abstract class TestContextTransactionUtils { * @throws IllegalStateException if more than one TransactionManagementConfigurer * exists in the ApplicationContext */ - @Nullable - public static PlatformTransactionManager retrieveTransactionManager(TestContext testContext, @Nullable String name) { + public static @Nullable PlatformTransactionManager retrieveTransactionManager(TestContext testContext, @Nullable String name) { Assert.notNull(testContext, "TestContext must not be null"); BeanFactory bf = testContext.getApplicationContext().getAutowireCapableBeanFactory(); @@ -277,8 +275,7 @@ public abstract class TestContextTransactionUtils { } @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } } diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java index 73886f2412..fde1518087 100644 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java +++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContext.java @@ -20,8 +20,8 @@ import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.context.TestContext; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -52,8 +52,7 @@ class TransactionContext { private boolean flaggedForRollback; - @Nullable - private TransactionStatus transactionStatus; + private @Nullable TransactionStatus transactionStatus; private final AtomicInteger transactionsStarted = new AtomicInteger(); @@ -69,8 +68,7 @@ class TransactionContext { } - @Nullable - TransactionStatus getTransactionStatus() { + @Nullable TransactionStatus getTransactionStatus() { return this.transactionStatus; } diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java index 3d1a1bcbcc..91ea7504d2 100644 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java +++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionContextHolder.java @@ -16,8 +16,9 @@ package org.springframework.test.context.transaction; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedInheritableThreadLocal; -import org.springframework.lang.Nullable; /** * {@link InheritableThreadLocal}-based holder for the current {@link TransactionContext}. @@ -39,13 +40,11 @@ final class TransactionContextHolder { currentTransactionContext.set(transactionContext); } - @Nullable - static TransactionContext getCurrentTransactionContext() { + static @Nullable TransactionContext getCurrentTransactionContext() { return currentTransactionContext.get(); } - @Nullable - static TransactionContext removeCurrentTransactionContext() { + static @Nullable TransactionContext removeCurrentTransactionContext() { TransactionContext transactionContext = currentTransactionContext.get(); currentTransactionContext.remove(); return transactionContext; diff --git a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java index 8322a84b60..c19eb72f66 100644 --- a/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java +++ b/spring-test/src/main/java/org/springframework/test/context/transaction/TransactionalTestExecutionListener.java @@ -25,12 +25,12 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.test.annotation.Commit; import org.springframework.test.annotation.Rollback; import org.springframework.test.context.TestContext; @@ -155,8 +155,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis protected final TransactionAttributeSource attributeSource = new AnnotationTransactionAttributeSource(false) { @Override - @Nullable - protected TransactionAttribute findTransactionAttribute(Class clazz) { + protected @Nullable TransactionAttribute findTransactionAttribute(Class clazz) { // @Transactional present in inheritance hierarchy? TransactionAttribute result = super.findTransactionAttribute(clazz); if (result != null) { @@ -166,8 +165,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis return findTransactionAttributeInEnclosingClassHierarchy(clazz); } - @Nullable - private TransactionAttribute findTransactionAttributeInEnclosingClassHierarchy(Class clazz) { + private @Nullable TransactionAttribute findTransactionAttributeInEnclosingClassHierarchy(Class clazz) { if (TestContextAnnotationUtils.searchEnclosingClass(clazz)) { return findTransactionAttribute(clazz.getEnclosingClass()); } @@ -361,8 +359,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis * @throws BeansException if an error occurs while retrieving the transaction manager * @see #getTransactionManager(TestContext) */ - @Nullable - protected PlatformTransactionManager getTransactionManager(TestContext testContext, @Nullable String qualifier) { + protected @Nullable PlatformTransactionManager getTransactionManager(TestContext testContext, @Nullable String qualifier) { // Look up by type and qualifier from @Transactional if (StringUtils.hasText(qualifier)) { try { @@ -400,8 +397,7 @@ public class TransactionalTestExecutionListener extends AbstractTestExecutionLis * exists in the ApplicationContext * @see #getTransactionManager(TestContext, String) */ - @Nullable - protected PlatformTransactionManager getTransactionManager(TestContext testContext) { + protected @Nullable PlatformTransactionManager getTransactionManager(TestContext testContext) { return TestContextTransactionUtils.retrieveTransactionManager(testContext, null); } 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 51a8296e45..3cb1ecb283 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,9 +1,7 @@ /** * Transactional support classes for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.transaction; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f4addd2e9e..2875ad70df 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,9 +1,7 @@ /** * Common utilities used within the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.util; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 79c948a30b..4284a57719 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 @@ -19,12 +19,13 @@ package org.springframework.test.context.web; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContextInitializer; import org.springframework.core.io.support.PropertySourceDescriptor; import org.springframework.core.style.DefaultToStringStyler; import org.springframework.core.style.SimpleValueStyler; 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; @@ -105,9 +106,9 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration { * {@link #WebMergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, String, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)} */ @Deprecated(since = "6.1") - public WebMergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public WebMergedContextConfiguration(Class testClass, String @Nullable [] locations, @Nullable Class[] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, @Nullable String[] propertySourceProperties, + String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, String resourceBasePath, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { @@ -144,9 +145,9 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration { * {@link #WebMergedContextConfiguration(Class, String[], Class[], Set, String[], List, String[], Set, String, ContextLoader, CacheAwareContextLoaderDelegate, MergedContextConfiguration)} */ @Deprecated(since = "6.1") - public WebMergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public WebMergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, @Nullable String[] propertySourceLocations, @Nullable String[] propertySourceProperties, + String @Nullable [] activeProfiles, String @Nullable [] propertySourceLocations, String @Nullable [] propertySourceProperties, @Nullable Set contextCustomizers, String resourceBasePath, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { @@ -180,10 +181,10 @@ public class WebMergedContextConfiguration extends MergedContextConfiguration { * @param parent the parent configuration or {@code null} if there is no parent * @since 6.1 */ - public WebMergedContextConfiguration(Class testClass, @Nullable String[] locations, @Nullable Class[] classes, + public WebMergedContextConfiguration(Class testClass, String @Nullable [] locations, Class @Nullable [] classes, @Nullable Set>> contextInitializerClasses, - @Nullable String[] activeProfiles, - List propertySourceDescriptors, @Nullable String[] propertySourceProperties, + String @Nullable [] activeProfiles, + List propertySourceDescriptors, String @Nullable [] propertySourceProperties, @Nullable Set contextCustomizers, String resourceBasePath, ContextLoader contextLoader, CacheAwareContextLoaderDelegate cacheAwareContextLoaderDelegate, @Nullable MergedContextConfiguration parent) { diff --git a/spring-test/src/main/java/org/springframework/test/context/web/WebTestContextBootstrapper.java b/spring-test/src/main/java/org/springframework/test/context/web/WebTestContextBootstrapper.java index 6db3a3351d..ec39473b46 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/WebTestContextBootstrapper.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/WebTestContextBootstrapper.java @@ -16,7 +16,8 @@ package org.springframework.test.context.web; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.context.ContextLoader; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.test.context.TestContextAnnotationUtils; @@ -71,8 +72,7 @@ public class WebTestContextBootstrapper extends DefaultTestContextBootstrapper { } } - @Nullable - private static WebAppConfiguration getWebAppConfiguration(Class testClass) { + private static @Nullable WebAppConfiguration getWebAppConfiguration(Class testClass) { return TestContextAnnotationUtils.findMergedAnnotation(testClass, WebAppConfiguration.class); } 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 e4f9b40942..82d61b9f0e 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,9 +1,7 @@ /** * Web support classes for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.web; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizer.java b/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizer.java index 441615cf1c..67b6298ad3 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizer.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizer.java @@ -17,9 +17,9 @@ package org.springframework.test.context.web.socket; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.MergedContextConfiguration; import org.springframework.web.context.WebApplicationContext; diff --git a/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java b/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java index 667b789f8b..fee36dd3bd 100644 --- a/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java +++ b/spring-test/src/main/java/org/springframework/test/context/web/socket/MockServerContainerContextCustomizerFactory.java @@ -18,7 +18,8 @@ package org.springframework.test.context.web.socket; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextCustomizerFactory; @@ -42,8 +43,7 @@ class MockServerContainerContextCustomizerFactory implements ContextCustomizerFa @Override - @Nullable - public ContextCustomizer createContextCustomizer(Class testClass, + public @Nullable ContextCustomizer createContextCustomizer(Class testClass, List configAttributes) { if (webSocketPresent && isAnnotatedWithWebAppConfiguration(testClass)) { 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 8aa1072223..f3401796d7 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,9 +1,7 @@ /** * WebSocket support classes for the Spring TestContext Framework. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.web.socket; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/http/MediaTypeAssert.java b/spring-test/src/main/java/org/springframework/test/http/MediaTypeAssert.java index a25b39094d..277419daf7 100644 --- a/spring-test/src/main/java/org/springframework/test/http/MediaTypeAssert.java +++ b/spring-test/src/main/java/org/springframework/test/http/MediaTypeAssert.java @@ -20,10 +20,10 @@ import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.Assertions; import org.assertj.core.error.BasicErrorMessageFactory; import org.assertj.core.internal.Failures; +import org.jspecify.annotations.Nullable; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** diff --git a/spring-test/src/main/java/org/springframework/test/http/package-info.java b/spring-test/src/main/java/org/springframework/test/http/package-info.java index 6613b8a012..0782d4904b 100644 --- a/spring-test/src/main/java/org/springframework/test/http/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/http/package-info.java @@ -1,9 +1,7 @@ /** * Test support for HTTP concepts. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.http; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java b/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java index 57d21d4422..4bfe45270a 100644 --- a/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java +++ b/spring-test/src/main/java/org/springframework/test/jdbc/JdbcTestUtils.java @@ -18,11 +18,11 @@ package org.springframework.test.jdbc; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.jdbc.core.JdbcOperations; import org.springframework.jdbc.core.SqlParameterValue; import org.springframework.jdbc.core.simple.JdbcClient; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** 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 e382f90462..7f2e3d9c89 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,9 +1,7 @@ /** * Support classes for tests based on JDBC. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.jdbc; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java index e034682b59..78797c43e8 100644 --- a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonContentAssert.java @@ -34,6 +34,7 @@ import org.assertj.core.api.Assertions; import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.error.BasicErrorMessageFactory; import org.assertj.core.internal.Failures; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; import org.springframework.core.io.ByteArrayResource; @@ -44,7 +45,6 @@ import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.mock.http.MockHttpInputMessage; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.Assert; @@ -77,14 +77,11 @@ public abstract class AbstractJsonContentAssert resourceLoadClass; + private @Nullable Class resourceLoadClass; - @Nullable - private Charset charset; + private @Nullable Charset charset; private JsonLoader jsonLoader; @@ -488,8 +485,7 @@ public abstract class AbstractJsonContentAssert selfType, diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonAssert.java b/spring-test/src/main/java/org/springframework/test/json/JsonAssert.java index a8d2bf404a..f1e1c12274 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonAssert.java @@ -17,14 +17,13 @@ package org.springframework.test.json; import org.json.JSONException; +import org.jspecify.annotations.Nullable; import org.skyscreamer.jsonassert.JSONCompare; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; import org.skyscreamer.jsonassert.comparator.DefaultComparator; import org.skyscreamer.jsonassert.comparator.JSONComparator; -import org.springframework.lang.Nullable; - /** * Useful methods that can be used with {@code org.skyscreamer.jsonassert}. * diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonComparator.java b/spring-test/src/main/java/org/springframework/test/json/JsonComparator.java index bc8dae2ee8..2fee94ef11 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonComparator.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonComparator.java @@ -16,7 +16,8 @@ package org.springframework.test.json; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.json.JsonComparison.Result; /** diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonComparison.java b/spring-test/src/main/java/org/springframework/test/json/JsonComparison.java index 6930bc9833..eb2a60fe0f 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonComparison.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonComparison.java @@ -16,7 +16,7 @@ package org.springframework.test.json; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A comparison of two JSON strings as returned from a {@link JsonComparator}. @@ -28,8 +28,7 @@ public final class JsonComparison { private final Result result; - @Nullable - private final String message; + private final @Nullable String message; private JsonComparison(Result result, @Nullable String message) { @@ -66,8 +65,7 @@ public final class JsonComparison { /** * Return a message describing the comparison. */ - @Nullable - public String getMessage() { + public @Nullable String getMessage() { return this.message; } diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonContent.java b/spring-test/src/main/java/org/springframework/test/json/JsonContent.java index 28b02082e4..7d3eba83f1 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonContent.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonContent.java @@ -17,8 +17,8 @@ package org.springframework.test.json; import org.assertj.core.api.AssertProvider; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.Assert; @@ -34,8 +34,7 @@ public final class JsonContent implements AssertProvider { private final String json; - @Nullable - private final HttpMessageContentConverter contentConverter; + private final @Nullable HttpMessageContentConverter contentConverter; /** @@ -78,8 +77,7 @@ public final class JsonContent implements AssertProvider { /** * Return the {@link HttpMessageContentConverter} to use to deserialize content. */ - @Nullable - HttpMessageContentConverter getContentConverter() { + @Nullable HttpMessageContentConverter getContentConverter() { return this.contentConverter; } diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java b/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java index 9728a76249..b5bacb0ebf 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonContentAssert.java @@ -16,7 +16,7 @@ package org.springframework.test.json; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Default {@link AbstractJsonContentAssert} implementation. diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonLoader.java b/spring-test/src/main/java/org/springframework/test/json/JsonLoader.java index fe905c000a..dbf5f44580 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonLoader.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonLoader.java @@ -22,9 +22,10 @@ import java.io.InputStreamReader; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -37,8 +38,7 @@ import org.springframework.util.FileCopyUtils; */ class JsonLoader { - @Nullable - private final Class resourceLoadClass; + private final @Nullable Class resourceLoadClass; private final Charset charset; @@ -49,8 +49,7 @@ class JsonLoader { } - @Nullable - String getJson(@Nullable CharSequence source) { + @Nullable String getJson(@Nullable CharSequence source) { if (source == null) { return null; } diff --git a/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java b/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java index c30843e87c..1dd07ba0e3 100644 --- a/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/JsonPathValueAssert.java @@ -17,8 +17,8 @@ package org.springframework.test.json; import com.jayway.jsonpath.JsonPath; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.http.HttpMessageContentConverter; /** diff --git a/spring-test/src/main/java/org/springframework/test/json/package-info.java b/spring-test/src/main/java/org/springframework/test/json/package-info.java index cf1085f3b4..75c7dff9f8 100644 --- a/spring-test/src/main/java/org/springframework/test/json/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/json/package-info.java @@ -1,9 +1,7 @@ /** * Testing support for JSON. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.json; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/util/AssertionErrors.java b/spring-test/src/main/java/org/springframework/test/util/AssertionErrors.java index db51fb160c..80815647e5 100644 --- a/spring-test/src/main/java/org/springframework/test/util/AssertionErrors.java +++ b/spring-test/src/main/java/org/springframework/test/util/AssertionErrors.java @@ -16,8 +16,9 @@ package org.springframework.test.util; +import org.jspecify.annotations.Nullable; + import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** diff --git a/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java index f3e8841e65..a7e8ec4e52 100644 --- a/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/JsonPathExpectationsHelper.java @@ -29,9 +29,9 @@ import com.jayway.jsonpath.spi.mapper.MappingProvider; import org.hamcrest.CoreMatchers; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -330,8 +330,7 @@ public class JsonPathExpectationsHelper { * @return the result of the evaluation * @throws AssertionError if the evaluation fails */ - @Nullable - public Object evaluateJsonPath(String content) { + public @Nullable Object evaluateJsonPath(String content) { try { return this.jsonPath.read(content, this.configuration); } @@ -371,8 +370,7 @@ public class JsonPathExpectationsHelper { context.read(this.expression, new TypeRefAdapter<>(targetType))); } - @Nullable - private Object assertExistsAndReturn(String content) { + private @Nullable Object assertExistsAndReturn(String content) { Object value = evaluateJsonPath(content); String reason = "No value at JSON path \"" + this.expression + "\""; AssertionErrors.assertTrue(reason, value != null); diff --git a/spring-test/src/main/java/org/springframework/test/util/MethodAssert.java b/spring-test/src/main/java/org/springframework/test/util/MethodAssert.java index a346aa6a54..81a57afddc 100644 --- a/spring-test/src/main/java/org/springframework/test/util/MethodAssert.java +++ b/spring-test/src/main/java/org/springframework/test/util/MethodAssert.java @@ -20,8 +20,7 @@ import java.lang.reflect.Method; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.Assertions; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * AssertJ {@link org.assertj.core.api.Assert assertions} that can be applied 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 f63738405e..a924a62c4b 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 @@ -21,9 +21,9 @@ import java.lang.reflect.Method; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MethodInvoker; @@ -214,8 +214,7 @@ public abstract class ReflectionTestUtils { * @return the field's current value * @see #getField(Class, String) */ - @Nullable - public static Object getField(Object targetObject, String name) { + public static @Nullable Object getField(Object targetObject, String name) { return getField(targetObject, null, name); } @@ -231,8 +230,7 @@ public abstract class ReflectionTestUtils { * @since 4.2 * @see #getField(Object, String) */ - @Nullable - public static Object getField(Class targetClass, String name) { + public static @Nullable Object getField(Class targetClass, String name) { return getField(null, targetClass, name); } @@ -260,9 +258,8 @@ public abstract class ReflectionTestUtils { * @see ReflectionUtils#getField(Field, Object) * @see AopTestUtils#getUltimateTargetObject(Object) */ - @Nullable @SuppressWarnings("NullAway") - public static Object getField(@Nullable Object targetObject, @Nullable Class targetClass, String name) { + public static @Nullable 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"); @@ -391,8 +388,7 @@ public abstract class ReflectionTestUtils { * @see ReflectionUtils#invokeMethod(Method, Object, Object[]) * @see AopTestUtils#getUltimateTargetObject(Object) */ - @Nullable - public static Object invokeGetterMethod(Object target, String name) { + public static @Nullable Object invokeGetterMethod(Object target, String name) { Assert.notNull(target, "Target object must not be null"); Assert.hasText(name, "Method name must not be empty"); @@ -437,8 +433,7 @@ public abstract class ReflectionTestUtils { * @see #invokeMethod(Class, String, Object...) * @see #invokeMethod(Object, Class, String, Object...) */ - @Nullable - public static T invokeMethod(Object target, String name, Object... args) { + public static @Nullable T invokeMethod(Object target, String name, Object... args) { Assert.notNull(target, "Target object must not be null"); return invokeMethod(target, null, name, args); } @@ -456,8 +451,7 @@ public abstract class ReflectionTestUtils { * @see #invokeMethod(Object, String, Object...) * @see #invokeMethod(Object, Class, String, Object...) */ - @Nullable - public static T invokeMethod(Class targetClass, String name, Object... args) { + public static @Nullable T invokeMethod(Class targetClass, String name, Object... args) { Assert.notNull(targetClass, "Target class must not be null"); return invokeMethod(null, targetClass, name, args); } @@ -489,8 +483,7 @@ public abstract class ReflectionTestUtils { * @see AopTestUtils#getUltimateTargetObject(Object) */ @SuppressWarnings("unchecked") - @Nullable - public static T invokeMethod(@Nullable Object targetObject, @Nullable Class targetClass, String name, + public static @Nullable T invokeMethod(@Nullable Object targetObject, @Nullable Class targetClass, String name, Object... args) { Assert.isTrue(targetObject != null || targetClass != null, 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 046c0d406f..18aabd19a9 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 @@ -31,12 +31,12 @@ import javax.xml.xpath.XPathFactory; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; 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; @@ -214,8 +214,7 @@ public class XpathExpectationsHelper { * @throws Exception if content parsing or expression evaluation fails * @since 5.1 */ - @Nullable - public T evaluateXpath(byte[] content, @Nullable String encoding, Class targetClass) throws Exception { + public @Nullable T evaluateXpath(byte[] content, @Nullable String encoding, Class targetClass) throws Exception { Document document = parseXmlByteArray(content, encoding); return evaluateXpath(document, toQName(targetClass), targetClass); } @@ -242,8 +241,7 @@ public class XpathExpectationsHelper { * @throws XPathExpressionException if expression evaluation failed */ @SuppressWarnings("unchecked") - @Nullable - protected T evaluateXpath(Document document, QName evaluationType, Class expectedClass) + protected @Nullable T evaluateXpath(Document document, QName evaluationType, Class expectedClass) throws XPathExpressionException { return (T) getXpathExpression().evaluate(document, evaluationType); 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 aa08fffb79..12a3726e06 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,9 +1,7 @@ /** * General utility classes for use in unit and integration tests. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.util; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/validation/package-info.java b/spring-test/src/main/java/org/springframework/test/validation/package-info.java index caa3fdcadd..d4348ea12e 100644 --- a/spring-test/src/main/java/org/springframework/test/validation/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/validation/package-info.java @@ -1,9 +1,7 @@ /** * Testing support for validation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.validation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/UriAssert.java b/spring-test/src/main/java/org/springframework/test/web/UriAssert.java index 7fac1976fb..03e63dedfa 100644 --- a/spring-test/src/main/java/org/springframework/test/web/UriAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/UriAssert.java @@ -20,8 +20,8 @@ import org.assertj.core.api.AbstractStringAssert; import org.assertj.core.api.Assertions; import org.assertj.core.error.BasicErrorMessageFactory; import org.assertj.core.internal.Failures; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.web.util.UriComponentsBuilder; 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 6e075ff930..07c91a4afe 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 @@ -30,10 +30,11 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + 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; /** @@ -219,8 +220,7 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect /** * Return a matching expectation, or {@code null} if none match. */ - @Nullable - public RequestExpectation findExpectation(ClientHttpRequest request) throws IOException { + public @Nullable RequestExpectation findExpectation(ClientHttpRequest request) throws IOException { for (RequestExpectation expectation : this.expectations) { try { expectation.match(request); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java b/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java index d1fc550fa1..7ebbbad16c 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/DefaultRequestExpectation.java @@ -20,9 +20,10 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -38,8 +39,7 @@ public class DefaultRequestExpectation implements RequestExpectation { private final List requestMatchers = new ArrayList<>(1); - @Nullable - private ResponseCreator responseCreator; + private @Nullable ResponseCreator responseCreator; /** @@ -63,8 +63,7 @@ public class DefaultRequestExpectation implements RequestExpectation { return this.requestMatchers; } - @Nullable - protected ResponseCreator getResponseCreator() { + protected @Nullable ResponseCreator getResponseCreator() { return this.responseCreator; } diff --git a/spring-test/src/main/java/org/springframework/test/web/client/ResponseCreator.java b/spring-test/src/main/java/org/springframework/test/web/client/ResponseCreator.java index c9eb4e9c68..990d9b2d89 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/ResponseCreator.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/ResponseCreator.java @@ -18,9 +18,10 @@ package org.springframework.test.web.client; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.test.web.client.response.MockRestResponseCreators; /** diff --git a/spring-test/src/main/java/org/springframework/test/web/client/SimpleRequestExpectationManager.java b/spring-test/src/main/java/org/springframework/test/web/client/SimpleRequestExpectationManager.java index 12799b2588..b8c66ef832 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/SimpleRequestExpectationManager.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/SimpleRequestExpectationManager.java @@ -19,8 +19,9 @@ package org.springframework.test.web.client; import java.io.IOException; import java.util.Iterator; +import org.jspecify.annotations.Nullable; + import org.springframework.http.client.ClientHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -38,8 +39,7 @@ import org.springframework.util.Assert; public class SimpleRequestExpectationManager extends AbstractRequestExpectationManager { /** Expectations in the order of declaration (count may be > 1). */ - @Nullable - private Iterator expectationIterator; + private @Nullable Iterator expectationIterator; /** Track expectations that have a remaining count. */ private final RequestExpectationGroup repeatExpectations = new RequestExpectationGroup(); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java b/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java index de937e6051..fb9cb60204 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/match/ContentRequestMatchers.java @@ -32,6 +32,7 @@ import org.apache.tomcat.util.http.fileupload.FileUpload; import org.apache.tomcat.util.http.fileupload.UploadContext; import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Node; import org.springframework.core.io.Resource; @@ -39,7 +40,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.converter.FormHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.mock.http.MockHttpInputMessage; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.test.json.JsonAssert; @@ -424,13 +424,11 @@ public class ContentRequestMatchers { List fileItems = fileUpload.parseRequest(new UploadContext() { private final byte[] body = request.getBodyAsBytes(); @Override - @Nullable - public String getCharacterEncoding() { + public @Nullable String getCharacterEncoding() { return request.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING); } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return request.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); } @Override 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 da90493f25..a539a1b35f 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 @@ -21,10 +21,10 @@ import java.util.Map; import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; 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; 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 cb8a23d931..e8ce5ff395 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,9 +4,7 @@ * {@link org.springframework.test.web.client.match.MockRestRequestMatchers} * to gain access to instances of those implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.client.match; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ecfaf0c4a6..ddcf087c76 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,9 +2,7 @@ * Contains client-side REST testing support. * @see org.springframework.test.web.client.MockRestServiceServer */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.client; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java b/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java index 745f59e4b2..bed82cc6e9 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/response/DefaultResponseCreator.java @@ -21,6 +21,8 @@ import java.net.URI; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; @@ -28,7 +30,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.mock.http.client.MockClientHttpResponse; import org.springframework.test.web.client.ResponseCreator; import org.springframework.util.Assert; @@ -46,8 +47,7 @@ public class DefaultResponseCreator implements ResponseCreator { private byte[] content = new byte[0]; - @Nullable - private Resource contentResource; + private @Nullable Resource contentResource; private final HttpHeaders headers = new HttpHeaders(); diff --git a/spring-test/src/main/java/org/springframework/test/web/client/response/ExecutingResponseCreator.java b/spring-test/src/main/java/org/springframework/test/web/client/response/ExecutingResponseCreator.java index cbaa820b92..9ab07a724b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/client/response/ExecutingResponseCreator.java +++ b/spring-test/src/main/java/org/springframework/test/web/client/response/ExecutingResponseCreator.java @@ -18,10 +18,11 @@ package org.springframework.test.web.client.response; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.mock.http.client.MockClientHttpRequest; import org.springframework.test.web.client.ResponseCreator; import org.springframework.util.Assert; 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 dd84f73624..1cf47771f3 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 @@ -19,12 +19,13 @@ package org.springframework.test.web.client.response; import java.io.IOException; import java.net.URI; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.test.web.client.ResponseCreator; /** 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 242530cd14..aaa3062c04 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,9 +4,7 @@ * {@link org.springframework.test.web.client.response.MockRestResponseCreators} * to gain access to instances of those implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.client.response; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/package-info.java b/spring-test/src/main/java/org/springframework/test/web/package-info.java index 932a82dcfa..79de8a4d92 100644 --- a/spring-test/src/main/java/org/springframework/test/web/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/package-info.java @@ -1,9 +1,7 @@ /** * Helper classes for unit tests based on Spring's web support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/AbstractMockServerSpec.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/AbstractMockServerSpec.java index 856fe3f715..21dbcf3901 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/AbstractMockServerSpec.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/AbstractMockServerSpec.java @@ -20,7 +20,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.web.server.WebFilter; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; @@ -37,14 +38,11 @@ import org.springframework.web.server.session.WebSessionManager; abstract class AbstractMockServerSpec> implements WebTestClient.MockServerSpec { - @Nullable - private List filters; + private @Nullable List filters; - @Nullable - private WebSessionManager sessionManager; + private @Nullable WebSessionManager sessionManager; - @Nullable - private List configurers; + private @Nullable List configurers; AbstractMockServerSpec() { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java index 900a985c25..f01f772742 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultControllerSpec.java @@ -20,12 +20,13 @@ import java.util.ArrayList; import java.util.List; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.format.FormatterRegistry; import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.validation.Validator; @@ -153,32 +154,23 @@ class DefaultControllerSpec extends AbstractMockServerSpec contentTypeResolverConsumer; + private @Nullable Consumer contentTypeResolverConsumer; - @Nullable - private Consumer corsRegistryConsumer; + private @Nullable Consumer corsRegistryConsumer; - @Nullable - private Consumer argumentResolverConsumer; + private @Nullable Consumer argumentResolverConsumer; - @Nullable - private Consumer pathMatchConsumer; + private @Nullable Consumer pathMatchConsumer; - @Nullable - private Consumer messageCodecsConsumer; + private @Nullable Consumer messageCodecsConsumer; - @Nullable - private Consumer formattersConsumer; + private @Nullable Consumer formattersConsumer; - @Nullable - private Validator validator; + private @Nullable Validator validator; - @Nullable - private Consumer viewResolversConsumer; + private @Nullable Consumer viewResolversConsumer; - @Nullable - private Consumer executionConsumer; + private @Nullable Consumer executionConsumer; @Override public void configureContentTypeResolver(RequestedContentTypeResolverBuilder builder) { @@ -223,8 +215,7 @@ class DefaultControllerSpec extends AbstractMockServerSpec defaultCookies; + private final @Nullable MultiValueMap defaultCookies; private final Consumer> entityResultConsumer; @@ -183,21 +180,17 @@ class DefaultWebTestClient implements WebTestClient { private final HttpMethod httpMethod; - @Nullable - private URI uri; + private @Nullable URI uri; private final HttpHeaders headers; - @Nullable - private MultiValueMap cookies; + private @Nullable MultiValueMap cookies; - @Nullable - private BodyInserter inserter; + private @Nullable BodyInserter inserter; private final Map attributes = new LinkedHashMap<>(4); - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; private final String requestId; @@ -411,8 +404,7 @@ class DefaultWebTestClient implements WebTestClient { private final ClientResponse response; - @Nullable - private final JsonEncoderDecoder jsonEncoderDecoder; + private final @Nullable JsonEncoderDecoder jsonEncoderDecoder; private final Consumer> entityResultConsumer; @@ -649,8 +641,7 @@ class DefaultWebTestClient implements WebTestClient { private final EntityExchangeResult result; - @Nullable - private final JsonEncoderDecoder jsonEncoderDecoder; + private final @Nullable JsonEncoderDecoder jsonEncoderDecoder; private final boolean isEmpty; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java index 61a5e47f5a..8b704c7adb 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClientBuilder.java @@ -23,6 +23,8 @@ import java.util.List; import java.util.function.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.HttpComponentsClientHttpConnector; @@ -31,7 +33,6 @@ import org.springframework.http.client.reactive.JettyClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.client.reactive.ReactorNetty2ClientHttpConnector; import org.springframework.http.codec.ClientCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -76,37 +77,27 @@ class DefaultWebTestClientBuilder implements WebTestClient.Builder { } - @Nullable - private final WebHttpHandlerBuilder httpHandlerBuilder; + private final @Nullable WebHttpHandlerBuilder httpHandlerBuilder; - @Nullable - private ClientHttpConnector connector; + private @Nullable ClientHttpConnector connector; - @Nullable - private String baseUrl; + private @Nullable String baseUrl; - @Nullable - private UriBuilderFactory uriBuilderFactory; + private @Nullable UriBuilderFactory uriBuilderFactory; - @Nullable - private HttpHeaders defaultHeaders; + private @Nullable HttpHeaders defaultHeaders; - @Nullable - private MultiValueMap defaultCookies; + private @Nullable MultiValueMap defaultCookies; - @Nullable - private List filters; + private @Nullable List filters; private Consumer> entityResultConsumer = result -> {}; - @Nullable - private ExchangeStrategies strategies; + private @Nullable ExchangeStrategies strategies; - @Nullable - private List> strategiesConfigurers; + private @Nullable List> strategiesConfigurers; - @Nullable - private Duration responseTimeout; + private @Nullable Duration responseTimeout; /** Determine connector via classpath detection. */ diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProvider.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProvider.java index f6a6dc1cdd..fc5778eb77 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProvider.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/EncoderDecoderMappingProvider.java @@ -22,6 +22,7 @@ import java.util.Map; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.TypeRef; import com.jayway.jsonpath.spi.mapper.MappingProvider; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; import org.springframework.core.codec.Decoder; @@ -29,7 +30,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; @@ -56,21 +56,18 @@ final class EncoderDecoderMappingProvider implements MappingProvider { } - @Nullable @Override - public T map(Object source, Class targetType, Configuration configuration) { + public @Nullable T map(Object source, Class targetType, Configuration configuration) { return mapToTargetType(source, ResolvableType.forClass(targetType)); } - @Nullable @Override - public T map(Object source, TypeRef targetType, Configuration configuration) { + public @Nullable T map(Object source, TypeRef targetType, Configuration configuration) { return mapToTargetType(source, ResolvableType.forType(targetType.getType())); } @SuppressWarnings("unchecked") - @Nullable - private T mapToTargetType(Object source, ResolvableType targetType) { + private @Nullable T mapToTargetType(Object source, ResolvableType targetType) { DataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance; MimeType mimeType = MimeTypeUtils.APPLICATION_JSON; Map hints = Collections.emptyMap(); diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java index d071cbf628..98c013e086 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/EntityExchangeResult.java @@ -16,7 +16,7 @@ package org.springframework.test.web.reactive.server; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * {@code ExchangeResult} sub-class that exposes the response body fully @@ -29,8 +29,7 @@ import org.springframework.lang.Nullable; */ public class EntityExchangeResult extends ExchangeResult { - @Nullable - private final T body; + private final @Nullable T body; EntityExchangeResult(ExchangeResult result, @Nullable T body) { @@ -42,8 +41,7 @@ public class EntityExchangeResult extends ExchangeResult { /** * Return the entity extracted from the response body. */ - @Nullable - public T getResponseBody() { + public @Nullable T getResponseBody() { return this.body; } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java index 554fddfccb..c68c349eeb 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/ExchangeResult.java @@ -25,6 +25,7 @@ import java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; @@ -35,7 +36,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; 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.MultiValueMap; @@ -74,11 +74,9 @@ public class ExchangeResult { private final Duration timeout; - @Nullable - private final String uriTemplate; + private final @Nullable String uriTemplate; - @Nullable - private final Object mockServerResult; + private final @Nullable Object mockServerResult; /** Ensure single logging, for example, for expectAll. */ private boolean diagnosticsLogged; @@ -146,8 +144,7 @@ public class ExchangeResult { /** * Return the original URI template used to prepare the request, if any. */ - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } @@ -164,8 +161,7 @@ public class ExchangeResult { * for any reason yet, use of this method will trigger consumption. * @throws IllegalStateException if the request body has not been fully written. */ - @Nullable - public byte[] getRequestBodyContent() { + public byte @Nullable [] getRequestBodyContent() { return this.requestBody.block(this.timeout); } @@ -196,8 +192,7 @@ public class ExchangeResult { * yet, use of this method will trigger consumption. * @throws IllegalStateException if the response has not been fully read. */ - @Nullable - public byte[] getResponseBodyContent() { + public byte @Nullable [] getResponseBodyContent() { return this.responseBody.block(this.timeout); } @@ -207,8 +202,7 @@ public class ExchangeResult { * @since 5.3 * @see org.springframework.test.web.servlet.client.MockMvcWebTestClient#resultActionsFor(ExchangeResult) */ - @Nullable - public Object getMockServerResult() { + public @Nullable Object getMockServerResult() { return this.mockServerResult; } @@ -260,8 +254,7 @@ public class ExchangeResult { .collect(Collectors.joining(delimiter)); } - @Nullable - private String formatBody(@Nullable MediaType contentType, Mono body) { + private @Nullable String formatBody(@Nullable MediaType contentType, Mono body) { return body .map(bytes -> { if (contentType == null) { diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java index fe4abf6c85..f1c0558edf 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/HeaderAssertions.java @@ -22,12 +22,12 @@ import java.util.List; import java.util.function.Consumer; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.springframework.http.CacheControl; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonEncoderDecoder.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonEncoderDecoder.java index ae861713eb..311e88a804 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonEncoderDecoder.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonEncoderDecoder.java @@ -20,6 +20,8 @@ import java.util.Collection; import java.util.Map; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.codec.Decoder; import org.springframework.core.codec.Encoder; @@ -28,7 +30,6 @@ import org.springframework.http.codec.DecoderHttpMessageReader; import org.springframework.http.codec.EncoderHttpMessageWriter; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.HttpMessageWriter; -import org.springframework.lang.Nullable; /** * {@link Encoder} and {@link Decoder} that is able to encode and decode @@ -56,8 +57,7 @@ record JsonEncoderDecoder(Encoder encoder, Decoder decoder) { * @return a {@link JsonEncoderDecoder} or {@code null} if a suitable codec * is not available */ - @Nullable - static JsonEncoderDecoder from(Collection> messageWriters, + static @Nullable JsonEncoderDecoder from(Collection> messageWriters, Collection> messageReaders) { Encoder jsonEncoder = findJsonEncoder(messageWriters); @@ -75,15 +75,13 @@ record JsonEncoderDecoder(Encoder encoder, Decoder decoder) { * @param writers the writers to inspect * @return a suitable JSON {@link Encoder} or {@code null} */ - @Nullable - private static Encoder findJsonEncoder(Collection> writers) { + private static @Nullable Encoder findJsonEncoder(Collection> writers) { return findJsonEncoder(writers.stream() .filter(EncoderHttpMessageWriter.class::isInstance) .map(writer -> ((EncoderHttpMessageWriter) writer).getEncoder())); } - @Nullable - private static Encoder findJsonEncoder(Stream> stream) { + private static @Nullable Encoder findJsonEncoder(Stream> stream) { return stream .filter(encoder -> encoder.canEncode(MAP_TYPE, MediaType.APPLICATION_JSON)) .findFirst() @@ -96,15 +94,13 @@ record JsonEncoderDecoder(Encoder encoder, Decoder decoder) { * @param readers the readers to inspect * @return a suitable JSON {@link Decoder} or {@code null} */ - @Nullable - private static Decoder findJsonDecoder(Collection> readers) { + private static @Nullable Decoder findJsonDecoder(Collection> readers) { return findJsonDecoder(readers.stream() .filter(DecoderHttpMessageReader.class::isInstance) .map(reader -> ((DecoderHttpMessageReader) reader).getDecoder())); } - @Nullable - private static Decoder findJsonDecoder(Stream> decoderStream) { + private static @Nullable Decoder findJsonDecoder(Stream> decoderStream) { return decoderStream .filter(decoder -> decoder.canDecode(MAP_TYPE, MediaType.APPLICATION_JSON)) .findFirst() diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java index 6881a799bf..2094cc6858 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/JsonPathAssertions.java @@ -20,9 +20,9 @@ import java.util.function.Consumer; import com.jayway.jsonpath.Configuration; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.lang.Nullable; import org.springframework.test.util.JsonPathExpectationsHelper; import org.springframework.util.Assert; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java index 8d766d001c..e77d49b705 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClient.java @@ -26,6 +26,7 @@ import java.util.function.Consumer; import java.util.function.Function; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.context.ApplicationContext; @@ -39,7 +40,6 @@ import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.codec.ClientCodecConfigurer; import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.test.json.JsonComparator; import org.springframework.test.json.JsonCompareMode; import org.springframework.test.json.JsonComparison; diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClientConfigurer.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClientConfigurer.java index bf5bfb4393..6a31444089 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClientConfigurer.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WebTestClientConfigurer.java @@ -16,8 +16,9 @@ package org.springframework.test.web.reactive.server; +import org.jspecify.annotations.Nullable; + import org.springframework.http.client.reactive.ClientHttpConnector; -import org.springframework.lang.Nullable; import org.springframework.web.server.adapter.WebHttpHandlerBuilder; /** diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java index c502d883ad..4c13e93e77 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/WiretapConnector.java @@ -23,6 +23,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.Scannable; import reactor.core.publisher.Flux; @@ -37,7 +38,6 @@ import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.client.reactive.ClientHttpRequestDecorator; import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.client.reactive.ClientHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -129,11 +129,9 @@ class WiretapConnector implements ClientHttpConnector { */ static final class WiretapRecorder { - @Nullable - private final Flux publisher; + private final @Nullable Flux publisher; - @Nullable - private final Flux> publisherNested; + private final @Nullable Flux> publisherNested; private final DataBuffer buffer = DefaultDataBufferFactory.sharedInstance.allocateBuffer(256); @@ -223,8 +221,7 @@ class WiretapConnector implements ClientHttpConnector { */ private static class WiretapClientHttpRequest extends ClientHttpRequestDecorator { - @Nullable - private WiretapRecorder recorder; + private @Nullable WiretapRecorder recorder; public WiretapClientHttpRequest(ClientHttpRequest delegate) { @@ -280,8 +277,7 @@ class WiretapConnector implements ClientHttpConnector { return Flux.from(this.recorder.getPublisherToUse()); } - @Nullable - public Object getMockServerResult() { + public @Nullable Object getMockServerResult() { return (getDelegate() instanceof MockServerClientHttpResponse mockResponse ? mockResponse.getServerResult() : null); } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java index 57355a914f..396446e500 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/XpathAssertions.java @@ -24,9 +24,9 @@ import java.util.function.Consumer; import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.test.util.XpathExpectationsHelper; import org.springframework.util.Assert; import org.springframework.util.MimeType; 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 6813594214..cd03453759 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,9 +2,7 @@ * Support for testing Spring WebFlux server endpoints via * {@link org.springframework.test.web.reactive.server.WebTestClient}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.reactive.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java index 5582235cfb..82a5aa8e01 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/DefaultMvcResult.java @@ -20,7 +20,8 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.util.Assert; @@ -45,22 +46,17 @@ class DefaultMvcResult implements MvcResult { private final MockHttpServletResponse mockResponse; - @Nullable - private Object handler; + private @Nullable Object handler; - @Nullable - private HandlerInterceptor[] interceptors; + private HandlerInterceptor @Nullable [] interceptors; - @Nullable - private ModelAndView modelAndView; + private @Nullable ModelAndView modelAndView; - @Nullable - private Exception resolvedException; + private @Nullable Exception resolvedException; private final AtomicReference asyncResult = new AtomicReference<>(RESULT_NONE); - @Nullable - private CountDownLatch asyncDispatchLatch; + private @Nullable CountDownLatch asyncDispatchLatch; /** @@ -87,18 +83,16 @@ class DefaultMvcResult implements MvcResult { } @Override - @Nullable - public Object getHandler() { + public @Nullable Object getHandler() { return this.handler; } - public void setInterceptors(@Nullable HandlerInterceptor... interceptors) { + public void setInterceptors(HandlerInterceptor @Nullable ... interceptors) { this.interceptors = interceptors; } @Override - @Nullable - public HandlerInterceptor[] getInterceptors() { + public HandlerInterceptor @Nullable [] getInterceptors() { return this.interceptors; } @@ -107,8 +101,7 @@ class DefaultMvcResult implements MvcResult { } @Override - @Nullable - public Exception getResolvedException() { + public @Nullable Exception getResolvedException() { return this.resolvedException; } @@ -117,8 +110,7 @@ class DefaultMvcResult implements MvcResult { } @Override - @Nullable - public ModelAndView getModelAndView() { + public @Nullable ModelAndView getModelAndView() { return this.modelAndView; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java b/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java index 7acf46ba15..2d38806620 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvc.java @@ -27,9 +27,9 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.jspecify.annotations.Nullable; import org.springframework.beans.Mergeable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockFilterChain; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; @@ -78,11 +78,9 @@ public final class MockMvc { private final ServletContext servletContext; - @Nullable - private RequestBuilder defaultRequestBuilder; + private @Nullable RequestBuilder defaultRequestBuilder; - @Nullable - private Charset defaultResponseCharacterEncoding; + private @Nullable Charset defaultResponseCharacterEncoding; private List defaultResultMatchers = new ArrayList<>(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvcBuilderSupport.java b/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvcBuilderSupport.java index 40403ddf60..dd3a48eec4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvcBuilderSupport.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/MockMvcBuilderSupport.java @@ -21,9 +21,9 @@ import java.util.List; import jakarta.servlet.Filter; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockServletConfig; import org.springframework.web.context.WebApplicationContext; 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 31b2e15b47..9688bcd321 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,7 +16,8 @@ package org.springframework.test.web.servlet; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.web.servlet.FlashMap; @@ -48,30 +49,26 @@ public interface MvcResult { * Return the executed handler. * @return the handler, possibly {@code null} if none were executed */ - @Nullable - Object getHandler(); + @Nullable Object getHandler(); /** * Return interceptors around the handler. * @return interceptors, or {@code null} if none were selected */ - @Nullable - HandlerInterceptor[] getInterceptors(); + HandlerInterceptor @Nullable [] getInterceptors(); /** * Return the {@code ModelAndView} prepared by the handler. * @return a {@code ModelAndView}, or {@code null} if none */ - @Nullable - ModelAndView getModelAndView(); + @Nullable ModelAndView getModelAndView(); /** * Return any exception raised by a handler and successfully resolved * through a {@link HandlerExceptionResolver}. * @return an exception, or {@code null} if none */ - @Nullable - Exception getResolvedException(); + @Nullable Exception getResolvedException(); /** * Return the "output" flash attributes saved during request processing. diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java b/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java index 8b3b6d2d7b..afea3bfaa4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/TestDispatcherServlet.java @@ -24,8 +24,8 @@ import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockAsyncContext; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.util.Assert; @@ -118,8 +118,7 @@ final class TestDispatcherServlet extends DispatcherServlet { } @Override - @Nullable - protected HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { + protected @Nullable HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { HandlerExecutionChain chain = super.getHandler(request); if (chain != null) { DefaultMvcResult mvcResult = getMvcResult(request); @@ -139,8 +138,7 @@ final class TestDispatcherServlet extends DispatcherServlet { } @Override - @Nullable - protected ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, + protected @Nullable ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) throws Exception { ModelAndView mav = super.processHandlerException(request, response, handler, ex); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java index 6fc0dbd79a..d1dd8e3eb1 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/AbstractMockHttpServletResponseAssert.java @@ -23,8 +23,8 @@ import org.assertj.core.api.AbstractStringAssert; import org.assertj.core.api.Assertions; import org.assertj.core.api.ByteArrayAssert; import org.assertj.core.api.StringAssert; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.test.json.AbstractJsonContentAssert; @@ -44,8 +44,7 @@ import org.springframework.test.web.UriAssert; public abstract class AbstractMockHttpServletResponseAssert, ACTUAL> extends AbstractHttpServletResponseAssert { - @Nullable - private final HttpMessageContentConverter contentConverter; + private final @Nullable HttpMessageContentConverter contentConverter; protected AbstractMockHttpServletResponseAssert( @Nullable HttpMessageContentConverter contentConverter, ACTUAL actual, Class selfType) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java index 5a0303def5..67620be778 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/DefaultMvcTestResult.java @@ -16,7 +16,8 @@ package org.springframework.test.web.servlet.assertj; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.test.web.servlet.MvcResult; @@ -28,14 +29,11 @@ import org.springframework.test.web.servlet.MvcResult; */ final class DefaultMvcTestResult implements MvcTestResult { - @Nullable - private final MvcResult mvcResult; + private final @Nullable MvcResult mvcResult; - @Nullable - private final Exception unresolvedException; + private final @Nullable Exception unresolvedException; - @Nullable - private final HttpMessageContentConverter contentConverter; + private final @Nullable HttpMessageContentConverter contentConverter; DefaultMvcTestResult(@Nullable MvcResult mvcResult, @Nullable Exception unresolvedException, @@ -57,13 +55,11 @@ final class DefaultMvcTestResult implements MvcTestResult { } @Override - @Nullable - public Exception getUnresolvedException() { + public @Nullable Exception getUnresolvedException() { return this.unresolvedException; } - @Nullable - public Exception getResolvedException() { + public @Nullable Exception getResolvedException() { return getMvcResult().getResolvedException(); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java index e97be143bd..0f50be3926 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/HandlerResultAssert.java @@ -20,9 +20,9 @@ import java.lang.reflect.Method; import org.assertj.core.api.AbstractObjectAssert; import org.assertj.core.api.Assertions; +import org.jspecify.annotations.Nullable; import org.springframework.cglib.core.internal.Function; -import org.springframework.lang.Nullable; import org.springframework.test.util.MethodAssert; import org.springframework.util.ClassUtils; import org.springframework.web.method.HandlerMethod; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java index 309ee6c78a..9c8cfcc50d 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MockMvcTester.java @@ -24,10 +24,10 @@ import java.util.function.Function; import jakarta.servlet.DispatcherType; import org.assertj.core.api.AssertProvider; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockMultipartHttpServletRequest; import org.springframework.test.http.HttpMessageContentConverter; @@ -132,8 +132,7 @@ public final class MockMvcTester { private final MockMvc mockMvc; - @Nullable - private final HttpMessageContentConverter contentConverter; + private final @Nullable HttpMessageContentConverter contentConverter; private MockMvcTester(MockMvc mockMvc, @Nullable HttpMessageContentConverter contentConverter) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java index 73bcebdacc..c58773b538 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/ModelAssert.java @@ -24,8 +24,8 @@ import java.util.function.Predicate; import org.assertj.core.api.AbstractMapAssert; import org.assertj.core.error.BasicErrorMessageFactory; import org.assertj.core.internal.Failures; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.validation.AbstractBindingResultAssert; import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResultUtils; @@ -142,8 +142,7 @@ public class ModelAssert extends AbstractMapAssert { * Return the exception that was thrown unexpectedly while processing the * request, if any. */ - @Nullable - Exception getUnresolvedException(); + @Nullable Exception getUnresolvedException(); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java index 55fd9e0ec6..46c50fd4d7 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResultAssert.java @@ -30,8 +30,8 @@ import org.assertj.core.api.Assertions; import org.assertj.core.api.MapAssert; import org.assertj.core.error.BasicErrorMessageFactory; import org.assertj.core.internal.Failures; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.http.HttpMessageContentConverter; @@ -204,8 +204,7 @@ public class MvcTestResultAssert extends AbstractMockHttpServletResponseAssert initRequestBuilder( - HttpMethod httpMethod, URI uri, MockClientHttpRequest httpRequest, @Nullable byte[] bytes) { + HttpMethod httpMethod, URI uri, MockClientHttpRequest httpRequest, byte @Nullable [] bytes) { String contentType = httpRequest.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE); if (!StringUtils.startsWithIgnoreCase(contentType, "multipart/")) { @@ -266,27 +266,23 @@ public class MockMvcHttpConnector implements ClientHttpConnector { return this.mvcResult.getResponse(); } - @Nullable @Override - public Object getHandler() { + public @Nullable Object getHandler() { return this.mvcResult.getHandler(); } - @Nullable @Override - public HandlerInterceptor[] getInterceptors() { + public HandlerInterceptor @Nullable [] getInterceptors() { return this.mvcResult.getInterceptors(); } - @Nullable @Override - public ModelAndView getModelAndView() { + public @Nullable ModelAndView getModelAndView() { return this.mvcResult.getModelAndView(); } - @Nullable @Override - public Exception getResolvedException() { + public @Nullable Exception getResolvedException() { return this.mvcResult.getResolvedException(); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java index 28df853a01..bab99a0a41 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcWebTestClient.java @@ -19,11 +19,11 @@ package org.springframework.test.web.servlet.client; import java.util.function.Supplier; import jakarta.servlet.Filter; +import org.jspecify.annotations.Nullable; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.test.web.reactive.server.ExchangeResult; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.servlet.DispatcherServletCustomizer; @@ -297,7 +297,7 @@ public interface MockMvcWebTestClient { * {@link StandaloneMockMvcBuilder#addMappedInterceptors(String[], HandlerInterceptor...)}. */ ControllerSpec mappedInterceptors( - @Nullable String[] pathPatterns, HandlerInterceptor... interceptors); + String @Nullable [] pathPatterns, HandlerInterceptor... interceptors); /** * Set a ContentNegotiationManager. @@ -414,7 +414,7 @@ public interface MockMvcWebTestClient { * {@link RouterFunctionMockMvcBuilder#addMappedInterceptors(String[], HandlerInterceptor...)}. */ RouterFunctionSpec mappedInterceptors( - @Nullable String[] pathPatterns, HandlerInterceptor... interceptors); + String @Nullable [] pathPatterns, HandlerInterceptor... interceptors); /** * Specify the timeout value for async execution. diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/RouterFunctionMockMvcSpec.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/RouterFunctionMockMvcSpec.java index 5ff3e1dfc2..6a53caa81b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/RouterFunctionMockMvcSpec.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/RouterFunctionMockMvcSpec.java @@ -16,8 +16,9 @@ package org.springframework.test.web.servlet.client; +import org.jspecify.annotations.Nullable; + import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.setup.ConfigurableMockMvcBuilder; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.RouterFunctionMockMvcBuilder; @@ -58,7 +59,7 @@ class RouterFunctionMockMvcSpec extends AbstractMockMvcServerSpec { - @Nullable - private WebClient webClient; + private @Nullable WebClient webClient; protected MockMvcWebClientBuilder(MockMvc mockMvc) { 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 165a9c0c56..c79f231e71 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 @@ -28,8 +28,8 @@ import org.htmlunit.WebConnection; import org.htmlunit.WebRequest; import org.htmlunit.WebResponse; import org.htmlunit.util.Cookie; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpSession; import org.springframework.test.web.servlet.MockMvc; @@ -63,8 +63,7 @@ public final class MockMvcWebConnection implements WebConnection { private final MockMvc mockMvc; - @Nullable - private final String contextPath; + private final @Nullable String contextPath; private WebClient webClient; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/package-info.java index 9219e76328..98757e3787 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/package-info.java @@ -3,9 +3,7 @@ * and HtmlUnit. * @see org.springframework.test.web.servlet.MockMvc */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.htmlunit; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilder.java index 4092859f8f..219a5f8ab6 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/MockMvcHtmlUnitDriverBuilder.java @@ -18,9 +18,9 @@ package org.springframework.test.web.servlet.htmlunit.webdriver; import org.htmlunit.BrowserVersion; import org.htmlunit.WebClient; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.htmlunit.HtmlUnitDriver; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.htmlunit.MockMvcWebConnectionBuilderSupport; import org.springframework.test.web.servlet.htmlunit.WebRequestMatcher; @@ -49,8 +49,7 @@ import org.springframework.web.context.WebApplicationContext; */ public class MockMvcHtmlUnitDriverBuilder extends MockMvcWebConnectionBuilderSupport { - @Nullable - private HtmlUnitDriver driver; + private @Nullable HtmlUnitDriver driver; private boolean javascriptEnabled = true; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/package-info.java index e314c09e6f..85aa06c116 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/webdriver/package-info.java @@ -4,9 +4,7 @@ * @see org.springframework.test.web.servlet.MockMvc * @see org.openqa.selenium.htmlunit.HtmlUnitDriver */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.htmlunit.webdriver; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/package-info.java index 63a7fb0faa..46cbb3de8f 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/package-info.java @@ -2,9 +2,7 @@ * Contains server-side support for testing Spring MVC applications. * @see org.springframework.test.web.servlet.MockMvc */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java index 84e7cb47ef..44e45bdfbe 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockHttpServletRequestBuilder.java @@ -36,6 +36,7 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.beans.Mergeable; import org.springframework.beans.factory.NoSuchBeanDefinitionException; @@ -45,7 +46,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.FormHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.mock.web.MockHttpSession; @@ -82,39 +82,29 @@ public abstract class AbstractMockHttpServletRequestBuilder headers = new LinkedMultiValueMap<>(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockMultipartHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockMultipartHttpServletRequestBuilder.java index 9b9de5adb5..3fb7a6d127 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockMultipartHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/AbstractMockMultipartHttpServletRequestBuilder.java @@ -27,10 +27,10 @@ import java.util.List; import jakarta.servlet.ServletContext; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartHttpServletRequest; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java index 4ec50f72c0..a07eadbee6 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java @@ -23,11 +23,11 @@ import java.util.Locale; import java.util.Map; import jakarta.servlet.http.Cookie; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; 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.MockMvc; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilder.java index 4817e7fb49..d55417c112 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/MockMultipartHttpServletRequestBuilder.java @@ -27,10 +27,10 @@ import java.util.List; import jakarta.servlet.ServletContext; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartHttpServletRequest; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/request/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/request/package-info.java index 35a802a763..46d9933899 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/request/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/request/package-info.java @@ -4,9 +4,7 @@ * {@link org.springframework.test.web.servlet.request.MockMvcRequestBuilders} * to gain access to instances of those implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.request; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java index ce66b04499..5c711971e2 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/FlashAttributeResultMatchers.java @@ -17,8 +17,8 @@ package org.springframework.test.web.servlet.result; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.ResultMatcher; import static org.hamcrest.MatcherAssert.assertThat; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java index 01e722fffd..7222894da3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/JsonPathResultMatchers.java @@ -22,8 +22,8 @@ import com.jayway.jsonpath.JsonPath; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.hamcrest.core.StringStartsWith; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.util.JsonPathExpectationsHelper; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultMatcher; @@ -47,8 +47,7 @@ public class JsonPathResultMatchers { private final JsonPathExpectationsHelper jsonPathHelper; - @Nullable - private String prefix; + private @Nullable String prefix; /** diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java index f03d6c6ef3..7edc993435 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultHandlers.java @@ -23,8 +23,8 @@ import java.io.Writer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultHandler; import org.springframework.util.CollectionUtils; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java index a3392535bb..a5cc5e036a 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/MockMvcResultMatchers.java @@ -21,8 +21,8 @@ import java.util.Map; import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.util.AntPathMatcher; import org.springframework.web.util.UriComponentsBuilder; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java index 599c05f09b..68edeec652 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java @@ -17,8 +17,8 @@ package org.springframework.test.web.servlet.result; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.ui.ModelMap; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/PrintingResultHandler.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/PrintingResultHandler.java index 61952f7373..c155895175 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/PrintingResultHandler.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/PrintingResultHandler.java @@ -24,10 +24,10 @@ import java.util.stream.Collectors; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.core.style.ToStringCreator; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.web.servlet.MvcResult; @@ -172,7 +172,7 @@ public class PrintingResultHandler implements ResultHandler { /** * Print the handler. */ - protected void printHandler(@Nullable Object handler, @Nullable HandlerInterceptor[] interceptors) + protected void printHandler(@Nullable Object handler, HandlerInterceptor @Nullable [] interceptors) throws Exception { if (handler == null) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java index 2cd6f3b9fc..415d07373c 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/RequestResultMatchers.java @@ -21,8 +21,8 @@ import java.util.concurrent.Callable; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.util.Assert; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java b/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java index 3925b5ccab..bc7107a433 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/result/XpathResultMatchers.java @@ -21,10 +21,10 @@ import java.util.Map; import javax.xml.xpath.XPathExpressionException; import org.hamcrest.Matcher; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.util.XpathExpectationsHelper; import org.springframework.test.web.servlet.ResultMatcher; @@ -85,8 +85,7 @@ public class XpathResultMatchers { /** * Get the response encoding if explicitly defined in the response, {@code null} otherwise. */ - @Nullable - private String getDefinedEncoding(MockHttpServletResponse response) { + private @Nullable String getDefinedEncoding(MockHttpServletResponse response) { return (response.isCharset() ? response.getCharacterEncoding() : null); } 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 67057faef9..4c1c13105c 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,9 +4,7 @@ * and {@link org.springframework.test.web.servlet.result.MockMvcResultHandlers} * to access instances of those implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.result; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java index 1180d5a4a4..bf95cfee92 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/AbstractMockMvcBuilder.java @@ -26,8 +26,8 @@ import jakarta.servlet.DispatcherType; import jakarta.servlet.Filter; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockServletConfig; import org.springframework.test.web.servlet.DispatcherServletCustomizer; import org.springframework.test.web.servlet.MockMvc; @@ -62,11 +62,9 @@ public abstract class AbstractMockMvcBuilder private final List filters = new ArrayList<>(); - @Nullable - private RequestBuilder defaultRequestBuilder; + private @Nullable RequestBuilder defaultRequestBuilder; - @Nullable - private Charset defaultResponseCharacterEncoding; + private @Nullable Charset defaultResponseCharacterEncoding; private final List globalResultMatchers = new ArrayList<>(); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java index 40de7774f2..109280cd53 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/ConfigurableMockMvcBuilder.java @@ -23,8 +23,8 @@ import java.util.Map; import jakarta.servlet.DispatcherType; import jakarta.servlet.Filter; import jakarta.servlet.FilterConfig; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.DispatcherServletCustomizer; import org.springframework.test.web.servlet.MockMvcBuilder; import org.springframework.test.web.servlet.RequestBuilder; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurer.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurer.java index b7707efde9..bc00d50a1a 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurer.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurer.java @@ -16,7 +16,8 @@ package org.springframework.test.web.servlet.setup; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.web.context.WebApplicationContext; @@ -60,8 +61,7 @@ public interface MockMvcConfigurer { * @return a post processor to be applied to every request performed * through the {@code MockMvc} instance. */ - @Nullable - default RequestPostProcessor beforeMockMvcCreated( + default @Nullable RequestPostProcessor beforeMockMvcCreated( ConfigurableMockMvcBuilder builder, WebApplicationContext context) { return null; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurerAdapter.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurerAdapter.java index be680aef9b..2e18d12005 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurerAdapter.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcConfigurerAdapter.java @@ -16,7 +16,8 @@ package org.springframework.test.web.servlet.setup; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.web.context.WebApplicationContext; @@ -33,8 +34,7 @@ public abstract class MockMvcConfigurerAdapter implements MockMvcConfigurer { } @Override - @Nullable - public RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder builder, WebApplicationContext cxt) { + public @Nullable RequestPostProcessor beforeMockMvcCreated(ConfigurableMockMvcBuilder builder, WebApplicationContext cxt) { return null; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java index f07720d4ab..2204277e2d 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/MockMvcFilterDecorator.java @@ -32,8 +32,8 @@ import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockFilterConfig; import org.springframework.mock.web.MockFilterRegistration; import org.springframework.mock.web.MockServletContext; @@ -58,11 +58,9 @@ final class MockMvcFilterDecorator implements Filter { private final Filter delegate; - @Nullable - private final Function filterConfigInitializer; + private final @Nullable Function filterConfigInitializer; - @Nullable - private final EnumSet dispatcherTypes; + private final @Nullable EnumSet dispatcherTypes; private final boolean hasPatterns; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java index 079b363a26..716657637d 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/RouterFunctionMockMvcBuilder.java @@ -23,13 +23,13 @@ import java.util.List; import java.util.function.Supplier; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockServletContext; import org.springframework.util.Assert; import org.springframework.web.accept.ContentNegotiationManager; @@ -80,17 +80,13 @@ public class RouterFunctionMockMvcBuilder extends AbstractMockMvcBuilder mappedInterceptors = new ArrayList<>(); - @Nullable - private List handlerExceptionResolvers; + private @Nullable List handlerExceptionResolvers; - @Nullable - private Long asyncRequestTimeout; + private @Nullable Long asyncRequestTimeout; - @Nullable - private List viewResolvers; + private @Nullable List viewResolvers; - @Nullable - private PathPatternParser patternParser; + private @Nullable PathPatternParser patternParser; private Supplier handlerMappingFactory = RouterFunctionMapping::new; @@ -124,7 +120,7 @@ public class RouterFunctionMockMvcBuilder extends AbstractMockMvcBuilder controllers; - @Nullable - private List controllerAdvice; + private @Nullable List controllerAdvice; private List> messageConverters = new ArrayList<>(); @@ -102,36 +101,27 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder mappedInterceptors = new ArrayList<>(); - @Nullable - private Validator validator; + private @Nullable Validator validator; - @Nullable - private ContentNegotiationManager contentNegotiationManager; + private @Nullable ContentNegotiationManager contentNegotiationManager; - @Nullable - private FormattingConversionService conversionService; + private @Nullable FormattingConversionService conversionService; - @Nullable - private List handlerExceptionResolvers; + private @Nullable List handlerExceptionResolvers; - @Nullable - private Long asyncRequestTimeout; + private @Nullable Long asyncRequestTimeout; - @Nullable - private List viewResolvers; + private @Nullable List viewResolvers; private LocaleResolver localeResolver = new AcceptHeaderLocaleResolver(); - @Nullable - private FlashMapManager flashMapManager; + private @Nullable FlashMapManager flashMapManager; private boolean preferPathMatcher = false; - @Nullable - private PathPatternParser patternParser; + private @Nullable PathPatternParser patternParser; - @Nullable - private Boolean removeSemicolonContent; + private @Nullable Boolean removeSemicolonContent; private final Map placeholderValues = new HashMap<>(); @@ -210,7 +200,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder T getBean(Class requiredType, Object... args) throws BeansException { + public T getBean(Class requiredType, @Nullable Object @Nullable ... args) throws BeansException { return this.beanFactory.getBean(requiredType, args); } @@ -219,14 +218,12 @@ class StubWebApplicationContext implements WebApplicationContext { } @Override - @Nullable - public Class getType(String name) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name) throws NoSuchBeanDefinitionException { return this.beanFactory.getType(name); } @Override - @Nullable - public Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { + public @Nullable Class getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { return this.beanFactory.getType(name, allowFactoryBeanInit); } @@ -310,16 +307,14 @@ class StubWebApplicationContext implements WebApplicationContext { } @Override - @Nullable - public A findAnnotationOnBean(String beanName, Class annotationType) + public @Nullable A findAnnotationOnBean(String beanName, Class annotationType) throws NoSuchBeanDefinitionException{ return this.beanFactory.findAnnotationOnBean(beanName, annotationType); } @Override - @Nullable - public A findAnnotationOnBean( + public @Nullable A findAnnotationOnBean( String beanName, Class annotationType, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { @@ -340,8 +335,7 @@ class StubWebApplicationContext implements WebApplicationContext { //--------------------------------------------------------------------- @Override - @Nullable - public BeanFactory getParentBeanFactory() { + public @Nullable BeanFactory getParentBeanFactory() { return null; } @@ -356,13 +350,12 @@ class StubWebApplicationContext implements WebApplicationContext { //--------------------------------------------------------------------- @Override - @Nullable - public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) { + public @Nullable String getMessage(String code, Object @Nullable [] args, @Nullable String defaultMessage, Locale locale) { return this.messageSource.getMessage(code, args, defaultMessage, locale); } @Override - public String getMessage(String code, @Nullable Object[] args, Locale locale) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args, Locale locale) throws NoSuchMessageException { return this.messageSource.getMessage(code, args, locale); } @@ -377,8 +370,7 @@ class StubWebApplicationContext implements WebApplicationContext { //--------------------------------------------------------------------- @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -461,14 +453,12 @@ class StubWebApplicationContext implements WebApplicationContext { } @Override - @Nullable - public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) { + public @Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName) { throw new UnsupportedOperationException("Dependency resolution not supported"); } @Override - @Nullable - public Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, + public @Nullable Object resolveDependency(DependencyDescriptor descriptor, @Nullable String requestingBeanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) { throw new UnsupportedOperationException("Dependency resolution not supported"); } 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 f030410ea8..3d1b982464 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,9 +3,7 @@ * Use {@link org.springframework.test.web.servlet.setup.MockMvcBuilders} * to access to instances of those implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.setup; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactoryTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactoryTests.java index 2ed2498993..3d1ca60275 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactoryTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerFactoryTests.java @@ -19,9 +19,9 @@ package org.springframework.test.context.bean.override; import java.util.Collections; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.DummyBean.DummyBeanOverrideProcessor.DummyBeanOverrideHandler; import static org.assertj.core.api.Assertions.assertThat; @@ -90,8 +90,7 @@ class BeanOverrideContextCustomizerFactoryTests { }; } - @Nullable - private BeanOverrideContextCustomizer createContextCustomizer(Class testClass) { + private @Nullable BeanOverrideContextCustomizer createContextCustomizer(Class testClass) { return this.factory.createContextCustomizer(testClass, Collections.emptyList()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java index 9e01f72ca8..9e05c0499b 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTestUtils.java @@ -18,8 +18,9 @@ package org.springframework.test.context.bean.override; import java.util.Collections; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.MergedContextConfiguration; @@ -42,8 +43,7 @@ public abstract class BeanOverrideContextCustomizerTestUtils { * @param testClass a test class to introspect * @return a context customizer for bean override support, or null */ - @Nullable - public static ContextCustomizer createContextCustomizer(Class testClass) { + public static @Nullable ContextCustomizer createContextCustomizer(Class testClass) { return factory.createContextCustomizer(testClass, Collections.emptyList()); } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTests.java index 8944aeb2be..03886cf570 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideContextCustomizerTests.java @@ -20,11 +20,11 @@ import java.util.Arrays; import java.util.LinkedHashSet; import java.util.Objects; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java index 1a64107989..7b75f1343f 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/BeanOverrideHandlerTests.java @@ -26,10 +26,10 @@ import java.util.HashSet; import java.util.List; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.DummyBean.DummyBeanOverrideProcessor.DummyBeanOverrideHandler; import org.springframework.test.context.bean.override.example.CustomQualifier; import org.springframework.test.context.bean.override.example.ExampleService; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/DummyBean.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/DummyBean.java index d6beaf4ba3..b285510219 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/DummyBean.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/DummyBean.java @@ -24,9 +24,10 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.DummyBean.DummyBeanOverrideProcessor; import org.springframework.util.StringUtils; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java index c5cacb9472..4d04b95435 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/convention/TestBeanOverrideProcessorTests.java @@ -19,10 +19,10 @@ package org.springframework.test.context.bean.override.convention; import java.lang.reflect.Field; import java.lang.reflect.Method; +import org.jspecify.annotations.NonNull; import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.NonNull; import org.springframework.test.context.bean.override.example.ExampleService; import org.springframework.test.context.bean.override.example.TestBeanFactory; import org.springframework.util.ReflectionUtils; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/easymock/EasyMockBeanOverrideHandler.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/easymock/EasyMockBeanOverrideHandler.java index d93fafb783..519c009dbe 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/easymock/EasyMockBeanOverrideHandler.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/easymock/EasyMockBeanOverrideHandler.java @@ -20,11 +20,11 @@ import java.lang.reflect.Field; import org.easymock.EasyMock; import org.easymock.MockType; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.SingletonBeanRegistry; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.BeanOverrideHandler; import static org.springframework.test.context.bean.override.BeanOverrideStrategy.REPLACE_OR_CREATE; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/example/package-info.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/example/package-info.java index c642f01155..e140d79198 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/example/package-info.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/example/package-info.java @@ -1,9 +1,7 @@ /** * Example components for testing spring-test Bean overriding feature. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.context.bean.override.example; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java index fccb4b25ee..94acd25191 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanOverrideProcessorTests.java @@ -19,10 +19,10 @@ package org.springframework.test.context.bean.override.mockito; import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.BeanOverrideHandler; import org.springframework.test.context.bean.override.example.ExampleService; @@ -70,10 +70,9 @@ public class MockitoBeanOverrideProcessorTests { } static class MockitoConf { - @Nullable @MockitoBean @MockitoSpyBean - public ExampleService a; + public @Nullable ExampleService a; } } diff --git a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanWithResetIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanWithResetIntegrationTests.java index d75e512170..45846a83b2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanWithResetIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/bean/override/mockito/MockitoBeanWithResetIntegrationTests.java @@ -16,6 +16,7 @@ package org.springframework.test.context.bean.override.mockito; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; import org.junit.jupiter.api.Order; import org.junit.jupiter.api.Test; @@ -25,7 +26,6 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.lang.Nullable; import org.springframework.test.context.bean.override.example.ExampleService; import org.springframework.test.context.bean.override.example.FailingExampleService; import org.springframework.test.context.bean.override.example.RealExampleService; @@ -88,15 +88,13 @@ public class MockitoBeanWithResetIntegrationTests { } static class FailingExampleServiceFactory implements FactoryBean { - @Nullable @Override - public FailingExampleService getObject() { + public @Nullable FailingExampleService getObject() { return new FailingExampleService(); } - @Nullable @Override - public Class getObjectType() { + public @Nullable Class getObjectType() { return FailingExampleService.class; } } diff --git a/spring-test/src/test/java/org/springframework/test/context/customizers/GlobalFruitContextCustomizerFactory.java b/spring-test/src/test/java/org/springframework/test/context/customizers/GlobalFruitContextCustomizerFactory.java index 9a4e52c53b..27edfb51f2 100644 --- a/spring-test/src/test/java/org/springframework/test/context/customizers/GlobalFruitContextCustomizerFactory.java +++ b/spring-test/src/test/java/org/springframework/test/context/customizers/GlobalFruitContextCustomizerFactory.java @@ -18,8 +18,9 @@ package org.springframework.test.context.customizers; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.context.ContextConfigurationAttributes; import org.springframework.test.context.ContextCustomizer; import org.springframework.test.context.ContextCustomizerFactory; diff --git a/spring-test/src/test/java/org/springframework/test/context/failures/TrackingApplicationContextFailureProcessor.java b/spring-test/src/test/java/org/springframework/test/context/failures/TrackingApplicationContextFailureProcessor.java index 9b97c17a4b..504b32c65d 100644 --- a/spring-test/src/test/java/org/springframework/test/context/failures/TrackingApplicationContextFailureProcessor.java +++ b/spring-test/src/test/java/org/springframework/test/context/failures/TrackingApplicationContextFailureProcessor.java @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; -import org.springframework.lang.Nullable; import org.springframework.test.context.ApplicationContextFailureProcessor; /** diff --git a/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java b/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java index 994f349158..6873a2d341 100644 --- a/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java +++ b/spring-test/src/test/java/org/springframework/test/http/HttpMessageContentConverterTests.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.ResolvableType; @@ -30,7 +31,6 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.SmartHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.mock.http.MockHttpInputMessage; import org.springframework.mock.http.MockHttpOutputMessage; import org.springframework.util.StreamUtils; diff --git a/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java b/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java index 3e0536dfdd..dc5175957d 100644 --- a/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/http/MediaTypeAssertTests.java @@ -16,10 +16,10 @@ package org.springframework.test.http; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -201,8 +201,7 @@ class MediaTypeAssertTests { } - @Nullable - private static MediaType mediaType(@Nullable String mediaType) { + private static @Nullable MediaType mediaType(@Nullable String mediaType) { return (mediaType != null ? MediaType.parseMediaType(mediaType) : null); } diff --git a/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java b/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java index 1c276b2463..307ab69fd2 100644 --- a/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/json/AbstractJsonContentAssertTests.java @@ -34,6 +34,7 @@ import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.api.InstanceOfAssertFactory; import org.json.JSONException; import org.json.JSONObject; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestInstance; @@ -52,7 +53,6 @@ import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.FileCopyUtils; diff --git a/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java b/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java index 60a30b7799..12a41c164f 100644 --- a/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/json/JsonPathValueAssertTests.java @@ -25,11 +25,11 @@ import com.fasterxml.jackson.databind.ObjectMapper; import org.assertj.core.api.AssertProvider; import org.assertj.core.api.InstanceOfAssertFactories; import org.assertj.core.data.Offset; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.StringUtils; diff --git a/spring-test/src/test/java/org/springframework/test/util/MethodAssertTests.java b/spring-test/src/test/java/org/springframework/test/util/MethodAssertTests.java index 17f294d4ed..01b082a075 100644 --- a/spring-test/src/test/java/org/springframework/test/util/MethodAssertTests.java +++ b/spring-test/src/test/java/org/springframework/test/util/MethodAssertTests.java @@ -18,9 +18,9 @@ package org.springframework.test.util; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; diff --git a/spring-test/src/test/java/org/springframework/test/web/Person.java b/spring-test/src/test/java/org/springframework/test/web/Person.java index c3f11753b7..ac0df63ba3 100644 --- a/spring-test/src/test/java/org/springframework/test/web/Person.java +++ b/spring-test/src/test/java/org/springframework/test/web/Person.java @@ -18,8 +18,8 @@ package org.springframework.test.web; import jakarta.validation.constraints.NotNull; import jakarta.xml.bind.annotation.XmlRootElement; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; @XmlRootElement diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java index d90c55690c..c2ec58631d 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/ExchangeMutatorTests.java @@ -18,11 +18,11 @@ package org.springframework.test.web.reactive.server.samples; import java.security.Principal; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; import org.springframework.http.client.reactive.ClientHttpConnector; -import org.springframework.lang.Nullable; import org.springframework.test.web.reactive.server.MockServerConfigurer; import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.test.web.reactive.server.WebTestClientConfigurer; diff --git a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/Person.java b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/Person.java index 9092a82cef..7b4a5724a0 100644 --- a/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/Person.java +++ b/spring-test/src/test/java/org/springframework/test/web/reactive/server/samples/Person.java @@ -19,8 +19,7 @@ package org.springframework.test.web.reactive.server.samples; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import jakarta.xml.bind.annotation.XmlRootElement; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; @XmlRootElement class Person { diff --git a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java index 1ca87ca3d4..ec3625f08e 100644 --- a/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java +++ b/spring-test/src/test/java/org/springframework/test/web/servlet/assertj/MockMvcTesterTests.java @@ -25,6 +25,7 @@ import java.util.function.Consumer; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.cglib.core.internal.Function; @@ -35,7 +36,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockServletContext; import org.springframework.test.json.AbstractJsonContentAssert; diff --git a/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java b/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java index c385798a0f..65ebc3bb49 100644 --- a/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java +++ b/spring-tx/src/main/java/org/springframework/dao/CannotAcquireLockException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on failure to acquire a lock during an update, diff --git a/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java b/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java index 5487ffa670..ffeaa08da3 100644 --- a/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/ConcurrencyFailureException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on various data access concurrency failures. diff --git a/spring-tx/src/main/java/org/springframework/dao/DataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/DataAccessException.java index 9664399b13..e69f542dcd 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DataAccessException.java @@ -16,8 +16,9 @@ package org.springframework.dao; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Root of the hierarchy of data access exceptions discussed in diff --git a/spring-tx/src/main/java/org/springframework/dao/DataAccessResourceFailureException.java b/spring-tx/src/main/java/org/springframework/dao/DataAccessResourceFailureException.java index d484703785..3953829bd3 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DataAccessResourceFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DataAccessResourceFailureException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Data access exception thrown when a resource fails completely: diff --git a/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java b/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java index a4044aa648..32c1cb9f3f 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DataIntegrityViolationException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when an attempt to execute an SQL statement fails to map diff --git a/spring-tx/src/main/java/org/springframework/dao/DataRetrievalFailureException.java b/spring-tx/src/main/java/org/springframework/dao/DataRetrievalFailureException.java index 67e055adb3..a0c70c5eb6 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DataRetrievalFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DataRetrievalFailureException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown if certain expected data could not be retrieved, for example, diff --git a/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java b/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java index 06051f6e6e..94b8f229c5 100644 --- a/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java +++ b/spring-tx/src/main/java/org/springframework/dao/DuplicateKeyException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when an attempt to insert or update data diff --git a/spring-tx/src/main/java/org/springframework/dao/EmptyResultDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/EmptyResultDataAccessException.java index f3308118b7..61293d8b14 100644 --- a/spring-tx/src/main/java/org/springframework/dao/EmptyResultDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/EmptyResultDataAccessException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Data access exception thrown when a result was expected to have at least diff --git a/spring-tx/src/main/java/org/springframework/dao/IncorrectResultSizeDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/IncorrectResultSizeDataAccessException.java index 66b5d79a23..919c5bc896 100644 --- a/spring-tx/src/main/java/org/springframework/dao/IncorrectResultSizeDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/IncorrectResultSizeDataAccessException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Data access exception thrown when a result was not of the expected size, diff --git a/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessApiUsageException.java b/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessApiUsageException.java index dbf1b536dd..ffb80ae25a 100644 --- a/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessApiUsageException.java +++ b/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessApiUsageException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on incorrect usage of the API, such as failing to diff --git a/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessResourceUsageException.java b/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessResourceUsageException.java index e13fc2db7b..fd7a7febeb 100644 --- a/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessResourceUsageException.java +++ b/spring-tx/src/main/java/org/springframework/dao/InvalidDataAccessResourceUsageException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Root for exceptions thrown when we use a data access resource incorrectly. diff --git a/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessException.java index 7620c039f2..e682d47246 100644 --- a/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Root of the hierarchy of data access exceptions that are considered non-transient - diff --git a/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessResourceException.java b/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessResourceException.java index 5d8a8ebfbf..d750a90705 100644 --- a/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessResourceException.java +++ b/spring-tx/src/main/java/org/springframework/dao/NonTransientDataAccessResourceException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Data access exception thrown when a resource fails completely and the failure is permanent. diff --git a/spring-tx/src/main/java/org/springframework/dao/OptimisticLockingFailureException.java b/spring-tx/src/main/java/org/springframework/dao/OptimisticLockingFailureException.java index 09f16de1d7..fa8f685d06 100644 --- a/spring-tx/src/main/java/org/springframework/dao/OptimisticLockingFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/OptimisticLockingFailureException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on an optimistic locking violation. diff --git a/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java b/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java index 82749d8778..e7840f072c 100644 --- a/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java +++ b/spring-tx/src/main/java/org/springframework/dao/PessimisticLockingFailureException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on a pessimistic locking violation. diff --git a/spring-tx/src/main/java/org/springframework/dao/QueryTimeoutException.java b/spring-tx/src/main/java/org/springframework/dao/QueryTimeoutException.java index 6787815eba..6783352bdf 100644 --- a/spring-tx/src/main/java/org/springframework/dao/QueryTimeoutException.java +++ b/spring-tx/src/main/java/org/springframework/dao/QueryTimeoutException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception to be thrown on a query timeout. This could have different causes depending on diff --git a/spring-tx/src/main/java/org/springframework/dao/TransientDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/TransientDataAccessException.java index 761baabca1..1bb3883274 100644 --- a/spring-tx/src/main/java/org/springframework/dao/TransientDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/TransientDataAccessException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Root of the hierarchy of data access exceptions that are considered transient - diff --git a/spring-tx/src/main/java/org/springframework/dao/TypeMismatchDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/TypeMismatchDataAccessException.java index ac8c75651f..45560a00c2 100644 --- a/spring-tx/src/main/java/org/springframework/dao/TypeMismatchDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/TypeMismatchDataAccessException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown on mismatch between Java type and database type: diff --git a/spring-tx/src/main/java/org/springframework/dao/UncategorizedDataAccessException.java b/spring-tx/src/main/java/org/springframework/dao/UncategorizedDataAccessException.java index c8f1ff2a49..d987869fa0 100644 --- a/spring-tx/src/main/java/org/springframework/dao/UncategorizedDataAccessException.java +++ b/spring-tx/src/main/java/org/springframework/dao/UncategorizedDataAccessException.java @@ -16,7 +16,7 @@ package org.springframework.dao; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Normal superclass when we can't distinguish anything more specific 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 17d23ed157..4bf6941a46 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,9 +2,7 @@ * Annotation support for DAOs. Contains a bean post-processor for translating * persistence exceptions based on a repository stereotype annotation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.dao.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 da3fd7911e..b0ed420b86 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,9 +13,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.dao; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-tx/src/main/java/org/springframework/dao/support/ChainedPersistenceExceptionTranslator.java b/spring-tx/src/main/java/org/springframework/dao/support/ChainedPersistenceExceptionTranslator.java index 0496afe5ea..58b033e3f9 100644 --- a/spring-tx/src/main/java/org/springframework/dao/support/ChainedPersistenceExceptionTranslator.java +++ b/spring-tx/src/main/java/org/springframework/dao/support/ChainedPersistenceExceptionTranslator.java @@ -19,8 +19,9 @@ package org.springframework.dao.support; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -55,8 +56,7 @@ public class ChainedPersistenceExceptionTranslator implements PersistenceExcepti @Override - @Nullable - public DataAccessException translateExceptionIfPossible(RuntimeException ex) { + public @Nullable DataAccessException translateExceptionIfPossible(RuntimeException ex) { for (PersistenceExceptionTranslator pet : this.delegates) { DataAccessException translatedDex = pet.translateExceptionIfPossible(ex); if (translatedDex != null) { 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 6d610a9466..a35d5a117b 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,11 +22,12 @@ import java.util.List; import java.util.Optional; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + 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; @@ -50,8 +51,7 @@ public abstract class DataAccessUtils { * @throws IncorrectResultSizeDataAccessException if more than one * element has been found in the given Collection */ - @Nullable - public static T singleResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { + public static @Nullable T singleResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { if (CollectionUtils.isEmpty(results)) { return null; } @@ -71,8 +71,7 @@ public abstract class DataAccessUtils { * element has been found in the given Stream * @since 6.1 */ - @Nullable - public static T singleResult(@Nullable Stream results) throws IncorrectResultSizeDataAccessException { + public static @Nullable T singleResult(@Nullable Stream results) throws IncorrectResultSizeDataAccessException { if (results == null) { return null; } @@ -95,8 +94,7 @@ public abstract class DataAccessUtils { * element has been found in the given Iterator * @since 6.1 */ - @Nullable - public static T singleResult(@Nullable Iterator results) throws IncorrectResultSizeDataAccessException { + public static @Nullable T singleResult(@Nullable Iterator results) throws IncorrectResultSizeDataAccessException { if (results == null) { return null; } @@ -186,8 +184,7 @@ public abstract class DataAccessUtils { * has been found in the given Collection * @since 5.0.2 */ - @Nullable - public static T nullableSingleResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { + public static @Nullable T nullableSingleResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { // This is identical to the requiredSingleResult implementation but differs in the // semantics of the incoming Collection (which we currently can't formally express) if (CollectionUtils.isEmpty(results)) { @@ -209,8 +206,7 @@ public abstract class DataAccessUtils { * result object has been found in the given Collection * @see org.springframework.util.CollectionUtils#hasUniqueObject */ - @Nullable - public static T uniqueResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { + public static @Nullable T uniqueResult(@Nullable Collection results) throws IncorrectResultSizeDataAccessException { if (CollectionUtils.isEmpty(results)) { return null; } diff --git a/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java b/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java index 5844eb1c70..564f11649d 100644 --- a/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java +++ b/spring-tx/src/main/java/org/springframework/dao/support/PersistenceExceptionTranslationInterceptor.java @@ -18,6 +18,7 @@ package org.springframework.dao.support; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanCreationNotAllowedException; @@ -25,7 +26,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -46,13 +46,11 @@ import org.springframework.util.ReflectionUtils; public class PersistenceExceptionTranslationInterceptor implements MethodInterceptor, BeanFactoryAware, InitializingBean { - @Nullable - private volatile PersistenceExceptionTranslator persistenceExceptionTranslator; + private volatile @Nullable PersistenceExceptionTranslator persistenceExceptionTranslator; private boolean alwaysTranslate = false; - @Nullable - private ListableBeanFactory beanFactory; + private @Nullable ListableBeanFactory beanFactory; /** @@ -132,8 +130,7 @@ public class PersistenceExceptionTranslationInterceptor @Override - @Nullable - public Object invoke(MethodInvocation mi) throws Throwable { + public @Nullable Object invoke(MethodInvocation mi) throws Throwable { try { return mi.proceed(); } 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 282d6c5c1a..6640ee14ba 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 @@ -16,8 +16,9 @@ package org.springframework.dao.support; +import org.jspecify.annotations.Nullable; + import org.springframework.dao.DataAccessException; -import org.springframework.lang.Nullable; /** * Interface implemented by Spring integrations with data access technologies @@ -52,7 +53,6 @@ public interface PersistenceExceptionTranslator { * @see org.springframework.dao.DataIntegrityViolationException * @see org.springframework.jdbc.support.SQLExceptionTranslator */ - @Nullable - DataAccessException translateExceptionIfPossible(RuntimeException ex); + @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 1efd755dd1..fc49b288be 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,9 +2,7 @@ * Support classes for DAO implementations, * providing miscellaneous utility methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.dao.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 e6b8eae942..9ec48e76ac 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 @@ -29,9 +29,9 @@ import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.lang.Nullable; import org.springframework.transaction.jta.SimpleTransactionFactory; import org.springframework.transaction.jta.TransactionFactory; import org.springframework.util.Assert; @@ -51,16 +51,13 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private TransactionFactory transactionFactory; + private @Nullable TransactionFactory transactionFactory; - @Nullable - private String transactionName; + private @Nullable String transactionName; private int transactionTimeout = -1; - @Nullable - private String beanName; + private @Nullable String beanName; /** @@ -141,8 +138,7 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF * @see #setBeanName */ @Override - @Nullable - public String getActivationName() { + public @Nullable String getActivationName() { return this.beanName; } @@ -151,8 +147,7 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF * returning {@code} null in order to indicate a synthetic endpoint type. */ @Override - @Nullable - public Class getEndpointClass() { + public @Nullable Class getEndpointClass() { return null; } @@ -206,13 +201,11 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF */ protected abstract class AbstractMessageEndpoint implements MessageEndpoint { - @Nullable - private TransactionDelegate transactionDelegate; + private @Nullable TransactionDelegate transactionDelegate; private boolean beforeDeliveryCalled = false; - @Nullable - private ClassLoader previousContextClassLoader; + private @Nullable ClassLoader previousContextClassLoader; /** * Initialize this endpoint's TransactionDelegate. @@ -319,11 +312,9 @@ public abstract class AbstractMessageEndpointFactory implements MessageEndpointF */ private class TransactionDelegate { - @Nullable - private final XAResource xaResource; + private final @Nullable XAResource xaResource; - @Nullable - private Transaction transaction; + private @Nullable Transaction transaction; private boolean rollbackOnly; diff --git a/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java b/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java index 7ac7272c76..874471dc8b 100644 --- a/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java +++ b/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointFactory.java @@ -23,10 +23,10 @@ import jakarta.resource.spi.UnavailableException; import jakarta.resource.spi.endpoint.MessageEndpoint; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.support.DelegatingIntroductionInterceptor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; @@ -54,8 +54,7 @@ import org.springframework.util.ReflectionUtils; */ public class GenericMessageEndpointFactory extends AbstractMessageEndpointFactory { - @Nullable - private Object messageListener; + private @Nullable Object messageListener; /** @@ -108,8 +107,7 @@ public class GenericMessageEndpointFactory extends AbstractMessageEndpointFactor private class GenericMessageEndpoint extends AbstractMessageEndpoint implements MethodInterceptor { @Override - @Nullable - public Object invoke(MethodInvocation methodInvocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation methodInvocation) throws Throwable { Throwable endpointEx = null; boolean applyDeliveryCalls = !hasBeforeDeliveryBeenCalled(); if (applyDeliveryCalls) { diff --git a/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointManager.java b/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointManager.java index 8ae0cbd274..5512f638fa 100644 --- a/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointManager.java +++ b/spring-tx/src/main/java/org/springframework/jca/endpoint/GenericMessageEndpointManager.java @@ -20,11 +20,11 @@ import jakarta.resource.ResourceException; import jakarta.resource.spi.ActivationSpec; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.endpoint.MessageEndpointFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.SmartLifecycle; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -152,14 +152,11 @@ import org.springframework.util.Assert; */ public class GenericMessageEndpointManager implements SmartLifecycle, InitializingBean, DisposableBean { - @Nullable - private ResourceAdapter resourceAdapter; + private @Nullable ResourceAdapter resourceAdapter; - @Nullable - private MessageEndpointFactory messageEndpointFactory; + private @Nullable MessageEndpointFactory messageEndpointFactory; - @Nullable - private ActivationSpec activationSpec; + private @Nullable ActivationSpec activationSpec; private boolean autoStartup = true; @@ -180,8 +177,7 @@ public class GenericMessageEndpointManager implements SmartLifecycle, Initializi /** * Return the JCA ResourceAdapter to manage endpoints for. */ - @Nullable - public ResourceAdapter getResourceAdapter() { + public @Nullable ResourceAdapter getResourceAdapter() { return this.resourceAdapter; } @@ -200,8 +196,7 @@ public class GenericMessageEndpointManager implements SmartLifecycle, Initializi /** * Return the JCA MessageEndpointFactory to activate. */ - @Nullable - public MessageEndpointFactory getMessageEndpointFactory() { + public @Nullable MessageEndpointFactory getMessageEndpointFactory() { return this.messageEndpointFactory; } @@ -217,8 +212,7 @@ public class GenericMessageEndpointManager implements SmartLifecycle, Initializi /** * Return the JCA ActivationSpec to use for activating the endpoint. */ - @Nullable - public ActivationSpec getActivationSpec() { + public @Nullable ActivationSpec getActivationSpec() { return this.activationSpec; } 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 45f3610a9e..845c4abcc8 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,9 +1,7 @@ /** * This package provides a facility for generic JCA message endpoint management. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jca.endpoint; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-tx/src/main/java/org/springframework/jca/support/LocalConnectionFactoryBean.java b/spring-tx/src/main/java/org/springframework/jca/support/LocalConnectionFactoryBean.java index f7a0be1fe4..95edc20fff 100644 --- a/spring-tx/src/main/java/org/springframework/jca/support/LocalConnectionFactoryBean.java +++ b/spring-tx/src/main/java/org/springframework/jca/support/LocalConnectionFactoryBean.java @@ -19,10 +19,10 @@ package org.springframework.jca.support; import jakarta.resource.ResourceException; import jakarta.resource.spi.ConnectionManager; import jakarta.resource.spi.ManagedConnectionFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * {@link org.springframework.beans.factory.FactoryBean} that creates @@ -69,14 +69,11 @@ import org.springframework.lang.Nullable; */ public class LocalConnectionFactoryBean implements FactoryBean, InitializingBean { - @Nullable - private ManagedConnectionFactory managedConnectionFactory; + private @Nullable ManagedConnectionFactory managedConnectionFactory; - @Nullable - private ConnectionManager connectionManager; + private @Nullable ConnectionManager connectionManager; - @Nullable - private Object connectionFactory; + private @Nullable Object connectionFactory; /** @@ -126,14 +123,12 @@ public class LocalConnectionFactoryBean implements FactoryBean, Initiali @Override - @Nullable - public Object getObject() { + public @Nullable Object getObject() { return this.connectionFactory; } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return (this.connectionFactory != null ? this.connectionFactory.getClass() : null); } diff --git a/spring-tx/src/main/java/org/springframework/jca/support/ResourceAdapterFactoryBean.java b/spring-tx/src/main/java/org/springframework/jca/support/ResourceAdapterFactoryBean.java index 9969c97d57..9bec3c3e71 100644 --- a/spring-tx/src/main/java/org/springframework/jca/support/ResourceAdapterFactoryBean.java +++ b/spring-tx/src/main/java/org/springframework/jca/support/ResourceAdapterFactoryBean.java @@ -21,12 +21,12 @@ import jakarta.resource.spi.BootstrapContext; import jakarta.resource.spi.ResourceAdapter; import jakarta.resource.spi.XATerminator; import jakarta.resource.spi.work.WorkManager; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * {@link org.springframework.beans.factory.FactoryBean} that bootstraps @@ -50,17 +50,13 @@ import org.springframework.lang.Nullable; */ public class ResourceAdapterFactoryBean implements FactoryBean, InitializingBean, DisposableBean { - @Nullable - private ResourceAdapter resourceAdapter; + private @Nullable ResourceAdapter resourceAdapter; - @Nullable - private BootstrapContext bootstrapContext; + private @Nullable BootstrapContext bootstrapContext; - @Nullable - private WorkManager workManager; + private @Nullable WorkManager workManager; - @Nullable - private XATerminator xaTerminator; + private @Nullable XATerminator xaTerminator; /** @@ -129,8 +125,7 @@ public class ResourceAdapterFactoryBean implements FactoryBean, @Override - @Nullable - public ResourceAdapter getObject() { + public @Nullable ResourceAdapter getObject() { return this.resourceAdapter; } 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 fac8e45d5a..2ad24cea85 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 @@ -24,8 +24,8 @@ import jakarta.resource.spi.XATerminator; import jakarta.resource.spi.work.WorkContext; import jakarta.resource.spi.work.WorkManager; import jakarta.transaction.TransactionSynchronizationRegistry; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,14 +42,11 @@ import org.springframework.util.Assert; */ public class SimpleBootstrapContext implements BootstrapContext { - @Nullable - private final WorkManager workManager; + private final @Nullable WorkManager workManager; - @Nullable - private XATerminator xaTerminator; + private @Nullable XATerminator xaTerminator; - @Nullable - private TransactionSynchronizationRegistry transactionSynchronizationRegistry; + private @Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry; /** @@ -96,8 +93,7 @@ public class SimpleBootstrapContext implements BootstrapContext { } @Override - @Nullable - public XATerminator getXATerminator() { + public @Nullable XATerminator getXATerminator() { return this.xaTerminator; } @@ -112,8 +108,7 @@ public class SimpleBootstrapContext implements BootstrapContext { } @Override - @Nullable - public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { + public @Nullable TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { return this.transactionSynchronizationRegistry; } 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 547844092e..ee725852c5 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,9 +2,7 @@ * Provides generic support classes for JCA usage within Spring, * mainly for local setup of a JCA ResourceAdapter and/or ConnectionFactory. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.jca.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 345b5bf27f..08910f4f98 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/PlatformTransactionManager.java @@ -16,7 +16,7 @@ package org.springframework.transaction; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * This is the central interface in Spring's imperative transaction infrastructure. diff --git a/spring-tx/src/main/java/org/springframework/transaction/ReactiveTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/ReactiveTransactionManager.java index 6be097faf7..a62f38bbe8 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/ReactiveTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/ReactiveTransactionManager.java @@ -16,10 +16,9 @@ package org.springframework.transaction; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; - /** * This is the central interface in Spring's reactive transaction infrastructure. * Applications can use this directly, but it is not primarily meant as an API: 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 5b07f20378..2a35ced3d8 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/TransactionDefinition.java +++ b/spring-tx/src/main/java/org/springframework/transaction/TransactionDefinition.java @@ -16,7 +16,7 @@ package org.springframework.transaction; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface that defines Spring-compliant transaction properties. @@ -272,8 +272,7 @@ public interface TransactionDefinition { * @see org.springframework.transaction.interceptor.TransactionAspectSupport * @see org.springframework.transaction.support.TransactionSynchronizationManager#getCurrentTransactionName() */ - @Nullable - default String getName() { + default @Nullable String getName() { return null; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/TransactionExecutionListener.java b/spring-tx/src/main/java/org/springframework/transaction/TransactionExecutionListener.java index 768c90cbdb..cf0ce824de 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/TransactionExecutionListener.java +++ b/spring-tx/src/main/java/org/springframework/transaction/TransactionExecutionListener.java @@ -16,7 +16,7 @@ package org.springframework.transaction; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Callback interface for stateless listening to transaction creation/completion steps 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 eb1e833ccf..3615a2b156 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/TransactionSystemException.java +++ b/spring-tx/src/main/java/org/springframework/transaction/TransactionSystemException.java @@ -16,7 +16,8 @@ package org.springframework.transaction; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -29,8 +30,7 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class TransactionSystemException extends TransactionException { - @Nullable - private Throwable applicationException; + private @Nullable Throwable applicationException; /** @@ -71,8 +71,7 @@ public class TransactionSystemException extends TransactionException { * if any. * @return the application exception, or {@code null} if none set */ - @Nullable - public final Throwable getApplicationException() { + public final @Nullable Throwable getApplicationException() { return this.applicationException; } @@ -81,8 +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() { + public @Nullable Throwable getOriginalException() { return (this.applicationException != null ? this.applicationException : getCause()); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java index 178bd5640d..8f2dfb724a 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/AbstractTransactionManagementConfiguration.java @@ -18,6 +18,8 @@ package org.springframework.transaction.annotation; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Bean; @@ -26,7 +28,6 @@ import org.springframework.context.annotation.ImportAware; import org.springframework.context.annotation.Role; import org.springframework.core.annotation.AnnotationAttributes; import org.springframework.core.type.AnnotationMetadata; -import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionManager; import org.springframework.transaction.config.TransactionManagementConfigUtils; import org.springframework.transaction.event.TransactionalEventListenerFactory; @@ -47,14 +48,12 @@ import org.springframework.util.CollectionUtils; @Configuration public abstract class AbstractTransactionManagementConfiguration implements ImportAware { - @Nullable - protected AnnotationAttributes enableTx; + protected @Nullable AnnotationAttributes enableTx; /** * Default transaction manager, as configured through a {@link TransactionManagementConfigurer}. */ - @Nullable - protected TransactionManager txManager; + protected @Nullable TransactionManager txManager; @Override 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 bc89a10511..7d11562bd0 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,7 +23,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.interceptor.AbstractFallbackTransactionAttributeSource; import org.springframework.transaction.interceptor.RollbackRuleAttribute; import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute; @@ -73,8 +74,7 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa private boolean publicMethodsOnly = true; - @Nullable - private Set defaultRollbackRules; + private @Nullable Set defaultRollbackRules; /** @@ -175,14 +175,12 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa } @Override - @Nullable - protected TransactionAttribute findTransactionAttribute(Class clazz) { + protected @Nullable TransactionAttribute findTransactionAttribute(Class clazz) { return determineTransactionAttribute(clazz); } @Override - @Nullable - protected TransactionAttribute findTransactionAttribute(Method method) { + protected @Nullable TransactionAttribute findTransactionAttribute(Method method) { return determineTransactionAttribute(method); } @@ -196,8 +194,7 @@ public class AnnotationTransactionAttributeSource extends AbstractFallbackTransa * @param element the annotated method or class * @return the configured transaction attribute, or {@code null} if none was found */ - @Nullable - protected TransactionAttribute determineTransactionAttribute(AnnotatedElement element) { + protected @Nullable TransactionAttribute determineTransactionAttribute(AnnotatedElement element) { for (TransactionAnnotationParser parser : this.annotationParsers) { TransactionAttribute attr = parser.parseTransactionAnnotation(element); if (attr != null) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java index 52fd72c192..5aab318831 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/Ejb3TransactionAnnotationParser.java @@ -21,9 +21,9 @@ import java.lang.reflect.AnnotatedElement; import jakarta.ejb.ApplicationException; import jakarta.ejb.TransactionAttributeType; +import org.jspecify.annotations.Nullable; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.transaction.interceptor.DefaultTransactionAttribute; import org.springframework.transaction.interceptor.TransactionAttribute; @@ -44,8 +44,7 @@ public class Ejb3TransactionAnnotationParser implements TransactionAnnotationPar } @Override - @Nullable - public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { + public @Nullable TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { jakarta.ejb.TransactionAttribute ann = element.getAnnotation(jakarta.ejb.TransactionAttribute.class); if (ann != null) { return parseTransactionAnnotation(ann); diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/JtaTransactionAnnotationParser.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/JtaTransactionAnnotationParser.java index ab933c6c11..f12133d9c6 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/JtaTransactionAnnotationParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/JtaTransactionAnnotationParser.java @@ -21,10 +21,11 @@ import java.lang.reflect.AnnotatedElement; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + 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.transaction.interceptor.NoRollbackRuleAttribute; import org.springframework.transaction.interceptor.RollbackRuleAttribute; import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute; @@ -47,8 +48,7 @@ public class JtaTransactionAnnotationParser implements TransactionAnnotationPars } @Override - @Nullable - public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { + public @Nullable TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { AnnotationAttributes attributes = AnnotatedElementUtils.getMergedAnnotationAttributes( element, jakarta.transaction.Transactional.class); if (attributes != null) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java index 36dd09936b..942b50f5ab 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/SpringTransactionAnnotationParser.java @@ -22,10 +22,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + 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.transaction.interceptor.NoRollbackRuleAttribute; import org.springframework.transaction.interceptor.RollbackRuleAttribute; import org.springframework.transaction.interceptor.RuleBasedTransactionAttribute; @@ -51,8 +52,7 @@ public class SpringTransactionAnnotationParser implements TransactionAnnotationP } @Override - @Nullable - public TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { + public @Nullable TransactionAttribute parseTransactionAnnotation(AnnotatedElement element) { AnnotationAttributes attributes = AnnotatedElementUtils.findMergedAnnotationAttributes( element, Transactional.class, false, false); if (attributes != null) { 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 8aa5f2b280..14043deec4 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,7 +18,8 @@ package org.springframework.transaction.annotation; import java.lang.reflect.AnnotatedElement; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.interceptor.TransactionAttribute; /** @@ -66,7 +67,6 @@ public interface TransactionAnnotationParser { * @return the configured transaction attribute, or {@code null} if none found * @see AnnotationTransactionAttributeSource#determineTransactionAttribute */ - @Nullable - TransactionAttribute parseTransactionAnnotation(AnnotatedElement element); + @Nullable TransactionAttribute parseTransactionAnnotation(AnnotatedElement element); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessor.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessor.java index 93f8114cf7..7f2ea3e9e6 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessor.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessor.java @@ -20,6 +20,8 @@ import java.lang.reflect.AnnotatedElement; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotProcessor; import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.annotation.MergedAnnotations; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -47,8 +48,7 @@ class TransactionBeanRegistrationAotProcessor implements BeanRegistrationAotProc @Override - @Nullable - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); if (isTransactional(beanClass)) { return new AotContribution(beanClass); diff --git a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java index 94f968d951..06918ff2bc 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java +++ b/spring-tx/src/main/java/org/springframework/transaction/annotation/TransactionRuntimeHints.java @@ -16,12 +16,13 @@ package org.springframework.transaction.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint; import org.springframework.aot.hint.TypeReference; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that registers runtime hints 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 fdef1fa4b5..af05a2af60 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,9 +3,7 @@ * Hooked into Spring's transaction interception infrastructure * via a special TransactionAttributeSource implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-tx/src/main/java/org/springframework/transaction/config/AnnotationDrivenBeanDefinitionParser.java b/spring-tx/src/main/java/org/springframework/transaction/config/AnnotationDrivenBeanDefinitionParser.java index d7dca39ef5..5a0ffac962 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/config/AnnotationDrivenBeanDefinitionParser.java +++ b/spring-tx/src/main/java/org/springframework/transaction/config/AnnotationDrivenBeanDefinitionParser.java @@ -16,6 +16,7 @@ package org.springframework.transaction.config; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.aop.config.AopNamespaceUtils; @@ -26,7 +27,6 @@ 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.transaction.event.TransactionalEventListenerFactory; import org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor; import org.springframework.transaction.interceptor.TransactionInterceptor; @@ -58,8 +58,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { * with the container as necessary. */ @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { registerTransactionalEventListenerFactory(parserContext); String mode = element.getAttribute("mode"); if ("aspectj".equals(mode)) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/config/JtaTransactionManagerFactoryBean.java b/spring-tx/src/main/java/org/springframework/transaction/config/JtaTransactionManagerFactoryBean.java index 7ca1edb538..ff807e18d4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/config/JtaTransactionManagerFactoryBean.java +++ b/spring-tx/src/main/java/org/springframework/transaction/config/JtaTransactionManagerFactoryBean.java @@ -16,9 +16,10 @@ package org.springframework.transaction.config; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.jta.JtaTransactionManager; @@ -41,8 +42,7 @@ public class JtaTransactionManagerFactoryBean implements FactoryBean targetClass) { + public @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { return getTransactionAttribute(method, targetClass, true); } @@ -107,8 +105,7 @@ public abstract class AbstractFallbackTransactionAttributeSource * @return a TransactionAttribute for this method, or {@code null} if the method * is not transactional */ - @Nullable - private TransactionAttribute getTransactionAttribute( + private @Nullable TransactionAttribute getTransactionAttribute( Method method, @Nullable Class targetClass, boolean cacheNull) { if (ReflectionUtils.isObjectMethod(method)) { @@ -160,8 +157,7 @@ public abstract class AbstractFallbackTransactionAttributeSource * @since 4.1.8 * @see #getTransactionAttribute */ - @Nullable - protected TransactionAttribute computeTransactionAttribute(Method method, @Nullable Class targetClass) { + protected @Nullable TransactionAttribute computeTransactionAttribute(Method method, @Nullable Class targetClass) { // Don't allow non-public methods, as configured. if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) { return null; @@ -206,8 +202,7 @@ public abstract class AbstractFallbackTransactionAttributeSource * @param clazz the class to retrieve the attribute for * @return all transaction attribute associated with this class, or {@code null} if none */ - @Nullable - protected abstract TransactionAttribute findTransactionAttribute(Class clazz); + protected abstract @Nullable TransactionAttribute findTransactionAttribute(Class clazz); /** * Subclasses need to implement this to return the transaction attribute for the @@ -215,8 +210,7 @@ public abstract class AbstractFallbackTransactionAttributeSource * @param method the method to retrieve the attribute for * @return all transaction attribute associated with this method, or {@code null} if none */ - @Nullable - protected abstract TransactionAttribute findTransactionAttribute(Method method); + protected abstract @Nullable TransactionAttribute findTransactionAttribute(Method method); /** * Should only public methods be allowed to have transactional semantics? diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/CompositeTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/CompositeTransactionAttributeSource.java index d547829066..4848427aa7 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/CompositeTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/CompositeTransactionAttributeSource.java @@ -19,7 +19,8 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -74,8 +75,7 @@ public class CompositeTransactionAttributeSource implements TransactionAttribute } @Override - @Nullable - public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { + public @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { for (TransactionAttributeSource source : this.transactionAttributeSources) { TransactionAttribute attr = source.getTransactionAttribute(method, targetClass); if (attr != null) { 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 c373271c28..875fe3f309 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 @@ -20,7 +20,8 @@ import java.util.Collection; import java.util.Collections; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.support.DefaultTransactionDefinition; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; @@ -38,14 +39,11 @@ import org.springframework.util.StringValueResolver; @SuppressWarnings("serial") public class DefaultTransactionAttribute extends DefaultTransactionDefinition implements TransactionAttribute { - @Nullable - private String descriptor; + private @Nullable String descriptor; - @Nullable - private String timeoutString; + private @Nullable String timeoutString; - @Nullable - private String qualifier; + private @Nullable String qualifier; private Collection labels = Collections.emptyList(); @@ -102,8 +100,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im * or {@code null} if none. * @since 4.3.4 */ - @Nullable - public String getDescriptor() { + public @Nullable String getDescriptor() { return this.descriptor; } @@ -125,8 +122,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im * @see #getTimeout * @see #resolveAttributeStrings */ - @Nullable - public String getTimeoutString() { + public @Nullable String getTimeoutString() { return this.timeoutString; } @@ -146,8 +142,7 @@ public class DefaultTransactionAttribute extends DefaultTransactionDefinition im * @since 3.0 */ @Override - @Nullable - public String getQualifier() { + public @Nullable String getQualifier() { return this.qualifier; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DelegatingTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DelegatingTransactionAttribute.java index 7d74ac5897..3c8bef92aa 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/DelegatingTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/DelegatingTransactionAttribute.java @@ -19,7 +19,8 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; import java.util.Collection; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.support.DelegatingTransactionDefinition; /** @@ -50,8 +51,7 @@ public abstract class DelegatingTransactionAttribute extends DelegatingTransacti @Override - @Nullable - public String getQualifier() { + public @Nullable String getQualifier() { return this.targetAttribute.getQualifier(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java index 4f94d16f19..701810770d 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MatchAlwaysTransactionAttributeSource.java @@ -19,7 +19,8 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -57,8 +58,7 @@ public class MatchAlwaysTransactionAttributeSource implements TransactionAttribu @Override - @Nullable - public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { + public @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { return (ClassUtils.isUserLevelMethod(method) ? this.transactionAttribute : null); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java index a4fe2cac71..95626e903b 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/MethodMapTransactionAttributeSource.java @@ -24,11 +24,11 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -52,14 +52,11 @@ public class MethodMapTransactionAttributeSource protected final Log logger = LogFactory.getLog(getClass()); /** Map from method name to attribute value. */ - @Nullable - private Map methodMap; + private @Nullable Map methodMap; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; - @Nullable - private ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); + private @Nullable ClassLoader beanClassLoader = ClassUtils.getDefaultClassLoader(); private boolean eagerlyInitialized = false; @@ -221,8 +218,7 @@ public class MethodMapTransactionAttributeSource @Override - @Nullable - public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { + public @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { if (this.eagerlyInitialized) { return this.transactionAttributeMap.get(method); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java index 7eb8942303..c3f733d706 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/NameMatchTransactionAttributeSource.java @@ -25,10 +25,10 @@ import java.util.Properties; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.EmbeddedValueResolverAware; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.PatternMatchUtils; @@ -56,8 +56,7 @@ public class NameMatchTransactionAttributeSource /** Keys are method names; values are TransactionAttributes. */ private final Map nameMap = new HashMap<>(); - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; /** @@ -123,8 +122,7 @@ public class NameMatchTransactionAttributeSource @Override - @Nullable - public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { + public @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { if (!ClassUtils.isUserLevelMethod(method)) { return null; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java index 2f9e23296d..31422c4dc7 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java @@ -18,7 +18,8 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -87,8 +88,7 @@ public class RollbackRuleAttribute implements Serializable{ * a thrown exception's class hierarchy. * @since 6.0 */ - @Nullable - private final Class exceptionType; + private final @Nullable Class exceptionType; /** diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java index f1425fc798..0ee2671f74 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/RuleBasedTransactionAttribute.java @@ -20,7 +20,7 @@ import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * TransactionAttribute implementation that works out whether a given exception @@ -45,8 +45,7 @@ public class RuleBasedTransactionAttribute extends DefaultTransactionAttribute i public static final String PREFIX_COMMIT_RULE = "+"; - @Nullable - private List rollbackRules; + private @Nullable List rollbackRules; /** 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 89dd571025..f1c2c32a60 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 @@ -25,6 +25,7 @@ import java.util.concurrent.Future; import io.vavr.control.Try; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.NamedThreadLocal; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.transaction.NoTransactionException; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.ReactiveTransaction; @@ -140,8 +140,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 { + protected static @Nullable TransactionInfo currentTransactionInfo() throws NoTransactionException { return transactionInfoHolder.get(); } @@ -170,20 +169,15 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private final ReactiveAdapterRegistry reactiveAdapterRegistry; + private final @Nullable ReactiveAdapterRegistry reactiveAdapterRegistry; - @Nullable - private String transactionManagerBeanName; + private @Nullable String transactionManagerBeanName; - @Nullable - private TransactionManager transactionManager; + private @Nullable TransactionManager transactionManager; - @Nullable - private TransactionAttributeSource transactionAttributeSource; + private @Nullable TransactionAttributeSource transactionAttributeSource; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; private final ConcurrentMap transactionManagerCache = new ConcurrentReferenceHashMap<>(4); @@ -214,8 +208,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init /** * Return the name of the default transaction manager bean. */ - @Nullable - protected final String getTransactionManagerBeanName() { + protected final @Nullable String getTransactionManagerBeanName() { return this.transactionManagerBeanName; } @@ -237,8 +230,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init *

    This can either be a traditional {@link PlatformTransactionManager} or a * {@link ReactiveTransactionManager} for reactive transaction management. */ - @Nullable - public TransactionManager getTransactionManager() { + public @Nullable TransactionManager getTransactionManager() { return this.transactionManager; } @@ -288,8 +280,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init /** * Return the transaction attribute source. */ - @Nullable - public TransactionAttributeSource getTransactionAttributeSource() { + public @Nullable TransactionAttributeSource getTransactionAttributeSource() { return this.transactionAttributeSource; } @@ -304,8 +295,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init /** * Return the BeanFactory to use for retrieving {@code TransactionManager} beans. */ - @Nullable - protected final BeanFactory getBeanFactory() { + protected final @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @@ -338,8 +328,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, @Nullable Class targetClass, + protected @Nullable Object invokeWithinTransaction(Method method, @Nullable Class targetClass, final InvocationCallback invocation) throws Throwable { // If the transaction attribute is null, the method is non-transactional. @@ -493,8 +482,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init * @param targetClass the target class that the attribute has been declared on * @since 6.2 */ - @Nullable - protected TransactionManager determineTransactionManager( + protected @Nullable TransactionManager determineTransactionManager( @Nullable TransactionAttribute txAttr, @Nullable Class targetClass) { TransactionManager tm = determineTransactionManager(txAttr); @@ -546,8 +534,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init * @deprecated as of 6.2, in favor of {@link #determineTransactionManager(TransactionAttribute, Class)} */ @Deprecated - @Nullable - protected TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr) { + protected @Nullable TransactionManager determineTransactionManager(@Nullable TransactionAttribute txAttr) { return null; } @@ -561,8 +548,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init return txManager; } - @Nullable - private PlatformTransactionManager asPlatformTransactionManager(@Nullable Object transactionManager) { + private @Nullable PlatformTransactionManager asPlatformTransactionManager(@Nullable Object transactionManager) { if (transactionManager == null) { return null; } @@ -602,8 +588,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, @Nullable Class targetClass) { + protected @Nullable String methodIdentification(Method method, @Nullable Class targetClass) { return null; } @@ -762,19 +747,15 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init */ protected static final class TransactionInfo { - @Nullable - private final PlatformTransactionManager transactionManager; + private final @Nullable PlatformTransactionManager transactionManager; - @Nullable - private final TransactionAttribute transactionAttribute; + private final @Nullable TransactionAttribute transactionAttribute; private final String joinpointIdentification; - @Nullable - private TransactionStatus transactionStatus; + private @Nullable TransactionStatus transactionStatus; - @Nullable - private TransactionInfo oldTransactionInfo; + private @Nullable TransactionInfo oldTransactionInfo; public TransactionInfo(@Nullable PlatformTransactionManager transactionManager, @Nullable TransactionAttribute transactionAttribute, String joinpointIdentification) { @@ -789,8 +770,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init return this.transactionManager; } - @Nullable - public TransactionAttribute getTransactionAttribute() { + public @Nullable TransactionAttribute getTransactionAttribute() { return this.transactionAttribute; } @@ -806,8 +786,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init this.transactionStatus = status; } - @Nullable - public TransactionStatus getTransactionStatus() { + public @Nullable TransactionStatus getTransactionStatus() { return this.transactionStatus; } @@ -846,8 +825,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init @FunctionalInterface protected interface InvocationCallback { - @Nullable - Object proceedWithInvocation() throws Throwable; + @Nullable Object proceedWithInvocation() throws Throwable; } @@ -856,8 +834,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init */ private static class ThrowableHolder { - @Nullable - public Throwable throwable; + public @Nullable Throwable throwable; } @@ -1085,16 +1062,13 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init */ private static final class ReactiveTransactionInfo { - @Nullable - private final ReactiveTransactionManager transactionManager; + private final @Nullable ReactiveTransactionManager transactionManager; - @Nullable - private final TransactionAttribute transactionAttribute; + private final @Nullable TransactionAttribute transactionAttribute; private final String joinpointIdentification; - @Nullable - private ReactiveTransaction reactiveTransaction; + private @Nullable ReactiveTransaction reactiveTransaction; public ReactiveTransactionInfo(@Nullable ReactiveTransactionManager transactionManager, @Nullable TransactionAttribute transactionAttribute, String joinpointIdentification) { @@ -1109,8 +1083,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init return this.transactionManager; } - @Nullable - public TransactionAttribute getTransactionAttribute() { + public @Nullable TransactionAttribute getTransactionAttribute() { return this.transactionAttribute; } @@ -1126,8 +1099,7 @@ public abstract class TransactionAspectSupport implements BeanFactoryAware, Init this.reactiveTransaction = transaction; } - @Nullable - public ReactiveTransaction getReactiveTransaction() { + public @Nullable ReactiveTransaction getReactiveTransaction() { return this.reactiveTransaction; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttribute.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttribute.java index afddd2f95f..0dd0f79342 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttribute.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttribute.java @@ -18,7 +18,8 @@ package org.springframework.transaction.interceptor; import java.util.Collection; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionDefinition; /** @@ -41,8 +42,7 @@ public interface TransactionAttribute extends TransactionDefinition { * to process this specific transaction. * @since 3.0 */ - @Nullable - String getQualifier(); + @Nullable String getQualifier(); /** * Return labels associated with this transaction attribute. 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 8514092f4f..9c084d22b5 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,7 +18,7 @@ package org.springframework.transaction.interceptor; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface used by {@link TransactionInterceptor} for metadata retrieval. @@ -74,7 +74,6 @@ public interface TransactionAttributeSource { * in which case the declaring class of the method must be used) * @return the matching transaction attribute, or {@code null} if none found */ - @Nullable - TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass); + @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourceAdvisor.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourceAdvisor.java index bbaca68870..7a59b81c9f 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourceAdvisor.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionAttributeSourceAdvisor.java @@ -17,11 +17,11 @@ package org.springframework.transaction.interceptor; import org.aopalliance.aop.Advice; +import org.jspecify.annotations.Nullable; import org.springframework.aop.ClassFilter; import org.springframework.aop.Pointcut; import org.springframework.aop.support.AbstractPointcutAdvisor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -40,8 +40,7 @@ import org.springframework.util.Assert; @SuppressWarnings("serial") public class TransactionAttributeSourceAdvisor extends AbstractPointcutAdvisor { - @Nullable - private TransactionInterceptor transactionInterceptor; + private @Nullable TransactionInterceptor transactionInterceptor; private final TransactionAttributeSourcePointcut pointcut = new TransactionAttributeSourcePointcut(); 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 319715b456..2814b8144f 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 @@ -19,10 +19,11 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.ClassFilter; import org.springframework.aop.support.StaticMethodMatcherPointcut; import org.springframework.dao.support.PersistenceExceptionTranslator; -import org.springframework.lang.Nullable; import org.springframework.transaction.TransactionManager; import org.springframework.util.ObjectUtils; @@ -37,8 +38,7 @@ import org.springframework.util.ObjectUtils; @SuppressWarnings("serial") final class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { - @Nullable - private TransactionAttributeSource transactionAttributeSource; + private @Nullable TransactionAttributeSource transactionAttributeSource; public TransactionAttributeSourcePointcut() { @@ -89,8 +89,7 @@ final class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointc return (transactionAttributeSource == null || transactionAttributeSource.isCandidateClass(clazz)); } - @Nullable - private TransactionAttributeSource getTransactionAttributeSource() { + private @Nullable TransactionAttributeSource getTransactionAttributeSource() { return transactionAttributeSource; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionInterceptor.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionInterceptor.java index 863c23506c..dad6ba5ea6 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionInterceptor.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionInterceptor.java @@ -24,10 +24,10 @@ import java.util.Properties; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.BeanFactory; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionManager; @@ -108,8 +108,7 @@ public class TransactionInterceptor extends TransactionAspectSupport implements @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { // Work out the target class: may be {@code null}. // The TransactionAttributeSource should be passed the target class // as well as the method, which may be from an interface. diff --git a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionProxyFactoryBean.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionProxyFactoryBean.java index 723d1eb877..ed5247bbb8 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionProxyFactoryBean.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/TransactionProxyFactoryBean.java @@ -18,6 +18,8 @@ package org.springframework.transaction.interceptor; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.Pointcut; import org.springframework.aop.framework.AbstractSingletonProxyFactoryBean; import org.springframework.aop.framework.ProxyFactory; @@ -26,7 +28,6 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.ListableBeanFactory; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; /** @@ -117,8 +118,7 @@ public class TransactionProxyFactoryBean extends AbstractSingletonProxyFactoryBe private final TransactionInterceptor transactionInterceptor = new TransactionInterceptor(); - @Nullable - private Pointcut pointcut; + private @Nullable Pointcut pointcut; /** 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 44e8ff8b6c..5ad15b9073 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,9 +11,7 @@ * This allows declarative transaction management in any environment, * even without JTA if an application uses only a single database. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.interceptor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c937dbcd3b..9f56a26197 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 @@ -35,10 +35,10 @@ import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; import jakarta.transaction.TransactionSynchronizationRegistry; import jakarta.transaction.UserTransaction; +import org.jspecify.annotations.Nullable; 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; @@ -141,11 +141,9 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager private transient JndiTemplate jndiTemplate = new JndiTemplate(); - @Nullable - private transient UserTransaction userTransaction; + private transient @Nullable UserTransaction userTransaction; - @Nullable - private String userTransactionName; + private @Nullable String userTransactionName; private boolean autodetectUserTransaction = true; @@ -153,19 +151,15 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager private boolean userTransactionObtainedFromJndi = false; - @Nullable - private transient TransactionManager transactionManager; + private transient @Nullable TransactionManager transactionManager; - @Nullable - private String transactionManagerName; + private @Nullable String transactionManagerName; private boolean autodetectTransactionManager = true; - @Nullable - private transient TransactionSynchronizationRegistry transactionSynchronizationRegistry; + private transient @Nullable TransactionSynchronizationRegistry transactionSynchronizationRegistry; - @Nullable - private String transactionSynchronizationRegistryName; + private @Nullable String transactionSynchronizationRegistryName; private boolean autodetectTransactionSynchronizationRegistry = true; @@ -248,8 +242,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JNDI environment to use for JNDI lookups. */ - @Nullable - public Properties getJndiEnvironment() { + public @Nullable Properties getJndiEnvironment() { return this.jndiTemplate.getEnvironment(); } @@ -268,8 +261,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JTA UserTransaction that this transaction manager uses. */ - @Nullable - public UserTransaction getUserTransaction() { + public @Nullable UserTransaction getUserTransaction() { return this.userTransaction; } @@ -332,8 +324,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JTA TransactionManager that this transaction manager uses, if any. */ - @Nullable - public TransactionManager getTransactionManager() { + public @Nullable TransactionManager getTransactionManager() { return this.transactionManager; } @@ -385,8 +376,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager /** * Return the JTA 1.1 TransactionSynchronizationRegistry that this transaction manager uses, if any. */ - @Nullable - public TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { + public @Nullable TransactionSynchronizationRegistry getTransactionSynchronizationRegistry() { return this.transactionSynchronizationRegistry; } @@ -635,8 +625,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * @see #setUserTransaction * @see #setUserTransactionName */ - @Nullable - protected UserTransaction retrieveUserTransaction() throws TransactionSystemException { + protected @Nullable UserTransaction retrieveUserTransaction() throws TransactionSystemException { return null; } @@ -649,8 +638,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * @see #setTransactionManager * @see #setTransactionManagerName */ - @Nullable - protected TransactionManager retrieveTransactionManager() throws TransactionSystemException { + protected @Nullable TransactionManager retrieveTransactionManager() throws TransactionSystemException { return null; } @@ -662,8 +650,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * or {@code null} if none found * @throws TransactionSystemException in case of errors */ - @Nullable - protected TransactionSynchronizationRegistry retrieveTransactionSynchronizationRegistry() throws TransactionSystemException { + protected @Nullable TransactionSynchronizationRegistry retrieveTransactionSynchronizationRegistry() throws TransactionSystemException { return null; } @@ -673,8 +660,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() { + protected @Nullable UserTransaction findUserTransaction() { String jndiName = DEFAULT_USER_TRANSACTION_NAME; try { UserTransaction ut = getJndiTemplate().lookup(jndiName, UserTransaction.class); @@ -700,8 +686,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(@Nullable UserTransaction ut) { + protected @Nullable TransactionManager findTransactionManager(@Nullable UserTransaction ut) { if (ut instanceof TransactionManager tm) { if (logger.isDebugEnabled()) { logger.debug("JTA UserTransaction object [" + ut + "] implements TransactionManager"); @@ -740,8 +725,7 @@ public class JtaTransactionManager extends AbstractPlatformTransactionManager * or {@code null} if none found * @throws TransactionSystemException in case of errors */ - @Nullable - protected TransactionSynchronizationRegistry findTransactionSynchronizationRegistry( + protected @Nullable TransactionSynchronizationRegistry findTransactionSynchronizationRegistry( @Nullable UserTransaction ut, @Nullable TransactionManager tm) throws TransactionSystemException { if (this.userTransactionObtainedFromJndi) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java b/spring-tx/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java index f0977ac25e..030659a6bf 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java +++ b/spring-tx/src/main/java/org/springframework/transaction/jta/SimpleTransactionFactory.java @@ -20,8 +20,8 @@ import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; import jakarta.transaction.Transaction; import jakarta.transaction.TransactionManager; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-tx/src/main/java/org/springframework/transaction/jta/SpringJtaSynchronizationAdapter.java b/spring-tx/src/main/java/org/springframework/transaction/jta/SpringJtaSynchronizationAdapter.java index 622339fcdf..7618f979bc 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/jta/SpringJtaSynchronizationAdapter.java +++ b/spring-tx/src/main/java/org/springframework/transaction/jta/SpringJtaSynchronizationAdapter.java @@ -22,8 +22,8 @@ import jakarta.transaction.TransactionManager; import jakarta.transaction.UserTransaction; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.support.TransactionSynchronization; import org.springframework.transaction.support.TransactionSynchronizationManager; import org.springframework.util.Assert; @@ -48,8 +48,7 @@ public class SpringJtaSynchronizationAdapter implements Synchronization { private final TransactionSynchronization springSynchronization; - @Nullable - private UserTransaction jtaTransaction; + private @Nullable UserTransaction jtaTransaction; private boolean beforeCompletionCalled = false; 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 b0ac314208..7b9b7a7b39 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 @@ -19,8 +19,7 @@ package org.springframework.transaction.jta; import jakarta.transaction.NotSupportedException; import jakarta.transaction.SystemException; import jakarta.transaction.Transaction; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for creating JTA {@link jakarta.transaction.Transaction} 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 677749eb0a..8be9c82a9b 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,9 +1,7 @@ /** * Transaction SPI implementation for JTA. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.jta; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 94ee460c5f..abd9c1ee27 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,9 +3,7 @@ * management system); an exception hierarchy for Spring's transaction infrastructure; * and transaction manager, definition, and status interfaces. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java index 8a3a5056b6..33614071f2 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/AbstractReactiveTransactionManager.java @@ -28,10 +28,10 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.transaction.ConfigurableTransactionManager; import org.springframework.transaction.IllegalTransactionStateException; import org.springframework.transaction.InvalidTimeoutException; @@ -976,19 +976,15 @@ public abstract class AbstractReactiveTransactionManager */ protected static final class SuspendedResourcesHolder { - @Nullable - private final Object suspendedResources; + private final @Nullable Object suspendedResources; - @Nullable - private List suspendedSynchronizations; + private @Nullable List suspendedSynchronizations; - @Nullable - private String name; + private @Nullable String name; private boolean readOnly; - @Nullable - private Integer isolationLevel; + private @Nullable Integer isolationLevel; private boolean wasActive; diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/GenericReactiveTransaction.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/GenericReactiveTransaction.java index 0cf7a5833d..6456b2d5e5 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/GenericReactiveTransaction.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/GenericReactiveTransaction.java @@ -16,7 +16,8 @@ package org.springframework.transaction.reactive; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.ReactiveTransaction; import org.springframework.util.Assert; @@ -40,11 +41,9 @@ import org.springframework.util.Assert; */ public class GenericReactiveTransaction implements ReactiveTransaction { - @Nullable - private final String transactionName; + private final @Nullable String transactionName; - @Nullable - private final Object transaction; + private final @Nullable Object transaction; private final boolean newTransaction; @@ -56,8 +55,7 @@ public class GenericReactiveTransaction implements ReactiveTransaction { private final boolean debug; - @Nullable - private final Object suspendedResources; + private final @Nullable Object suspendedResources; private boolean rollbackOnly = false; @@ -151,8 +149,7 @@ public class GenericReactiveTransaction implements ReactiveTransaction { * Return the holder for resources that have been suspended for this transaction, * if any. */ - @Nullable - public Object getSuspendedResources() { + public @Nullable Object getSuspendedResources() { return this.suspendedResources; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java index 9a6c191a91..8fdb9c7ecf 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionContext.java @@ -20,7 +20,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mutable transaction context that encapsulates transactional synchronizations and @@ -36,21 +36,17 @@ import org.springframework.lang.Nullable; */ public class TransactionContext { - @Nullable - private final TransactionContext parent; + private final @Nullable TransactionContext parent; private final Map resources = new LinkedHashMap<>(); - @Nullable - private Set synchronizations; + private @Nullable Set synchronizations; - @Nullable - private volatile String currentTransactionName; + private volatile @Nullable String currentTransactionName; private volatile boolean currentTransactionReadOnly; - @Nullable - private volatile Integer currentTransactionIsolationLevel; + private volatile @Nullable Integer currentTransactionIsolationLevel; private volatile boolean actualTransactionActive; @@ -64,8 +60,7 @@ public class TransactionContext { } - @Nullable - public TransactionContext getParent() { + public @Nullable TransactionContext getParent() { return this.parent; } @@ -77,8 +72,7 @@ public class TransactionContext { this.synchronizations = synchronizations; } - @Nullable - public Set getSynchronizations() { + public @Nullable Set getSynchronizations() { return this.synchronizations; } @@ -86,8 +80,7 @@ public class TransactionContext { this.currentTransactionName = currentTransactionName; } - @Nullable - public String getCurrentTransactionName() { + public @Nullable String getCurrentTransactionName() { return this.currentTransactionName; } @@ -103,8 +96,7 @@ public class TransactionContext { this.currentTransactionIsolationLevel = currentTransactionIsolationLevel; } - @Nullable - public Integer getCurrentTransactionIsolationLevel() { + public @Nullable Integer getCurrentTransactionIsolationLevel() { return this.currentTransactionIsolationLevel; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java index 1c2fa3a5bf..4b08bb60d4 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionSynchronizationManager.java @@ -23,10 +23,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.Nullable; import org.springframework.transaction.NoTransactionException; import org.springframework.util.Assert; @@ -107,8 +107,7 @@ public class TransactionSynchronizationManager { * @return a value bound to the current context (usually the active * resource object), or {@code null} if none */ - @Nullable - public Object getResource(Object key) { + public @Nullable Object getResource(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); return doGetResource(actualKey); } @@ -116,8 +115,7 @@ public class TransactionSynchronizationManager { /** * Actually check the value of the resource that is bound for the given key. */ - @Nullable - private Object doGetResource(Object actualKey) { + private @Nullable Object doGetResource(Object actualKey) { return this.transactionContext.getResources().get(actualKey); } @@ -158,8 +156,7 @@ public 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 Object unbindResourceIfPossible(Object key) { + public @Nullable Object unbindResourceIfPossible(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); return doUnbindResource(actualKey); } @@ -167,8 +164,7 @@ public class TransactionSynchronizationManager { /** * Actually remove the value of the resource that is bound for the given key. */ - @Nullable - private Object doUnbindResource(Object actualKey) { + private @Nullable Object doUnbindResource(Object actualKey) { Map map = this.transactionContext.getResources(); return map.remove(actualKey); } @@ -279,8 +275,7 @@ public class TransactionSynchronizationManager { * for example to optimize fetch strategies for specific named transactions. * @see org.springframework.transaction.TransactionDefinition#getName() */ - @Nullable - public String getCurrentTransactionName() { + public @Nullable String getCurrentTransactionName() { return this.transactionContext.getCurrentTransactionName(); } @@ -339,8 +334,7 @@ public class TransactionSynchronizationManager { * @see org.springframework.transaction.TransactionDefinition#ISOLATION_SERIALIZABLE * @see org.springframework.transaction.TransactionDefinition#getIsolationLevel() */ - @Nullable - public Integer getCurrentTransactionIsolationLevel() { + public @Nullable Integer getCurrentTransactionIsolationLevel() { return this.transactionContext.getCurrentTransactionIsolationLevel(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperatorImpl.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperatorImpl.java index d812235dd9..c5f4654e0a 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperatorImpl.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/TransactionalOperatorImpl.java @@ -18,10 +18,10 @@ package org.springframework.transaction.reactive; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.transaction.ReactiveTransaction; import org.springframework.transaction.ReactiveTransactionManager; import org.springframework.transaction.TransactionDefinition; diff --git a/spring-tx/src/main/java/org/springframework/transaction/reactive/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/reactive/package-info.java index ef36611986..7ad37c2cb3 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/reactive/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/reactive/package-info.java @@ -3,9 +3,7 @@ * Provides an abstract base class for reactive transaction manager implementations, * and a transactional operator plus callback for transaction demarcation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 73b56a2015..894580699e 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 @@ -26,8 +26,8 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.transaction.ConfigurableTransactionManager; import org.springframework.transaction.IllegalTransactionStateException; import org.springframework.transaction.InvalidTimeoutException; @@ -611,8 +611,7 @@ public abstract class AbstractPlatformTransactionManager * @see #doSuspend * @see #resume */ - @Nullable - protected final SuspendedResourcesHolder suspend(@Nullable Object transaction) throws TransactionException { + protected final @Nullable SuspendedResourcesHolder suspend(@Nullable Object transaction) throws TransactionException { if (TransactionSynchronizationManager.isSynchronizationActive()) { List suspendedSynchronizations = doSuspendSynchronization(); try { @@ -1332,19 +1331,15 @@ public abstract class AbstractPlatformTransactionManager */ protected static final class SuspendedResourcesHolder { - @Nullable - private final Object suspendedResources; + private final @Nullable Object suspendedResources; - @Nullable - private List suspendedSynchronizations; + private @Nullable List suspendedSynchronizations; - @Nullable - private String name; + private @Nullable String name; private boolean readOnly; - @Nullable - private Integer isolationLevel; + private @Nullable Integer isolationLevel; private boolean wasActive; 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 fa7fcff4ae..1b3b75597f 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,7 +16,8 @@ package org.springframework.transaction.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.NestedTransactionNotSupportedException; import org.springframework.transaction.SavepointManager; import org.springframework.transaction.TransactionException; @@ -50,8 +51,7 @@ public abstract class AbstractTransactionStatus implements TransactionStatus { private boolean completed = false; - @Nullable - private Object savepoint; + private @Nullable Object savepoint; //--------------------------------------------------------------------- @@ -129,8 +129,7 @@ public abstract class AbstractTransactionStatus implements TransactionStatus { /** * Get the savepoint for this transaction, if any. */ - @Nullable - protected Object getSavepoint() { + protected @Nullable 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 5cc9ee59f5..a37af8cd14 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,7 +16,8 @@ package org.springframework.transaction.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -54,8 +55,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(@Nullable TransactionDefinition definition, TransactionCallback callback) + @Nullable T execute(@Nullable TransactionDefinition definition, TransactionCallback callback) throws TransactionException; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionDefinition.java b/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionDefinition.java index 4faabde754..74cc341e36 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionDefinition.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/DefaultTransactionDefinition.java @@ -19,7 +19,8 @@ package org.springframework.transaction.support; import java.io.Serializable; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionDefinition; import org.springframework.util.Assert; @@ -85,8 +86,7 @@ public class DefaultTransactionDefinition implements TransactionDefinition, Seri private boolean readOnly = false; - @Nullable - private String name; + private @Nullable String name; /** @@ -270,8 +270,7 @@ public class DefaultTransactionDefinition implements TransactionDefinition, Seri } @Override - @Nullable - public final String getName() { + public final @Nullable String getName() { return this.name; } 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 1d71e544d4..bb4d07bc42 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,7 +16,8 @@ package org.springframework.transaction.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.NestedTransactionNotSupportedException; import org.springframework.transaction.SavepointManager; import org.springframework.util.Assert; @@ -50,11 +51,9 @@ import org.springframework.util.Assert; */ public class DefaultTransactionStatus extends AbstractTransactionStatus { - @Nullable - private final String transactionName; + private final @Nullable String transactionName; - @Nullable - private final Object transaction; + private final @Nullable Object transaction; private final boolean newTransaction; @@ -66,8 +65,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { private final boolean debug; - @Nullable - private final Object suspendedResources; + private final @Nullable Object suspendedResources; /** @@ -157,8 +155,7 @@ public class DefaultTransactionStatus extends AbstractTransactionStatus { * Return the holder for resources that have been suspended for this transaction, * if any. */ - @Nullable - public Object getSuspendedResources() { + public @Nullable Object getSuspendedResources() { return this.suspendedResources; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/DelegatingTransactionDefinition.java b/spring-tx/src/main/java/org/springframework/transaction/support/DelegatingTransactionDefinition.java index 29228b6f69..11a0adb72f 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/DelegatingTransactionDefinition.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/DelegatingTransactionDefinition.java @@ -18,7 +18,8 @@ package org.springframework.transaction.support; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionDefinition; import org.springframework.util.Assert; @@ -68,8 +69,7 @@ public abstract class DelegatingTransactionDefinition implements TransactionDefi } @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.targetDefinition.getName(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/ResourceHolderSupport.java b/spring-tx/src/main/java/org/springframework/transaction/support/ResourceHolderSupport.java index c0b2bdaf63..ea2b5a0806 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/ResourceHolderSupport.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/ResourceHolderSupport.java @@ -18,7 +18,8 @@ package org.springframework.transaction.support; import java.util.Date; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionTimedOutException; /** @@ -39,8 +40,7 @@ public abstract class ResourceHolderSupport implements ResourceHolder { private boolean rollbackOnly = false; - @Nullable - private Date deadline; + private @Nullable Date deadline; private int referenceCount = 0; @@ -113,8 +113,7 @@ public abstract class ResourceHolderSupport implements ResourceHolder { * Return the expiration deadline of this object. * @return the deadline as Date object */ - @Nullable - public Date getDeadline() { + public @Nullable Date getDeadline() { return this.deadline; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionScope.java b/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionScope.java index fb0f11574a..dacebd9119 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionScope.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/SimpleTransactionScope.java @@ -20,9 +20,10 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.Scope; -import org.springframework.lang.Nullable; /** * A simple transaction-backed {@link Scope} implementation, delegating to @@ -61,8 +62,7 @@ public class SimpleTransactionScope implements Scope { } @Override - @Nullable - public Object remove(String name) { + public @Nullable Object remove(String name) { ScopedObjectsHolder scopedObjects = (ScopedObjectsHolder) TransactionSynchronizationManager.getResource(this); if (scopedObjects != null) { scopedObjects.destructionCallbacks.remove(name); @@ -82,14 +82,12 @@ public class SimpleTransactionScope implements Scope { } @Override - @Nullable - public Object resolveContextualObject(String key) { + public @Nullable Object resolveContextualObject(String key) { return null; } @Override - @Nullable - public String getConversationId() { + public @Nullable String getConversationId() { return TransactionSynchronizationManager.getCurrentTransactionName(); } 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 70b76cf96f..f155b117f5 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,7 +16,8 @@ package org.springframework.transaction.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionStatus; /** @@ -52,7 +53,6 @@ public interface TransactionCallback { * @see TransactionTemplate#execute * @see CallbackPreferringPlatformTransactionManager#execute */ - @Nullable - T doInTransaction(TransactionStatus status); + @Nullable T doInTransaction(TransactionStatus status); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java index 4552e57961..6a21cd926d 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionCallbackWithoutResult.java @@ -16,7 +16,8 @@ package org.springframework.transaction.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionStatus; /** @@ -31,8 +32,7 @@ import org.springframework.transaction.TransactionStatus; public abstract class TransactionCallbackWithoutResult implements TransactionCallback { @Override - @Nullable - public final Object doInTransaction(TransactionStatus status) { + public final @Nullable Object doInTransaction(TransactionStatus status) { doInTransactionWithoutResult(status); return null; } 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 3ba6d3f288..c09ff5bc1a 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 @@ -18,7 +18,8 @@ package org.springframework.transaction.support; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionException; import org.springframework.transaction.TransactionStatus; @@ -45,8 +46,7 @@ public interface TransactionOperations { * @throws RuntimeException if thrown by the TransactionCallback * @see #executeWithoutResult(Consumer) */ - @Nullable - T execute(TransactionCallback action) throws TransactionException; + @Nullable T execute(TransactionCallback action) throws TransactionException; /** * Execute the action specified by the given {@link Runnable} within a transaction. 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 0b310c99e1..08253d3190 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 @@ -24,9 +24,10 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NamedThreadLocal; import org.springframework.core.OrderComparator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -129,8 +130,7 @@ public abstract class TransactionSynchronizationManager { * resource object), or {@code null} if none * @see ResourceTransactionManager#getResourceFactory() */ - @Nullable - public static Object getResource(Object key) { + public static @Nullable Object getResource(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); return doGetResource(actualKey); } @@ -138,8 +138,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) { + private static @Nullable Object doGetResource(Object actualKey) { Map map = resources.get(); if (map == null) { return null; @@ -205,8 +204,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) { + public static @Nullable Object unbindResourceIfPossible(Object key) { Object actualKey = TransactionSynchronizationUtils.unwrapResourceIfNecessary(key); return doUnbindResource(actualKey); } @@ -214,8 +212,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) { + private static @Nullable Object doUnbindResource(Object actualKey) { Map map = resources.get(); if (map == null) { return null; @@ -341,8 +338,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() { + public static @Nullable String getCurrentTransactionName() { return currentTransactionName.get(); } @@ -410,8 +406,7 @@ public abstract class TransactionSynchronizationManager { * @see org.springframework.transaction.TransactionDefinition#ISOLATION_SERIALIZABLE * @see org.springframework.transaction.TransactionDefinition#getIsolationLevel() */ - @Nullable - public static Integer getCurrentTransactionIsolationLevel() { + public static @Nullable Integer getCurrentTransactionIsolationLevel() { return currentTransactionIsolationLevel.get(); } diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationUtils.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationUtils.java index 8da53ffb9c..28709b2c15 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationUtils.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationUtils.java @@ -20,10 +20,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.aop.scope.ScopedObject; import org.springframework.core.InfrastructureProxy; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionTemplate.java b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionTemplate.java index 87c37645ea..2cffbe61df 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/TransactionTemplate.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/TransactionTemplate.java @@ -20,9 +20,9 @@ import java.lang.reflect.UndeclaredThrowableException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; @@ -68,8 +68,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private PlatformTransactionManager transactionManager; + private @Nullable PlatformTransactionManager transactionManager; /** @@ -112,8 +111,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition /** * Return the transaction management strategy to be used. */ - @Nullable - public PlatformTransactionManager getTransactionManager() { + public @Nullable PlatformTransactionManager getTransactionManager() { return this.transactionManager; } @@ -126,8 +124,7 @@ public class TransactionTemplate extends DefaultTransactionDefinition @Override - @Nullable - public T execute(TransactionCallback action) throws TransactionException { + public @Nullable T execute(TransactionCallback action) throws TransactionException { Assert.state(this.transactionManager != null, "No PlatformTransactionManager set"); if (this.transactionManager instanceof CallbackPreferringPlatformTransactionManager cpptm) { diff --git a/spring-tx/src/main/java/org/springframework/transaction/support/WithoutTransactionOperations.java b/spring-tx/src/main/java/org/springframework/transaction/support/WithoutTransactionOperations.java index 08a4e4cd43..6ec914ec33 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/support/WithoutTransactionOperations.java +++ b/spring-tx/src/main/java/org/springframework/transaction/support/WithoutTransactionOperations.java @@ -18,7 +18,8 @@ package org.springframework.transaction.support; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionException; import org.springframework.transaction.TransactionStatus; @@ -40,8 +41,7 @@ final class WithoutTransactionOperations implements TransactionOperations { @Override - @Nullable - public T execute(TransactionCallback action) throws TransactionException { + public @Nullable T execute(TransactionCallback action) throws TransactionException { return action.doInTransaction(new SimpleTransactionStatus(false)); } 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 59a310edf0..ba8447d396 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,9 +3,8 @@ * Provides an abstract base class for transaction manager implementations, * and a template plus callback for transaction demarcation. */ -@NonNullApi -@NonNullFields +@NullMarked + package org.springframework.transaction.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-tx/src/main/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensions.kt b/spring-tx/src/main/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensions.kt index 3b117b37ea..09d7e7efd2 100644 --- a/spring-tx/src/main/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensions.kt +++ b/spring-tx/src/main/kotlin/org/springframework/transaction/reactive/TransactionalOperatorExtensions.kt @@ -24,7 +24,7 @@ import kotlinx.coroutines.reactive.awaitLast import kotlinx.coroutines.reactor.asFlux import kotlinx.coroutines.reactor.mono import org.springframework.transaction.ReactiveTransaction -import java.util.Optional +import java.util.* import kotlin.coroutines.CoroutineContext import kotlin.coroutines.EmptyCoroutineContext diff --git a/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java b/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java index 655146a55e..693b298ba1 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/annotation/TransactionBeanRegistrationAotProcessorTests.java @@ -16,6 +16,7 @@ package org.springframework.transaction.annotation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aot.generate.GenerationContext; @@ -26,7 +27,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationAotContribution; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -96,8 +96,7 @@ class TransactionBeanRegistrationAotProcessorTests { } } - @Nullable - private BeanRegistrationAotContribution createContribution(Class beanClass) { + private @Nullable BeanRegistrationAotContribution createContribution(Class beanClass) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass)); return this.processor.processAheadOfTime(RegisteredBean.of(beanFactory, beanClass.getName())); diff --git a/spring-tx/src/test/java/org/springframework/transaction/event/CapturingSynchronizationCallback.java b/spring-tx/src/test/java/org/springframework/transaction/event/CapturingSynchronizationCallback.java index 6d8ad6e48f..262a6640d7 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/event/CapturingSynchronizationCallback.java +++ b/spring-tx/src/test/java/org/springframework/transaction/event/CapturingSynchronizationCallback.java @@ -16,8 +16,9 @@ package org.springframework.transaction.event; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; -import org.springframework.lang.Nullable; /** * @author Juergen Hoeller @@ -25,14 +26,11 @@ import org.springframework.lang.Nullable; */ class CapturingSynchronizationCallback implements TransactionalApplicationListener.SynchronizationCallback { - @Nullable - ApplicationEvent preEvent; + @Nullable ApplicationEvent preEvent; - @Nullable - ApplicationEvent postEvent; + @Nullable ApplicationEvent postEvent; - @Nullable - Throwable ex; + @Nullable Throwable ex; @Override public void preProcessEvent(ApplicationEvent event) { diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/BeanFactoryTransactionTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/BeanFactoryTransactionTests.java index 727369f4d7..13f0dd9013 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/BeanFactoryTransactionTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/BeanFactoryTransactionTests.java @@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,7 +37,6 @@ import org.springframework.beans.testfixture.beans.DerivedTestBean; import org.springframework.beans.testfixture.beans.ITestBean; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.core.io.ClassPathResource; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/PlatformTransactionManagerFacade.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/PlatformTransactionManagerFacade.java index 0fd25c0a3a..73702354ca 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/PlatformTransactionManagerFacade.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/PlatformTransactionManagerFacade.java @@ -16,7 +16,8 @@ package org.springframework.transaction.interceptor; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionStatus; diff --git a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java index adea2bb54a..6b4f22d643 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java +++ b/spring-tx/src/test/java/org/springframework/transaction/interceptor/TransactionInterceptorTests.java @@ -19,13 +19,13 @@ package org.springframework.transaction.interceptor; import java.io.Serializable; import java.util.Properties; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.framework.ProxyFactory; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.core.testfixture.io.SerializationTestUtils; -import org.springframework.lang.Nullable; import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; diff --git a/spring-tx/src/test/java/org/springframework/transaction/reactive/ReactiveTestTransactionManager.java b/spring-tx/src/test/java/org/springframework/transaction/reactive/ReactiveTestTransactionManager.java index 3a4dd0184f..ef9ae00d18 100644 --- a/spring-tx/src/test/java/org/springframework/transaction/reactive/ReactiveTestTransactionManager.java +++ b/spring-tx/src/test/java/org/springframework/transaction/reactive/ReactiveTestTransactionManager.java @@ -18,9 +18,9 @@ package org.springframework.transaction.reactive; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.transaction.CannotCreateTransactionException; import org.springframework.transaction.ReactiveTransactionManager; import org.springframework.transaction.TransactionDefinition; @@ -40,11 +40,9 @@ class ReactiveTestTransactionManager extends AbstractReactiveTransactionManager private final boolean canCreateTransaction; - @Nullable - private Function forceFailOnCommit; + private @Nullable Function forceFailOnCommit; - @Nullable - private Function forceFailOnRollback; + private @Nullable Function forceFailOnRollback; protected boolean begin = false; diff --git a/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt b/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt index 4f2437f1be..b560004938 100644 --- a/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt +++ b/spring-tx/src/test/kotlin/org/springframework/transaction/annotation/CoroutinesAnnotationTransactionInterceptorTests.kt @@ -22,7 +22,8 @@ import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.toList import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext -import org.assertj.core.api.Assertions.* +import org.assertj.core.api.Assertions.assertThat +import org.assertj.core.api.Assertions.assertThatIllegalStateException import org.junit.jupiter.api.Test import org.springframework.aop.framework.ProxyFactory import org.springframework.transaction.interceptor.TransactionInterceptor diff --git a/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt b/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt index 6843f2e796..6a2e357212 100644 --- a/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt +++ b/spring-tx/src/test/kotlin/org/springframework/transaction/interceptor/AbstractCoroutinesTransactionAspectTests.kt @@ -22,7 +22,7 @@ import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.mockito.BDDMockito.* +import org.mockito.BDDMockito.given import org.mockito.Mockito import org.springframework.transaction.* import org.springframework.transaction.reactive.TransactionContext diff --git a/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/MockCallbackPreferringTransactionManager.java b/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/MockCallbackPreferringTransactionManager.java index 108c65cadb..f49e275dc3 100644 --- a/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/MockCallbackPreferringTransactionManager.java +++ b/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/MockCallbackPreferringTransactionManager.java @@ -16,7 +16,8 @@ package org.springframework.transaction.testfixture; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionException; import org.springframework.transaction.TransactionStatus; diff --git a/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/TestTransactionExecutionListener.java b/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/TestTransactionExecutionListener.java index 66f9e88e66..c626c0c706 100644 --- a/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/TestTransactionExecutionListener.java +++ b/spring-tx/src/testFixtures/java/org/springframework/transaction/testfixture/TestTransactionExecutionListener.java @@ -16,7 +16,8 @@ package org.springframework.transaction.testfixture; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.TransactionExecution; import org.springframework.transaction.TransactionExecutionListener; @@ -30,22 +31,19 @@ public class TestTransactionExecutionListener implements TransactionExecutionLis public boolean afterBeginCalled; - @Nullable - public Throwable beginFailure; + public @Nullable Throwable beginFailure; public boolean beforeCommitCalled; public boolean afterCommitCalled; - @Nullable - public Throwable commitFailure; + public @Nullable Throwable commitFailure; public boolean beforeRollbackCalled; public boolean afterRollbackCalled; - @Nullable - public Throwable rollbackFailure; + public @Nullable Throwable rollbackFailure; @Override diff --git a/spring-web/src/jmh/java/org/springframework/http/support/HeadersAdaptersBaseline.java b/spring-web/src/jmh/java/org/springframework/http/support/HeadersAdaptersBaseline.java index e412ffd74d..606e75a5aa 100644 --- a/spring-web/src/jmh/java/org/springframework/http/support/HeadersAdaptersBaseline.java +++ b/spring-web/src/jmh/java/org/springframework/http/support/HeadersAdaptersBaseline.java @@ -33,9 +33,9 @@ import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpMessage; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -58,8 +58,7 @@ class HeadersAdaptersBaseline { @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { Header header = this.message.getFirstHeader(key); return (header != null ? header.getValue() : null); } @@ -117,9 +116,8 @@ class HeadersAdaptersBaseline { Arrays.stream(this.message.getHeaders()).anyMatch(h -> h.getValue().equals(value))); } - @Nullable @Override - public List get(Object key) { + public @Nullable List get(Object key) { List values = null; if (containsKey(key)) { Header[] headers = this.message.getHeaders((String) key); @@ -131,17 +129,15 @@ class HeadersAdaptersBaseline { return values; } - @Nullable @Override - public List put(String key, List values) { + public @Nullable List put(String key, List values) { List oldValues = remove(key); values.forEach(value -> add(key, value)); return oldValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List oldValues = get(key); this.message.removeHeaders(headerName); @@ -249,8 +245,7 @@ class HeadersAdaptersBaseline { private final HttpFields headers; - @Nullable - private final HttpFields.Mutable mutable; + private final HttpFields.@Nullable Mutable mutable; /** @@ -343,9 +338,8 @@ class HeadersAdaptersBaseline { return false; } - @Nullable @Override - public List get(Object key) { + public @Nullable List get(Object key) { List list = null; if (key instanceof String name) { for (HttpField f : this.headers) { @@ -360,9 +354,8 @@ class HeadersAdaptersBaseline { return list; } - @Nullable @Override - public List put(String key, List value) { + public @Nullable List put(String key, List value) { HttpFields.Mutable mutableHttpFields = mutableFields(); List oldValues = get(key); @@ -383,9 +376,8 @@ class HeadersAdaptersBaseline { return oldValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { HttpFields.Mutable mutableHttpFields = mutableFields(); List list = null; if (key instanceof String name) { @@ -515,8 +507,7 @@ class HeadersAdaptersBaseline { private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; @@ -563,8 +554,7 @@ class HeadersAdaptersBaseline { @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { return this.headers.get(key); } @@ -632,25 +622,22 @@ class HeadersAdaptersBaseline { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { if (containsKey(key)) { return this.headers.getAll((String) key); } return null; } - @Nullable @Override - public List put(String key, @Nullable List value) { + public @Nullable List put(String key, @Nullable List value) { List previousValues = this.headers.getAll(key); this.headers.set(key, value); return previousValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List previousValues = this.headers.getAll(headerName); this.headers.remove(headerName); @@ -762,8 +749,7 @@ class HeadersAdaptersBaseline { private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; @@ -810,8 +796,7 @@ class HeadersAdaptersBaseline { @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { CharSequence value = this.headers.get(key); return (value != null ? value.toString() : null); } @@ -876,8 +861,7 @@ class HeadersAdaptersBaseline { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { Iterator iterator = this.headers.valuesIterator((CharSequence) key); if (iterator.hasNext()) { List result = new ArrayList<>(); @@ -887,17 +871,15 @@ class HeadersAdaptersBaseline { return null; } - @Nullable @Override - public List put(String key, @Nullable List value) { + public @Nullable List put(String key, @Nullable List value) { List previousValues = get(key); this.headers.set(key, value); return previousValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List previousValues = get(headerName); this.headers.remove(headerName); @@ -1010,8 +992,7 @@ class HeadersAdaptersBaseline { private final Iterator iterator; - @Nullable - private CharSequence currentName; + private @Nullable CharSequence currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; 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 00b32d8aa4..afe7bd4d36 100644 --- a/spring-web/src/main/java/org/springframework/http/CacheControl.java +++ b/spring-web/src/main/java/org/springframework/http/CacheControl.java @@ -19,7 +19,8 @@ package org.springframework.http; import java.time.Duration; import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -51,8 +52,7 @@ import org.springframework.util.StringUtils; */ public class CacheControl { - @Nullable - private Duration maxAge; + private @Nullable Duration maxAge; private boolean noCache = false; @@ -68,14 +68,11 @@ public class CacheControl { private boolean proxyRevalidate = false; - @Nullable - private Duration staleWhileRevalidate; + private @Nullable Duration staleWhileRevalidate; - @Nullable - private Duration staleIfError; + private @Nullable Duration staleIfError; - @Nullable - private Duration sMaxAge; + private @Nullable Duration sMaxAge; private boolean immutable = false; @@ -341,8 +338,7 @@ public class CacheControl { * Return the "Cache-Control" header value, if any. * @return the header value, or {@code null} if no directive was added */ - @Nullable - public String getHeaderValue() { + public @Nullable String getHeaderValue() { String headerValue = toHeaderValue(); return (StringUtils.hasText(headerValue) ? headerValue : null); } 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 90d91a6fbe..c70bd822b5 100644 --- a/spring-web/src/main/java/org/springframework/http/ContentDisposition.java +++ b/spring-web/src/main/java/org/springframework/http/ContentDisposition.java @@ -26,7 +26,8 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StreamUtils; @@ -70,17 +71,13 @@ public final class ContentDisposition { } - @Nullable - private final String type; + private final @Nullable String type; - @Nullable - private final String name; + private final @Nullable String name; - @Nullable - private final String filename; + private final @Nullable String filename; - @Nullable - private final Charset charset; + private final @Nullable Charset charset; /** @@ -126,16 +123,14 @@ public final class ContentDisposition { * @see #isFormData() * @see #isInline() */ - @Nullable - public String getType() { + public @Nullable String getType() { return this.type; } /** * Return the value of the {@literal name} parameter, or {@code null} if not defined. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -144,16 +139,14 @@ public final class ContentDisposition { * from BASE64 encoding based on RFC 2047, or of the {@literal filename*} * parameter, possibly decoded as defined in the RFC 5987. */ - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.filename; } /** * Return the charset defined in {@literal filename*} parameter, or {@code null} if not defined. */ - @Nullable - public Charset getCharset() { + public @Nullable Charset getCharset() { return this.charset; } @@ -603,14 +596,11 @@ public final class ContentDisposition { private final String type; - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String filename; + private @Nullable String filename; - @Nullable - private Charset charset; + private @Nullable Charset charset; public BuilderImpl(String type) { diff --git a/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java b/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java index 0cf6650939..d6e66e395b 100644 --- a/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java +++ b/spring-web/src/main/java/org/springframework/http/DefaultHttpStatusCode.java @@ -18,7 +18,7 @@ package org.springframework.http; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Default implementation of {@link HttpStatusCode}. diff --git a/spring-web/src/main/java/org/springframework/http/HttpCookie.java b/spring-web/src/main/java/org/springframework/http/HttpCookie.java index e85bd9f9c8..ce7e2a954d 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpCookie.java +++ b/spring-web/src/main/java/org/springframework/http/HttpCookie.java @@ -16,7 +16,8 @@ package org.springframework.http; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/HttpEntity.java b/spring-web/src/main/java/org/springframework/http/HttpEntity.java index b3203e4e05..ffb2bf4d25 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpEntity.java +++ b/spring-web/src/main/java/org/springframework/http/HttpEntity.java @@ -16,7 +16,8 @@ package org.springframework.http; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -65,8 +66,7 @@ public class HttpEntity { private final HttpHeaders headers; - @Nullable - private final T body; + private final @Nullable T body; /** @@ -113,8 +113,7 @@ public class HttpEntity { /** * Returns the body of this entity. */ - @Nullable - public T getBody() { + public @Nullable T getBody() { return this.body; } 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 4cd56579cd..958d1012fa 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/HttpHeaders.java @@ -45,7 +45,8 @@ import java.util.StringJoiner; import java.util.function.BiConsumer; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedCaseInsensitiveMap; @@ -659,8 +660,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the value of the {@code Access-Control-Allow-Origin} response header. */ - @Nullable - public String getAccessControlAllowOrigin() { + public @Nullable String getAccessControlAllowOrigin() { return getFieldValues(ACCESS_CONTROL_ALLOW_ORIGIN); } @@ -726,8 +726,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the value of the {@code Access-Control-Request-Method} request header. */ - @Nullable - public HttpMethod getAccessControlRequestMethod() { + public @Nullable HttpMethod getAccessControlRequestMethod() { String requestMethod = getFirst(ACCESS_CONTROL_REQUEST_METHOD); if (requestMethod != null) { return HttpMethod.valueOf(requestMethod); @@ -896,8 +895,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the value of the {@code Cache-Control} header. */ - @Nullable - public String getCacheControl() { + public @Nullable String getCacheControl() { return getFieldValues(CACHE_CONTROL); } @@ -989,8 +987,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * if unknown * @since 5.0 */ - @Nullable - public Locale getContentLanguage() { + public @Nullable Locale getContentLanguage() { return getValuesAsList(CONTENT_LANGUAGE) .stream() .findFirst() @@ -1042,8 +1039,7 @@ public class HttpHeaders implements MultiValueMap, Serializable *

    Returns {@code null} when the {@code Content-Type} header is not set. * @throws InvalidMediaTypeException if the media type value cannot be parsed */ - @Nullable - public MediaType getContentType() { + public @Nullable MediaType getContentType() { String value = getFirst(CONTENT_TYPE); return (StringUtils.hasLength(value) ? MediaType.parseMediaType(value) : null); } @@ -1102,8 +1098,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the entity tag of the body, as specified by the {@code ETag} header. */ - @Nullable - public String getETag() { + public @Nullable String getETag() { return getFirst(ETAG); } @@ -1174,8 +1169,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * be {@code 0}. * @since 5.0 */ - @Nullable - public InetSocketAddress getHost() { + public @Nullable InetSocketAddress getHost() { String value = getFirst(HOST); if (value == null) { return null; @@ -1376,8 +1370,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() { + public @Nullable URI getLocation() { String value = getFirst(LOCATION); return (value != null ? URI.create(value) : null); } @@ -1392,8 +1385,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the value of the {@code Origin} header. */ - @Nullable - public String getOrigin() { + public @Nullable String getOrigin() { return getFirst(ORIGIN); } @@ -1407,8 +1399,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the value of the {@code Pragma} header. */ - @Nullable - public String getPragma() { + public @Nullable String getPragma() { return getFirst(PRAGMA); } @@ -1439,8 +1430,7 @@ public class HttpHeaders implements MultiValueMap, Serializable /** * Return the value of the {@code Upgrade} header. */ - @Nullable - public String getUpgrade() { + public @Nullable String getUpgrade() { return getFirst(UPGRADE); } @@ -1532,8 +1522,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * @return the parsed date header, or {@code null} if none * @since 5.0 */ - @Nullable - public ZonedDateTime getFirstZonedDateTime(String headerName) { + public @Nullable ZonedDateTime getFirstZonedDateTime(String headerName) { return getFirstZonedDateTime(headerName, true); } @@ -1548,8 +1537,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * in that case ({@code false}) * @return the parsed date header, or {@code null} if none (or invalid) */ - @Nullable - private ZonedDateTime getFirstZonedDateTime(String headerName, boolean rejectInvalid) { + private @Nullable ZonedDateTime getFirstZonedDateTime(String headerName, boolean rejectInvalid) { String headerValue = getFirst(headerName); if (headerValue == null) { // No header value sent at all @@ -1700,8 +1688,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * @return the combined result * @since 4.3 */ - @Nullable - protected String getFieldValues(String headerName) { + protected @Nullable String getFieldValues(String headerName) { List headerValues = get(headerName); return (headerValues != null ? toCommaDelimitedString(headerValues) : null); } @@ -1744,8 +1731,7 @@ public class HttpHeaders implements MultiValueMap, Serializable * @return the first header value, or {@code null} if none */ @Override - @Nullable - public String getFirst(String headerName) { + public @Nullable String getFirst(String headerName) { return this.headers.getFirst(headerName); } @@ -1818,8 +1804,7 @@ public class HttpHeaders implements MultiValueMap, Serializable } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { return this.headers.get(key); } @@ -2081,8 +2066,7 @@ public class HttpHeaders implements MultiValueMap, Serializable private final Iterator namesIterator; - @Nullable - private String currentName; + private @Nullable String currentName; private CaseInsensitiveIterator(Iterator namesIterator) { this.namesIterator = namesIterator; 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 e10185ecb4..95debcfbca 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMethod.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMethod.java @@ -18,7 +18,8 @@ package org.springframework.http; import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/HttpMimeTypesRuntimeHints.java b/spring-web/src/main/java/org/springframework/http/HttpMimeTypesRuntimeHints.java index d44cc646ee..a842b763c0 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpMimeTypesRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/http/HttpMimeTypesRuntimeHints.java @@ -16,9 +16,10 @@ package org.springframework.http; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that makes sure mime types diff --git a/spring-web/src/main/java/org/springframework/http/HttpRange.java b/spring-web/src/main/java/org/springframework/http/HttpRange.java index bc1d966657..a887e8b24e 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpRange.java +++ b/spring-web/src/main/java/org/springframework/http/HttpRange.java @@ -24,10 +24,11 @@ import java.util.List; import java.util.Objects; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourceRegion; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -234,8 +235,7 @@ public abstract class HttpRange { private final long firstPos; - @Nullable - private final Long lastPos; + private final @Nullable Long lastPos; public ByteRange(long firstPos, @Nullable Long lastPos) { assertPositions(firstPos, lastPos); diff --git a/spring-web/src/main/java/org/springframework/http/HttpStatus.java b/spring-web/src/main/java/org/springframework/http/HttpStatus.java index 94284d101d..b29deb1414 100644 --- a/spring-web/src/main/java/org/springframework/http/HttpStatus.java +++ b/spring-web/src/main/java/org/springframework/http/HttpStatus.java @@ -16,7 +16,7 @@ package org.springframework.http; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Enumeration of HTTP status codes. @@ -523,8 +523,7 @@ public enum HttpStatus implements HttpStatusCode { * @return the corresponding {@code HttpStatus}, or {@code null} if not found * @since 5.0 */ - @Nullable - public static HttpStatus resolve(int statusCode) { + public static @Nullable HttpStatus resolve(int statusCode) { // Use cached VALUES instead of values() to prevent array allocation. for (HttpStatus status : VALUES) { if (status.value == statusCode) { @@ -591,8 +590,7 @@ public enum HttpStatus implements HttpStatusCode { * @return the corresponding {@code Series}, or {@code null} if not found * @since 5.1.3 */ - @Nullable - public static Series resolve(int statusCode) { + public static @Nullable Series resolve(int statusCode) { int seriesCode = statusCode / 100; for (Series series : values()) { if (series.value == seriesCode) { diff --git a/spring-web/src/main/java/org/springframework/http/InvalidMediaTypeException.java b/spring-web/src/main/java/org/springframework/http/InvalidMediaTypeException.java index 905e95a0d0..f1be0ee6d7 100644 --- a/spring-web/src/main/java/org/springframework/http/InvalidMediaTypeException.java +++ b/spring-web/src/main/java/org/springframework/http/InvalidMediaTypeException.java @@ -16,7 +16,8 @@ package org.springframework.http; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.InvalidMimeTypeException; /** 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 e37d4ffdb9..80a545073a 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaType.java +++ b/spring-web/src/main/java/org/springframework/http/MediaType.java @@ -25,7 +25,8 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.InvalidMimeTypeException; 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 7491e3c876..3194b33146 100644 --- a/spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java +++ b/spring-web/src/main/java/org/springframework/http/MediaTypeFactory.java @@ -26,8 +26,9 @@ import java.util.List; import java.util.Locale; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/ProblemDetail.java b/spring-web/src/main/java/org/springframework/http/ProblemDetail.java index 016160acb5..4e0bf8a594 100644 --- a/spring-web/src/main/java/org/springframework/http/ProblemDetail.java +++ b/spring-web/src/main/java/org/springframework/http/ProblemDetail.java @@ -21,7 +21,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -56,19 +57,15 @@ public class ProblemDetail { private URI type = BLANK_TYPE; - @Nullable - private String title; + private @Nullable String title; private int status; - @Nullable - private String detail; + private @Nullable String detail; - @Nullable - private URI instance; + private @Nullable URI instance; - @Nullable - private Map properties; + private @Nullable Map properties; /** @@ -131,8 +128,7 @@ public class ProblemDetail { /** * Return the configured {@link #setTitle(String) problem title}. */ - @Nullable - public String getTitle() { + public @Nullable String getTitle() { if (this.title == null) { HttpStatus httpStatus = HttpStatus.resolve(this.status); if (httpStatus != null) { @@ -178,8 +174,7 @@ public class ProblemDetail { /** * Return the configured {@link #setDetail(String) problem detail}. */ - @Nullable - public String getDetail() { + public @Nullable String getDetail() { return this.detail; } @@ -196,8 +191,7 @@ public class ProblemDetail { /** * Return the configured {@link #setInstance(URI) problem instance}. */ - @Nullable - public URI getInstance() { + public @Nullable URI getInstance() { return this.instance; } @@ -239,8 +233,7 @@ public class ProblemDetail { * Otherwise, they are rendered as a {@code "properties"} sub-map. * @see org.springframework.http.converter.json.ProblemDetailJacksonMixin */ - @Nullable - public Map getProperties() { + public @Nullable Map getProperties() { return this.properties; } diff --git a/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java b/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java index b667207f93..e40118ad54 100644 --- a/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java +++ b/spring-web/src/main/java/org/springframework/http/ReadOnlyHttpHeaders.java @@ -26,7 +26,8 @@ import java.util.Set; import java.util.function.BiConsumer; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.MultiValueMap; /** @@ -42,12 +43,10 @@ class ReadOnlyHttpHeaders extends HttpHeaders { private static final long serialVersionUID = -8578554704772377436L; - @Nullable - private MediaType cachedContentType; + private @Nullable MediaType cachedContentType; - @Nullable @SuppressWarnings("serial") - private List cachedAccept; + private @Nullable List cachedAccept; ReadOnlyHttpHeaders(MultiValueMap headers) { @@ -56,8 +55,7 @@ class ReadOnlyHttpHeaders extends HttpHeaders { @Override - @Nullable - public MediaType getContentType() { + public @Nullable MediaType getContentType() { if (this.cachedContentType != null) { return this.cachedContentType; } @@ -86,8 +84,7 @@ class ReadOnlyHttpHeaders extends HttpHeaders { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { List values = this.headers.get(key); return (values != null ? Collections.unmodifiableList(values) : null); } 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 d387735f8b..a31e78cc03 100644 --- a/spring-web/src/main/java/org/springframework/http/RequestEntity.java +++ b/spring-web/src/main/java/org/springframework/http/RequestEntity.java @@ -25,7 +25,8 @@ import java.util.Arrays; import java.util.Map; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -66,14 +67,11 @@ import org.springframework.util.ObjectUtils; */ public class RequestEntity extends HttpEntity { - @Nullable - private final HttpMethod method; + private final @Nullable HttpMethod method; - @Nullable - private final URI url; + private final @Nullable URI url; - @Nullable - private final Type type; + private final @Nullable Type type; /** * Constructor with method and URL but without body nor headers. @@ -152,8 +150,7 @@ public class RequestEntity extends HttpEntity { * Return the HTTP method of the request. * @return the HTTP method as an {@code HttpMethod} enum value */ - @Nullable - public HttpMethod getMethod() { + public @Nullable HttpMethod getMethod() { return this.method; } @@ -185,8 +182,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() { + public @Nullable Type getType() { if (this.type == null) { T body = getBody(); if (body != null) { @@ -552,17 +548,13 @@ public class RequestEntity extends HttpEntity { private final HttpHeaders headers = new HttpHeaders(); - @Nullable - private final URI uri; + private final @Nullable URI uri; - @Nullable - private final String uriTemplate; + private final @Nullable String uriTemplate; - @Nullable - private final Object[] uriVarsArray; + private final Object @Nullable [] uriVarsArray; - @Nullable - private final Map uriVarsMap; + private final @Nullable Map uriVarsMap; DefaultBodyBuilder(HttpMethod method, URI url) { this.method = method; @@ -697,16 +689,14 @@ public class RequestEntity extends HttpEntity { private final String uriTemplate; - @Nullable - private final Object[] uriVarsArray; + private final Object @Nullable [] uriVarsArray; - @Nullable - private final Map uriVarsMap; + private final @Nullable Map uriVarsMap; UriTemplateRequestEntity( @Nullable T body, @Nullable MultiValueMap headers, @Nullable HttpMethod method, @Nullable Type type, String uriTemplate, - @Nullable Object[] uriVarsArray, @Nullable Map uriVarsMap) { + Object @Nullable [] uriVarsArray, @Nullable Map uriVarsMap) { super(body, headers, method, null, type); this.uriTemplate = uriTemplate; @@ -718,13 +708,11 @@ public class RequestEntity extends HttpEntity { return this.uriTemplate; } - @Nullable - public Object[] getVars() { + public Object @Nullable [] getVars() { return this.uriVarsArray; } - @Nullable - public Map getVarsMap() { + public @Nullable Map getVarsMap() { return this.uriVarsMap; } 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 67d8dbea39..5539fc60cc 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseCookie.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseCookie.java @@ -18,7 +18,8 @@ package org.springframework.http; import java.time.Duration; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -37,11 +38,9 @@ public final class ResponseCookie extends HttpCookie { private final Duration maxAge; - @Nullable - private final String domain; + private final @Nullable String domain; - @Nullable - private final String path; + private final @Nullable String path; private final boolean secure; @@ -49,8 +48,7 @@ public final class ResponseCookie extends HttpCookie { private final boolean partitioned; - @Nullable - private final String sameSite; + private final @Nullable String sameSite; /** @@ -91,16 +89,14 @@ public final class ResponseCookie extends HttpCookie { /** * Return the cookie "Domain" attribute, or {@code null} if not set. */ - @Nullable - public String getDomain() { + public @Nullable String getDomain() { return this.domain; } /** * Return the cookie "Path" attribute, or {@code null} if not set. */ - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.path; } @@ -135,8 +131,7 @@ public final class ResponseCookie extends HttpCookie { * @since 5.1 * @see RFC6265 bis */ - @Nullable - public String getSameSite() { + public @Nullable String getSameSite() { return this.sameSite; } @@ -403,18 +398,15 @@ public final class ResponseCookie extends HttpCookie { private final String name; - @Nullable - private String value; + private @Nullable String value; private final boolean lenient; private Duration maxAge = Duration.ofSeconds(-1); - @Nullable - private String domain; + private @Nullable String domain; - @Nullable - private String path; + private @Nullable String path; private boolean secure; @@ -422,8 +414,7 @@ public final class ResponseCookie extends HttpCookie { private boolean partitioned; - @Nullable - private String sameSite; + private @Nullable String sameSite; public DefaultResponseCookieBuilder(String name, @Nullable String value, boolean lenient) { this.name = name; @@ -455,8 +446,7 @@ public final class ResponseCookie extends HttpCookie { return this; } - @Nullable - private String initDomain(@Nullable String domain) { + private @Nullable String initDomain(@Nullable String domain) { if (this.lenient && StringUtils.hasLength(domain)) { String str = domain.trim(); if (str.startsWith("\"") && str.endsWith("\"")) { diff --git a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java index a6e16405e8..f5ea7cfc0d 100644 --- a/spring-web/src/main/java/org/springframework/http/ResponseEntity.java +++ b/spring-web/src/main/java/org/springframework/http/ResponseEntity.java @@ -25,7 +25,8 @@ import java.util.Optional; import java.util.Set; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; diff --git a/spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java index 5404493a34..d978f58f1e 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AbstractClientHttpRequest.java @@ -21,8 +21,9 @@ import java.io.OutputStream; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -38,11 +39,9 @@ public abstract class AbstractClientHttpRequest implements ClientHttpRequest { private boolean executed = false; - @Nullable - private HttpHeaders readOnlyHeaders; + private @Nullable HttpHeaders readOnlyHeaders; - @Nullable - private Map attributes; + private @Nullable Map attributes; @Override diff --git a/spring-web/src/main/java/org/springframework/http/client/AbstractStreamingClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/AbstractStreamingClientHttpRequest.java index fa3ea1dfea..a280401fd0 100644 --- a/spring-web/src/main/java/org/springframework/http/client/AbstractStreamingClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/AbstractStreamingClientHttpRequest.java @@ -19,9 +19,10 @@ package org.springframework.http.client; import java.io.IOException; import java.io.OutputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.StreamingHttpOutputMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FastByteArrayOutputStream; @@ -36,11 +37,9 @@ import org.springframework.util.FastByteArrayOutputStream; abstract class AbstractStreamingClientHttpRequest extends AbstractClientHttpRequest implements StreamingHttpOutputMessage { - @Nullable - private Body body; + private @Nullable Body body; - @Nullable - private FastByteArrayOutputStream bodyStream; + private @Nullable FastByteArrayOutputStream bodyStream; @Override diff --git a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java index 482a23e7da..204802ed14 100644 --- a/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java +++ b/spring-web/src/main/java/org/springframework/http/client/BufferingClientHttpResponseWrapper.java @@ -20,9 +20,10 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** @@ -36,8 +37,7 @@ final class BufferingClientHttpResponseWrapper implements ClientHttpResponse { private final ClientHttpResponse response; - @Nullable - private byte[] body; + private byte @Nullable [] body; BufferingClientHttpResponseWrapper(ClientHttpResponse response) { diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java index d2559a800d..0fa14e91eb 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpRequest.java @@ -33,10 +33,10 @@ import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.Method; import org.apache.hc.core5.http.io.entity.NullEntity; import org.apache.hc.core5.http.protocol.HttpContext; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -140,8 +140,7 @@ final class HttpComponentsClientHttpRequest extends AbstractStreamingClientHttpR } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.headers.getFirst(HttpHeaders.CONTENT_TYPE); } @@ -166,14 +165,12 @@ final class HttpComponentsClientHttpRequest extends AbstractStreamingClientHttpR } @Override - @Nullable - public Supplier> getTrailers() { + public @Nullable Supplier> getTrailers() { return null; } @Override - @Nullable - public String getContentEncoding() { + public @Nullable String getContentEncoding() { return this.headers.getFirst(HttpHeaders.CONTENT_ENCODING); } @@ -183,8 +180,7 @@ final class HttpComponentsClientHttpRequest extends AbstractStreamingClientHttpR } @Override - @Nullable - public Set getTrailerNames() { + public @Nullable Set getTrailerNames() { return null; } 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 3f3825c62f..f8477038d0 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 @@ -40,10 +40,10 @@ import org.apache.hc.client5.http.protocol.HttpClientContext; import org.apache.hc.core5.http.ClassicHttpRequest; import org.apache.hc.core5.http.io.SocketConfig; import org.apache.hc.core5.http.protocol.HttpContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -66,8 +66,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest private HttpClient httpClient; - @Nullable - private BiFunction httpContextFactory; + private @Nullable BiFunction httpContextFactory; private long connectTimeout = -1; @@ -269,8 +268,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest * @since 4.2 * @see #mergeRequestConfig(RequestConfig) */ - @Nullable - protected RequestConfig createRequestConfig(Object client) { + protected @Nullable RequestConfig createRequestConfig(Object client) { if (client instanceof Configurable configurableClient) { RequestConfig clientRequestConfig = configurableClient.getConfig(); return mergeRequestConfig(clientRequestConfig); @@ -354,8 +352,7 @@ public class HttpComponentsClientHttpRequestFactory implements ClientHttpRequest * @param uri the URI * @return the http context */ - @Nullable - protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { + protected @Nullable HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { return (this.httpContextFactory != null ? this.httpContextFactory.apply(httpMethod, uri) : null); } diff --git a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java index a636deeaac..f7bb0814b8 100644 --- a/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/HttpComponentsClientHttpResponse.java @@ -22,11 +22,11 @@ import java.io.InputStream; import org.apache.hc.core5.http.ClassicHttpResponse; import org.apache.hc.core5.http.HttpEntity; import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.support.HttpComponentsHeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -44,8 +44,7 @@ final class HttpComponentsClientHttpResponse implements ClientHttpResponse { private final ClassicHttpResponse httpResponse; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; HttpComponentsClientHttpResponse(ClassicHttpResponse httpResponse) { 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 d5e26381c0..4de6f75042 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 @@ -20,8 +20,9 @@ import java.net.URI; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; /** * {@link ClientHttpRequestFactory} wrapper with support for diff --git a/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequest.java index 79e0b8323f..99c7f2ae34 100644 --- a/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequest.java @@ -38,9 +38,10 @@ import java.util.concurrent.Executor; import java.util.concurrent.Flow; import java.util.concurrent.TimeUnit; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; @@ -67,8 +68,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest { private final Executor executor; - @Nullable - private final Duration timeout; + private final @Nullable Duration timeout; public JdkClientHttpRequest(HttpClient httpClient, URI uri, HttpMethod method, Executor executor, @@ -244,8 +244,7 @@ class JdkClientHttpRequest extends AbstractStreamingClientHttpRequest { } - @Nullable - public InputStream wrapInputStream(HttpResponse response) { + public @Nullable InputStream wrapInputStream(HttpResponse response) { InputStream body = response.body(); if (body == null) { return body; diff --git a/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequestFactory.java index 6597048cb1..5225a32be1 100644 --- a/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpRequestFactory.java @@ -22,9 +22,10 @@ import java.net.http.HttpClient; import java.time.Duration; import java.util.concurrent.Executor; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -40,8 +41,7 @@ public class JdkClientHttpRequestFactory implements ClientHttpRequestFactory { private final Executor executor; - @Nullable - private Duration readTimeout; + private @Nullable Duration readTimeout; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpResponse.java index 8f8ce96de8..3c22f6987d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/JdkClientHttpResponse.java @@ -24,10 +24,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.MultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/client/JettyClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/JettyClientHttpRequest.java index c846684e41..cd4d3f5ccd 100644 --- a/spring-web/src/main/java/org/springframework/http/client/JettyClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/JettyClientHttpRequest.java @@ -29,10 +29,10 @@ import org.eclipse.jetty.client.InputStreamResponseListener; import org.eclipse.jetty.client.OutputStreamRequestContent; import org.eclipse.jetty.client.Request; import org.eclipse.jetty.client.Response; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java b/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java index 46640fed41..80842db21f 100644 --- a/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/client/MultipartBodyBuilder.java @@ -21,6 +21,8 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.ParameterizedTypeReference; @@ -31,8 +33,6 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.codec.multipart.Part; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -276,11 +276,9 @@ public final class MultipartBodyBuilder { private final String name; - @Nullable - protected HttpHeaders headers; + protected @Nullable HttpHeaders headers; - @Nullable - protected final Object body; + protected final @Nullable Object body; public DefaultPartBuilder(String name, @Nullable HttpHeaders headers, @Nullable Object body) { this.name = name; @@ -381,8 +379,7 @@ public final class MultipartBodyBuilder { * Return the element type for the {@code Publisher} body. */ @Override - @NonNull - public ResolvableType getResolvableType() { + public @NonNull ResolvableType getResolvableType() { return this.resolvableType; } } diff --git a/spring-web/src/main/java/org/springframework/http/client/OutputStreamPublisher.java b/spring-web/src/main/java/org/springframework/http/client/OutputStreamPublisher.java index 8354172f68..553589b538 100644 --- a/spring-web/src/main/java/org/springframework/http/client/OutputStreamPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/client/OutputStreamPublisher.java @@ -26,7 +26,8 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.LockSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -136,8 +137,7 @@ final class OutputStreamPublisher implements Flow.Publisher { private final AtomicReference parkedThread = new AtomicReference<>(); - @Nullable - private volatile Throwable error; + private volatile @Nullable Throwable error; private long produced; diff --git a/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequest.java index b55dfee560..fd494d1df0 100644 --- a/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequest.java @@ -25,6 +25,7 @@ import java.util.concurrent.atomic.AtomicReference; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; +import org.jspecify.annotations.Nullable; import org.reactivestreams.FlowAdapters; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -34,7 +35,6 @@ import reactor.netty.http.client.HttpClientRequest; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** @@ -53,8 +53,7 @@ final class ReactorClientHttpRequest extends AbstractStreamingClientHttpRequest private final URI uri; - @Nullable - private final Duration exchangeTimeout; + private final @Nullable Duration exchangeTimeout; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequestFactory.java b/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequestFactory.java index 63cfc19ffa..2f35a367b5 100644 --- a/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequestFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpRequestFactory.java @@ -24,13 +24,13 @@ import java.util.function.Function; import io.netty.channel.ChannelOption; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.netty.http.client.HttpClient; import reactor.netty.resources.ConnectionProvider; import reactor.netty.resources.LoopResources; import org.springframework.context.SmartLifecycle; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,23 +52,17 @@ public class ReactorClientHttpRequestFactory implements ClientHttpRequestFactory client -> client.compress(true).responseTimeout(Duration.ofSeconds(10)); - @Nullable - private final ReactorResourceFactory resourceFactory; + private final @Nullable ReactorResourceFactory resourceFactory; - @Nullable - private final Function mapper; + private final @Nullable Function mapper; - @Nullable - private Integer connectTimeout; + private @Nullable Integer connectTimeout; - @Nullable - private Duration readTimeout; + private @Nullable Duration readTimeout; - @Nullable - private Duration exchangeTimeout; + private @Nullable Duration exchangeTimeout; - @Nullable - private volatile HttpClient httpClient; + private volatile @Nullable HttpClient httpClient; private final Object lifecycleMonitor = new Object(); diff --git a/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpResponse.java index 4f92c09979..b8bc57f4a2 100644 --- a/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/ReactorClientHttpResponse.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.io.InputStream; import io.netty.buffer.ByteBuf; +import org.jspecify.annotations.Nullable; import org.reactivestreams.FlowAdapters; import reactor.netty.Connection; import reactor.netty.http.client.HttpClientResponse; @@ -27,7 +28,6 @@ import reactor.netty.http.client.HttpClientResponse; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.support.Netty4HeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** @@ -45,8 +45,7 @@ final class ReactorClientHttpResponse implements ClientHttpResponse { private final HttpHeaders headers; - @Nullable - private volatile InputStream body; + private volatile @Nullable InputStream body; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/ReactorResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/ReactorResourceFactory.java index 6fe8b6c481..0ffb5bcfd1 100644 --- a/spring-web/src/main/java/org/springframework/http/client/ReactorResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/ReactorResourceFactory.java @@ -20,6 +20,7 @@ import java.time.Duration; import java.util.function.Consumer; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import reactor.netty.http.HttpResources; import reactor.netty.resources.ConnectionProvider; import reactor.netty.resources.LoopResources; @@ -29,7 +30,6 @@ import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.SmartLifecycle; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -55,18 +55,15 @@ public class ReactorResourceFactory private boolean useGlobalResources = true; - @Nullable - private Consumer globalResourcesConsumer; + private @Nullable Consumer globalResourcesConsumer; private Supplier connectionProviderSupplier = () -> ConnectionProvider.create("webflux", 500); - @Nullable - private volatile ConnectionProvider connectionProvider; + private volatile @Nullable ConnectionProvider connectionProvider; private Supplier loopResourcesSupplier = () -> LoopResources.create("webflux-http"); - @Nullable - private volatile LoopResources loopResources; + private volatile @Nullable LoopResources loopResources; private boolean manageConnectionProvider = false; @@ -76,8 +73,7 @@ public class ReactorResourceFactory private Duration shutdownTimeout = Duration.ofSeconds(LoopResources.DEFAULT_SHUTDOWN_TIMEOUT); - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; private volatile boolean running; diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequest.java index 9c6932e95c..97a1180e51 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpRequest.java @@ -22,9 +22,10 @@ import java.net.HttpURLConnection; import java.net.URI; import java.net.URISyntaxException; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** 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 baf2f9ef63..ddffc4e86a 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 @@ -24,8 +24,9 @@ import java.net.URL; import java.net.URLConnection; import java.time.Duration; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,8 +43,7 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory private static final int DEFAULT_CHUNK_SIZE = 4096; - @Nullable - private Proxy proxy; + private @Nullable Proxy proxy; private int chunkSize = DEFAULT_CHUNK_SIZE; diff --git a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpResponse.java index 728871cddd..48c47926c0 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/SimpleClientHttpResponse.java @@ -20,9 +20,10 @@ import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; @@ -38,11 +39,9 @@ final class SimpleClientHttpResponse implements ClientHttpResponse { private final HttpURLConnection connection; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; - @Nullable - private InputStream responseStream; + private @Nullable InputStream responseStream; SimpleClientHttpResponse(HttpURLConnection connection) { diff --git a/spring-web/src/main/java/org/springframework/http/client/SubscriberInputStream.java b/spring-web/src/main/java/org/springframework/http/client/SubscriberInputStream.java index ec3834d717..bd7abf52c6 100644 --- a/spring-web/src/main/java/org/springframework/http/client/SubscriberInputStream.java +++ b/spring-web/src/main/java/org/springframework/http/client/SubscriberInputStream.java @@ -32,9 +32,9 @@ import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.Exceptions; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -89,18 +89,15 @@ final class SubscriberInputStream extends InputStream implements Flow.Subscri private int consumed; - @Nullable - private byte[] available; + private byte @Nullable [] available; private int position; - @Nullable - private Flow.Subscription subscription; + private Flow.@Nullable Subscription subscription; private boolean done; - @Nullable - private Throwable error; + private @Nullable Throwable error; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java b/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java index a150dc8d95..258b889831 100644 --- a/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java +++ b/spring-web/src/main/java/org/springframework/http/client/observation/ClientRequestObservationContext.java @@ -17,10 +17,10 @@ package org.springframework.http.client.observation; import io.micrometer.observation.transport.RequestReplySenderContext; +import org.jspecify.annotations.Nullable; import org.springframework.http.client.ClientHttpRequest; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; /** * Context that holds information for metadata collection during the @@ -34,8 +34,7 @@ import org.springframework.lang.Nullable; */ public class ClientRequestObservationContext extends RequestReplySenderContext { - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; /** @@ -64,8 +63,7 @@ public class ClientRequestObservationContext extends RequestReplySenderContext>> commitActions = new ArrayList<>(4); - @Nullable - private HttpHeaders readOnlyHeaders; + private @Nullable HttpHeaders readOnlyHeaders; public AbstractClientHttpRequest() { diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java index c878792c0f..b2ac22eade 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/HttpComponentsClientHttpRequest.java @@ -29,6 +29,7 @@ import org.apache.hc.core5.http.message.BasicHttpRequest; import org.apache.hc.core5.http.nio.AsyncRequestProducer; import org.apache.hc.core5.http.nio.support.BasicRequestProducer; import org.apache.hc.core5.reactive.ReactiveEntityProducer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -40,7 +41,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.support.HttpComponentsHeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -59,8 +59,7 @@ class HttpComponentsClientHttpRequest extends AbstractClientHttpRequest { private final HttpClientContext context; - @Nullable - private Flux byteBufferFlux; + private @Nullable Flux byteBufferFlux; private transient long contentLength = -1; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java index 5b6f08de10..b0006d2267 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpConnector.java @@ -28,12 +28,12 @@ import java.util.concurrent.Executor; import java.util.concurrent.Flow; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,8 +50,7 @@ public class JdkClientHttpConnector implements ClientHttpConnector { private DataBufferFactory bufferFactory = DefaultDataBufferFactory.sharedInstance; - @Nullable - private Duration readTimeout; + private @Nullable Duration readTimeout; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java index 9eeebb6b27..8130238fa7 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpRequest.java @@ -27,6 +27,7 @@ import java.util.concurrent.Flow; import java.util.function.Function; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.adapter.JdkFlowAdapter; import reactor.core.publisher.Flux; @@ -37,7 +38,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpResponse.java index e1a742b33d..92ed16d8e4 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkClientHttpResponse.java @@ -28,6 +28,7 @@ import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; import reactor.adapter.JdkFlowAdapter; import reactor.core.publisher.Flux; @@ -37,7 +38,6 @@ import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.LinkedMultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java index f46fd8494a..734a3b819d 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JdkHttpClientResourceFactory.java @@ -22,9 +22,10 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.scheduling.concurrent.CustomizableThreadFactory; import org.springframework.util.Assert; @@ -41,8 +42,7 @@ import org.springframework.util.Assert; */ public class JdkHttpClientResourceFactory implements InitializingBean, DisposableBean { - @Nullable - private Executor executor; + private @Nullable Executor executor; private String threadPrefix = "jdk-http"; @@ -62,8 +62,7 @@ public class JdkHttpClientResourceFactory implements InitializingBean, Disposabl /** * Return the configured {@link Executor}. */ - @Nullable - public Executor getExecutor() { + public @Nullable Executor getExecutor() { return this.executor; } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java index ca255fe973..229e105e7f 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpConnector.java @@ -22,13 +22,13 @@ import java.util.function.Function; import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.Request; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.JettyDataBufferFactory; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java index cef7da388e..6f4e161f18 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyClientHttpResponse.java @@ -23,6 +23,7 @@ import java.util.regex.Pattern; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.reactive.client.ReactiveResponse; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.io.buffer.DataBuffer; @@ -30,7 +31,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; import org.springframework.http.support.JettyHeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -77,8 +77,7 @@ class JettyClientHttpResponse extends AbstractClientHttpResponse { return CollectionUtils.unmodifiableMultiValueMap(result); } - @Nullable - private static String parseSameSite(String headerValue) { + private static @Nullable String parseSameSite(String headerValue) { Matcher matcher = SAME_SITE_PATTERN.matcher(headerValue); return (matcher.matches() ? matcher.group(1) : null); } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java index 5b7dbc5464..0e1268bf70 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/JettyResourceFactory.java @@ -28,10 +28,10 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.Scheduler; import org.eclipse.jetty.util.thread.ThreadPool; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -46,14 +46,11 @@ import org.springframework.util.Assert; */ public class JettyResourceFactory implements InitializingBean, DisposableBean { - @Nullable - private Executor executor; + private @Nullable Executor executor; - @Nullable - private ByteBufferPool byteBufferPool; + private @Nullable ByteBufferPool byteBufferPool; - @Nullable - private Scheduler scheduler; + private @Nullable Scheduler scheduler; private String threadPrefix = "jetty-http"; @@ -100,24 +97,21 @@ public class JettyResourceFactory implements InitializingBean, DisposableBean { /** * Return the configured {@link Executor}. */ - @Nullable - public Executor getExecutor() { + public @Nullable Executor getExecutor() { return this.executor; } /** * Return the configured {@link ByteBufferPool}. */ - @Nullable - public ByteBufferPool getByteBufferPool() { + public @Nullable ByteBufferPool getByteBufferPool() { return this.byteBufferPool; } /** * Return the configured {@link Scheduler}. */ - @Nullable - public Scheduler getScheduler() { + public @Nullable Scheduler getScheduler() { return this.scheduler; } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java index db838d6ad0..11b1ef6cc1 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpConnector.java @@ -24,6 +24,7 @@ import java.util.function.Function; import io.netty.util.AttributeKey; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.netty.NettyOutbound; import reactor.netty.http.client.HttpClient; @@ -34,7 +35,6 @@ import reactor.netty.resources.LoopResources; import org.springframework.context.SmartLifecycle; import org.springframework.http.HttpMethod; import org.springframework.http.client.ReactorResourceFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -64,14 +64,11 @@ public class ReactorClientHttpConnector implements ClientHttpConnector, SmartLif private static final Function defaultInitializer = client -> client.compress(true); - @Nullable - private final ReactorResourceFactory resourceFactory; + private final @Nullable ReactorResourceFactory resourceFactory; - @Nullable - private final Function mapper; + private final @Nullable Function mapper; - @Nullable - private volatile HttpClient httpClient; + private volatile @Nullable HttpClient httpClient; private boolean lazyStart = false; diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java index 411fda8f20..fdd915be92 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorClientHttpResponse.java @@ -25,6 +25,7 @@ import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.codec.http.cookie.DefaultCookie; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.netty.ChannelOperationsId; import reactor.netty.Connection; @@ -38,7 +39,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; import org.springframework.http.support.Netty4HeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -152,8 +152,7 @@ class ReactorClientHttpResponse implements ClientHttpResponse { return CollectionUtils.unmodifiableMultiValueMap(result); } - @Nullable - private static String getSameSite(Cookie cookie) { + private static @Nullable String getSameSite(Cookie cookie) { if (cookie instanceof DefaultCookie defaultCookie && defaultCookie.sameSite() != null) { return defaultCookie.sameSite().name(); } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java index 2af3933d0e..623561cfa4 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ClientHttpResponse.java @@ -24,6 +24,7 @@ import io.netty5.handler.codec.http.headers.DefaultHttpSetCookie; import io.netty5.handler.codec.http.headers.HttpSetCookie; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.netty5.ChannelOperationsId; import reactor.netty5.Connection; @@ -37,7 +38,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; import org.springframework.http.support.Netty5HeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -136,8 +136,7 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse { return CollectionUtils.unmodifiableMultiValueMap(result); } - @Nullable - private static String toString(@Nullable CharSequence value) { + private static @Nullable String toString(@Nullable CharSequence value) { return (value != null ? value.toString() : null); } @@ -145,8 +144,7 @@ class ReactorNetty2ClientHttpResponse implements ClientHttpResponse { return (value != null ? value : -1); } - @Nullable - private static String getSameSite(HttpSetCookie cookie) { + private static @Nullable String getSameSite(HttpSetCookie cookie) { if (cookie instanceof DefaultHttpSetCookie defaultCookie && defaultCookie.sameSite() != null) { return defaultCookie.sameSite().name(); } diff --git a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ResourceFactory.java b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ResourceFactory.java index 41fb5a3fc9..9eb8b72384 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ResourceFactory.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/ReactorNetty2ResourceFactory.java @@ -20,6 +20,7 @@ import java.time.Duration; import java.util.function.Consumer; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import reactor.netty5.http.HttpResources; import reactor.netty5.resources.ConnectionProvider; import reactor.netty5.resources.LoopResources; @@ -27,7 +28,6 @@ import reactor.netty5.resources.LoopResources; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.client.ReactorResourceFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -47,18 +47,15 @@ public class ReactorNetty2ResourceFactory implements InitializingBean, Disposabl private boolean useGlobalResources = true; - @Nullable - private Consumer globalResourcesConsumer; + private @Nullable Consumer globalResourcesConsumer; private Supplier connectionProviderSupplier = () -> ConnectionProvider.create("webflux", 500); - @Nullable - private ConnectionProvider connectionProvider; + private @Nullable ConnectionProvider connectionProvider; private Supplier loopResourcesSupplier = () -> LoopResources.create("webflux-http"); - @Nullable - private LoopResources loopResources; + private @Nullable LoopResources loopResources; private boolean manageConnectionProvider = false; 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 b17f099cdb..abde1debf5 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,9 +4,7 @@ * {@link org.springframework.http.client.reactive.ClientHttpResponse} as well as a * {@link org.springframework.http.client.reactive.ClientHttpConnector}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.client.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/client/support/BasicAuthenticationInterceptor.java b/spring-web/src/main/java/org/springframework/http/client/support/BasicAuthenticationInterceptor.java index 71f09d6483..d812a8d31e 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/BasicAuthenticationInterceptor.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/BasicAuthenticationInterceptor.java @@ -19,12 +19,13 @@ package org.springframework.http.client.support; import java.io.IOException; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; /** * {@link ClientHttpRequestInterceptor} to apply a given HTTP Basic Authentication diff --git a/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java b/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java index b7bd440821..d1971fda66 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/InterceptingHttpAccessor.java @@ -19,11 +19,12 @@ package org.springframework.http.client.support; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.InterceptingClientHttpRequestFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -46,8 +47,7 @@ public abstract class InterceptingHttpAccessor extends HttpAccessor { private final List interceptors = new ArrayList<>(); - @Nullable - private volatile ClientHttpRequestFactory interceptingRequestFactory; + private volatile @Nullable ClientHttpRequestFactory interceptingRequestFactory; /** diff --git a/spring-web/src/main/java/org/springframework/http/client/support/ProxyFactoryBean.java b/spring-web/src/main/java/org/springframework/http/client/support/ProxyFactoryBean.java index e1b9e0c8c7..be9684c82b 100644 --- a/spring-web/src/main/java/org/springframework/http/client/support/ProxyFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/http/client/support/ProxyFactoryBean.java @@ -20,9 +20,10 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.SocketAddress; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -37,13 +38,11 @@ public class ProxyFactoryBean implements FactoryBean, InitializingBean { private Proxy.Type type = Proxy.Type.HTTP; - @Nullable - private String hostname; + private @Nullable String hostname; private int port = -1; - @Nullable - private Proxy proxy; + private @Nullable Proxy proxy; /** @@ -83,8 +82,7 @@ public class ProxyFactoryBean implements FactoryBean, InitializingBean { @Override - @Nullable - public Proxy getObject() { + public @Nullable Proxy getObject() { return this.proxy; } 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 0308cb51a3..d6040adf70 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,9 +2,7 @@ * This package provides generic HTTP support classes, * to be used by higher-level classes like RestTemplate. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.client.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java index a309838cc8..1b0aa23e70 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java +++ b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurer.java @@ -19,9 +19,10 @@ package org.springframework.http.codec; import java.util.List; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.core.codec.Decoder; import org.springframework.core.codec.Encoder; -import org.springframework.lang.Nullable; /** * Defines a common interface for configuring either client or server HTTP @@ -396,15 +397,13 @@ public interface CodecConfigurer { * Get the configured limit on the number of bytes that can be buffered whenever * the input stream needs to be aggregated. */ - @Nullable - Integer maxInMemorySize(); + @Nullable Integer maxInMemorySize(); /** * Whether to log form data at DEBUG level, and headers at TRACE level. * Both may contain sensitive information. */ - @Nullable - Boolean isEnableLoggingRequestDetails(); + @Nullable Boolean isEnableLoggingRequestDetails(); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurerRuntimeHints.java b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurerRuntimeHints.java index c317651075..ec26ef9edd 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurerRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/http/codec/CodecConfigurerRuntimeHints.java @@ -16,13 +16,14 @@ package org.springframework.http.codec; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeReference; import org.springframework.http.codec.support.DefaultClientCodecConfigurer; import org.springframework.http.codec.support.DefaultServerCodecConfigurer; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that registers runtime hints for diff --git a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java index 978e7f04c0..ab723681f1 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/DecoderHttpMessageReader.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -33,7 +34,6 @@ 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; import org.springframework.util.Assert; /** @@ -118,8 +118,7 @@ public class DecoderHttpMessageReader implements HttpMessageReader { * @param inputMessage the HTTP message * @return the MediaType, possibly {@code null}. */ - @Nullable - protected MediaType getContentType(HttpMessage inputMessage) { + protected @Nullable MediaType getContentType(HttpMessage inputMessage) { MediaType contentType = inputMessage.getHeaders().getContentType(); return (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java index fc791caab7..3bebe1195a 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/EncoderHttpMessageWriter.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,7 +36,6 @@ 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; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -63,8 +63,7 @@ public class EncoderHttpMessageWriter implements HttpMessageWriter { private final List mediaTypes; - @Nullable - private final MediaType defaultMediaType; + private final @Nullable MediaType defaultMediaType; /** @@ -86,8 +85,7 @@ public class EncoderHttpMessageWriter implements HttpMessageWriter { } } - @Nullable - private static MediaType initDefaultMediaType(List mediaTypes) { + private static @Nullable MediaType initDefaultMediaType(List mediaTypes) { return mediaTypes.stream().filter(MediaType::isConcrete).findFirst().orElse(null); } @@ -153,8 +151,7 @@ public class EncoderHttpMessageWriter implements HttpMessageWriter { return message.writeWith(body); } - @Nullable - private MediaType updateContentType(ReactiveHttpOutputMessage message, @Nullable MediaType mediaType) { + private @Nullable MediaType updateContentType(ReactiveHttpOutputMessage message, @Nullable MediaType mediaType) { MediaType result = message.getHeaders().getContentType(); if (result != null) { return result; diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java index b057fea344..83ac2c6258 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageReader.java @@ -23,6 +23,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -33,7 +34,6 @@ import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpInputMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java index 4b313089d7..db89918e45 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/FormHttpMessageWriter.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -33,7 +34,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java index b968236a9c..05cfb52508 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/HttpMessageEncoder.java @@ -19,13 +19,14 @@ package org.springframework.http.codec; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.codec.Encoder; import org.springframework.core.codec.Hints; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; /** * Extension of {@code Encoder} exposing extra methods relevant in the context 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 16d578b4f4..f042614d22 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 @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -29,7 +30,6 @@ 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 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 46a72b0ac1..bddb686d56 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 @@ -20,6 +20,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -29,7 +30,6 @@ 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 diff --git a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryDecoder.java index b0c05318d0..702f1cc3cc 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryDecoder.java @@ -21,6 +21,7 @@ import java.util.Map; import kotlinx.serialization.BinaryFormat; import kotlinx.serialization.KSerializer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -30,7 +31,6 @@ import org.springframework.core.codec.ByteArrayDecoder; import org.springframework.core.codec.Decoder; import org.springframework.core.codec.DecodingException; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryEncoder.java index de16320454..d65a9e76f3 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationBinaryEncoder.java @@ -21,6 +21,7 @@ import java.util.Map; import kotlinx.serialization.BinaryFormat; import kotlinx.serialization.KSerializer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -31,7 +32,6 @@ import org.springframework.core.codec.Encoder; import org.springframework.core.codec.EncodingException; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringDecoder.java index 79f42b43fb..89ab88630b 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringDecoder.java @@ -21,6 +21,7 @@ import java.util.Map; import kotlinx.serialization.KSerializer; import kotlinx.serialization.StringFormat; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -31,7 +32,6 @@ import org.springframework.core.codec.Decoder; import org.springframework.core.codec.DecodingException; import org.springframework.core.codec.StringDecoder; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringEncoder.java index f9ade37bce..000ed1eab4 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationStringEncoder.java @@ -25,6 +25,7 @@ import java.util.Set; import kotlinx.serialization.KSerializer; import kotlinx.serialization.StringFormat; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -36,7 +37,6 @@ import org.springframework.core.codec.EncodingException; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationSupport.java b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationSupport.java index bded9bb17c..53b7b804b6 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/KotlinSerializationSupport.java @@ -33,11 +33,11 @@ import kotlinx.serialization.SerialFormat; import kotlinx.serialization.SerializersKt; import kotlinx.serialization.descriptors.PolymorphicKind; import kotlinx.serialization.descriptors.SerialDescriptor; +import org.jspecify.annotations.Nullable; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.MimeType; @@ -126,8 +126,7 @@ public abstract class KotlinSerializationSupport { * @param resolvableType the type to find a serializer for * @return a resolved serializer for the given type, or {@code null} */ - @Nullable - protected final KSerializer serializer(ResolvableType resolvableType) { + protected final @Nullable KSerializer serializer(ResolvableType resolvableType) { if (resolvableType.getSource() instanceof MethodParameter parameter) { Method method = parameter.getMethod(); Assert.notNull(method, "Method must not be null"); diff --git a/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java index bbcc49b9be..5be851714d 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ResourceHttpMessageWriter.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -47,7 +48,6 @@ import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.ZeroCopyHttpOutputMessage; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.MimeTypeUtils; /** @@ -188,8 +188,7 @@ public class ResourceHttpMessageWriter implements HttpMessageWriter { } } - @Nullable - private static Mono zeroCopy(Resource resource, @Nullable ResourceRegion region, + private static @Nullable Mono zeroCopy(Resource resource, @Nullable ResourceRegion region, ReactiveHttpOutputMessage message, Map hints) { if (message instanceof ZeroCopyHttpOutputMessage zeroCopyHttpOutputMessage && resource.isFile()) { 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 3975244278..e84a8571fd 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 @@ -18,7 +18,8 @@ package org.springframework.http.codec; import java.time.Duration; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -36,20 +37,15 @@ import org.springframework.util.StringUtils; */ public final class ServerSentEvent { - @Nullable - private final String id; + private final @Nullable String id; - @Nullable - private final String event; + private final @Nullable String event; - @Nullable - private final Duration retry; + private final @Nullable Duration retry; - @Nullable - private final String comment; + private final @Nullable String comment; - @Nullable - private final T data; + private final @Nullable T data; private ServerSentEvent(@Nullable String id, @Nullable String event, @Nullable Duration retry, @@ -66,40 +62,35 @@ public final class ServerSentEvent { /** * Return the {@code id} field of this event, if available. */ - @Nullable - public String id() { + public @Nullable String id() { return this.id; } /** * Return the {@code event} field of this event, if available. */ - @Nullable - public String event() { + public @Nullable String event() { return this.event; } /** * Return the {@code retry} field of this event, if available. */ - @Nullable - public Duration retry() { + public @Nullable Duration retry() { return this.retry; } /** * Return the comment of this event, if available. */ - @Nullable - public String comment() { + public @Nullable String comment() { return this.comment; } /** * Return the {@code data} field of this event, if available. */ - @Nullable - public T data() { + public @Nullable T data() { return this.data; } @@ -229,20 +220,15 @@ public final class ServerSentEvent { private static class BuilderImpl implements Builder { - @Nullable - private String id; + private @Nullable String id; - @Nullable - private String event; + private @Nullable String event; - @Nullable - private Duration retry; + private @Nullable Duration retry; - @Nullable - private String comment; + private @Nullable String comment; - @Nullable - private T data; + private @Nullable T data; public BuilderImpl() { } diff --git a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java index 61289b03e9..e6c5f1d7a4 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageReader.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -34,7 +35,6 @@ import org.springframework.core.io.buffer.DataBufferLimitException; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpInputMessage; -import org.springframework.lang.Nullable; /** * Reader that supports a stream of {@link ServerSentEvent ServerSentEvents} and also plain @@ -50,8 +50,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader decoder; + private final @Nullable Decoder decoder; private final StringDecoder lineDecoder = StringDecoder.textPlainOnly(); @@ -76,8 +75,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader getDecoder() { + public @Nullable Decoder getDecoder() { return this.decoder; } @@ -137,9 +135,8 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader lines, ResolvableType valueType, boolean shouldWrap, + private @Nullable Object buildEvent(List lines, ResolvableType valueType, boolean shouldWrap, Map hints) { ServerSentEvent.Builder sseBuilder = (shouldWrap ? ServerSentEvent.builder() : null); @@ -191,8 +188,7 @@ public class ServerSentEventHttpMessageReader implements HttpMessageReader hints) { + private @Nullable Object decodeData(StringBuilder data, ResolvableType dataType, Map hints) { if (String.class == dataType.resolve()) { return data.substring(0, data.length() - 1); } 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 28aac85286..c8edf91969 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 @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ 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; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -59,8 +59,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter encoder; + private final @Nullable Encoder encoder; /** @@ -84,8 +83,7 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter getEncoder() { + public @Nullable Encoder getEncoder() { return this.encoder; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java index 7d04e82c14..9daf3b302d 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborDecoder.java @@ -20,6 +20,7 @@ import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -28,7 +29,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.MediaType; import org.springframework.http.codec.json.AbstractJackson2Decoder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; diff --git a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java index bee3462e73..9221953629 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/cbor/Jackson2CborEncoder.java @@ -20,6 +20,7 @@ import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -29,7 +30,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.MediaType; import org.springframework.http.codec.json.AbstractJackson2Encoder; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; diff --git a/spring-web/src/main/java/org/springframework/http/codec/cbor/package-info.java b/spring-web/src/main/java/org/springframework/http/codec/cbor/package-info.java index 9a7faa8f0e..30159b0eea 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/cbor/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/codec/cbor/package-info.java @@ -1,9 +1,7 @@ /** * CBOR encoder and decoder support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec.cbor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java index 03e5ea2c17..23b8b1a37f 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Decoder.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectReader; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; import com.fasterxml.jackson.databind.util.TokenBuffer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -49,7 +50,6 @@ import org.springframework.core.log.LogFormatUtils; import org.springframework.http.codec.HttpMessageDecoder; 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.util.MimeType; @@ -257,8 +257,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple return reader; } - @Nullable - private Class getContextClass(@Nullable ResolvableType elementType) { + private @Nullable Class getContextClass(@Nullable ResolvableType elementType) { MethodParameter param = (elementType != null ? getParameter(elementType) : null); return (param != null ? param.getContainingClass() : null); } @@ -307,8 +306,7 @@ public abstract class AbstractJackson2Decoder extends Jackson2CodecSupport imple // Jackson2CodecSupport @Override - @Nullable - protected A getAnnotation(MethodParameter parameter, Class annotType) { + protected @Nullable A getAnnotation(MethodParameter parameter, Class annotType) { return parameter.getParameterAnnotation(annotType); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java index 7965a651f9..587d8a7ef2 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/AbstractJackson2Encoder.java @@ -35,6 +35,7 @@ import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SequenceWriter; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; import com.fasterxml.jackson.databind.ser.FilterProvider; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -53,7 +54,6 @@ import org.springframework.http.codec.HttpMessageEncoder; import org.springframework.http.converter.json.MappingJacksonValue; 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.util.CollectionUtils; import org.springframework.util.MimeType; @@ -371,8 +371,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple * streaming} mime types. * @since 5.3 */ - @Nullable - protected byte[] getStreamingMediaTypeSeparator(@Nullable MimeType mimeType) { + protected byte @Nullable [] getStreamingMediaTypeSeparator(@Nullable MimeType mimeType) { for (MediaType streamingMediaType : this.streamingMediaTypes) { if (streamingMediaType.isCompatibleWith(mimeType)) { return NEWLINE_SEPARATOR; @@ -427,8 +426,7 @@ public abstract class AbstractJackson2Encoder extends Jackson2CodecSupport imple // Jackson2CodecSupport @Override - @Nullable - protected A getAnnotation(MethodParameter parameter, Class annotType) { + protected @Nullable A getAnnotation(MethodParameter parameter, Class annotType) { return parameter.getMethodAnnotation(annotType); } diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java index 56dcd96ae7..e9388e6f5a 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2CodecSupport.java @@ -31,6 +31,7 @@ import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; @@ -41,7 +42,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ProblemDetail; 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.util.CollectionUtils; import org.springframework.util.MimeType; @@ -85,8 +85,7 @@ public abstract class Jackson2CodecSupport { private ObjectMapper defaultObjectMapper; - @Nullable - private Map, Map> objectMapperRegistrations; + private @Nullable Map, Map> objectMapperRegistrations; private final List mimeTypes; @@ -150,8 +149,7 @@ public abstract class Jackson2CodecSupport { * or empty if in case of no registrations for the given class. * @since 5.3.4 */ - @Nullable - public Map getObjectMappersForType(Class clazz) { + public @Nullable Map getObjectMappersForType(Class clazz) { for (Map.Entry, Map> entry : getObjectMapperRegistrations().entrySet()) { if (entry.getKey().isAssignableFrom(clazz)) { return entry.getValue(); @@ -252,13 +250,11 @@ public abstract class Jackson2CodecSupport { return Hints.none(); } - @Nullable - protected MethodParameter getParameter(ResolvableType type) { + protected @Nullable MethodParameter getParameter(ResolvableType type) { return (type.getSource() instanceof MethodParameter methodParameter ? methodParameter : null); } - @Nullable - protected abstract A getAnnotation(MethodParameter parameter, Class annotType); + protected abstract @Nullable A getAnnotation(MethodParameter parameter, Class annotType); /** * Select an ObjectMapper to use, either the main ObjectMapper or another @@ -266,8 +262,7 @@ public abstract class Jackson2CodecSupport { * {@link #registerObjectMappersForType(Class, Consumer)}. * @since 5.3.4 */ - @Nullable - protected ObjectMapper selectObjectMapper(ResolvableType targetType, @Nullable MimeType targetMimeType) { + protected @Nullable ObjectMapper selectObjectMapper(ResolvableType targetType, @Nullable MimeType targetMimeType) { if (targetMimeType == null || CollectionUtils.isEmpty(this.objectMapperRegistrations)) { return this.defaultObjectMapper; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonDecoder.java index e92281bf1d..15a266c50b 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonDecoder.java @@ -23,6 +23,7 @@ import java.util.Arrays; import java.util.Map; import com.fasterxml.jackson.databind.ObjectMapper; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -31,7 +32,6 @@ import org.springframework.core.codec.CharBufferDecoder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java index 43643fa5bf..5276ae9e7e 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2JsonEncoder.java @@ -27,12 +27,12 @@ import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.ResolvableType; import org.springframework.http.MediaType; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** @@ -51,8 +51,7 @@ public class Jackson2JsonEncoder extends AbstractJackson2Encoder { Collections.singletonList(MediaType.APPLICATION_PROBLEM_JSON); - @Nullable - private final PrettyPrinter ssePrettyPrinter; + private final @Nullable PrettyPrinter ssePrettyPrinter; public Jackson2JsonEncoder() { diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2SmileEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2SmileEncoder.java index a5dfacef57..c79fe25cce 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2SmileEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/Jackson2SmileEncoder.java @@ -21,11 +21,11 @@ import java.util.List; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.smile.SmileFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.http.MediaType; import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; @@ -65,9 +65,8 @@ public class Jackson2SmileEncoder extends AbstractJackson2Encoder { * streaming} mime types. * @since 5.3 */ - @Nullable @Override - protected byte[] getStreamingMediaTypeSeparator(@Nullable MimeType mimeType) { + protected byte @Nullable [] getStreamingMediaTypeSeparator(@Nullable MimeType mimeType) { for (MediaType streamingMediaType : getStreamingMediaTypes()) { if (streamingMediaType.isCompatibleWith(mimeType)) { return STREAM_SEPARATOR; diff --git a/spring-web/src/main/java/org/springframework/http/codec/json/KotlinSerializationJsonEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/json/KotlinSerializationJsonEncoder.java index 92cd20e3b8..77b2bef777 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/json/KotlinSerializationJsonEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/json/KotlinSerializationJsonEncoder.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import kotlinx.serialization.json.Json; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -29,7 +30,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.MediaType; import org.springframework.http.codec.KotlinSerializationStringEncoder; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; /** 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 710d9c0251..a42d273457 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,9 +1,7 @@ /** * JSON encoder and decoder support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec.json; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReader.java index eecf24215a..81eed555a1 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReader.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; @@ -37,7 +38,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.LoggingCodecSupport; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -66,8 +66,7 @@ public class DefaultPartHttpMessageReader extends LoggingCodecSupport implements private int maxParts = -1; - @Nullable - private Scheduler blockingOperationScheduler; + private @Nullable Scheduler blockingOperationScheduler; private FileStorage fileStorage = FileStorage.tempDirectory(this::getBlockingOperationScheduler); diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/FilePartEvent.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/FilePartEvent.java index aecd92e170..1d84ea814f 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/FilePartEvent.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/FilePartEvent.java @@ -21,6 +21,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.http.ContentDisposition; import org.springframework.http.HttpHeaders; 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; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/FormPartEvent.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/FormPartEvent.java index a088729fe9..01134b6689 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/FormPartEvent.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/FormPartEvent.java @@ -19,12 +19,12 @@ package org.springframework.http.codec.multipart; import java.nio.charset.StandardCharsets; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageReader.java index 70092ba650..f6961fb2bf 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageReader.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.LoggingCodecSupport; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java index 2ca17063e5..cf7be2ea1b 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java @@ -25,6 +25,7 @@ import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -47,7 +48,6 @@ import org.springframework.http.codec.EncoderHttpMessageWriter; import org.springframework.http.codec.FormHttpMessageWriter; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ResourceHttpMessageWriter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -81,8 +81,7 @@ public class MultipartHttpMessageWriter extends MultipartWriterSupport private final Supplier>> partWritersSupplier; - @Nullable - private final HttpMessageWriter> formWriter; + private final @Nullable HttpMessageWriter> formWriter; /** @@ -154,8 +153,7 @@ public class MultipartHttpMessageWriter extends MultipartWriterSupport * Return the configured form writer. * @since 5.1.13 */ - @Nullable - public HttpMessageWriter> getFormWriter() { + public @Nullable HttpMessageWriter> getFormWriter() { return this.formWriter; } @@ -315,8 +313,7 @@ public class MultipartHttpMessageWriter extends MultipartWriterSupport private final AtomicBoolean committed = new AtomicBoolean(); - @Nullable - private Flux body; + private @Nullable Flux body; public MultipartHttpOutputMessage(DataBufferFactory bufferFactory) { this.bufferFactory = bufferFactory; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java index 789a3726e4..00cad97953 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartParser.java @@ -30,6 +30,7 @@ import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Subscription; import reactor.core.publisher.BaseSubscriber; import reactor.core.publisher.Flux; @@ -41,7 +42,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferLimitException; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; /** * Subscribes to a buffer stream and produces a flux of {@link Token} instances. diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartUtils.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartUtils.java index b7e4d07db0..46c5ebcab3 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartUtils.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartUtils.java @@ -23,10 +23,11 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * Various static utility methods for dealing with multipart parsing. @@ -50,8 +51,7 @@ abstract class MultipartUtils { return StandardCharsets.UTF_8; } - @Nullable - public static byte[] boundary(HttpMessage message, Charset headersCharset) { + public static byte @Nullable [] boundary(HttpMessage message, Charset headersCharset) { MediaType contentType = message.getHeaders().getContentType(); if (contentType != null) { String boundary = contentType.getParameter("boundary"); diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartWriterSupport.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartWriterSupport.java index 9e78ab9a9e..dba5351a73 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartWriterSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartWriterSupport.java @@ -22,6 +22,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; @@ -29,7 +30,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.codec.LoggingCodecSupport; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FastByteArrayOutputStream; import org.springframework.util.MimeTypeUtils; diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java index 68dc17e57f..26878ea666 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageReader.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -39,7 +40,6 @@ import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.LoggingCodecSupport; import org.springframework.http.codec.multipart.MultipartParser.HeadersToken; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriter.java index 86ec986627..ae9661e856 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartEventHttpMessageWriter.java @@ -19,6 +19,7 @@ package org.springframework.http.codec.multipart; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.codec.HttpMessageWriter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartHttpMessageWriter.java b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartHttpMessageWriter.java index ddf92c14ca..76cd4b6751 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/multipart/PartHttpMessageWriter.java +++ b/spring-web/src/main/java/org/springframework/http/codec/multipart/PartHttpMessageWriter.java @@ -18,6 +18,7 @@ package org.springframework.http.codec.multipart; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -31,7 +32,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.codec.HttpMessageWriter; -import org.springframework.lang.Nullable; /** * {@link HttpMessageWriter} for writing with {@link Part}. This can be useful 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 index 44dad3697d..b1dc18e1ac 100644 --- 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 @@ -1,9 +1,7 @@ /** * Multipart support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec.multipart; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a4c6b8505b..81be0978d4 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,9 +7,7 @@ * {@link org.springframework.http.codec.HttpMessageWriter} for reading and * writing the body of HTTP requests and responses. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufCodecSupport.java b/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufCodecSupport.java index aef7b72cbe..3571bddae7 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufCodecSupport.java +++ b/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufCodecSupport.java @@ -19,7 +19,8 @@ package org.springframework.http.codec.protobuf; import java.util.Arrays; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.MimeType; /** diff --git a/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufDecoder.java index c48a4f00b9..a06d6c0d9b 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/protobuf/ProtobufDecoder.java @@ -28,6 +28,7 @@ import java.util.function.Function; import com.google.protobuf.CodedInputStream; import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.Message; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import org.springframework.core.codec.DecodingException; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferLimitException; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; import org.springframework.util.MimeType; @@ -193,8 +193,7 @@ public class ProtobufDecoder extends ProtobufCodecSupport implements DecoderGoogle Protocol Buffers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec.protobuf; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java index 05c4c0f4a4..85896edc31 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/BaseDefaultCodecs.java @@ -23,6 +23,8 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.core.codec.AbstractDataBufferDecoder; import org.springframework.core.codec.ByteArrayDecoder; import org.springframework.core.codec.ByteArrayEncoder; @@ -72,7 +74,6 @@ import org.springframework.http.codec.protobuf.ProtobufEncoder; import org.springframework.http.codec.protobuf.ProtobufHttpMessageWriter; import org.springframework.http.codec.xml.Jaxb2XmlDecoder; import org.springframework.http.codec.xml.Jaxb2XmlEncoder; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -121,65 +122,45 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure } - @Nullable - private Decoder jackson2JsonDecoder; + private @Nullable Decoder jackson2JsonDecoder; - @Nullable - private Encoder jackson2JsonEncoder; + private @Nullable Encoder jackson2JsonEncoder; - @Nullable - private Encoder jackson2SmileEncoder; + private @Nullable Encoder jackson2SmileEncoder; - @Nullable - private Decoder jackson2SmileDecoder; + private @Nullable Decoder jackson2SmileDecoder; - @Nullable - private Decoder protobufDecoder; + private @Nullable Decoder protobufDecoder; - @Nullable - private Encoder protobufEncoder; + private @Nullable Encoder protobufEncoder; - @Nullable - private Decoder jaxb2Decoder; + private @Nullable Decoder jaxb2Decoder; - @Nullable - private Encoder jaxb2Encoder; + private @Nullable Encoder jaxb2Encoder; - @Nullable - private Decoder kotlinSerializationCborDecoder; + private @Nullable Decoder kotlinSerializationCborDecoder; - @Nullable - private Encoder kotlinSerializationCborEncoder; + private @Nullable Encoder kotlinSerializationCborEncoder; - @Nullable - private Decoder kotlinSerializationJsonDecoder; + private @Nullable Decoder kotlinSerializationJsonDecoder; - @Nullable - private Encoder kotlinSerializationJsonEncoder; + private @Nullable Encoder kotlinSerializationJsonEncoder; - @Nullable - private Decoder kotlinSerializationProtobufDecoder; + private @Nullable Decoder kotlinSerializationProtobufDecoder; - @Nullable - private Encoder kotlinSerializationProtobufEncoder; + private @Nullable Encoder kotlinSerializationProtobufEncoder; - @Nullable - private DefaultMultipartCodecs multipartCodecs; + private @Nullable DefaultMultipartCodecs multipartCodecs; - @Nullable - private Supplier>> partWritersSupplier; + private @Nullable Supplier>> partWritersSupplier; - @Nullable - private HttpMessageReader multipartReader; + private @Nullable HttpMessageReader multipartReader; - @Nullable - private Consumer codecConsumer; + private @Nullable Consumer codecConsumer; - @Nullable - private Integer maxInMemorySize; + private @Nullable Integer maxInMemorySize; - @Nullable - private Boolean enableLoggingRequestDetails; + private @Nullable Boolean enableLoggingRequestDetails; private boolean registerDefaults = true; @@ -352,8 +333,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure } @Override - @Nullable - public Integer maxInMemorySize() { + public @Nullable Integer maxInMemorySize() { return this.maxInMemorySize; } @@ -392,8 +372,7 @@ class BaseDefaultCodecs implements CodecConfigurer.DefaultCodecs, CodecConfigure } @Override - @Nullable - public Boolean isEnableLoggingRequestDetails() { + public @Nullable Boolean isEnableLoggingRequestDetails() { return this.enableLoggingRequestDetails; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java b/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java index a494a74cce..87dd4ddef1 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/ClientDefaultCodecsImpl.java @@ -18,11 +18,12 @@ package org.springframework.http.codec.support; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.codec.Decoder; import org.springframework.http.codec.ClientCodecConfigurer; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerSentEventHttpMessageReader; -import org.springframework.lang.Nullable; /** * Default implementation of {@link ClientCodecConfigurer.ClientDefaultCodecs}. @@ -31,8 +32,7 @@ import org.springframework.lang.Nullable; */ class ClientDefaultCodecsImpl extends BaseDefaultCodecs implements ClientCodecConfigurer.ClientDefaultCodecs { - @Nullable - private Decoder sseDecoder; + private @Nullable Decoder sseDecoder; ClientDefaultCodecsImpl() { diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java b/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java index 52c7bf4079..27ebcc6e68 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/ServerDefaultCodecsImpl.java @@ -18,11 +18,12 @@ package org.springframework.http.codec.support; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.codec.Encoder; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.codec.ServerSentEventHttpMessageWriter; -import org.springframework.lang.Nullable; /** * Default implementation of {@link ServerCodecConfigurer.ServerDefaultCodecs}. @@ -31,8 +32,7 @@ import org.springframework.lang.Nullable; */ class ServerDefaultCodecsImpl extends BaseDefaultCodecs implements ServerCodecConfigurer.ServerDefaultCodecs { - @Nullable - private Encoder sseEncoder; + private @Nullable Encoder sseEncoder; ServerDefaultCodecsImpl() { @@ -55,8 +55,7 @@ class ServerDefaultCodecsImpl extends BaseDefaultCodecs implements ServerCodecCo objectWriters.add(new ServerSentEventHttpMessageWriter(getSseEncoder())); } - @Nullable - private Encoder getSseEncoder() { + private @Nullable Encoder getSseEncoder() { return this.sseEncoder != null ? this.sseEncoder : jackson2Present ? getJackson2JsonEncoder() : kotlinSerializationJsonPresent ? getKotlinSerializationJsonEncoder() : diff --git a/spring-web/src/main/java/org/springframework/http/codec/support/package-info.java b/spring-web/src/main/java/org/springframework/http/codec/support/package-info.java index d2658887eb..f107b92007 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/codec/support/package-info.java @@ -3,9 +3,7 @@ * and {@link org.springframework.http.codec.ServerCodecConfigurer} based on the converter * implementations from {@code org.springframework.http.codec.json} and co. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Helper.java b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Helper.java index 976e116c35..6877ac7196 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Helper.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2Helper.java @@ -30,10 +30,10 @@ import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlSchema; import jakarta.xml.bind.annotation.XmlSeeAlso; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.SynchronousSink; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -150,8 +150,7 @@ abstract class Jaxb2Helper { private final Set names; - @Nullable - private List events; + private @Nullable List events; private int elementDepth = 0; diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java index cc67c3c758..100b2cef65 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlDecoder.java @@ -37,6 +37,8 @@ import jakarta.xml.bind.Unmarshaller; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlSeeAlso; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.Exceptions; import reactor.core.publisher.Flux; @@ -52,8 +54,6 @@ import org.springframework.core.io.buffer.DataBufferLimitException; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.MediaType; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; import org.springframework.util.xml.StaxUtils; @@ -172,8 +172,7 @@ public class Jaxb2XmlDecoder extends AbstractDecoder { } @Override - @NonNull - public Object decode(DataBuffer dataBuffer, ResolvableType targetType, + public @NonNull Object decode(DataBuffer dataBuffer, ResolvableType targetType, @Nullable MimeType mimeType, @Nullable Map hints) throws DecodingException { try { @@ -200,8 +199,7 @@ public class Jaxb2XmlDecoder extends AbstractDecoder { } } - @Nullable - private static String encoding(@Nullable MimeType mimeType) { + private static @Nullable String encoding(@Nullable MimeType mimeType) { if (mimeType == null) { return null; } diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java index b5a2b6d430..c4f8eaaa9d 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/Jaxb2XmlEncoder.java @@ -27,6 +27,7 @@ import jakarta.xml.bind.MarshalException; import jakarta.xml.bind.Marshaller; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -40,7 +41,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; diff --git a/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java b/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java index 877ac5a265..8851262102 100644 --- a/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java +++ b/spring-web/src/main/java/org/springframework/http/codec/xml/XmlEventDecoder.java @@ -33,6 +33,7 @@ import com.fasterxml.aalto.AsyncXMLInputFactory; import com.fasterxml.aalto.AsyncXMLStreamReader; import com.fasterxml.aalto.evt.EventAllocatorImpl; import com.fasterxml.aalto.stax.InputFactoryImpl; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -43,7 +44,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferLimitException; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; 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 2af5e7773e..8adf48afc9 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,9 +1,7 @@ /** * XML encoder and decoder support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.codec.xml; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 e6f31e8d6b..d8db25cdd6 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 @@ -21,11 +21,12 @@ import java.io.OutputStream; import java.lang.reflect.Type; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + 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. @@ -93,7 +94,7 @@ public abstract class AbstractGenericHttpMessageConverter extends AbstractHtt * and then calls {@link #writeInternal}. */ @Override - public final void write(final T t, @Nullable final Type type, @Nullable MediaType contentType, + public final void write(final T t, final @Nullable Type type, @Nullable MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { final HttpHeaders headers = outputMessage.getHeaders(); 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 9404d8a7c8..8c3c280d40 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 @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.List; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; @@ -31,7 +32,6 @@ import org.springframework.http.HttpLogging; 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; /** @@ -54,8 +54,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv private List supportedMediaTypes = Collections.emptyList(); - @Nullable - private Charset defaultCharset; + private @Nullable Charset defaultCharset; /** @@ -119,8 +118,7 @@ public abstract class AbstractHttpMessageConverter implements HttpMessageConv * Return the default character set, if any. * @since 4.3 */ - @Nullable - public Charset getDefaultCharset() { + public @Nullable Charset getDefaultCharset() { return this.defaultCharset; } @@ -281,8 +279,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 { + protected @Nullable MediaType getDefaultContentType(T t) throws IOException { List mediaTypes = getSupportedMediaTypes(); return (!mediaTypes.isEmpty() ? mediaTypes.get(0) : null); } @@ -294,8 +291,7 @@ 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 */ - @Nullable - protected Long getContentLength(T t, @Nullable MediaType contentType) throws IOException { + protected @Nullable Long getContentLength(T t, @Nullable MediaType contentType) throws IOException { return null; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractKotlinSerializationHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractKotlinSerializationHttpMessageConverter.java index e5a17226f6..a6f75e27b5 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractKotlinSerializationHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractKotlinSerializationHttpMessageConverter.java @@ -32,6 +32,7 @@ import kotlinx.serialization.SerialFormat; import kotlinx.serialization.SerializersKt; import kotlinx.serialization.descriptors.PolymorphicKind; import kotlinx.serialization.descriptors.SerialDescriptor; +import org.jspecify.annotations.Nullable; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; @@ -39,7 +40,6 @@ import org.springframework.core.ResolvableType; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentReferenceHashMap; @@ -143,8 +143,7 @@ public abstract class AbstractKotlinSerializationHttpMessageConverter serializer(ResolvableType resolvableType) { + private @Nullable KSerializer serializer(ResolvableType resolvableType) { if (resolvableType.getSource() instanceof MethodParameter parameter) { Method method = parameter.getMethod(); Assert.notNull(method, "Method must not be null"); diff --git a/spring-web/src/main/java/org/springframework/http/converter/AbstractSmartHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/AbstractSmartHttpMessageConverter.java index bcd9494ac7..b74352262a 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/AbstractSmartHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/AbstractSmartHttpMessageConverter.java @@ -20,13 +20,14 @@ import java.io.IOException; import java.io.OutputStream; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.http.HttpHeaders; 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; /** * Abstract base class for most {@link SmartHttpMessageConverter} implementations. diff --git a/spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java index cdb4025e40..b0ffcb3349 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/BufferedImageHttpMessageConverter.java @@ -39,11 +39,12 @@ import javax.imageio.stream.ImageOutputStream; import javax.imageio.stream.MemoryCacheImageInputStream; import javax.imageio.stream.MemoryCacheImageOutputStream; +import org.jspecify.annotations.Nullable; + 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.StreamUtils; import org.springframework.util.StringUtils; @@ -72,11 +73,9 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter readableMediaTypes = new ArrayList<>(); - @Nullable - private MediaType defaultContentType; + private @Nullable MediaType defaultContentType; - @Nullable - private File cacheDir; + private @Nullable File cacheDir; public BufferedImageHttpMessageConverter() { @@ -117,8 +116,7 @@ public class BufferedImageHttpMessageConverter implements HttpMessageConverter availableCharsets; + private volatile @Nullable List availableCharsets; private boolean writeAcceptCharset = false; 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 c8ffa97818..fd0561aa93 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,9 +1,7 @@ /** * Provides an HttpMessageConverter for the CBOR data format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.cbor; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 74d0e0656a..088b438899 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,9 +2,7 @@ * Provides HttpMessageConverter implementations for handling Atom and RSS feeds. * Based on the ROME tools project. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.feed; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 89320c8656..6f5a551926 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 @@ -49,6 +49,7 @@ import com.fasterxml.jackson.databind.SerializationConfig; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.exc.InvalidDefinitionException; import com.fasterxml.jackson.databind.ser.FilterProvider; +import org.jspecify.annotations.Nullable; import org.springframework.core.GenericTypeResolver; import org.springframework.http.HttpInputMessage; @@ -60,7 +61,6 @@ 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.CollectionUtils; import org.springframework.util.StreamUtils; @@ -94,14 +94,11 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener protected ObjectMapper defaultObjectMapper; - @Nullable - private Map, Map> objectMapperRegistrations; + private @Nullable Map, Map> objectMapperRegistrations; - @Nullable - private Boolean prettyPrint; + private @Nullable Boolean prettyPrint; - @Nullable - private final PrettyPrinter ssePrettyPrinter; + private final @Nullable PrettyPrinter ssePrettyPrinter; protected AbstractJackson2HttpMessageConverter(ObjectMapper objectMapper) { @@ -184,8 +181,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener * or empty if in case of no registrations for the given class. * @since 5.3.4 */ - @Nullable - public Map getObjectMappersForType(Class clazz) { + public @Nullable Map getObjectMappersForType(Class clazz) { for (Map.Entry, Map> entry : getObjectMapperRegistrations().entrySet()) { if (entry.getKey().isAssignableFrom(clazz)) { return entry.getValue(); @@ -297,8 +293,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener * if the handling for the given Class has been customized through * {@link #registerObjectMappersForType(Class, Consumer)}. */ - @Nullable - private ObjectMapper selectObjectMapper(Class targetType, @Nullable MediaType targetMediaType) { + private @Nullable ObjectMapper selectObjectMapper(Class targetType, @Nullable MediaType targetMediaType) { if (targetMediaType == null || CollectionUtils.isEmpty(this.objectMapperRegistrations)) { return this.defaultObjectMapper; } @@ -555,8 +550,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener } @Override - @Nullable - protected MediaType getDefaultContentType(Object object) throws IOException { + protected @Nullable MediaType getDefaultContentType(Object object) throws IOException { if (object instanceof MappingJacksonValue mappingJacksonValue) { object = mappingJacksonValue.getValue(); } @@ -564,8 +558,7 @@ public abstract class AbstractJackson2HttpMessageConverter extends AbstractGener } @Override - @Nullable - protected Long getContentLength(Object object, @Nullable MediaType contentType) throws IOException { + protected @Nullable Long getContentLength(Object object, @Nullable MediaType contentType) throws IOException { if (object instanceof MappingJacksonValue mappingJacksonValue) { object = mappingJacksonValue.getValue(); } 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 10382e9d97..1ee9591ea3 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 @@ -25,6 +25,8 @@ import java.lang.reflect.Type; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; + import org.springframework.core.GenericTypeResolver; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; @@ -33,7 +35,6 @@ 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, for example, Gson and JSON-B. @@ -55,8 +56,7 @@ public abstract class AbstractJsonHttpMessageConverter extends AbstractGenericHt */ public static final Charset DEFAULT_CHARSET = StandardCharsets.UTF_8; - @Nullable - private String jsonPrefix; + private @Nullable String jsonPrefix; public AbstractJsonHttpMessageConverter() { diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java b/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java index be63917f52..5ca15a7041 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/GsonFactoryBean.java @@ -20,10 +20,10 @@ import java.text.SimpleDateFormat; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * A {@link FactoryBean} for creating a Google Gson 2.x {@link Gson} instance. @@ -42,11 +42,9 @@ public class GsonFactoryBean implements FactoryBean, InitializingBean { private boolean disableHtmlEscaping = false; - @Nullable - private String dateFormatPattern; + private @Nullable String dateFormatPattern; - @Nullable - private Gson gson; + private @Nullable Gson gson; /** @@ -132,8 +130,7 @@ public class GsonFactoryBean implements FactoryBean, InitializingBean { * Return the created Gson instance. */ @Override - @Nullable - public Gson getObject() { + public @Nullable Gson getObject() { return this.gson; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java index 21b9a7ab2e..d13dea5f28 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/GsonHttpMessageConverter.java @@ -22,8 +22,8 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import com.google.gson.Gson; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java index a76e903388..de5314f1f7 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperBuilder.java @@ -57,12 +57,12 @@ import com.fasterxml.jackson.dataformat.xml.JacksonXmlModule; import com.fasterxml.jackson.dataformat.xml.XmlFactory; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationContext; import org.springframework.core.KotlinDetector; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; @@ -120,38 +120,27 @@ public class Jackson2ObjectMapperBuilder { private boolean createXmlMapper = false; - @Nullable - private JsonFactory factory; + private @Nullable JsonFactory factory; - @Nullable - private DateFormat dateFormat; + private @Nullable DateFormat dateFormat; - @Nullable - private Locale locale; + private @Nullable Locale locale; - @Nullable - private TimeZone timeZone; + private @Nullable TimeZone timeZone; - @Nullable - private AnnotationIntrospector annotationIntrospector; + private @Nullable AnnotationIntrospector annotationIntrospector; - @Nullable - private PropertyNamingStrategy propertyNamingStrategy; + private @Nullable PropertyNamingStrategy propertyNamingStrategy; - @Nullable - private TypeResolverBuilder defaultTyping; + private @Nullable TypeResolverBuilder defaultTyping; - @Nullable - private JsonInclude.Value serializationInclusion; + private JsonInclude.@Nullable Value serializationInclusion; - @Nullable - private FilterProvider filters; + private @Nullable FilterProvider filters; - @Nullable - private List modules; + private @Nullable List modules; - @Nullable - private Class[] moduleClasses; + private Class @Nullable [] moduleClasses; private boolean findModulesViaServiceLoader = false; @@ -159,17 +148,13 @@ public class Jackson2ObjectMapperBuilder { private ClassLoader moduleClassLoader = getClass().getClassLoader(); - @Nullable - private HandlerInstantiator handlerInstantiator; + private @Nullable HandlerInstantiator handlerInstantiator; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private Boolean defaultUseWrapper; + private @Nullable Boolean defaultUseWrapper; - @Nullable - private Consumer configurer; + private @Nullable Consumer configurer; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java index 63b5f3f13c..2a07b46acc 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/Jackson2ObjectMapperFactoryBean.java @@ -40,13 +40,13 @@ import com.fasterxml.jackson.databind.cfg.HandlerInstantiator; import com.fasterxml.jackson.databind.jsontype.TypeResolverBuilder; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.dataformat.xml.XmlMapper; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanClassLoaderAware; import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.lang.Nullable; /** * A {@link FactoryBean} for creating a Jackson 2.x {@link ObjectMapper} (default) or @@ -142,8 +142,7 @@ public class Jackson2ObjectMapperFactoryBean implements FactoryBean getObjectType() { + public @Nullable Class getObjectType() { return (this.objectMapper != null ? this.objectMapper.getClass() : null); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java b/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java index f7f07a9a7f..a3362db5d0 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/JacksonModulesRuntimeHints.java @@ -18,11 +18,12 @@ package org.springframework.http.converter.json; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.aot.hint.TypeHint.Builder; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that registers reflection hints diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java index 97c06b4b86..b235939ba4 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/JsonbHttpMessageConverter.java @@ -24,8 +24,8 @@ import java.lang.reflect.Type; import jakarta.json.bind.Jsonb; import jakarta.json.bind.JsonbBuilder; import jakarta.json.bind.JsonbConfig; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java index ecbd9400a7..15e1927a3f 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverter.java @@ -22,9 +22,9 @@ import java.util.List; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.ObjectMapper; +import org.jspecify.annotations.Nullable; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * Implementation of {@link org.springframework.http.converter.HttpMessageConverter} that can read and @@ -51,8 +51,7 @@ public class MappingJackson2HttpMessageConverter extends AbstractJackson2HttpMes Collections.singletonList(MediaType.APPLICATION_PROBLEM_JSON); - @Nullable - private String jsonPrefix; + private @Nullable String jsonPrefix; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonInputMessage.java b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonInputMessage.java index d882f3b0bc..aa73dc71f2 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonInputMessage.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonInputMessage.java @@ -19,9 +19,10 @@ package org.springframework.http.converter.json; import java.io.IOException; import java.io.InputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; -import org.springframework.lang.Nullable; /** * {@link HttpInputMessage} that can eventually stores a Jackson view that will be used @@ -36,8 +37,7 @@ public class MappingJacksonInputMessage implements HttpInputMessage { private final HttpHeaders headers; - @Nullable - private Class deserializationView; + private @Nullable Class deserializationView; public MappingJacksonInputMessage(InputStream body, HttpHeaders headers) { @@ -65,8 +65,7 @@ public class MappingJacksonInputMessage implements HttpInputMessage { this.deserializationView = deserializationView; } - @Nullable - public Class getDeserializationView() { + public @Nullable Class getDeserializationView() { return this.deserializationView; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonValue.java b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonValue.java index fad90875f2..2c08f45b05 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonValue.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/MappingJacksonValue.java @@ -17,8 +17,7 @@ package org.springframework.http.converter.json; import com.fasterxml.jackson.databind.ser.FilterProvider; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A simple holder for the POJO to serialize via @@ -39,11 +38,9 @@ public class MappingJacksonValue { private Object value; - @Nullable - private Class serializationView; + private @Nullable Class serializationView; - @Nullable - private FilterProvider filters; + private @Nullable FilterProvider filters; /** @@ -83,8 +80,7 @@ public class MappingJacksonValue { * @see com.fasterxml.jackson.databind.ObjectMapper#writerWithView(Class) * @see com.fasterxml.jackson.annotation.JsonView */ - @Nullable - public Class getSerializationView() { + public @Nullable Class getSerializationView() { return this.serializationView; } @@ -105,8 +101,7 @@ public class MappingJacksonValue { * @see com.fasterxml.jackson.databind.ObjectMapper#writer(FilterProvider) * @see com.fasterxml.jackson.annotation.JsonFilter */ - @Nullable - public FilterProvider getFilters() { + public @Nullable FilterProvider getFilters() { return this.filters; } diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonMixin.java b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonMixin.java index 23b32eeffa..0406a95c23 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonMixin.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonMixin.java @@ -21,9 +21,9 @@ import java.util.Map; import com.fasterxml.jackson.annotation.JsonAnyGetter; import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; +import org.jspecify.annotations.Nullable; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonXmlMixin.java b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonXmlMixin.java index b2b2802796..61a268267f 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonXmlMixin.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailJacksonXmlMixin.java @@ -24,8 +24,7 @@ import com.fasterxml.jackson.annotation.JsonAnySetter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY; diff --git a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java index d04fda433f..1e229245b2 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/http/converter/json/ProblemDetailRuntimeHints.java @@ -16,11 +16,12 @@ package org.springframework.http.converter.json; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** 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 5290f00a1c..97d99a6e39 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,9 +1,7 @@ /** * Provides HttpMessageConverter implementations for handling JSON. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.json; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 82ddae975e..3ae7acb594 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,9 +1,7 @@ /** * Provides an HttpMessageConverter abstraction to convert between Java objects and HTTP input/output messages. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java index 72029653db..c8fc030aa2 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/protobuf/ProtobufHttpMessageConverter.java @@ -32,6 +32,7 @@ import com.google.protobuf.ExtensionRegistry; import com.google.protobuf.Message; import com.google.protobuf.TextFormat; import com.google.protobuf.util.JsonFormat; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; @@ -40,7 +41,6 @@ import org.springframework.http.converter.AbstractHttpMessageConverter; import org.springframework.http.converter.HttpMessageConversionException; 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.ClassUtils; import org.springframework.util.ConcurrentReferenceHashMap; @@ -99,8 +99,7 @@ public class ProtobufHttpMessageConverter extends AbstractHttpMessageConverterGoogle Protocol Buffers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.protobuf; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 fee55e553b..a229e5cb74 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,9 +1,7 @@ /** * Provides an HttpMessageConverter for the Smile data format ("binary JSON"). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.smile; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 4dbf1c570a..b75b03e4ae 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,9 +1,7 @@ /** * Provides a comprehensive HttpMessageConverter variant for form handling. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java index 5730286baf..7a7997fc3b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverter.java @@ -37,6 +37,7 @@ import jakarta.xml.bind.UnmarshalException; import jakarta.xml.bind.Unmarshaller; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; @@ -46,7 +47,6 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConversionException; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; import org.springframework.util.xml.StaxUtils; diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java index 8cc8931818..9a2d2cf5e7 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/Jaxb2RootElementHttpMessageConverter.java @@ -35,6 +35,7 @@ import jakarta.xml.bind.UnmarshalException; import jakarta.xml.bind.Unmarshaller; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.Nullable; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -44,7 +45,6 @@ import org.springframework.core.annotation.AnnotationUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConversionException; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -71,8 +71,7 @@ public class Jaxb2RootElementHttpMessageConverter extends AbstractJaxb2HttpMessa private boolean processExternalEntities = false; - @Nullable - private volatile SAXParserFactory sourceParserFactory; + private volatile @Nullable SAXParserFactory sourceParserFactory; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java index 908b0246c5..3d59d9c564 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/MarshallingHttpMessageConverter.java @@ -19,10 +19,11 @@ package org.springframework.http.converter.xml; import javax.xml.transform.Result; import javax.xml.transform.Source; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.TypeMismatchException; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.oxm.Marshaller; import org.springframework.oxm.Unmarshaller; import org.springframework.util.Assert; @@ -43,11 +44,9 @@ import org.springframework.util.Assert; */ public class MarshallingHttpMessageConverter extends AbstractXmlHttpMessageConverter { - @Nullable - private Marshaller marshaller; + private @Nullable Marshaller marshaller; - @Nullable - private Unmarshaller unmarshaller; + private @Nullable Unmarshaller unmarshaller; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java index 1483ea0b4c..be6fa00f99 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/xml/SourceHttpMessageConverter.java @@ -42,6 +42,7 @@ import javax.xml.transform.stax.StAXSource; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Document; import org.xml.sax.EntityResolver; import org.xml.sax.InputSource; @@ -54,7 +55,6 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.AbstractHttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** @@ -85,14 +85,11 @@ public class SourceHttpMessageConverter extends AbstractHttpMe private boolean processExternalEntities = false; - @Nullable - private volatile DocumentBuilderFactory documentBuilderFactory; + private volatile @Nullable DocumentBuilderFactory documentBuilderFactory; - @Nullable - private volatile SAXParserFactory saxParserFactory; + private volatile @Nullable SAXParserFactory saxParserFactory; - @Nullable - private volatile XMLInputFactory xmlInputFactory; + private volatile @Nullable XMLInputFactory xmlInputFactory; /** @@ -266,8 +263,7 @@ public class SourceHttpMessageConverter extends AbstractHttpMe } @Override - @Nullable - protected Long getContentLength(T t, @Nullable MediaType contentType) { + protected @Nullable Long getContentLength(T t, @Nullable MediaType contentType) { if (t instanceof DOMSource) { try { CountingOutputStream os = new CountingOutputStream(); 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 34734d5403..10a7905e29 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,9 +1,7 @@ /** * Provides HttpMessageConverter implementations for handling XML. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.xml; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/converter/yaml/package-info.java b/spring-web/src/main/java/org/springframework/http/converter/yaml/package-info.java index ef3a649192..6b02aaceae 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/yaml/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/converter/yaml/package-info.java @@ -1,9 +1,7 @@ /** * Provides an {@code HttpMessageConverter} for the YAML data format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.converter.yaml; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 8c8e6c19f4..58fc72a63b 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,9 +2,7 @@ * Contains a basic abstraction over client/server-side HTTP. This package contains * the {@code HttpInputMessage} and {@code HttpOutputMessage} interfaces. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java b/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java index 05497984b9..b925bc9dde 100644 --- a/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java +++ b/spring-web/src/main/java/org/springframework/http/server/DefaultPathContainer.java @@ -25,7 +25,8 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; diff --git a/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java b/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java index 0ad453024d..ef1e435d33 100644 --- a/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java +++ b/spring-web/src/main/java/org/springframework/http/server/DefaultRequestPath.java @@ -18,7 +18,8 @@ package org.springframework.http.server; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** diff --git a/spring-web/src/main/java/org/springframework/http/server/RequestPath.java b/spring-web/src/main/java/org/springframework/http/server/RequestPath.java index e98b9b078b..846abfb850 100644 --- a/spring-web/src/main/java/org/springframework/http/server/RequestPath.java +++ b/spring-web/src/main/java/org/springframework/http/server/RequestPath.java @@ -18,7 +18,7 @@ package org.springframework.http.server; import java.net.URI; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Specialization of {@link PathContainer} that subdivides the path into a diff --git a/spring-web/src/main/java/org/springframework/http/server/ServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/ServerHttpRequest.java index c8b1a3a971..ad7b31b2c2 100644 --- a/spring-web/src/main/java/org/springframework/http/server/ServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/ServerHttpRequest.java @@ -19,9 +19,10 @@ package org.springframework.http.server; import java.net.InetSocketAddress; import java.security.Principal; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpRequest; -import org.springframework.lang.Nullable; /** * Represents a server-side HTTP request. @@ -37,8 +38,7 @@ public interface ServerHttpRequest extends HttpRequest, HttpInputMessage { * authenticated user. *

    If the user has not been authenticated, the method returns null. */ - @Nullable - Principal getPrincipal(); + @Nullable Principal getPrincipal(); /** * Return the address on which the request was received. diff --git a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpAsyncRequestControl.java b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpAsyncRequestControl.java index 8cb414d8c9..27d2e6d060 100644 --- a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpAsyncRequestControl.java +++ b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpAsyncRequestControl.java @@ -24,8 +24,8 @@ import jakarta.servlet.AsyncEvent; import jakarta.servlet.AsyncListener; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -43,8 +43,7 @@ public class ServletServerHttpAsyncRequestControl implements ServerHttpAsyncRequ private final ServletServerHttpResponse response; - @Nullable - private AsyncContext asyncContext; + private @Nullable AsyncContext asyncContext; private final AtomicBoolean asyncCompleted = new AtomicBoolean(); diff --git a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java index 39dbd08d4d..32da447629 100644 --- a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpRequest.java @@ -41,12 +41,12 @@ import java.util.Map; import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.InvalidMediaTypeException; 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; @@ -67,18 +67,14 @@ public class ServletServerHttpRequest implements ServerHttpRequest { private final HttpServletRequest servletRequest; - @Nullable - private URI uri; + private @Nullable URI uri; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; - @Nullable - private Map attributes; + private @Nullable Map attributes; - @Nullable - private ServerHttpAsyncRequestControl asyncRequestControl; + private @Nullable ServerHttpAsyncRequestControl asyncRequestControl; /** @@ -209,7 +205,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest { } @Override - public Principal getPrincipal() { + public @Nullable Principal getPrincipal() { return this.servletRequest.getUserPrincipal(); } @@ -305,14 +301,11 @@ public class ServletServerHttpRequest implements ServerHttpRequest { private final class AttributesMap extends AbstractMap { - @Nullable - private transient Set keySet; + private @Nullable transient Set keySet; - @Nullable - private transient Collection values; + private @Nullable transient Collection values; - @Nullable - private transient Set> entrySet; + private @Nullable transient Set> entrySet; @Override @@ -325,8 +318,7 @@ public class ServletServerHttpRequest implements ServerHttpRequest { } @Override - @Nullable - public Object get(Object key) { + public @Nullable Object get(Object key) { if (key instanceof String name) { return servletRequest.getAttribute(name); } @@ -336,16 +328,14 @@ public class ServletServerHttpRequest implements ServerHttpRequest { } @Override - @Nullable - public Object put(String key, Object value) { + public @Nullable Object put(String key, Object value) { Object old = get(key); servletRequest.setAttribute(key, value); return old; } @Override - @Nullable - public Object remove(Object key) { + public @Nullable Object remove(Object key) { if (key instanceof String name) { Object old = get(key); servletRequest.removeAttribute(name); diff --git a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java index f6d3ef6cbd..f09d8a9018 100644 --- a/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/ServletServerHttpResponse.java @@ -24,11 +24,11 @@ import java.util.Collections; import java.util.List; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -49,8 +49,7 @@ public class ServletServerHttpResponse implements ServerHttpResponse { private boolean bodyUsed = false; - @Nullable - private HttpHeaders readOnlyHeaders; + private @Nullable HttpHeaders readOnlyHeaders; /** @@ -157,8 +156,7 @@ public class ServletServerHttpResponse implements ServerHttpResponse { } @Override - @Nullable - public String getFirst(String headerName) { + public @Nullable String getFirst(String headerName) { if (headerName.equalsIgnoreCase(CONTENT_TYPE)) { // Content-Type is written as an override so check super first String value = super.getFirst(headerName); @@ -171,8 +169,7 @@ public class ServletServerHttpResponse implements ServerHttpResponse { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { Assert.isInstanceOf(String.class, key, "Key must be a String-based header name"); String headerName = (String) key; diff --git a/spring-web/src/main/java/org/springframework/http/server/observation/ServerRequestObservationContext.java b/spring-web/src/main/java/org/springframework/http/server/observation/ServerRequestObservationContext.java index bf37e01df1..f316767a36 100644 --- a/spring-web/src/main/java/org/springframework/http/server/observation/ServerRequestObservationContext.java +++ b/spring-web/src/main/java/org/springframework/http/server/observation/ServerRequestObservationContext.java @@ -19,8 +19,7 @@ package org.springframework.http.server.observation; import io.micrometer.observation.transport.RequestReplyReceiverContext; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Context that holds information for metadata collection regarding @@ -33,8 +32,7 @@ import org.springframework.lang.Nullable; */ public class ServerRequestObservationContext extends RequestReplyReceiverContext { - @Nullable - private String pathPattern; + private @Nullable String pathPattern; public ServerRequestObservationContext(HttpServletRequest request, HttpServletResponse response) { super(HttpServletRequest::getHeader); @@ -42,8 +40,7 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext setResponse(response); } - @Nullable - public String getPathPattern() { + public @Nullable String getPathPattern() { return this.pathPattern; } diff --git a/spring-web/src/main/java/org/springframework/http/server/observation/package-info.java b/spring-web/src/main/java/org/springframework/http/server/observation/package-info.java index aebdd17f17..7a60832776 100644 --- a/spring-web/src/main/java/org/springframework/http/server/observation/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/server/observation/package-info.java @@ -1,9 +1,7 @@ /** * Instrumentation for {@link io.micrometer.observation.Observation observing} HTTP server applications. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.server.observation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 8c7e71cd98..c2cd0afbf4 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,9 +3,7 @@ * contains the {@code ServerHttpRequest} and {@code ServerHttpResponse}, * as well as a Servlet-based implementation of these interfaces. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 72d68e8b05..75a93b8b1c 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 @@ -21,6 +21,7 @@ import java.util.concurrent.atomic.AtomicLongFieldUpdater; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -29,7 +30,6 @@ import reactor.core.publisher.Operators; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.core.log.LogDelegateFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -70,15 +70,13 @@ public abstract class AbstractListenerReadPublisher implements Publisher { private static final AtomicLongFieldUpdater DEMAND_FIELD_UPDATER = AtomicLongFieldUpdater.newUpdater(AbstractListenerReadPublisher.class, "demand"); - @Nullable - private volatile Subscriber subscriber; + private volatile @Nullable Subscriber subscriber; /** Flag to defer transition to COMPLETED briefly while SUBSCRIBING or READING. */ private volatile boolean completionPending; /** Flag to defer transition to COMPLETED briefly while SUBSCRIBING or READING. */ - @Nullable - private volatile Throwable errorPending; + private volatile @Nullable Throwable errorPending; private final String logPrefix; @@ -162,8 +160,7 @@ public abstract class AbstractListenerReadPublisher implements Publisher { * Read once from the input, if possible. * @return the item that was read; or {@code null} */ - @Nullable - protected abstract T read() throws IOException; + protected abstract @Nullable T read() throws IOException; /** * Invoked when reading is paused due to a lack of demand. diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java index 2392f85ea9..049a113562 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteFlushProcessor.java @@ -20,13 +20,13 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Processor; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import org.springframework.core.log.LogDelegateFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -56,13 +56,11 @@ public abstract class AbstractListenerWriteFlushProcessor implements Processo private final AtomicReference state = new AtomicReference<>(State.UNSUBSCRIBED); - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; private volatile boolean sourceCompleted; - @Nullable - private volatile AbstractListenerWriteProcessor currentWriteProcessor; + private volatile @Nullable AbstractListenerWriteProcessor currentWriteProcessor; private final WriteResultPublisher resultPublisher; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java index ef9b8976b1..8a401a644a 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractListenerWriteProcessor.java @@ -20,12 +20,12 @@ import java.io.IOException; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Processor; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import org.springframework.core.log.LogDelegateFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -58,11 +58,9 @@ public abstract class AbstractListenerWriteProcessor implements Processor state = new AtomicReference<>(State.UNSUBSCRIBED); - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; - @Nullable - private volatile T currentData; + private volatile @Nullable T currentData; /* Indicates "onComplete" was received during the (last) write. */ private volatile boolean sourceCompleted; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java index 9c9fea5e3c..19abe1646b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/AbstractServerHttpRequest.java @@ -25,11 +25,12 @@ import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -50,33 +51,25 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { private final URI uri; - @Nullable - private final String contextPath; + private final @Nullable String contextPath; - @Nullable - private RequestPath path; + private @Nullable RequestPath path; private final HttpHeaders headers; private final HttpMethod method; - @Nullable - private MultiValueMap queryParams; + private @Nullable MultiValueMap queryParams; - @Nullable - private MultiValueMap cookies; + private @Nullable MultiValueMap cookies; - @Nullable - private SslInfo sslInfo; + private @Nullable SslInfo sslInfo; - @Nullable - private String id; + private @Nullable String id; - @Nullable - private String logPrefix; + private @Nullable String logPrefix; - @Nullable - private Supplier> attributesSupplier; + private @Nullable Supplier> attributesSupplier; /** @@ -117,8 +110,7 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { * identity of this request instance is used. * @since 5.1 */ - @Nullable - protected String initId() { + protected @Nullable String initId() { return null; } @@ -209,9 +201,8 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { */ protected abstract MultiValueMap initCookies(); - @Nullable @Override - public SslInfo getSslInfo() { + public @Nullable SslInfo getSslInfo() { if (this.sslInfo == null) { this.sslInfo = initSslInfo(); } @@ -223,8 +214,7 @@ public abstract class AbstractServerHttpRequest implements ServerHttpRequest { * @return the session information, or {@code null} if none available * @since 5.0.2 */ - @Nullable - protected abstract SslInfo initSslInfo(); + protected abstract @Nullable SslInfo initSslInfo(); /** * Return the underlying server response. 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 fa15f6d522..79a169ef82 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 @@ -22,6 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; 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; @@ -60,8 +60,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { private final DataBufferFactory dataBufferFactory; - @Nullable - private HttpStatusCode statusCode; + private @Nullable HttpStatusCode statusCode; private final HttpHeaders headers; @@ -71,8 +70,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { private final List>> commitActions = new CopyOnWriteArrayList<>(); - @Nullable - private HttpHeaders readOnlyHeaders; + private @Nullable HttpHeaders readOnlyHeaders; public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory) { @@ -105,8 +103,7 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse { } @Override - @Nullable - public HttpStatusCode getStatusCode() { + public @Nullable HttpStatusCode getStatusCode() { return this.statusCode; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java index 6b1bf8d7e1..55c3420b6e 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ChannelSendOperator.java @@ -18,6 +18,7 @@ package org.springframework.http.server.reactive; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -30,7 +31,6 @@ import reactor.util.context.Context; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -60,9 +60,8 @@ public class ChannelSendOperator extends Mono implements Scannable { @Override - @Nullable @SuppressWarnings("rawtypes") - public Object scanUnsafe(Attr key) { + public @Nullable Object scanUnsafe(Attr key) { if (key == Attr.PREFETCH) { return Integer.MAX_VALUE; } @@ -126,16 +125,13 @@ public class ChannelSendOperator extends Mono implements Scannable { private final WriteCompletionBarrier writeCompletionBarrier; /* Upstream write source subscription */ - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; /** Cached data item before readyToWrite. */ - @Nullable - private T item; + private @Nullable T item; /** Cached error signal before readyToWrite. */ - @Nullable - private Throwable error; + private @Nullable Throwable error; /** Cached onComplete signal before readyToWrite. */ private boolean completed = false; @@ -147,8 +143,7 @@ public class ChannelSendOperator extends Mono implements Scannable { private State state = State.NEW; /** The actual writeSubscriber from the HTTP server adapter. */ - @Nullable - private Subscriber writeSubscriber; + private @Nullable Subscriber writeSubscriber; WriteBarrier(CoreSubscriber completionSubscriber) { @@ -383,8 +378,7 @@ public class ChannelSendOperator extends Mono implements Scannable { private final WriteBarrier writeBarrier; - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; public WriteCompletionBarrier(CoreSubscriber subscriber, WriteBarrier writeBarrier) { diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java index 6157e38ee7..1355ecd996 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultServerHttpRequestBuilder.java @@ -22,13 +22,13 @@ import java.net.URISyntaxException; import java.util.Arrays; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -49,17 +49,13 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder { private HttpMethod httpMethod; - @Nullable - private String uriPath; + private @Nullable String uriPath; - @Nullable - private String contextPath; + private @Nullable String contextPath; - @Nullable - private SslInfo sslInfo; + private @Nullable SslInfo sslInfo; - @Nullable - private InetSocketAddress remoteAddress; + private @Nullable InetSocketAddress remoteAddress; private final Flux body; @@ -182,11 +178,9 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder { private static class MutatedServerHttpRequest extends AbstractServerHttpRequest { - @Nullable - private final SslInfo sslInfo; + private final @Nullable SslInfo sslInfo; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; private final Flux body; @@ -209,20 +203,17 @@ class DefaultServerHttpRequestBuilder implements ServerHttpRequest.Builder { } @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return this.originalRequest.getLocalAddress(); } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.remoteAddress; } @Override - @Nullable - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { return this.sslInfo; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java index 4ca73c11d3..b47c095761 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/DefaultSslInfo.java @@ -23,7 +23,8 @@ import java.util.List; import javax.net.ssl.SSLSession; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -34,11 +35,9 @@ import org.springframework.util.Assert; */ final class DefaultSslInfo implements SslInfo { - @Nullable - private final String sessionId; + private final @Nullable String sessionId; - @Nullable - private final X509Certificate[] peerCertificates; + private final X509Certificate @Nullable [] peerCertificates; DefaultSslInfo(@Nullable String sessionId, X509Certificate[] peerCertificates) { @@ -55,20 +54,17 @@ final class DefaultSslInfo implements SslInfo { @Override - @Nullable - public String getSessionId() { + public @Nullable String getSessionId() { return this.sessionId; } @Override - @Nullable - public X509Certificate[] getPeerCertificates() { + public X509Certificate @Nullable [] getPeerCertificates() { return this.peerCertificates; } - @Nullable - private static String initSessionId(SSLSession session) { + private static @Nullable String initSessionId(SSLSession session) { byte [] bytes = session.getId(); if (bytes == null) { return null; @@ -88,8 +84,7 @@ final class DefaultSslInfo implements SslInfo { return sb.toString(); } - @Nullable - private static X509Certificate[] initCertificates(SSLSession session) { + private static X509Certificate @Nullable [] initCertificates(SSLSession session) { Certificate[] certificates; try { certificates = session.getPeerCertificates(); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpRequest.java index d97832a2ff..a43730b8b4 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpRequest.java @@ -24,6 +24,7 @@ import java.util.List; import org.eclipse.jetty.io.Content; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.server.Request; +import org.jspecify.annotations.Nullable; import org.reactivestreams.FlowAdapters; import reactor.core.publisher.Flux; @@ -33,7 +34,6 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.support.JettyHeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -75,8 +75,7 @@ class JettyCoreServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - public SslInfo initSslInfo() { + public @Nullable SslInfo initSslInfo() { if (this.request.getConnectionMetaData().isSecure() && this.request.getAttribute(EndPoint.SslSessionData.ATTRIBUTE) instanceof EndPoint.SslSessionData sessionData) { return new DefaultSslInfo(sessionData.sslSessionId(), sessionData.peerCertificates()); @@ -96,15 +95,13 @@ class JettyCoreServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { SocketAddress localAddress = this.request.getConnectionMetaData().getLocalSocketAddress(); return localAddress instanceof InetSocketAddress inet ? inet : null; } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { SocketAddress remoteAddress = this.request.getConnectionMetaData().getRemoteSocketAddress(); return remoteAddress instanceof InetSocketAddress inet ? inet : null; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpResponse.java index a53cab4219..dc319c1862 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/JettyCoreServerHttpResponse.java @@ -29,6 +29,7 @@ import org.eclipse.jetty.server.HttpCookieUtils; import org.eclipse.jetty.server.Response; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IteratingCallback; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -41,7 +42,6 @@ import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; import org.springframework.http.ZeroCopyHttpOutputMessage; import org.springframework.http.support.JettyHeadersAdapter; -import org.springframework.lang.Nullable; /** * Adapt an Eclipse Jetty {@link Response} to an {@link org.springframework.http.server.ServerHttpResponse}. @@ -192,20 +192,17 @@ class JettyCoreServerHttpResponse extends AbstractServerHttpResponse implements } @Override - @Nullable - public String getComment() { + public @Nullable String getComment() { return null; } @Override - @Nullable - public String getDomain() { + public @Nullable String getDomain() { return this.responseCookie.getDomain(); } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.responseCookie.getPath(); } @@ -214,9 +211,8 @@ class JettyCoreServerHttpResponse extends AbstractServerHttpResponse implements return this.responseCookie.isSecure(); } - @Nullable @Override - public SameSite getSameSite() { + public @Nullable SameSite getSameSite() { // Adding non-null return site breaks tests. return null; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java index d61f634381..f9dadffcc9 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorNetty2ServerHttpRequest.java @@ -28,6 +28,7 @@ import io.netty5.handler.codec.http.HttpHeaderNames; import io.netty5.handler.codec.http.headers.HttpCookiePair; import io.netty5.handler.ssl.SslHandler; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.netty5.ChannelOperationsId; import reactor.netty5.Connection; @@ -39,7 +40,6 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpLogging; import org.springframework.http.HttpMethod; import org.springframework.http.support.Netty5HeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -156,20 +156,17 @@ class ReactorNetty2ServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return this.request.hostAddress(); } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.request.remoteAddress(); } @Override - @Nullable - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { Channel channel = ((Connection) this.request).channel(); SslHandler sslHandler = channel.pipeline().get(SslHandler.class); if (sslHandler == null && channel.parent() != null) { // HTTP/2 @@ -194,8 +191,7 @@ class ReactorNetty2ServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - protected String initId() { + protected @Nullable String initId() { if (this.request instanceof Connection connection) { return connection.channel().id().asShortText() + "-" + logPrefixIndex.incrementAndGet(); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java index b136e9bbb7..6f71068a90 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ReactorServerHttpRequest.java @@ -26,6 +26,7 @@ import io.netty.channel.Channel; import io.netty.handler.codec.http.cookie.Cookie; import io.netty.handler.ssl.SslHandler; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.netty.ChannelOperationsId; import reactor.netty.Connection; @@ -37,7 +38,6 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpLogging; import org.springframework.http.HttpMethod; import org.springframework.http.support.Netty4HeadersAdapter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -86,20 +86,17 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return this.request.hostAddress(); } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.request.remoteAddress(); } @Override - @Nullable - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { Channel channel = ((Connection) this.request).channel(); SslHandler sslHandler = channel.pipeline().get(SslHandler.class); if (sslHandler == null && channel.parent() != null) { // HTTP/2 @@ -124,8 +121,7 @@ class ReactorServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - protected String initId() { + protected @Nullable String initId() { if (this.request instanceof Connection connection) { return connection.channel().id().asShortText() + "-" + logPrefixIndex.incrementAndGet(); 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 55f5fa2c65..63bf5fdc81 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 @@ -20,13 +20,14 @@ import java.net.InetSocketAddress; import java.net.URI; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpRequest; import org.springframework.http.ReactiveHttpInputMessage; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -73,16 +74,14 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage * Return the local address the request was accepted on, if available. * @since 5.2.3 */ - @Nullable - default InetSocketAddress getLocalAddress() { + default @Nullable InetSocketAddress getLocalAddress() { return null; } /** * Return the remote address where this request is connected to, if available. */ - @Nullable - default InetSocketAddress getRemoteAddress() { + default @Nullable InetSocketAddress getRemoteAddress() { return null; } @@ -92,8 +91,7 @@ public interface ServerHttpRequest extends HttpRequest, ReactiveHttpInputMessage * @return the session information, or {@code null} if none available * @since 5.0.2 */ - @Nullable - default SslInfo getSslInfo() { + default @Nullable SslInfo getSslInfo() { return null; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java index fbeacac718..793b8bd05b 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpRequestDecorator.java @@ -20,6 +20,7 @@ import java.net.InetSocketAddress; import java.net.URI; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.io.buffer.DataBuffer; @@ -27,7 +28,6 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -97,20 +97,17 @@ public class ServerHttpRequestDecorator implements ServerHttpRequest { } @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return getDelegate().getLocalAddress(); } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return getDelegate().getRemoteAddress(); } @Override - @Nullable - public SslInfo getSslInfo() { + public @Nullable SslInfo getSslInfo() { return getDelegate().getSslInfo(); } 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 11194f2154..595e81a231 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 @@ -16,10 +16,11 @@ package org.springframework.http.server.reactive; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpStatusCode; import org.springframework.http.ReactiveHttpOutputMessage; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** @@ -46,8 +47,7 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage { * be {@code null} if there is no default value from the * underlying server. */ - @Nullable - HttpStatusCode getStatusCode(); + @Nullable HttpStatusCode getStatusCode(); /** * Set the HTTP status code to the given value as an integer. diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java index f9f7fda828..a93faf282e 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServerHttpResponseDecorator.java @@ -18,6 +18,7 @@ package org.springframework.http.server.reactive; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -26,7 +27,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -61,8 +61,7 @@ public class ServerHttpResponseDecorator implements ServerHttpResponse { } @Override - @Nullable - public HttpStatusCode getStatusCode() { + public @Nullable HttpStatusCode getStatusCode() { return getDelegate().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 e16a4b6287..4441625970 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 @@ -35,6 +35,7 @@ import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -42,7 +43,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpLogging; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -67,8 +67,7 @@ public class ServletHttpHandlerAdapter implements Servlet { private int bufferSize = DEFAULT_BUFFER_SIZE; - @Nullable - private String servletPath; + private @Nullable String servletPath; private DataBufferFactory dataBufferFactory = DefaultDataBufferFactory.sharedInstance; @@ -102,8 +101,7 @@ public class ServletHttpHandlerAdapter implements Servlet { * a prefix (i.e. "/" or "/*"), or {@code null} if this method is invoked * before the {@link #init(ServletConfig)} Servlet container callback. */ - @Nullable - public String getServletPath() { + public @Nullable String getServletPath() { return this.servletPath; } @@ -219,8 +217,7 @@ public class ServletHttpHandlerAdapter implements Servlet { } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { return null; } @@ -357,8 +354,7 @@ public class ServletHttpHandlerAdapter implements Servlet { private final String logPrefix; - @Nullable - private volatile Subscription subscription; + private volatile @Nullable Subscription subscription; public HandlerResultSubscriber(AsyncContext asyncContext, AtomicBoolean completionFlag, String logPrefix) { this.asyncContext = asyncContext; 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 ee2b9a5014..c361c566f9 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 @@ -35,6 +35,8 @@ import jakarta.servlet.ServletInputStream; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.io.buffer.DataBuffer; @@ -45,8 +47,6 @@ import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedCaseInsensitiveMap; @@ -214,31 +214,26 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest { } @Override - @NonNull - public InetSocketAddress getLocalAddress() { + public @NonNull InetSocketAddress getLocalAddress() { return new InetSocketAddress(this.request.getLocalAddr(), this.request.getLocalPort()); } @Override - @NonNull - public InetSocketAddress getRemoteAddress() { + public @NonNull InetSocketAddress getRemoteAddress() { return new InetSocketAddress(this.request.getRemoteHost(), this.request.getRemotePort()); } @Override - @Nullable - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { X509Certificate[] certificates = getX509Certificates(); return (certificates != null ? new DefaultSslInfo(getSslSessionId(), certificates) : null); } - @Nullable - private String getSslSessionId() { + private @Nullable String getSslSessionId() { return (String) this.request.getAttribute("jakarta.servlet.request.ssl_session_id"); } - @Nullable - private X509Certificate[] getX509Certificates() { + private X509Certificate @Nullable [] getX509Certificates() { return (X509Certificate[]) this.request.getAttribute("jakarta.servlet.request.X509Certificate"); } @@ -359,8 +354,7 @@ class ServletServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - protected DataBuffer read() throws IOException { + protected @Nullable DataBuffer read() throws IOException { if (this.inputStream.isReady()) { DataBuffer dataBuffer = readFromInputStream(); if (dataBuffer == EOF_BUFFER) { diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java index c2ccdbbcdd..e2a5aa2043 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/ServletServerHttpResponse.java @@ -27,6 +27,7 @@ import jakarta.servlet.ServletOutputStream; import jakarta.servlet.WriteListener; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Processor; import org.reactivestreams.Publisher; @@ -37,7 +38,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -54,11 +54,9 @@ class ServletServerHttpResponse extends AbstractListenerServerHttpResponse { private final ServletOutputStream outputStream; - @Nullable - private volatile ResponseBodyFlushProcessor bodyFlushProcessor; + private volatile @Nullable ResponseBodyFlushProcessor bodyFlushProcessor; - @Nullable - private volatile ResponseBodyProcessor bodyProcessor; + private volatile @Nullable ResponseBodyProcessor bodyProcessor; private volatile boolean flushOnNext; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java b/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java index 47e4f9a1bf..04ad09ffda 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/SslInfo.java @@ -18,7 +18,7 @@ package org.springframework.http.server.reactive; import java.security.cert.X509Certificate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A holder for SSL session information. @@ -31,13 +31,11 @@ public interface SslInfo { /** * Return the SSL session id, if any. */ - @Nullable - String getSessionId(); + @Nullable String getSessionId(); /** * Return SSL certificates associated with the request, if any. */ - @Nullable - X509Certificate[] getPeerCertificates(); + X509Certificate @Nullable [] getPeerCertificates(); } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java index b5f37e7b3c..83aeb13933 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java @@ -29,9 +29,9 @@ import java.util.Set; import org.apache.tomcat.util.buf.MessageBytes; import org.apache.tomcat.util.http.MimeHeaders; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -128,8 +128,7 @@ class TomcatHeadersAdapter implements MultiValueMap { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { if (containsKey(key)) { return Collections.list(this.headers.values((String) key)); } @@ -137,8 +136,7 @@ class TomcatHeadersAdapter implements MultiValueMap { } @Override - @Nullable - public List put(String key, List value) { + public @Nullable List put(String key, List value) { List previousValues = get(key); this.headers.removeHeader(key); value.forEach(v -> this.headers.addValue(key).setString(v)); @@ -146,8 +144,7 @@ class TomcatHeadersAdapter implements MultiValueMap { } @Override - @Nullable - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List previousValues = get(key); this.headers.removeHeader(headerName); @@ -227,15 +224,13 @@ class TomcatHeadersAdapter implements MultiValueMap { return this.key; } - @Nullable @Override - public List getValue() { + public @Nullable List getValue() { return get(this.key); } - @Nullable @Override - public List setValue(List value) { + public @Nullable List setValue(List value) { List previous = getValue(); headers.removeHeader(this.key); addAll(this.key, value); @@ -267,8 +262,7 @@ class TomcatHeadersAdapter implements MultiValueMap { private final Enumeration enumeration; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Enumeration enumeration) { this.enumeration = enumeration; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHeadersAdapter.java index 9e24903187..e00b1565f2 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowHeadersAdapter.java @@ -28,8 +28,8 @@ import java.util.stream.Collectors; import io.undertow.util.HeaderMap; import io.undertow.util.HeaderValues; import io.undertow.util.HttpString; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -113,22 +113,19 @@ class UndertowHeadersAdapter implements MultiValueMap { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { return (key instanceof String headerName ? this.headers.get(headerName) : null); } @Override - @Nullable - public List put(String key, List value) { + public @Nullable List put(String key, List value) { HeaderValues previousValues = this.headers.get(key); this.headers.putAll(HttpString.tryFromString(key), value); return previousValues; } @Override - @Nullable - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { Collection removed = this.headers.remove(headerName); if (removed != null) { @@ -243,8 +240,7 @@ class UndertowHeadersAdapter implements MultiValueMap { private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java index 324e734ad5..008023ee74 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpRequest.java @@ -29,6 +29,7 @@ import io.undertow.connector.ByteBufferPool; import io.undertow.connector.PooledByteBuffer; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.Cookie; +import org.jspecify.annotations.Nullable; import org.xnio.channels.StreamSourceChannel; import reactor.core.publisher.Flux; @@ -36,7 +37,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.HttpCookie; 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; @@ -90,20 +90,17 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return this.exchange.getDestinationAddress(); } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.exchange.getSourceAddress(); } - @Nullable @Override - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { SSLSession session = this.exchange.getConnection().getSslSession(); if (session != null) { return new DefaultSslInfo(session); @@ -167,8 +164,7 @@ class UndertowServerHttpRequest extends AbstractServerHttpRequest { } @Override - @Nullable - protected DataBuffer read() throws IOException { + protected @Nullable DataBuffer read() throws IOException { PooledByteBuffer pooledByteBuffer = this.byteBufferPool.allocate(); try (pooledByteBuffer) { ByteBuffer byteBuffer = pooledByteBuffer.getBuffer(); diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java index 65ed91a604..1a3f0f9ca4 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/UndertowServerHttpResponse.java @@ -25,6 +25,7 @@ import java.nio.file.StandardOpenOption; import io.undertow.server.HttpServerExchange; import io.undertow.server.handlers.Cookie; import io.undertow.server.handlers.CookieImpl; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Processor; import org.reactivestreams.Publisher; import org.xnio.channels.StreamSinkChannel; @@ -38,7 +39,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; import org.springframework.http.ZeroCopyHttpOutputMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -56,8 +56,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl private final UndertowServerHttpRequest request; - @Nullable - private StreamSinkChannel responseChannel; + private @Nullable StreamSinkChannel responseChannel; UndertowServerHttpResponse( @@ -157,8 +156,7 @@ class UndertowServerHttpResponse extends AbstractListenerServerHttpResponse impl private final StreamSinkChannel channel; - @Nullable - private volatile ByteBuffer byteBuffer; + private volatile @Nullable ByteBuffer byteBuffer; /** Keep track of write listener calls, for {@link #writePossible}. */ private volatile boolean writePossible; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java b/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java index da41ee1450..9f0d8adcdb 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/WriteResultPublisher.java @@ -19,13 +19,13 @@ package org.springframework.http.server.reactive; import java.util.concurrent.atomic.AtomicReference; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.publisher.Operators; import org.springframework.core.log.LogDelegateFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -53,13 +53,11 @@ class WriteResultPublisher implements Publisher { private final Runnable cancelTask; - @Nullable - private volatile Subscriber subscriber; + private volatile @Nullable Subscriber subscriber; private volatile boolean completedBeforeSubscribed; - @Nullable - private volatile Throwable errorBeforeSubscribed; + private volatile @Nullable Throwable errorBeforeSubscribed; private final String logPrefix; diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java b/spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java index fa7454afac..658edf44c5 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/observation/ServerRequestObservationContext.java @@ -21,10 +21,10 @@ import java.util.Map; import java.util.Optional; import io.micrometer.observation.transport.RequestReplyReceiverContext; +import org.jspecify.annotations.Nullable; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; /** * Context that holds information for metadata collection regarding @@ -49,8 +49,7 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext private final Map attributes; - @Nullable - private String pathPattern; + private @Nullable String pathPattern; private boolean connectionAborted; @@ -84,8 +83,7 @@ public class ServerRequestObservationContext extends RequestReplyReceiverContext *

    Path patterns must have a low cardinality for the entire application. * @return the path pattern, or {@code null} if none found */ - @Nullable - public String getPathPattern() { + public @Nullable String getPathPattern() { return this.pathPattern; } diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/observation/package-info.java b/spring-web/src/main/java/org/springframework/http/server/reactive/observation/package-info.java index d00ac21e82..f0e8992ed0 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/observation/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/observation/package-info.java @@ -1,9 +1,7 @@ /** * Instrumentation for {@link io.micrometer.observation.Observation observing} reactive HTTP server applications. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.server.reactive.observation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 25e89a1f03..10c41e5feb 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,9 +7,7 @@ *

    Also provides implementations adapting to different runtimes * including Servlet containers, Netty + Reactor IO, and Undertow. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.server.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/http/support/HttpComponentsHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/support/HttpComponentsHeadersAdapter.java index 7bb2682aec..9628b39c49 100644 --- a/spring-web/src/main/java/org/springframework/http/support/HttpComponentsHeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/support/HttpComponentsHeadersAdapter.java @@ -29,9 +29,9 @@ import java.util.Set; import org.apache.hc.core5.http.Header; import org.apache.hc.core5.http.HttpMessage; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.MultiValueMap; @@ -66,8 +66,7 @@ public final class HttpComponentsHeadersAdapter implements MultiValueMap h.getValue().equals(value))); } - @Nullable @Override - public List get(Object key) { + public @Nullable List get(Object key) { List values = null; if (containsKey(key)) { Header[] headers = this.message.getHeaders((String) key); @@ -141,17 +139,15 @@ public final class HttpComponentsHeadersAdapter implements MultiValueMap put(String key, List values) { + public @Nullable List put(String key, List values) { List oldValues = remove(key); values.forEach(value -> add(key, value)); return oldValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List oldValues = get(key); this.headerNames.remove(headerName); @@ -267,8 +263,7 @@ public final class HttpComponentsHeadersAdapter implements MultiValueMap iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; diff --git a/spring-web/src/main/java/org/springframework/http/support/JettyHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/support/JettyHeadersAdapter.java index aa98ae4223..ee0b35e08c 100644 --- a/spring-web/src/main/java/org/springframework/http/support/JettyHeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/support/JettyHeadersAdapter.java @@ -28,9 +28,9 @@ import java.util.Set; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.http.HttpFields; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.MultiValueMap; @@ -48,8 +48,7 @@ public final class JettyHeadersAdapter implements MultiValueMap private final HttpFields headers; - @Nullable - private final HttpFields.Mutable mutable; + private final HttpFields.@Nullable Mutable mutable; /** @@ -143,9 +142,8 @@ public final class JettyHeadersAdapter implements MultiValueMap return false; } - @Nullable @Override - public List get(Object key) { + public @Nullable List get(Object key) { List list = null; if (key instanceof String name) { for (HttpField f : this.headers) { @@ -160,9 +158,8 @@ public final class JettyHeadersAdapter implements MultiValueMap return list; } - @Nullable @Override - public List put(String key, List value) { + public @Nullable List put(String key, List value) { HttpFields.Mutable mutableHttpFields = mutableFields(); List oldValues = get(key); @@ -183,9 +180,8 @@ public final class JettyHeadersAdapter implements MultiValueMap return oldValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { HttpFields.Mutable mutableHttpFields = mutableFields(); List list = null; if (key instanceof String name) { @@ -315,8 +311,7 @@ public final class JettyHeadersAdapter implements MultiValueMap private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; diff --git a/spring-web/src/main/java/org/springframework/http/support/Netty4HeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/support/Netty4HeadersAdapter.java index 4a4fa8f578..a9ec05b7b2 100644 --- a/spring-web/src/main/java/org/springframework/http/support/Netty4HeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/support/Netty4HeadersAdapter.java @@ -25,8 +25,8 @@ import java.util.Map; import java.util.Set; import io.netty.handler.codec.http.HttpHeaders; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.MultiValueMap; @@ -55,8 +55,7 @@ public final class Netty4HeadersAdapter implements MultiValueMap @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { return this.headers.get(key); } @@ -125,25 +124,22 @@ public final class Netty4HeadersAdapter implements MultiValueMap } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { if (containsKey(key)) { return this.headers.getAll((String) key); } return null; } - @Nullable @Override - public List put(String key, @Nullable List value) { + public @Nullable List put(String key, @Nullable List value) { List previousValues = this.headers.getAll(key); this.headers.set(key, value); return previousValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List previousValues = this.headers.getAll(headerName); this.headers.remove(headerName); @@ -255,8 +251,7 @@ public final class Netty4HeadersAdapter implements MultiValueMap private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; diff --git a/spring-web/src/main/java/org/springframework/http/support/Netty5HeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/support/Netty5HeadersAdapter.java index 79f6750d76..8b54f470fa 100644 --- a/spring-web/src/main/java/org/springframework/http/support/Netty5HeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/support/Netty5HeadersAdapter.java @@ -28,8 +28,8 @@ import java.util.Set; import java.util.stream.StreamSupport; import io.netty5.handler.codec.http.headers.HttpHeaders; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.MultiValueMap; @@ -57,8 +57,7 @@ public final class Netty5HeadersAdapter implements MultiValueMap @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { CharSequence value = this.headers.get(key); return (value != null ? value.toString() : null); } @@ -124,8 +123,7 @@ public final class Netty5HeadersAdapter implements MultiValueMap } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { Iterator iterator = this.headers.valuesIterator((CharSequence) key); if (iterator.hasNext()) { List result = new ArrayList<>(); @@ -135,17 +133,15 @@ public final class Netty5HeadersAdapter implements MultiValueMap return null; } - @Nullable @Override - public List put(String key, @Nullable List value) { + public @Nullable List put(String key, @Nullable List value) { List previousValues = get(key); this.headers.set(key, value); return previousValues; } - @Nullable @Override - public List remove(Object key) { + public @Nullable List remove(Object key) { if (key instanceof String headerName) { List previousValues = get(headerName); this.headers.remove(headerName); @@ -258,8 +254,7 @@ public final class Netty5HeadersAdapter implements MultiValueMap private final Iterator iterator; - @Nullable - private CharSequence currentName; + private @Nullable CharSequence currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; diff --git a/spring-web/src/main/java/org/springframework/http/support/package-info.java b/spring-web/src/main/java/org/springframework/http/support/package-info.java index 1dbbc6c43e..831ecb6d26 100644 --- a/spring-web/src/main/java/org/springframework/http/support/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/support/package-info.java @@ -2,9 +2,7 @@ * This package provides internal HTTP support classes, * to be used by higher-level client and server classes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java b/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java index 72774ba60c..ce92a70e0d 100644 --- a/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/DefaultErrorResponseBuilder.java @@ -19,10 +19,11 @@ package org.springframework.web; import java.net.URI; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; @@ -38,8 +39,7 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder { private final HttpStatusCode statusCode; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; private final ProblemDetail problemDetail; @@ -49,8 +49,7 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder { private String detailMessageCode; - @Nullable - private Object[] detailMessageArguments; + private Object @Nullable [] detailMessageArguments; DefaultErrorResponseBuilder(Throwable ex, ProblemDetail problemDetail) { @@ -169,13 +168,12 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder { private final String detailMessageCode; - @Nullable - private final Object[] detailMessageArguments; + private final Object @Nullable [] detailMessageArguments; SimpleErrorResponse( Throwable ex, HttpStatusCode statusCode, @Nullable HttpHeaders headers, ProblemDetail problemDetail, String typeMessageCode, String titleMessageCode, String detailMessageCode, - @Nullable Object[] detailMessageArguments) { + Object @Nullable [] detailMessageArguments) { this.exception = ex; this.statusCode = statusCode; @@ -218,8 +216,7 @@ final class DefaultErrorResponseBuilder implements ErrorResponse.Builder { } @Override - @Nullable - public Object[] getDetailMessageArguments() { + public Object @Nullable [] getDetailMessageArguments() { return this.detailMessageArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/ErrorResponse.java b/spring-web/src/main/java/org/springframework/web/ErrorResponse.java index c077b83d9d..acf73e7127 100644 --- a/spring-web/src/main/java/org/springframework/web/ErrorResponse.java +++ b/spring-web/src/main/java/org/springframework/web/ErrorResponse.java @@ -20,11 +20,12 @@ import java.net.URI; import java.util.Locale; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; /** * Representation of a complete RFC 9457 error response including status, @@ -109,8 +110,7 @@ public interface ErrorResponse { * through a {@link MessageSource}. The arguments are expanded * into placeholders of the message value, for example, "Invalid content type {0}". */ - @Nullable - default Object[] getDetailMessageArguments() { + default Object @Nullable [] getDetailMessageArguments() { return null; } @@ -123,8 +123,7 @@ public interface ErrorResponse { * @param messageSource the {@code MessageSource} to use for the lookup * @param locale the {@code Locale} to use for the lookup */ - @Nullable - default Object[] getDetailMessageArguments(MessageSource messageSource, Locale locale) { + default Object @Nullable [] getDetailMessageArguments(MessageSource messageSource, Locale locale) { return getDetailMessageArguments(); } diff --git a/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java b/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java index 53f3fccb49..fcd6e2deba 100644 --- a/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java +++ b/spring-web/src/main/java/org/springframework/web/ErrorResponseException.java @@ -18,11 +18,12 @@ package org.springframework.web; import java.net.URI; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; /** * {@link RuntimeException} that implements {@link ErrorResponse} to expose @@ -48,8 +49,7 @@ public class ErrorResponseException extends NestedRuntimeException implements Er private final String messageDetailCode; - @Nullable - private final Object[] messageDetailArguments; + private final Object @Nullable [] messageDetailArguments; /** @@ -82,7 +82,7 @@ public class ErrorResponseException extends NestedRuntimeException implements Er */ public ErrorResponseException( HttpStatusCode status, ProblemDetail body, @Nullable Throwable cause, - @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { super(null, cause); this.status = status; @@ -165,8 +165,7 @@ public class ErrorResponseException extends NestedRuntimeException implements Er } @Override - @Nullable - public Object[] getDetailMessageArguments() { + public Object @Nullable [] getDetailMessageArguments() { return this.messageDetailArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java index 870c13f65b..888dae7db3 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeException.java @@ -20,10 +20,10 @@ import java.util.Collections; import java.util.List; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.http.MediaType; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; /** * Abstract base for exceptions related to media types. Adds a list of supported {@link MediaType MediaTypes}. @@ -40,8 +40,7 @@ public abstract class HttpMediaTypeException extends ServletException implements private final String messageDetailCode; - @Nullable - private final Object[] messageDetailArguments; + private final Object @Nullable [] messageDetailArguments; /** @@ -54,7 +53,7 @@ public abstract class HttpMediaTypeException extends ServletException implements * @since 6.0 */ protected HttpMediaTypeException(@Nullable String message, List supportedMediaTypes, - @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { super(message); this.supportedMediaTypes = Collections.unmodifiableList(supportedMediaTypes); @@ -82,8 +81,7 @@ public abstract class HttpMediaTypeException extends ServletException implements } @Override - @Nullable - public Object[] getDetailMessageArguments() { + public Object @Nullable [] getDetailMessageArguments() { return this.messageDetailArguments; } diff --git a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java index 4ce57138a5..bcba1c9953 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpMediaTypeNotSupportedException.java @@ -19,12 +19,13 @@ package org.springframework.web; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -42,11 +43,9 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException { ErrorResponse.getDefaultDetailMessageCode(HttpMediaTypeNotSupportedException.class, "parseError"); - @Nullable - private final MediaType contentType; + private final @Nullable MediaType contentType; - @Nullable - private final HttpMethod httpMethod; + private final @Nullable HttpMethod httpMethod; /** @@ -114,8 +113,7 @@ public class HttpMediaTypeNotSupportedException extends HttpMediaTypeException { /** * Return the HTTP request content type method that caused the failure. */ - @Nullable - public MediaType getContentType() { + public @Nullable MediaType getContentType() { return this.contentType; } 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 3d78325f90..d397c2d01d 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpRequestMethodNotSupportedException.java @@ -20,13 +20,13 @@ import java.util.Collection; import java.util.Set; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -44,8 +44,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException imp private final String method; - @Nullable - private final String[] supportedMethods; + private final String @Nullable [] supportedMethods; private final ProblemDetail body; @@ -72,7 +71,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException imp * @param method the unsupported HTTP request method * @param supportedMethods the actually supported HTTP methods (possibly {@code null}) */ - private HttpRequestMethodNotSupportedException(String method, @Nullable String[] supportedMethods) { + private HttpRequestMethodNotSupportedException(String method, String @Nullable [] supportedMethods) { super("Request method '" + method + "' is not supported"); this.method = method; this.supportedMethods = supportedMethods; @@ -92,8 +91,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException imp /** * Return the actually supported HTTP methods, or {@code null} if not known. */ - @Nullable - public String[] getSupportedMethods() { + public String @Nullable [] getSupportedMethods() { return this.supportedMethods; } @@ -102,8 +100,7 @@ public class HttpRequestMethodNotSupportedException extends ServletException imp * or {@code null} if not known. * @since 3.2 */ - @Nullable - public Set getSupportedHttpMethods() { + public @Nullable 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 eaffd9d96b..b311973be5 100644 --- a/spring-web/src/main/java/org/springframework/web/HttpSessionRequiredException.java +++ b/spring-web/src/main/java/org/springframework/web/HttpSessionRequiredException.java @@ -17,8 +17,7 @@ package org.springframework.web; import jakarta.servlet.ServletException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when an HTTP request handler requires a pre-existing session. @@ -29,8 +28,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class HttpSessionRequiredException extends ServletException { - @Nullable - private final String expectedAttribute; + private final @Nullable String expectedAttribute; /** @@ -58,8 +56,7 @@ public class HttpSessionRequiredException extends ServletException { * Return the name of the expected session attribute, if any. * @since 4.3 */ - @Nullable - public String getExpectedAttribute() { + public @Nullable String getExpectedAttribute() { return this.expectedAttribute; } diff --git a/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java b/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java index 5ced8bf39e..6befe1eeea 100644 --- a/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java +++ b/spring-web/src/main/java/org/springframework/web/SpringServletContainerInitializer.java @@ -27,9 +27,9 @@ import jakarta.servlet.ServletContainerInitializer; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.annotation.HandlesTypes; +import org.jspecify.annotations.Nullable; import org.springframework.core.annotation.AnnotationAwareOrderComparator; -import org.springframework.lang.Nullable; import org.springframework.util.ReflectionUtils; /** 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 ed3189bc68..92da6452c1 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 @@ -23,10 +23,10 @@ import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.HttpMediaTypeNotAcceptableException; import org.springframework.web.context.request.NativeWebRequest; @@ -129,8 +129,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} if none */ - @Nullable - protected abstract String getMediaTypeKey(NativeWebRequest request); + protected abstract @Nullable String getMediaTypeKey(NativeWebRequest request); /** * Override to provide handling when a key is successfully resolved via @@ -145,8 +144,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) + protected @Nullable MediaType handleNoMatch(NativeWebRequest request, String key) throws HttpMediaTypeNotAcceptableException { if (!isUseRegisteredExtensionsOnly()) { 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 dec192ca15..023f1ac0d6 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 @@ -27,8 +27,9 @@ import java.util.Map; import java.util.Set; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.web.HttpMediaTypeNotAcceptableException; @@ -103,8 +104,7 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy, Me * @since 4.3 */ @SuppressWarnings("unchecked") - @Nullable - public T getStrategy(Class strategyType) { + public @Nullable T getStrategy(Class strategyType) { for (ContentNegotiationStrategy strategy : getStrategies()) { if (strategyType.isInstance(strategy)) { return (T) strategy; diff --git a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java index 11f499271e..f547cad8a8 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ContentNegotiationManagerFactoryBean.java @@ -23,11 +23,12 @@ import java.util.Locale; import java.util.Map; import java.util.Properties; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -82,8 +83,7 @@ import org.springframework.util.CollectionUtils; */ public class ContentNegotiationManagerFactoryBean implements FactoryBean, InitializingBean { - @Nullable - private List strategies; + private @Nullable List strategies; private boolean favorParameter = false; @@ -92,16 +92,13 @@ public class ContentNegotiationManagerFactoryBean implements FactoryBean mediaTypes = new HashMap<>(); - @Nullable - private Boolean useRegisteredExtensionsOnly; + private @Nullable Boolean useRegisteredExtensionsOnly; private boolean ignoreAcceptHeader = false; - @Nullable - private ContentNegotiationStrategy defaultNegotiationStrategy; + private @Nullable ContentNegotiationStrategy defaultNegotiationStrategy; - @Nullable - private ContentNegotiationManager contentNegotiationManager; + private @Nullable ContentNegotiationManager contentNegotiationManager; /** @@ -286,8 +283,7 @@ public class ContentNegotiationManagerFactoryBean implements FactoryBean{@link org.springframework.web.accept.ContentNegotiationManager} is used to delegate to one * ore more of the above strategies in a specific order. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.accept; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java b/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java index 9edffefc90..96e412fd8c 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java +++ b/spring-web/src/main/java/org/springframework/web/bind/EscapedErrors.java @@ -19,7 +19,8 @@ package org.springframework.web.bind; import java.util.ArrayList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.validation.Errors; import org.springframework.validation.FieldError; @@ -95,7 +96,7 @@ public class EscapedErrors implements Errors { } @Override - public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + public void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.source.reject(errorCode, errorArgs, defaultMessage); } @@ -111,7 +112,7 @@ public class EscapedErrors implements Errors { @Override public void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.source.rejectValue(field, errorCode, errorArgs, defaultMessage); } @@ -153,8 +154,7 @@ public class EscapedErrors implements Errors { } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return escapeObjectError(this.source.getGlobalError()); } @@ -174,8 +174,7 @@ public class EscapedErrors implements Errors { } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.source.getFieldError(); } @@ -195,27 +194,23 @@ public class EscapedErrors implements Errors { } @Override - @Nullable - public FieldError getFieldError(String field) { + public @Nullable FieldError getFieldError(String field) { return escapeObjectError(this.source.getFieldError(field)); } @Override - @Nullable - public Object getFieldValue(String field) { + public @Nullable Object getFieldValue(String field) { Object value = this.source.getFieldValue(field); return (value instanceof String text ? HtmlUtils.htmlEscape(text) : value); } @Override - @Nullable - public Class getFieldType(String field) { + public @Nullable Class getFieldType(String field) { return this.source.getFieldType(field); } @SuppressWarnings("unchecked") - @Nullable - private T escapeObjectError(@Nullable T source) { + private @Nullable T escapeObjectError(@Nullable T source) { if (source == null) { return null; } diff --git a/spring-web/src/main/java/org/springframework/web/bind/MissingRequestValueException.java b/spring-web/src/main/java/org/springframework/web/bind/MissingRequestValueException.java index bc606373b8..d5edaae850 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/MissingRequestValueException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/MissingRequestValueException.java @@ -16,8 +16,9 @@ package org.springframework.web.bind; +import org.jspecify.annotations.Nullable; + import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; /** * Base class for {@link ServletRequestBindingException} exceptions that could @@ -56,7 +57,7 @@ public class MissingRequestValueException extends ServletRequestBindingException * @since 6.0 */ protected MissingRequestValueException(String msg, boolean missingAfterConversion, - @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { super(msg, messageDetailCode, messageDetailArguments); this.missingAfterConversion = missingAfterConversion; diff --git a/spring-web/src/main/java/org/springframework/web/bind/MissingServletRequestParameterException.java b/spring-web/src/main/java/org/springframework/web/bind/MissingServletRequestParameterException.java index 93480e3712..f958f47f0b 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/MissingServletRequestParameterException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/MissingServletRequestParameterException.java @@ -16,8 +16,9 @@ package org.springframework.web.bind; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * {@link ServletRequestBindingException} subclass that indicates a missing parameter. @@ -32,8 +33,7 @@ public class MissingServletRequestParameterException extends MissingRequestValue private final String parameterType; - @Nullable - private final MethodParameter parameter; + private final @Nullable MethodParameter parameter; /** @@ -97,8 +97,7 @@ public class MissingServletRequestParameterException extends MissingRequestValue * a controller method argument. * @since 6.1 */ - @Nullable - public MethodParameter getMethodParameter() { + public @Nullable MethodParameter getMethodParameter() { return this.parameter; } diff --git a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java index b0ca83d61c..efd2d07978 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestBindingException.java @@ -17,11 +17,11 @@ package org.springframework.web.bind; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.web.ErrorResponse; /** @@ -42,8 +42,7 @@ public class ServletRequestBindingException extends ServletException implements private final String messageDetailCode; - @Nullable - private final Object[] messageDetailArguments; + private final Object @Nullable [] messageDetailArguments; /** @@ -73,7 +72,7 @@ public class ServletRequestBindingException extends ServletException implements * @since 6.0 */ protected ServletRequestBindingException( - @Nullable String msg, @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String msg, @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { this(msg, null, messageDetailCode, messageDetailArguments); } @@ -89,7 +88,7 @@ public class ServletRequestBindingException extends ServletException implements * @since 6.0 */ protected ServletRequestBindingException(@Nullable String msg, @Nullable Throwable cause, - @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { super(msg, cause); this.messageDetailCode = initMessageDetailCode(messageDetailCode); @@ -118,8 +117,7 @@ public class ServletRequestBindingException extends ServletException implements } @Override - @Nullable - public Object[] getDetailMessageArguments() { + public Object @Nullable [] getDetailMessageArguments() { return this.messageDetailArguments; } 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 07ae355566..9d2ea62377 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 @@ -25,12 +25,12 @@ import java.util.Set; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.beans.MutablePropertyValues; import org.springframework.core.MethodParameter; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindException; @@ -216,8 +216,7 @@ public class ServletRequestDataBinder extends WebDataBinder { private final WebDataBinder dataBinder; - @Nullable - private Set parameterNames; + private @Nullable Set parameterNames; protected ServletRequestValueResolver(ServletRequest request, WebDataBinder dataBinder) { this.request = request; @@ -228,9 +227,8 @@ public class ServletRequestDataBinder extends WebDataBinder { return this.request; } - @Nullable @Override - public final Object resolveValue(String name, Class paramType) { + public @Nullable final Object resolveValue(String name, Class paramType) { Object value = getRequestParameter(name, paramType); if (value == null) { value = this.dataBinder.resolvePrefixValue(name, paramType, this::getRequestParameter); @@ -241,14 +239,12 @@ public class ServletRequestDataBinder extends WebDataBinder { return value; } - @Nullable - protected Object getRequestParameter(String name, Class type) { + protected @Nullable Object getRequestParameter(String name, Class type) { Object value = this.request.getParameterValues(name); return (ObjectUtils.isArray(value) && Array.getLength(value) == 1 ? Array.get(value, 0) : value); } - @Nullable - private Object getMultipartValue(String name) { + private @Nullable Object getMultipartValue(String name) { MultipartRequest multipartRequest = WebUtils.getNativeRequest(this.request, MultipartRequest.class); if (multipartRequest != null) { List files = multipartRequest.getFiles(name); diff --git a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestParameterPropertyValues.java b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestParameterPropertyValues.java index e07bc6c73d..b5f944d154 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/ServletRequestParameterPropertyValues.java +++ b/spring-web/src/main/java/org/springframework/web/bind/ServletRequestParameterPropertyValues.java @@ -17,9 +17,9 @@ package org.springframework.web.bind; import jakarta.servlet.ServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.beans.MutablePropertyValues; -import org.springframework.lang.Nullable; import org.springframework.web.util.WebUtils; /** 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 4b61e256af..43c07cf6c8 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 @@ -17,8 +17,7 @@ package org.springframework.web.bind; import jakarta.servlet.ServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Parameter extraction methods, for an approach distinct from data binding, @@ -55,8 +54,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) + public static @Nullable Integer getIntParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { @@ -134,8 +132,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) + public static @Nullable Long getLongParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { @@ -213,8 +210,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) + public static @Nullable Float getFloatParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { @@ -292,8 +288,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) + public static @Nullable Double getDoubleParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { @@ -373,8 +368,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) + public static @Nullable Boolean getBooleanParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { @@ -461,8 +455,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) + public static @Nullable String getStringParameter(ServletRequest request, String name) throws ServletRequestBindingException { if (request.getParameter(name) == null) { 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 cb907effab..1826f6f9ce 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 @@ -22,10 +22,11 @@ import java.util.List; import java.util.Map; import java.util.function.BiFunction; +import org.jspecify.annotations.Nullable; + 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; @@ -85,11 +86,9 @@ public class WebDataBinder extends DataBinder { */ public static final String DEFAULT_FIELD_DEFAULT_PREFIX = "!"; - @Nullable - private String fieldMarkerPrefix = DEFAULT_FIELD_MARKER_PREFIX; + private @Nullable String fieldMarkerPrefix = DEFAULT_FIELD_MARKER_PREFIX; - @Nullable - private String fieldDefaultPrefix = DEFAULT_FIELD_DEFAULT_PREFIX; + private @Nullable String fieldDefaultPrefix = DEFAULT_FIELD_DEFAULT_PREFIX; private boolean bindEmptyMultipartFiles = true; @@ -143,8 +142,7 @@ public class WebDataBinder extends DataBinder { /** * Return the prefix for parameters that mark potentially empty fields. */ - @Nullable - public String getFieldMarkerPrefix() { + public @Nullable String getFieldMarkerPrefix() { return this.fieldMarkerPrefix; } @@ -169,8 +167,7 @@ public class WebDataBinder extends DataBinder { /** * Return the prefix for parameters that mark default fields. */ - @Nullable - public String getFieldDefaultPrefix() { + public @Nullable String getFieldDefaultPrefix() { return this.fieldDefaultPrefix; } @@ -203,8 +200,7 @@ public class WebDataBinder extends DataBinder { * @return the resolved value, or {@code null} * @since 6.1 */ - @Nullable - protected Object resolvePrefixValue(String name, Class type, BiFunction, Object> resolver) { + protected @Nullable Object resolvePrefixValue(String name, Class type, BiFunction, Object> resolver) { Object value = resolver.apply(name, type); if (value == null) { String prefix = getFieldDefaultPrefix(); @@ -316,8 +312,7 @@ public class WebDataBinder extends DataBinder { * @param fieldType the type of the field * @return the empty value (for most fields: {@code null}) */ - @Nullable - protected Object getEmptyValue(String field, @Nullable Class fieldType) { + protected @Nullable Object getEmptyValue(String field, @Nullable Class fieldType) { return (fieldType != null ? getEmptyValue(fieldType) : null); } @@ -335,8 +330,7 @@ public class WebDataBinder extends DataBinder { * @return the empty value (for most fields: {@code null}) * @since 5.0 */ - @Nullable - public Object getEmptyValue(Class fieldType) { + public @Nullable Object getEmptyValue(Class fieldType) { try { if (boolean.class == fieldType || Boolean.class == fieldType) { // Special handling of boolean property. diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java index 564206809d..914da4206e 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/ControllerMappingReflectiveProcessor.java @@ -21,6 +21,8 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.BindingReflectionHintsRegistrar; import org.springframework.aot.hint.ExecutableMode; import org.springframework.aot.hint.ReflectionHints; @@ -29,7 +31,6 @@ import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.HttpEntity; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.util.ReflectionUtils; @@ -111,8 +112,7 @@ class ControllerMappingReflectiveProcessor implements ReflectiveProcessor { } } - @Nullable - private Type getHttpEntityType(MethodParameter parameter) { + private @Nullable Type getHttpEntityType(MethodParameter parameter) { MethodParameter nestedParameter = parameter.nested(); return (nestedParameter.getNestedParameterType() == nestedParameter.getParameterType() ? null : nestedParameter.getNestedParameterType()); diff --git a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMethod.java b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMethod.java index c7564093cd..b1f5438b90 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMethod.java +++ b/spring-web/src/main/java/org/springframework/web/bind/annotation/RequestMethod.java @@ -16,8 +16,9 @@ package org.springframework.web.bind.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -48,8 +49,7 @@ public enum RequestMethod { * @return the corresponding {@code RequestMethod}, or {@code null} if not found * @since 6.0.6 */ - @Nullable - public static RequestMethod resolve(String method) { + public static @Nullable RequestMethod resolve(String method) { Assert.notNull(method, "Method must not be null"); return switch (method) { case "GET" -> GET; @@ -71,8 +71,7 @@ public enum RequestMethod { * @return the corresponding {@code RequestMethod}, or {@code null} if not found * @since 6.0.6 */ - @Nullable - public static RequestMethod resolve(HttpMethod httpMethod) { + public static @Nullable RequestMethod resolve(HttpMethod httpMethod) { Assert.notNull(httpMethod, "HttpMethod must not be null"); return resolve(httpMethod.name()); } 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 fb7e6cc76f..0c9bb1c11f 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,9 +2,7 @@ * Annotations for binding requests to controllers and handler methods * as well as for binding request parameters to method arguments. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.bind.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 7b87239b23..f1415cca35 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,9 +1,7 @@ /** * Provides web-specific data binding functionality. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.bind; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java b/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java index 5b50bb8515..811971c550 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/BindParamNameResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.bind.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.DataBinder; import org.springframework.web.bind.annotation.BindParam; @@ -33,8 +34,7 @@ import org.springframework.web.bind.annotation.BindParam; public final class BindParamNameResolver implements DataBinder.NameResolver { @Override - @Nullable - public String resolveName(MethodParameter parameter) { + public @Nullable String resolveName(MethodParameter parameter) { BindParam bindParam = parameter.getParameterAnnotation(BindParam.class); if (bindParam != null) { if (StringUtils.hasText(bindParam.value())) { 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 293bb83a0c..fe1a923344 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 @@ -16,9 +16,10 @@ package org.springframework.web.bind.support; +import org.jspecify.annotations.Nullable; + 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; @@ -44,23 +45,17 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer private boolean directFieldAccess = false; - @Nullable - private Boolean declarativeBinding; + private @Nullable Boolean declarativeBinding; - @Nullable - private MessageCodesResolver messageCodesResolver; + private @Nullable MessageCodesResolver messageCodesResolver; - @Nullable - private BindingErrorProcessor bindingErrorProcessor; + private @Nullable BindingErrorProcessor bindingErrorProcessor; - @Nullable - private Validator validator; + private @Nullable Validator validator; - @Nullable - private ConversionService conversionService; + private @Nullable ConversionService conversionService; - @Nullable - private PropertyEditorRegistrar[] propertyEditorRegistrars; + private PropertyEditorRegistrar @Nullable [] propertyEditorRegistrars; /** @@ -133,8 +128,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the strategy to use for resolving errors into message codes. */ - @Nullable - public final MessageCodesResolver getMessageCodesResolver() { + public final @Nullable MessageCodesResolver getMessageCodesResolver() { return this.messageCodesResolver; } @@ -152,8 +146,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the strategy to use for processing binding errors. */ - @Nullable - public final BindingErrorProcessor getBindingErrorProcessor() { + public final @Nullable BindingErrorProcessor getBindingErrorProcessor() { return this.bindingErrorProcessor; } @@ -167,8 +160,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the Validator to apply after each binding step, if any. */ - @Nullable - public final Validator getValidator() { + public final @Nullable Validator getValidator() { return this.validator; } @@ -183,8 +175,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Return the ConversionService which will apply to every DataBinder. */ - @Nullable - public final ConversionService getConversionService() { + public final @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -198,15 +189,14 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer /** * Specify multiple PropertyEditorRegistrars to be applied to every DataBinder. */ - public final void setPropertyEditorRegistrars(@Nullable PropertyEditorRegistrar[] propertyEditorRegistrars) { + public final void setPropertyEditorRegistrars(PropertyEditorRegistrar @Nullable [] propertyEditorRegistrars) { this.propertyEditorRegistrars = propertyEditorRegistrars; } /** * Return the PropertyEditorRegistrars to be applied to every DataBinder. */ - @Nullable - public final PropertyEditorRegistrar[] getPropertyEditorRegistrars() { + public final PropertyEditorRegistrar @Nullable [] getPropertyEditorRegistrars() { return this.propertyEditorRegistrars; } @@ -242,8 +232,7 @@ public class ConfigurableWebBindingInitializer implements WebBindingInitializer } } - @Nullable - private static Class getTargetType(WebDataBinder binder) { + private static @Nullable Class getTargetType(WebDataBinder binder) { Class type = null; if (binder.getTarget() != null) { type = binder.getTarget().getClass(); 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 35bbfd51de..fd9c3bee39 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 @@ -18,9 +18,10 @@ package org.springframework.web.bind.support; import java.lang.annotation.Annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.validation.DataBinder; import org.springframework.validation.SmartValidator; import org.springframework.web.bind.WebDataBinder; @@ -35,8 +36,7 @@ import org.springframework.web.context.request.NativeWebRequest; */ public class DefaultDataBinderFactory implements WebDataBinderFactory { - @Nullable - private final WebBindingInitializer initializer; + private final @Nullable WebBindingInitializer initializer; private boolean methodValidationApplicable; diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/DefaultSessionAttributeStore.java b/spring-web/src/main/java/org/springframework/web/bind/support/DefaultSessionAttributeStore.java index 30952bf81f..2e488b3d49 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/DefaultSessionAttributeStore.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/DefaultSessionAttributeStore.java @@ -16,7 +16,8 @@ package org.springframework.web.bind.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.web.context.request.WebRequest; @@ -56,8 +57,7 @@ public class DefaultSessionAttributeStore implements SessionAttributeStore { } @Override - @Nullable - public Object retrieveAttribute(WebRequest request, String attributeName) { + public @Nullable Object retrieveAttribute(WebRequest request, String attributeName) { Assert.notNull(request, "WebRequest must not be null"); Assert.notNull(attributeName, "Attribute name must not be null"); String storeAttributeName = getAttributeNameInSession(request, attributeName); 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 42acf3bbf1..269de308f2 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,7 +16,8 @@ package org.springframework.web.bind.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.context.request.WebRequest; /** @@ -47,8 +48,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); + @Nullable Object retrieveAttribute(WebRequest request, String attributeName); /** * Clean up the specified attribute in the backend session. diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java index 58574d4864..01318ebcd0 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.bind.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** @@ -59,7 +60,6 @@ public interface WebArgumentResolver { * @return the argument value, or {@code UNRESOLVED} if not resolvable * @throws Exception in case of resolution failure */ - @Nullable - Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception; + @Nullable Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception; } 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 3411d363e2..c3c31ba334 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,8 +16,9 @@ package org.springframework.web.bind.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.context.request.NativeWebRequest; diff --git a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java index d7204f7498..015486796d 100644 --- a/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java +++ b/spring-web/src/main/java/org/springframework/web/bind/support/WebExchangeBindException.java @@ -21,10 +21,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.PropertyEditorRegistry; import org.springframework.context.MessageSource; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.BindingResult; @@ -117,7 +118,7 @@ public class WebExchangeBindException extends ServerWebInputException implements } @Override - public void reject(String errorCode, @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + public void reject(String errorCode, Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.bindingResult.reject(errorCode, errorArgs, defaultMessage); } @@ -133,7 +134,7 @@ public class WebExchangeBindException extends ServerWebInputException implements @Override public void rejectValue(@Nullable String field, String errorCode, - @Nullable Object[] errorArgs, @Nullable String defaultMessage) { + Object @Nullable [] errorArgs, @Nullable String defaultMessage) { this.bindingResult.rejectValue(field, errorCode, errorArgs, defaultMessage); } @@ -174,8 +175,7 @@ public class WebExchangeBindException extends ServerWebInputException implements } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return this.bindingResult.getGlobalError(); } @@ -195,8 +195,7 @@ public class WebExchangeBindException extends ServerWebInputException implements } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.bindingResult.getFieldError(); } @@ -216,26 +215,22 @@ public class WebExchangeBindException extends ServerWebInputException implements } @Override - @Nullable - public FieldError getFieldError(String field) { + public @Nullable FieldError getFieldError(String field) { return this.bindingResult.getFieldError(field); } @Override - @Nullable - public Object getFieldValue(String field) { + public @Nullable Object getFieldValue(String field) { return this.bindingResult.getFieldValue(field); } @Override - @Nullable - public Class getFieldType(String field) { + public @Nullable Class getFieldType(String field) { return this.bindingResult.getFieldType(field); } @Override - @Nullable - public Object getTarget() { + public @Nullable Object getTarget() { return this.bindingResult.getTarget(); } @@ -245,21 +240,18 @@ public class WebExchangeBindException extends ServerWebInputException implements } @Override - @Nullable - public Object getRawFieldValue(String field) { + public @Nullable Object getRawFieldValue(String field) { return this.bindingResult.getRawFieldValue(field); } @Override @SuppressWarnings("rawtypes") - @Nullable - public PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { + public @Nullable PropertyEditor findEditor(@Nullable String field, @Nullable Class valueType) { return this.bindingResult.findEditor(field, valueType); } @Override - @Nullable - public PropertyEditorRegistry getPropertyEditorRegistry() { + public @Nullable PropertyEditorRegistry getPropertyEditorRegistry() { return this.bindingResult.getPropertyEditorRegistry(); } 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 4bfeb06326..04c3a9c28f 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 @@ -21,13 +21,13 @@ import java.util.Map; import java.util.Set; import java.util.TreeMap; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.MutablePropertyValues; import org.springframework.core.MethodParameter; 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; @@ -168,8 +168,7 @@ public class WebExchangeDataBinder extends WebDataBinder { private record MapValueResolver(Map map) implements ValueResolver { @Override - @Nullable - public Object resolveValue(String name, Class type) { + public @Nullable Object resolveValue(String name, Class type) { return this.map.get(name); } 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 2d7d31264f..1e393922f3 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 @@ -19,13 +19,13 @@ package org.springframework.web.bind.support; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.beans.MutablePropertyValues; import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.BindException; import org.springframework.web.bind.ServletRequestDataBinder; 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 c55741fc04..40325caafe 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,9 +1,7 @@ /** * Support classes for web data binding. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.bind.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 b9767b6b83..7e6759758a 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 @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.List; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.HttpHeaders; @@ -35,7 +37,6 @@ import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -60,8 +61,7 @@ import org.springframework.util.ObjectUtils; */ public class DefaultResponseErrorHandler implements ResponseErrorHandler { - @Nullable - private List> messageConverters; + private @Nullable List> messageConverters; /** @@ -194,8 +194,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) { + protected @Nullable Charset getCharset(ClientHttpResponse response) { MediaType contentType = response.getHeaders().getContentType(); return (contentType != null ? contentType.getCharset() : null); } @@ -207,7 +206,7 @@ public class DefaultResponseErrorHandler implements ResponseErrorHandler { * */ private String getErrorMessage( - int rawStatusCode, String statusText, @Nullable byte[] responseBody, @Nullable Charset charset, + int rawStatusCode, String statusText, byte @Nullable [] responseBody, @Nullable Charset charset, @Nullable URI url, @Nullable HttpMethod method) { StringBuilder msg = new StringBuilder(rawStatusCode + " " + statusText); diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java index 9e88dfdc91..3660a6f30b 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClient.java @@ -37,6 +37,7 @@ import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; @@ -61,7 +62,6 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.SmartHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -91,25 +91,19 @@ final class DefaultRestClient implements RestClient { private final ClientHttpRequestFactory clientRequestFactory; - @Nullable - private volatile ClientHttpRequestFactory interceptingRequestFactory; + private volatile @Nullable ClientHttpRequestFactory interceptingRequestFactory; - @Nullable - private final List initializers; + private final @Nullable List initializers; - @Nullable - private final List interceptors; + private final @Nullable List interceptors; private final UriBuilderFactory uriBuilderFactory; - @Nullable - private final HttpHeaders defaultHeaders; + private final @Nullable HttpHeaders defaultHeaders; - @Nullable - private final MultiValueMap defaultCookies; + private final @Nullable MultiValueMap defaultCookies; - @Nullable - private final Consumer> defaultRequest; + private final @Nullable Consumer> defaultRequest; private final List defaultStatusHandlers; @@ -119,8 +113,7 @@ final class DefaultRestClient implements RestClient { private final ObservationRegistry observationRegistry; - @Nullable - private final ClientRequestObservationConvention observationConvention; + private final @Nullable ClientRequestObservationConvention observationConvention; DefaultRestClient(ClientHttpRequestFactory clientRequestFactory, @@ -204,9 +197,8 @@ final class DefaultRestClient implements RestClient { return new DefaultRestClientBuilder(this.builder); } - @Nullable @SuppressWarnings({"rawtypes", "unchecked"}) - private T readWithMessageConverters( + private @Nullable T readWithMessageConverters( ClientHttpResponse clientResponse, Runnable callback, Type bodyType, Class bodyClass) { MediaType contentType = getContentType(clientResponse); @@ -289,23 +281,17 @@ final class DefaultRestClient implements RestClient { private final HttpMethod httpMethod; - @Nullable - private URI uri; + private @Nullable URI uri; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; - @Nullable - private MultiValueMap cookies; + private @Nullable MultiValueMap cookies; - @Nullable - private InternalBody body; + private @Nullable InternalBody body; - @Nullable - private Map attributes; + private @Nullable Map attributes; - @Nullable - private Consumer httpRequestConsumer; + private @Nullable Consumer httpRequestConsumer; public DefaultRequestBodyUriSpec(HttpMethod httpMethod) { this.httpMethod = httpMethod; @@ -530,13 +516,11 @@ final class DefaultRestClient implements RestClient { } @Override - @Nullable - public T exchange(ExchangeFunction exchangeFunction, boolean close) { + public @Nullable T exchange(ExchangeFunction exchangeFunction, boolean close) { return exchangeInternal(exchangeFunction, close); } - @Nullable - private T exchangeInternal(ExchangeFunction exchangeFunction, boolean close) { + private @Nullable T exchangeInternal(ExchangeFunction exchangeFunction, boolean close) { Assert.notNull(exchangeFunction, "ExchangeFunction must not be null"); ClientHttpResponse clientResponse = null; @@ -603,8 +587,7 @@ final class DefaultRestClient implements RestClient { return (this.uri != null ? this.uri : DefaultRestClient.this.uriBuilderFactory.expand("")); } - @Nullable - private String serializeCookies() { + private @Nullable String serializeCookies() { MultiValueMap map; MultiValueMap defaultCookies = DefaultRestClient.this.defaultCookies; if (CollectionUtils.isEmpty(this.cookies)) { @@ -638,8 +621,7 @@ final class DefaultRestClient implements RestClient { return sb.toString(); } - @Nullable - private HttpHeaders initHeaders() { + private @Nullable HttpHeaders initHeaders() { HttpHeaders defaultHeaders = DefaultRestClient.this.defaultHeaders; if (CollectionUtils.isEmpty(this.headers)) { return defaultHeaders; @@ -740,14 +722,12 @@ final class DefaultRestClient implements RestClient { } @Override - @Nullable - public T body(Class bodyType) { + public @Nullable T body(Class bodyType) { return executeAndExtract((request, response) -> readBody(request, response, bodyType, bodyType)); } @Override - @Nullable - public T body(ParameterizedTypeReference bodyType) { + public @Nullable T body(ParameterizedTypeReference bodyType) { Type type = bodyType.getType(); Class bodyClass = bodyClass(type); return executeAndExtract((request, response) -> readBody(request, response, type, bodyClass)); @@ -804,13 +784,11 @@ final class DefaultRestClient implements RestClient { return entity; } - @Nullable - public T executeAndExtract(RequestHeadersSpec.ExchangeFunction exchangeFunction) { + public @Nullable T executeAndExtract(RequestHeadersSpec.ExchangeFunction exchangeFunction) { return this.requestHeadersSpec.exchange(exchangeFunction); } - @Nullable - private T readBody(HttpRequest request, ClientHttpResponse response, Type bodyType, Class bodyClass) { + private @Nullable T readBody(HttpRequest request, ClientHttpResponse response, Type bodyType, Class bodyClass) { return DefaultRestClient.this.readWithMessageConverters( response, () -> applyStatusHandlers(request, response), bodyType, bodyClass); @@ -844,15 +822,13 @@ final class DefaultRestClient implements RestClient { this.delegate = delegate; } - @Nullable @Override - public T bodyTo(Class bodyType) { + public @Nullable T bodyTo(Class bodyType) { return readWithMessageConverters(this.delegate, () -> {} , bodyType, bodyType); } - @Nullable @Override - public T bodyTo(ParameterizedTypeReference bodyType) { + public @Nullable T bodyTo(ParameterizedTypeReference bodyType) { Type type = bodyType.getType(); Class bodyClass = bodyClass(type); return readWithMessageConverters(this.delegate, () -> {}, type, bodyClass); diff --git a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java index 975b1f183f..0c682dde9e 100644 --- a/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/client/DefaultRestClientBuilder.java @@ -27,6 +27,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; @@ -52,7 +53,6 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert import org.springframework.http.converter.smile.MappingJackson2SmileHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; import org.springframework.http.converter.yaml.MappingJackson2YamlHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -117,43 +117,31 @@ final class DefaultRestClientBuilder implements RestClient.Builder { jackson2YamlPresent = ClassUtils.isPresent("com.fasterxml.jackson.dataformat.yaml.YAMLFactory", loader); } - @Nullable - private String baseUrl; + private @Nullable String baseUrl; - @Nullable - private Map defaultUriVariables; + private @Nullable Map defaultUriVariables; - @Nullable - private UriBuilderFactory uriBuilderFactory; + private @Nullable UriBuilderFactory uriBuilderFactory; - @Nullable - private HttpHeaders defaultHeaders; + private @Nullable HttpHeaders defaultHeaders; - @Nullable - private MultiValueMap defaultCookies; + private @Nullable MultiValueMap defaultCookies; - @Nullable - private Consumer> defaultRequest; + private @Nullable Consumer> defaultRequest; - @Nullable - private List statusHandlers; + private @Nullable List statusHandlers; - @Nullable - private ClientHttpRequestFactory requestFactory; + private @Nullable ClientHttpRequestFactory requestFactory; - @Nullable - private List> messageConverters; + private @Nullable List> messageConverters; - @Nullable - private List interceptors; + private @Nullable List interceptors; - @Nullable - private List initializers; + private @Nullable List initializers; private ObservationRegistry observationRegistry = ObservationRegistry.NOOP; - @Nullable - private ClientRequestObservationConvention observationConvention; + private @Nullable ClientRequestObservationConvention observationConvention; public DefaultRestClientBuilder() { @@ -209,8 +197,7 @@ final class DefaultRestClientBuilder implements RestClient.Builder { this.observationConvention = restTemplate.getObservationConvention(); } - @Nullable - private static UriBuilderFactory getUriBuilderFactory(RestTemplate restTemplate) { + private static @Nullable UriBuilderFactory getUriBuilderFactory(RestTemplate restTemplate) { UriTemplateHandler uriTemplateHandler = restTemplate.getUriTemplateHandler(); if (uriTemplateHandler instanceof DefaultUriBuilderFactory builderFactory) { // only reuse the DefaultUriBuilderFactory if it has been customized @@ -517,8 +504,7 @@ final class DefaultRestClientBuilder implements RestClient.Builder { return factory; } - @Nullable - private HttpHeaders copyDefaultHeaders() { + private @Nullable HttpHeaders copyDefaultHeaders() { if (this.defaultHeaders == null) { return null; } @@ -527,8 +513,7 @@ final class DefaultRestClientBuilder implements RestClient.Builder { return HttpHeaders.readOnlyHttpHeaders(copy); } - @Nullable - private MultiValueMap copyDefaultCookies() { + private @Nullable MultiValueMap copyDefaultCookies() { if (this.defaultCookies == null) { return null; } diff --git a/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java b/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java index e2c95a992b..0db94b0f63 100644 --- a/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/ExtractingResponseErrorHandler.java @@ -23,12 +23,13 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** 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 19a1cdb682..c498128763 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 @@ -18,10 +18,11 @@ package org.springframework.web.client; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; /** * Exception thrown when an HTTP 4xx is received. @@ -53,7 +54,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { * Constructor with a status code and status text, and content. */ public HttpClientErrorException( - HttpStatusCode statusCode, String statusText, @Nullable byte[] body, @Nullable Charset responseCharset) { + HttpStatusCode statusCode, String statusText, byte @Nullable [] body, @Nullable Charset responseCharset) { super(statusCode, statusText, body, responseCharset); } @@ -62,7 +63,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { * Constructor with a status code and status text, headers, and content. */ public HttpClientErrorException(HttpStatusCode statusCode, String statusText, - @Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset responseCharset) { + @Nullable HttpHeaders headers, byte @Nullable [] body, @Nullable Charset responseCharset) { super(statusCode, statusText, headers, body, responseCharset); } @@ -73,7 +74,7 @@ public class HttpClientErrorException extends HttpStatusCodeException { * @since 5.2.2 */ public HttpClientErrorException(String message, HttpStatusCode statusCode, String statusText, - @Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset responseCharset) { + @Nullable HttpHeaders headers, byte @Nullable [] body, @Nullable Charset responseCharset) { super(message, statusCode, statusText, headers, body, responseCharset); } diff --git a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java index 3f79cfa7ec..bf1077cd88 100644 --- a/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java +++ b/spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java @@ -22,6 +22,7 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.ResolvableType; import org.springframework.http.MediaType; @@ -30,7 +31,6 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.SmartHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; @@ -48,8 +48,7 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { private final Type responseType; - @Nullable - private final Class responseClass; + private final @Nullable Class responseClass; private final List> messageConverters; @@ -85,9 +84,8 @@ public class HttpMessageConverterExtractor implements ResponseExtractor { @Override - @Nullable @SuppressWarnings({"rawtypes", "unchecked", "resource"}) - public T extractData(ClientHttpResponse response) throws IOException { + public @Nullable T extractData(ClientHttpResponse response) throws IOException { IntrospectingClientHttpResponse responseWrapper = new IntrospectingClientHttpResponse(response); if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) { return null; 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 4de3c2a684..3a8ddeb9b2 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 @@ -18,10 +18,11 @@ package org.springframework.web.client; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; /** * Exception thrown when an HTTP 5xx is received. @@ -53,7 +54,7 @@ public class HttpServerErrorException extends HttpStatusCodeException { * Constructor with a status code and status text, and content. */ public HttpServerErrorException( - HttpStatusCode statusCode, String statusText, @Nullable byte[] body, @Nullable Charset charset) { + HttpStatusCode statusCode, String statusText, byte @Nullable [] body, @Nullable Charset charset) { super(statusCode, statusText, body, charset); } @@ -62,7 +63,7 @@ public class HttpServerErrorException extends HttpStatusCodeException { * Constructor with a status code and status text, headers, and content. */ public HttpServerErrorException(HttpStatusCode statusCode, String statusText, - @Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset) { + @Nullable HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(statusCode, statusText, headers, body, charset); } @@ -73,7 +74,7 @@ public class HttpServerErrorException extends HttpStatusCodeException { * @since 5.2.2 */ public HttpServerErrorException(String message, HttpStatusCode statusCode, String statusText, - @Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset charset) { + @Nullable HttpHeaders headers, byte @Nullable [] body, @Nullable Charset charset) { super(message, statusCode, statusText, headers, body, charset); } @@ -83,7 +84,7 @@ public class HttpServerErrorException extends HttpStatusCodeException { * @since 5.1 */ public static HttpServerErrorException create(HttpStatusCode statusCode, - String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) { + String statusText, HttpHeaders headers, byte [] body, @Nullable Charset charset) { return create(null, statusCode, statusText, headers, body, charset); } 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 a5e7a624c8..5da26da0fc 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 @@ -18,10 +18,11 @@ package org.springframework.web.client; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -72,7 +73,7 @@ public abstract class HttpStatusCodeException extends RestClientResponseExceptio * @since 3.0.5 */ protected HttpStatusCodeException(HttpStatusCode statusCode, String statusText, - @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + byte @Nullable [] responseBody, @Nullable Charset responseCharset) { this(statusCode, statusText, null, responseBody, responseCharset); } @@ -88,7 +89,7 @@ public abstract class HttpStatusCodeException extends RestClientResponseExceptio * @since 3.1.2 */ protected HttpStatusCodeException(HttpStatusCode statusCode, String statusText, - @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, byte @Nullable [] responseBody, @Nullable Charset responseCharset) { this(getMessage(statusCode, statusText), statusCode, statusText, responseHeaders, responseBody, responseCharset); @@ -106,7 +107,7 @@ public abstract class HttpStatusCodeException extends RestClientResponseExceptio * @since 5.2.2 */ protected HttpStatusCodeException(String message, HttpStatusCode statusCode, String statusText, - @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, byte @Nullable [] responseBody, @Nullable Charset responseCharset) { super(message, statusCode, statusText, responseHeaders, responseBody, responseCharset); } diff --git a/spring-web/src/main/java/org/springframework/web/client/IntrospectingClientHttpResponse.java b/spring-web/src/main/java/org/springframework/web/client/IntrospectingClientHttpResponse.java index 264722bccf..8abbf7ee46 100644 --- a/spring-web/src/main/java/org/springframework/web/client/IntrospectingClientHttpResponse.java +++ b/spring-web/src/main/java/org/springframework/web/client/IntrospectingClientHttpResponse.java @@ -20,10 +20,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.PushbackInputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; /** * Implementation of {@link ClientHttpResponse} that can not only check if @@ -37,8 +38,7 @@ import org.springframework.lang.Nullable; */ class IntrospectingClientHttpResponse extends ClientHttpResponseDecorator { - @Nullable - private PushbackInputStream pushbackInputStream; + private @Nullable PushbackInputStream pushbackInputStream; public IntrospectingClientHttpResponse(ClientHttpResponse response) { diff --git a/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java b/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java index 349f068a0a..31a5300a70 100644 --- a/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java +++ b/spring-web/src/main/java/org/springframework/web/client/ResourceAccessException.java @@ -18,7 +18,7 @@ package org.springframework.web.client; import java.io.IOException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Exception thrown when an I/O error occurs. 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 c20b0e9c88..1a2b120dda 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,8 +19,9 @@ package org.springframework.web.client; import java.io.IOException; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; /** * Generic callback interface used by {@link RestTemplate}'s retrieval methods. @@ -46,7 +47,6 @@ public interface ResponseExtractor { * @return the extracted data * @throws IOException in case of I/O errors */ - @Nullable - T extractData(ClientHttpResponse response) throws IOException; + @Nullable T extractData(ClientHttpResponse response) throws IOException; } diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClient.java b/spring-web/src/main/java/org/springframework/web/client/RestClient.java index 1b7016d77e..5371bdd393 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClient.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClient.java @@ -28,6 +28,7 @@ import java.util.function.Function; import java.util.function.Predicate; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; @@ -45,7 +46,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.observation.ClientRequestObservationConvention; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.lang.CheckReturnValue; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.UriBuilder; @@ -672,8 +672,7 @@ public interface RestClient { * @param the type the response will be transformed to * @return the value returned from the exchange function */ - @Nullable - default T exchange(ExchangeFunction exchangeFunction) { + default @Nullable T exchange(ExchangeFunction exchangeFunction) { return exchange(exchangeFunction, true); } @@ -704,8 +703,7 @@ public interface RestClient { * @param the type the response will be transformed to * @return the value returned from the exchange function */ - @Nullable - T exchange(ExchangeFunction exchangeFunction, boolean close); + @Nullable T exchange(ExchangeFunction exchangeFunction, boolean close); /** @@ -722,8 +720,7 @@ public interface RestClient { * @return the exchanged type * @throws IOException in case of I/O errors */ - @Nullable - T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException; + @Nullable T exchange(HttpRequest clientRequest, ConvertibleClientHttpResponse clientResponse) throws IOException; } @@ -738,8 +735,7 @@ public interface RestClient { * @param the body type * @return the body, or {@code null} if no response body was available */ - @Nullable - T bodyTo(Class bodyType); + @Nullable T bodyTo(Class bodyType); /** * Extract the response body as an object of the given type. @@ -747,8 +743,7 @@ public interface RestClient { * @param the body type * @return the body, or {@code null} if no response body was available */ - @Nullable - T bodyTo(ParameterizedTypeReference bodyType); + @Nullable T bodyTo(ParameterizedTypeReference bodyType); } } @@ -860,8 +855,7 @@ public interface RestClient { * {@link #onStatus(Predicate, ErrorHandler)} to customize error response * handling. */ - @Nullable - T body(Class bodyType); + @Nullable T body(Class bodyType); /** * Extract the body as an object of the given type. @@ -873,8 +867,7 @@ public interface RestClient { * {@link #onStatus(Predicate, ErrorHandler)} to customize error response * handling. */ - @Nullable - T body(ParameterizedTypeReference bodyType); + @Nullable T body(ParameterizedTypeReference bodyType); /** * Return a {@code ResponseEntity} with the body decoded to an Object of diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClientException.java b/spring-web/src/main/java/org/springframework/web/client/RestClientException.java index c5d969be82..f75de85033 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClientException.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClientException.java @@ -16,9 +16,10 @@ package org.springframework.web.client; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; /** * Base class for exceptions thrown by {@link RestTemplate} in case a request 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 163c383ee8..7f96b69f0b 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 @@ -22,11 +22,12 @@ import java.nio.charset.StandardCharsets; import java.util.Locale; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedCaseInsensitiveMap; @@ -51,14 +52,11 @@ public class RestClientResponseException extends RestClientException { private final byte[] responseBody; - @Nullable - private final HttpHeaders responseHeaders; + private final @Nullable HttpHeaders responseHeaders; - @Nullable - private final String responseCharset; + private final @Nullable String responseCharset; - @Nullable - private transient Function bodyConvertFunction; + private transient @Nullable Function bodyConvertFunction; /** @@ -71,7 +69,7 @@ public class RestClientResponseException extends RestClientException { */ public RestClientResponseException( String message, int statusCode, String statusText, @Nullable HttpHeaders headers, - @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + byte @Nullable [] responseBody, @Nullable Charset responseCharset) { this(message, HttpStatusCode.valueOf(statusCode), statusText, headers, responseBody, responseCharset); } @@ -87,7 +85,7 @@ public class RestClientResponseException extends RestClientException { */ public RestClientResponseException( String message, HttpStatusCode statusCode, String statusText, @Nullable HttpHeaders headers, - @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + byte @Nullable [] responseBody, @Nullable Charset responseCharset) { super(message); this.statusCode = statusCode; @@ -101,8 +99,7 @@ public class RestClientResponseException extends RestClientException { * Copies the given headers, because the backing map might not be * serializable. */ - @Nullable - private static HttpHeaders copyHeaders(@Nullable HttpHeaders headers) { + private static @Nullable HttpHeaders copyHeaders(@Nullable HttpHeaders headers) { if (headers != null) { MultiValueMap result = CollectionUtils.toMultiValueMap(new LinkedCaseInsensitiveMap<>(headers.size(), Locale.ROOT)); @@ -133,8 +130,7 @@ public class RestClientResponseException extends RestClientException { /** * Return the HTTP response headers. */ - @Nullable - public HttpHeaders getResponseHeaders() { + public @Nullable HttpHeaders getResponseHeaders() { return this.responseHeaders; } @@ -179,8 +175,7 @@ public class RestClientResponseException extends RestClientException { * @return the converted object, or {@code null} if there is no content * @since 6.0 */ - @Nullable - public E getResponseBodyAs(Class targetType) { + public @Nullable E getResponseBodyAs(Class targetType) { return getResponseBodyAs(ResolvableType.forClass(targetType)); } @@ -189,14 +184,12 @@ public class RestClientResponseException extends RestClientException { * {@link ParameterizedTypeReference}. * @since 6.0 */ - @Nullable - public E getResponseBodyAs(ParameterizedTypeReference targetType) { + public @Nullable E getResponseBodyAs(ParameterizedTypeReference targetType) { return getResponseBodyAs(ResolvableType.forType(targetType.getType())); } @SuppressWarnings("unchecked") - @Nullable - private E getResponseBodyAs(ResolvableType targetType) { + private @Nullable E getResponseBodyAs(ResolvableType targetType) { Assert.state(this.bodyConvertFunction != null, "Function to convert body not set"); return (E) this.bodyConvertFunction.apply(targetType); } diff --git a/spring-web/src/main/java/org/springframework/web/client/RestClientUtils.java b/spring-web/src/main/java/org/springframework/web/client/RestClientUtils.java index 157d11ace4..b38f398978 100644 --- a/spring-web/src/main/java/org/springframework/web/client/RestClientUtils.java +++ b/spring-web/src/main/java/org/springframework/web/client/RestClientUtils.java @@ -19,11 +19,12 @@ package org.springframework.web.client; import java.io.IOException; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -43,8 +44,7 @@ abstract class RestClientUtils { return new byte[0]; } - @Nullable - public static Charset getCharset(HttpMessage response) { + public static @Nullable Charset getCharset(HttpMessage response) { HttpHeaders headers = response.getHeaders(); MediaType contentType = headers.getContentType(); return (contentType != null ? contentType.getCharset() : null); 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 5429c25196..bcdb4214ce 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 @@ -20,13 +20,14 @@ import java.net.URI; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpEntity; 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. @@ -52,8 +53,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; + @Nullable T getForObject(String url, Class responseType, Object... uriVariables) throws RestClientException; /** * Retrieve a representation by doing a GET on the URI template. @@ -64,8 +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; + @Nullable T getForObject(String url, Class responseType, Map uriVariables) throws RestClientException; /** * Retrieve a representation by doing a GET on the URL. @@ -74,8 +73,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; + @Nullable T getForObject(URI url, Class responseType) throws RestClientException; /** * Retrieve an entity by doing a GET on the specified URL. @@ -161,8 +159,7 @@ public interface RestOperations { * @return the value for the {@code Location} header * @see HttpEntity */ - @Nullable - URI postForLocation(String url, @Nullable Object request, Object... uriVariables) throws RestClientException; + @Nullable 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 return the value of @@ -181,8 +178,7 @@ public interface RestOperations { * @return the value for the {@code Location} header * @see HttpEntity */ - @Nullable - URI postForLocation(String url, @Nullable Object request, Map uriVariables) + @Nullable URI postForLocation(String url, @Nullable Object request, Map uriVariables) throws RestClientException; /** @@ -200,8 +196,7 @@ public interface RestOperations { * @return the value for the {@code Location} header * @see HttpEntity */ - @Nullable - URI postForLocation(URI url, @Nullable Object request) throws RestClientException; + @Nullable URI postForLocation(URI url, @Nullable Object request) throws RestClientException; /** * Create a new resource by POSTing the given object to the URI template, @@ -221,8 +216,7 @@ public interface RestOperations { * @return the converted object * @see HttpEntity */ - @Nullable - T postForObject(String url, @Nullable Object request, Class responseType, + @Nullable T postForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -243,8 +237,7 @@ public interface RestOperations { * @return the converted object * @see HttpEntity */ - @Nullable - T postForObject(String url, @Nullable Object request, Class responseType, + @Nullable T postForObject(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException; /** @@ -263,8 +256,7 @@ public interface RestOperations { * @return the converted object * @see HttpEntity */ - @Nullable - T postForObject(URI url, @Nullable 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, @@ -385,8 +377,7 @@ public interface RestOperations { * @see RestTemplate#setRequestFactory * @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory */ - @Nullable - T patchForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) + @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException; /** @@ -407,8 +398,7 @@ public interface RestOperations { * @see RestTemplate#setRequestFactory * @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory */ - @Nullable - T patchForObject(String url, @Nullable Object request, Class responseType, + @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException; /** @@ -427,8 +417,7 @@ public interface RestOperations { * @see RestTemplate#setRequestFactory * @see org.springframework.http.client.HttpComponentsClientHttpRequestFactory */ - @Nullable - T patchForObject(URI url, @Nullable Object request, Class responseType) + @Nullable T patchForObject(URI url, @Nullable Object request, Class responseType) throws RestClientException; @@ -658,8 +647,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 uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, + @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor, Object... uriVariables) throws RestClientException; @@ -674,8 +662,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 uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, + @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor, Map uriVariables) throws RestClientException; @@ -688,8 +675,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, @Nullable RequestCallback requestCallback, + @Nullable T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable 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 e9784a5e43..6f7b992bdb 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 @@ -31,6 +31,7 @@ import java.util.stream.Stream; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationConvention; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; @@ -69,7 +70,6 @@ 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.yaml.MappingJackson2YamlHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.MimeTypeUtils; @@ -174,8 +174,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat private ObservationRegistry observationRegistry = ObservationRegistry.NOOP; - @Nullable - private ClientRequestObservationConvention observationConvention; + private @Nullable ClientRequestObservationConvention observationConvention; /** @@ -398,8 +397,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * Return the configured {@link ClientRequestObservationConvention}, or {@code null} if not set. * @since 6.1 */ - @Nullable - public ClientRequestObservationConvention getObservationConvention() { + public @Nullable ClientRequestObservationConvention getObservationConvention() { return this.observationConvention; } @@ -407,8 +405,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat // GET @Override - @Nullable - public T getForObject(String url, Class responseType, Object... uriVariables) throws RestClientException { + public @Nullable T getForObject(String url, Class responseType, Object... uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor responseExtractor = new HttpMessageConverterExtractor<>(responseType, getMessageConverters(), logger); @@ -416,8 +413,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public T getForObject(String url, Class responseType, Map uriVariables) throws RestClientException { + public @Nullable T getForObject(String url, Class responseType, Map uriVariables) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor responseExtractor = new HttpMessageConverterExtractor<>(responseType, getMessageConverters(), logger); @@ -425,8 +421,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public T getForObject(URI url, Class responseType) throws RestClientException { + public @Nullable T getForObject(URI url, Class responseType) throws RestClientException { RequestCallback requestCallback = acceptHeaderRequestCallback(responseType); HttpMessageConverterExtractor responseExtractor = new HttpMessageConverterExtractor<>(responseType, getMessageConverters(), logger); @@ -480,8 +475,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat // POST @Override - @Nullable - public URI postForLocation(String url, @Nullable Object request, Object... uriVariables) + public @Nullable URI postForLocation(String url, @Nullable Object request, Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); @@ -490,8 +484,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public URI postForLocation(String url, @Nullable Object request, Map uriVariables) + public @Nullable URI postForLocation(String url, @Nullable Object request, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); @@ -500,16 +493,14 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public URI postForLocation(URI url, @Nullable Object request) throws RestClientException { + public @Nullable URI postForLocation(URI url, @Nullable Object request) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request); HttpHeaders headers = execute(url, HttpMethod.POST, requestCallback, headersExtractor()); return (headers != null ? headers.getLocation() : null); } @Override - @Nullable - public T postForObject(String url, @Nullable Object request, Class responseType, + public @Nullable T postForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); @@ -519,8 +510,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public T postForObject(String url, @Nullable Object request, Class responseType, + public @Nullable T postForObject(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); @@ -530,8 +520,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public T postForObject(URI url, @Nullable Object request, Class responseType) + public @Nullable T postForObject(URI url, @Nullable Object request, Class responseType) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); @@ -596,8 +585,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat // PATCH @Override - @Nullable - public T patchForObject(String url, @Nullable Object request, Class responseType, + public @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, Object... uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); @@ -607,8 +595,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public T patchForObject(String url, @Nullable Object request, Class responseType, + public @Nullable T patchForObject(String url, @Nullable Object request, Class responseType, Map uriVariables) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); @@ -618,8 +605,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } @Override - @Nullable - public T patchForObject(URI url, @Nullable Object request, Class responseType) + public @Nullable T patchForObject(URI url, @Nullable Object request, Class responseType) throws RestClientException { RequestCallback requestCallback = httpEntityCallback(request, responseType); @@ -768,8 +754,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat } } - @Nullable - private String resolveUriTemplate(RequestEntity entity) { + private @Nullable String resolveUriTemplate(RequestEntity entity) { if (entity instanceof RequestEntity.UriTemplateRequestEntity templated) { return templated.getUriTemplate(); } @@ -793,8 +778,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * */ @Override - @Nullable - public T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, + public @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor, Object... uriVariables) throws RestClientException { URI url = getUriTemplateHandler().expand(uriTemplate, uriVariables); @@ -813,8 +797,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * */ @Override - @Nullable - public T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, + public @Nullable T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor, Map uriVariables) throws RestClientException { @@ -834,8 +817,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * */ @Override - @Nullable - public T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, + public @Nullable T execute(URI url, HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor) throws RestClientException { return doExecute(url, null, method, requestCallback, responseExtractor); @@ -852,9 +834,8 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * @return an arbitrary object, as returned by the {@link ResponseExtractor} * @deprecated in favor of {@link #doExecute(URI, String, HttpMethod, RequestCallback, ResponseExtractor)} */ - @Nullable @Deprecated - protected T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, + protected @Nullable T doExecute(URI url, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor) throws RestClientException { return doExecute(url, null, method, requestCallback, responseExtractor); @@ -872,9 +853,8 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat * @return an arbitrary object, as returned by the {@link ResponseExtractor} * @since 6.0 */ - @Nullable @SuppressWarnings("try") - protected T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, + protected @Nullable T doExecute(URI url, @Nullable String uriTemplate, @Nullable HttpMethod method, @Nullable RequestCallback requestCallback, @Nullable ResponseExtractor responseExtractor) throws RestClientException { Assert.notNull(url, "url is required"); @@ -1008,8 +988,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat */ private class AcceptHeaderRequestCallback implements RequestCallback { - @Nullable - private final Type responseType; + private final @Nullable Type responseType; public AcceptHeaderRequestCallback(@Nullable Type responseType) { this.responseType = responseType; @@ -1165,8 +1144,7 @@ public class RestTemplate extends InterceptingHttpAccessor implements RestOperat */ private class ResponseEntityResponseExtractor implements ResponseExtractor> { - @Nullable - private final HttpMessageConverterExtractor delegate; + private final @Nullable HttpMessageConverterExtractor delegate; public ResponseEntityResponseExtractor(@Nullable Type responseType) { if (responseType != null && Void.class != responseType) { diff --git a/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java b/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java index 2b2f7ea8f6..1d5cb0bc9f 100644 --- a/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java +++ b/spring-web/src/main/java/org/springframework/web/client/StatusHandler.java @@ -25,6 +25,8 @@ import java.util.List; import java.util.function.Function; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.HttpHeaders; @@ -32,7 +34,6 @@ import org.springframework.http.HttpRequest; import org.springframework.http.HttpStatusCode; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -119,7 +120,7 @@ final class StatusHandler { } - private static String getErrorMessage(int rawStatusCode, String statusText, @Nullable byte[] responseBody, + private static String getErrorMessage(int rawStatusCode, String statusText, byte @Nullable [] responseBody, @Nullable Charset charset) { String preface = rawStatusCode + " " + statusText + ": "; diff --git a/spring-web/src/main/java/org/springframework/web/client/UnknownContentTypeException.java b/spring-web/src/main/java/org/springframework/web/client/UnknownContentTypeException.java index df9a7b3670..89785e0fe2 100644 --- a/spring-web/src/main/java/org/springframework/web/client/UnknownContentTypeException.java +++ b/spring-web/src/main/java/org/springframework/web/client/UnknownContentTypeException.java @@ -19,10 +19,11 @@ package org.springframework.web.client; import java.lang.reflect.Type; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * Raised when no suitable @@ -130,8 +131,7 @@ public class UnknownContentTypeException extends RestClientException { /** * Return the HTTP response headers. */ - @Nullable - public HttpHeaders getResponseHeaders() { + public @Nullable HttpHeaders getResponseHeaders() { return this.responseHeaders; } 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 a1676d5302..aaf76c0e55 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 @@ -18,8 +18,9 @@ package org.springframework.web.client; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; -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, @Nullable HttpHeaders responseHeaders, - @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + byte @Nullable [] responseBody, @Nullable Charset responseCharset) { this("Unknown status code [" + rawStatusCode + "]" + " " + statusText, rawStatusCode, statusText, responseHeaders, responseBody, responseCharset); @@ -59,7 +60,7 @@ public class UnknownHttpStatusCodeException extends RestClientResponseException * @since 5.2.2 */ public UnknownHttpStatusCodeException(String message, int rawStatusCode, String statusText, - @Nullable HttpHeaders responseHeaders, @Nullable byte[] responseBody, @Nullable Charset responseCharset) { + @Nullable HttpHeaders responseHeaders, byte @Nullable [] responseBody, @Nullable Charset responseCharset) { super(message, 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 bc1e16e248..917fb979a2 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,9 +2,7 @@ * Core package of the client-side web support. * Provides the RestTemplate and RestClient. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.client; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java b/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java index 67c4ecca90..2b2552e3d4 100644 --- a/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/client/support/RestClientAdapter.java @@ -20,12 +20,13 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.client.RestClient; import org.springframework.web.service.invoker.HttpExchangeAdapter; @@ -70,8 +71,7 @@ public final class RestClientAdapter implements HttpExchangeAdapter { } @Override - @Nullable - public T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference bodyType) { + public @Nullable T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference bodyType) { return newRequest(values).retrieve().body(bodyType); } diff --git a/spring-web/src/main/java/org/springframework/web/client/support/RestTemplateAdapter.java b/spring-web/src/main/java/org/springframework/web/client/support/RestTemplateAdapter.java index 364caa6be3..b431575b39 100644 --- a/spring-web/src/main/java/org/springframework/web/client/support/RestTemplateAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/client/support/RestTemplateAdapter.java @@ -20,13 +20,14 @@ import java.net.URI; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpCookie; 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; import org.springframework.util.Assert; import org.springframework.web.client.RestTemplate; import org.springframework.web.service.invoker.HttpExchangeAdapter; @@ -71,8 +72,7 @@ public final class RestTemplateAdapter implements HttpExchangeAdapter { } @Override - @Nullable - public T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference bodyType) { + public @Nullable T exchangeForBody(HttpRequestValues values, ParameterizedTypeReference bodyType) { return this.restTemplate.exchange(newRequest(values), bodyType).getBody(); } 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 ba9c45a63f..858e120c13 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,9 +2,7 @@ * Classes supporting the {@code org.springframework.web.client} package. * Contains a base class for RestTemplate usage. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.client.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 065acbadb2..d5187a5af2 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 @@ -20,9 +20,9 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContextInitializer; -import org.springframework.lang.Nullable; import org.springframework.web.WebApplicationInitializer; /** @@ -79,8 +79,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication * desired * @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer */ - @Nullable - protected abstract WebApplicationContext createRootApplicationContext(); + protected abstract @Nullable WebApplicationContext createRootApplicationContext(); /** * Specify application context initializers to be applied to the root application @@ -89,8 +88,7 @@ public abstract class AbstractContextLoaderInitializer implements WebApplication * @see #createRootApplicationContext() * @see ContextLoaderListener#setContextInitializers */ - @Nullable - protected ApplicationContextInitializer[] getRootApplicationContextInitializers() { + protected ApplicationContextInitializer @Nullable [] 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 831bad5cf1..8d71157878 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 @@ -18,9 +18,9 @@ package org.springframework.web.context; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.lang.Nullable; /** * Interface to be implemented by configurable web application contexts. @@ -70,8 +70,7 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext /** * Return the ServletConfig for this web application context, if any. */ - @Nullable - ServletConfig getServletConfig(); + @Nullable ServletConfig getServletConfig(); /** * Set the namespace for this web application context, @@ -83,8 +82,7 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext /** * Return the namespace for this web application context, if any. */ - @Nullable - String getNamespace(); + @Nullable String getNamespace(); /** * Set the config locations for this web application context in init-param style, @@ -105,7 +103,6 @@ public interface ConfigurableWebApplicationContext extends WebApplicationContext * Return the config locations for this web application context, * or {@code null} if none specified. */ - @Nullable - String[] getConfigLocations(); + String @Nullable [] 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 d077036403..f1ed6ff1d2 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 @@ -18,9 +18,9 @@ package org.springframework.web.context; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.lang.Nullable; /** * Specialization of {@link ConfigurableEnvironment} allowing initialization of 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 83c9297bd6..2c24db7c97 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 @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import jakarta.servlet.ServletContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationContext; @@ -37,7 +38,6 @@ 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; @@ -142,17 +142,14 @@ public class ContextLoader { * The 'current' WebApplicationContext, if the ContextLoader class is * deployed in the web app ClassLoader itself. */ - @Nullable - private static volatile WebApplicationContext currentContext; + private static volatile @Nullable WebApplicationContext currentContext; - @Nullable - private static Properties defaultStrategies; + private static @Nullable Properties defaultStrategies; /** * The root WebApplicationContext instance that this loader manages. */ - @Nullable - private WebApplicationContext rootContext; + private @Nullable WebApplicationContext rootContext; /** Actual ApplicationContextInitializer instances to apply to the context. */ private final List> contextInitializers = @@ -222,7 +219,7 @@ public class ContextLoader { * @see #customizeContext */ @SuppressWarnings("unchecked") - public void setContextInitializers(@Nullable ApplicationContextInitializer... initializers) { + public void setContextInitializers(ApplicationContextInitializer @Nullable ... initializers) { if (initializers != null) { for (ApplicationContextInitializer initializer : initializers) { this.contextInitializers.add((ApplicationContextInitializer) initializer); @@ -492,8 +489,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) { + protected @Nullable ApplicationContext loadParentContext(ServletContext servletContext) { return null; } @@ -531,8 +527,7 @@ public class ContextLoader { * if none found * @see org.springframework.web.context.support.SpringBeanAutowiringSupport */ - @Nullable - public static WebApplicationContext getCurrentWebApplicationContext() { + public static @Nullable WebApplicationContext getCurrentWebApplicationContext() { ClassLoader ccl = Thread.currentThread().getContextClassLoader(); if (ccl != null) { WebApplicationContext ccpt = currentContextPerThread.get(ccl); diff --git a/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java b/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java index e065e41526..c6594b4e79 100644 --- a/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java +++ b/spring-web/src/main/java/org/springframework/web/context/ContextLoaderListener.java @@ -19,8 +19,7 @@ package org.springframework.web.context; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContextEvent; import jakarta.servlet.ServletContextListener; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Bootstrap listener to start up and shut down Spring's root {@link WebApplicationContext}. @@ -39,8 +38,7 @@ import org.springframework.lang.Nullable; */ public class ContextLoaderListener extends ContextLoader implements ServletContextListener { - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; /** diff --git a/spring-web/src/main/java/org/springframework/web/context/WebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/WebApplicationContext.java index cef0509848..df2de3a2aa 100644 --- a/spring-web/src/main/java/org/springframework/web/context/WebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/WebApplicationContext.java @@ -17,9 +17,9 @@ package org.springframework.web.context; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContext; -import org.springframework.lang.Nullable; /** * Interface to provide configuration for a web application. This is read-only while @@ -100,7 +100,6 @@ public interface WebApplicationContext extends ApplicationContext { /** * Return the standard Servlet API ServletContext for this application. */ - @Nullable - ServletContext getServletContext(); + @Nullable ServletContext getServletContext(); } 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 a339a8b0e5..467cae8341 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,9 +1,7 @@ /** * Provides convenience annotations for web scopes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.context.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 01aa390001..1bb64bec44 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,9 +2,7 @@ * Contains a variant of the application context interface for web applications, * and the ContextLoaderListener that bootstraps a root web application context. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.context; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java b/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java index 89dc05ac8c..c02e3479ad 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/AbstractRequestAttributesScope.java @@ -16,9 +16,10 @@ package org.springframework.web.context.request; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.Scope; -import org.springframework.lang.Nullable; /** * Abstract {@link Scope} implementation that reads from a particular scope @@ -57,8 +58,7 @@ public abstract class AbstractRequestAttributesScope implements Scope { } @Override - @Nullable - public Object remove(String name) { + public @Nullable Object remove(String name) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); Object scopedObject = attributes.getAttribute(name, getScope()); if (scopedObject != null) { @@ -77,8 +77,7 @@ public abstract class AbstractRequestAttributesScope implements Scope { } @Override - @Nullable - public Object resolveContextualObject(String key) { + public @Nullable Object resolveContextualObject(String key) { RequestAttributes attributes = RequestContextHolder.currentRequestAttributes(); return attributes.resolveReference(key); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java b/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java index df96f12398..441d01372d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/FacesRequestAttributes.java @@ -23,8 +23,8 @@ import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; @@ -103,8 +103,7 @@ public class FacesRequestAttributes implements RequestAttributes { @Override - @Nullable - public Object getAttribute(String name, int scope) { + public @Nullable Object getAttribute(String name, int scope) { return getAttributeMap(scope).get(name); } @@ -132,8 +131,7 @@ public class FacesRequestAttributes implements RequestAttributes { } @Override - @Nullable - public Object resolveReference(String key) { + public @Nullable Object resolveReference(String key) { return switch (key) { case REFERENCE_REQUEST -> getExternalContext().getRequest(); case REFERENCE_SESSION -> getExternalContext().getSession(true); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java index b8163ad273..538e432e09 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/FacesWebRequest.java @@ -23,8 +23,8 @@ import java.util.Map; import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -58,9 +58,8 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb } @Override - @Nullable @SuppressWarnings("unchecked") - public T getNativeRequest(@Nullable Class requiredType) { + public @Nullable T getNativeRequest(@Nullable Class requiredType) { if (requiredType != null) { Object request = getExternalContext().getRequest(); if (requiredType.isInstance(request)) { @@ -71,9 +70,8 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb } @Override - @Nullable @SuppressWarnings("unchecked") - public T getNativeResponse(@Nullable Class requiredType) { + public @Nullable T getNativeResponse(@Nullable Class requiredType) { if (requiredType != null) { Object response = getExternalContext().getResponse(); if (requiredType.isInstance(response)) { @@ -85,14 +83,12 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb @Override - @Nullable - public String getHeader(String headerName) { + public @Nullable String getHeader(String headerName) { return getExternalContext().getRequestHeaderMap().get(headerName); } @Override - @Nullable - public String[] getHeaderValues(String headerName) { + public String @Nullable [] getHeaderValues(String headerName) { return getExternalContext().getRequestHeaderValuesMap().get(headerName); } @@ -102,8 +98,7 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb } @Override - @Nullable - public String getParameter(String paramName) { + public @Nullable String getParameter(String paramName) { return getExternalContext().getRequestParameterMap().get(paramName); } @@ -113,8 +108,7 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb } @Override - @Nullable - public String[] getParameterValues(String paramName) { + public String @Nullable [] getParameterValues(String paramName) { return getExternalContext().getRequestParameterValuesMap().get(paramName); } @@ -134,14 +128,12 @@ public class FacesWebRequest extends FacesRequestAttributes implements NativeWeb } @Override - @Nullable - public String getRemoteUser() { + public @Nullable String getRemoteUser() { return getFacesContext().getExternalContext().getRemoteUser(); } @Override - @Nullable - public Principal getUserPrincipal() { + public @Nullable Principal getUserPrincipal() { return getFacesContext().getExternalContext().getUserPrincipal(); } 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 8d90775760..5af8f19c19 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,7 +16,7 @@ package org.springframework.web.context.request; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Extension of the {@link WebRequest} interface, exposing the @@ -40,8 +40,7 @@ public interface NativeWebRequest extends WebRequest { * Return the underlying native response object, if any. * @see jakarta.servlet.http.HttpServletResponse */ - @Nullable - Object getNativeResponse(); + @Nullable Object getNativeResponse(); /** * Return the underlying native request object, if available. @@ -50,8 +49,7 @@ public interface NativeWebRequest extends WebRequest { * of that type is available * @see jakarta.servlet.http.HttpServletRequest */ - @Nullable - T getNativeRequest(@Nullable Class requiredType); + @Nullable T getNativeRequest(@Nullable Class requiredType); /** * Return the underlying native response object, if available. @@ -60,7 +58,6 @@ public interface NativeWebRequest extends WebRequest { * of that type is available * @see jakarta.servlet.http.HttpServletResponse */ - @Nullable - T getNativeResponse(@Nullable Class requiredType); + @Nullable T getNativeResponse(@Nullable 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 00becf5e3d..bb26845617 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,7 +16,7 @@ package org.springframework.web.context.request; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstraction for accessing attribute objects associated with a request. @@ -65,8 +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); + @Nullable Object getAttribute(String name, int scope); /** * Set the value for the scoped attribute of the given name, @@ -125,8 +124,7 @@ public interface RequestAttributes { * @param key the contextual key * @return the corresponding object, or {@code null} if none found */ - @Nullable - Object resolveReference(String key); + @Nullable Object resolveReference(String key); /** * Return an id for the current underlying session. diff --git a/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributesThreadLocalAccessor.java b/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributesThreadLocalAccessor.java index fcaf2b4549..73f06f5b1f 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributesThreadLocalAccessor.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/RequestAttributesThreadLocalAccessor.java @@ -22,8 +22,7 @@ import java.util.Map; import io.micrometer.context.ThreadLocalAccessor; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Adapt {@link RequestContextHolder} to the {@link ThreadLocalAccessor} contract @@ -48,8 +47,7 @@ public class RequestAttributesThreadLocalAccessor implements ThreadLocalAccessor } @Override - @Nullable - public RequestAttributes getValue() { + public @Nullable RequestAttributes getValue() { RequestAttributes request = RequestContextHolder.getRequestAttributes(); if (request instanceof ServletRequestAttributes sra && !(sra instanceof SnapshotServletRequestAttributes)) { request = new SnapshotServletRequestAttributes(sra); @@ -101,9 +99,8 @@ public class RequestAttributesThreadLocalAccessor implements ThreadLocalAccessor // Delegate methods that check isRequestActive() - @Nullable @Override - public Object getAttribute(String name, int scope) { + public @Nullable Object getAttribute(String name, int scope) { if (scope == RequestAttributes.SCOPE_REQUEST && !this.delegate.isRequestActive()) { return this.attributeMap.get(name); } 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 b9e55dd6cf..f4422e5a5c 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 @@ -17,10 +17,10 @@ package org.springframework.web.context.request; import jakarta.faces.context.FacesContext; +import org.jspecify.annotations.Nullable; import org.springframework.core.NamedInheritableThreadLocal; import org.springframework.core.NamedThreadLocal; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; /** @@ -100,8 +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() { + public static @Nullable RequestAttributes getRequestAttributes() { RequestAttributes attributes = requestAttributesHolder.get(); if (attributes == null) { attributes = inheritableRequestAttributesHolder.get(); @@ -145,8 +144,7 @@ public abstract class RequestContextHolder { */ private static class FacesRequestAttributesFactory { - @Nullable - public static RequestAttributes getFacesRequestAttributes() { + public static @Nullable RequestAttributes getFacesRequestAttributes() { try { FacesContext facesContext = FacesContext.getCurrentInstance(); return (facesContext != null ? new FacesRequestAttributes(facesContext) : null); diff --git a/spring-web/src/main/java/org/springframework/web/context/request/RequestScope.java b/spring-web/src/main/java/org/springframework/web/context/request/RequestScope.java index 4919ba598d..74423d9cc1 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/RequestScope.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/RequestScope.java @@ -16,7 +16,7 @@ package org.springframework.web.context.request; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Request-backed {@link org.springframework.beans.factory.config.Scope} @@ -49,8 +49,7 @@ public class RequestScope extends AbstractRequestAttributesScope { * returns {@code null}. */ @Override - @Nullable - public String getConversationId() { + public @Nullable String getConversationId() { return 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 52cddccba7..25c300e1b2 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,8 +24,8 @@ import java.util.concurrent.ConcurrentHashMap; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.NumberUtils; import org.springframework.util.StringUtils; @@ -63,11 +63,9 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { private final HttpServletRequest request; - @Nullable - private HttpServletResponse response; + private @Nullable HttpServletResponse response; - @Nullable - private volatile HttpSession session; + private volatile @Nullable HttpSession session; private final Map sessionAttributesToUpdate = new ConcurrentHashMap<>(1); @@ -102,8 +100,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { /** * Exposes the native {@link HttpServletResponse} that we're wrapping (if any). */ - @Nullable - public final HttpServletResponse getResponse() { + public final @Nullable HttpServletResponse getResponse() { return this.response; } @@ -111,8 +108,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { * Exposes the {@link HttpSession} that we're wrapping. * @param allowCreate whether to allow creation of a new session if none exists yet */ - @Nullable - protected final HttpSession getSession(boolean allowCreate) { + protected final @Nullable HttpSession getSession(boolean allowCreate) { if (isRequestActive()) { HttpSession session = this.request.getSession(allowCreate); this.session = session; @@ -143,8 +139,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { @Override - @Nullable - public Object getAttribute(String name, int scope) { + public @Nullable Object getAttribute(String name, int scope) { if (scope == SCOPE_REQUEST) { if (!isRequestActive()) { throw new IllegalStateException( @@ -243,8 +238,7 @@ public class ServletRequestAttributes extends AbstractRequestAttributes { } @Override - @Nullable - public Object resolveReference(String key) { + public @Nullable Object resolveReference(String key) { if (REFERENCE_REQUEST.equals(key)) { return this.request; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java index 64690c9495..dfe36b39e2 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/ServletWebRequest.java @@ -29,12 +29,12 @@ import java.util.TimeZone; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.http.ETag; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -91,20 +91,17 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ } @Override - @Nullable - public Object getNativeResponse() { + public @Nullable Object getNativeResponse() { return getResponse(); } @Override - @Nullable - public T getNativeRequest(@Nullable Class requiredType) { + public @Nullable T getNativeRequest(@Nullable Class requiredType) { return WebUtils.getNativeRequest(getRequest(), requiredType); } @Override - @Nullable - public T getNativeResponse(@Nullable Class requiredType) { + public @Nullable T getNativeResponse(@Nullable Class requiredType) { HttpServletResponse response = getResponse(); return (response != null ? WebUtils.getNativeResponse(response, requiredType) : null); } @@ -118,14 +115,12 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ } @Override - @Nullable - public String getHeader(String headerName) { + public @Nullable String getHeader(String headerName) { return getRequest().getHeader(headerName); } @Override - @Nullable - public String[] getHeaderValues(String headerName) { + public String @Nullable [] getHeaderValues(String headerName) { String[] headerValues = StringUtils.toStringArray(getRequest().getHeaders(headerName)); return (!ObjectUtils.isEmpty(headerValues) ? headerValues : null); } @@ -136,14 +131,12 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ } @Override - @Nullable - public String getParameter(String paramName) { + public @Nullable String getParameter(String paramName) { return getRequest().getParameter(paramName); } @Override - @Nullable - public String[] getParameterValues(String paramName) { + public String @Nullable [] getParameterValues(String paramName) { return getRequest().getParameterValues(paramName); } @@ -168,14 +161,12 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ } @Override - @Nullable - public String getRemoteUser() { + public @Nullable String getRemoteUser() { return getRequest().getRemoteUser(); } @Override - @Nullable - public Principal getUserPrincipal() { + public @Nullable Principal getUserPrincipal() { return getRequest().getUserPrincipal(); } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/SessionScope.java b/spring-web/src/main/java/org/springframework/web/context/request/SessionScope.java index 3c2c9d2ad0..514783edf8 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/SessionScope.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/SessionScope.java @@ -16,8 +16,9 @@ package org.springframework.web.context.request; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.ObjectFactory; -import org.springframework.lang.Nullable; /** * Session-backed {@link org.springframework.beans.factory.config.Scope} @@ -59,8 +60,7 @@ public class SessionScope extends AbstractRequestAttributesScope { } @Override - @Nullable - public Object remove(String name) { + public @Nullable Object remove(String name) { Object mutex = RequestContextHolder.currentRequestAttributes().getSessionMutex(); synchronized (mutex) { return super.remove(name); 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 f3b597d0e4..08fe2abdf3 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,7 +21,7 @@ import java.util.Iterator; import java.util.Locale; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Generic interface for a web request. Mainly intended for generic web @@ -41,8 +41,7 @@ public interface WebRequest extends RequestAttributes { * @since 3.0 * @see jakarta.servlet.http.HttpServletRequest#getHeader(String) */ - @Nullable - String getHeader(String headerName); + @Nullable String getHeader(String headerName); /** * Return the request header values for the given header name, @@ -51,8 +50,7 @@ public interface WebRequest extends RequestAttributes { * @since 3.0 * @see jakarta.servlet.http.HttpServletRequest#getHeaders(String) */ - @Nullable - String[] getHeaderValues(String headerName); + String @Nullable [] getHeaderValues(String headerName); /** * Return an Iterator over request header names. @@ -66,8 +64,7 @@ public interface WebRequest extends RequestAttributes { *

    Retrieves the first parameter value in case of a multi-value parameter. * @see jakarta.servlet.http.HttpServletRequest#getParameter(String) */ - @Nullable - String getParameter(String paramName); + @Nullable String getParameter(String paramName); /** * Return the request parameter values for the given parameter name, @@ -75,8 +72,7 @@ public interface WebRequest extends RequestAttributes { *

    A single-value parameter will be exposed as an array with a single element. * @see jakarta.servlet.http.HttpServletRequest#getParameterValues(String) */ - @Nullable - String[] getParameterValues(String paramName); + String @Nullable [] getParameterValues(String paramName); /** * Return an Iterator over request parameter names. @@ -110,15 +106,13 @@ public interface WebRequest extends RequestAttributes { * Return the remote user for this request, if any. * @see jakarta.servlet.http.HttpServletRequest#getRemoteUser() */ - @Nullable - String getRemoteUser(); + @Nullable String getRemoteUser(); /** * Return the user principal for this request, if any. * @see jakarta.servlet.http.HttpServletRequest#getUserPrincipal() */ - @Nullable - Principal getUserPrincipal(); + @Nullable Principal getUserPrincipal(); /** * Determine whether the user is in the given role for this request. 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 46a75bade5..6e23b678f1 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,7 +16,8 @@ package org.springframework.web.context.request; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.ModelMap; /** 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 f20c68d5c7..0444f2b83f 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 @@ -18,7 +18,8 @@ package org.springframework.web.context.request.async; import java.util.function.Consumer; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.context.request.NativeWebRequest; /** diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java index 282af1a500..a78a9c9d54 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableInterceptorChain.java @@ -22,8 +22,8 @@ import java.util.concurrent.Future; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** @@ -41,8 +41,7 @@ class CallableInterceptorChain { private int preProcessIndex = -1; - @Nullable - private volatile Future taskFuture; + private volatile @Nullable Future taskFuture; public CallableInterceptorChain(List interceptors) { @@ -68,8 +67,7 @@ class CallableInterceptorChain { } } - @Nullable - public Object applyPostProcess(NativeWebRequest request, Callable task, @Nullable Object concurrentResult) { + public @Nullable Object applyPostProcess(NativeWebRequest request, Callable task, @Nullable Object concurrentResult) { Throwable exceptionResult = null; for (int i = this.preProcessIndex; i >= 0; i--) { try { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java index c5bb505bef..e78b40e0ca 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/CallableProcessingInterceptor.java @@ -18,8 +18,9 @@ package org.springframework.web.context.request.async; import java.util.concurrent.Callable; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.AsyncTaskExecutor; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** 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 3fbd694e8b..4a0847cf03 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 @@ -23,8 +23,8 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -59,25 +59,19 @@ public class DeferredResult { private static final Log logger = LogFactory.getLog(DeferredResult.class); - @Nullable - private final Long timeoutValue; + private final @Nullable Long timeoutValue; private final Supplier timeoutResult; - @Nullable - private Runnable timeoutCallback; + private @Nullable Runnable timeoutCallback; - @Nullable - private Consumer errorCallback; + private @Nullable Consumer errorCallback; - @Nullable - private Runnable completionCallback; + private @Nullable Runnable completionCallback; - @Nullable - private DeferredResultHandler resultHandler; + private @Nullable DeferredResultHandler resultHandler; - @Nullable - private volatile Object result = RESULT_NONE; + private volatile @Nullable Object result = RESULT_NONE; private volatile boolean expired; @@ -149,8 +143,7 @@ public class DeferredResult { * to check if there is a result prior to calling this method. * @since 4.0 */ - @Nullable - public Object getResult() { + public @Nullable Object getResult() { Object resultToCheck = this.result; return (resultToCheck != RESULT_NONE ? resultToCheck : null); } @@ -158,8 +151,7 @@ public class DeferredResult { /** * Return the configured timeout value in milliseconds. */ - @Nullable - final Long getTimeoutValue() { + final @Nullable Long getTimeoutValue() { return this.timeoutValue; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java index 855892faeb..c89c8472bc 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultInterceptorChain.java @@ -20,8 +20,8 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** @@ -58,8 +58,7 @@ class DeferredResultInterceptorChain { } } - @Nullable - public Object applyPostProcess(NativeWebRequest request, DeferredResult deferredResult, + public @Nullable Object applyPostProcess(NativeWebRequest request, DeferredResult deferredResult, @Nullable Object concurrentResult) { try { diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultProcessingInterceptor.java b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultProcessingInterceptor.java index 8c79c180da..35a3b33fff 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultProcessingInterceptor.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/DeferredResultProcessingInterceptor.java @@ -16,7 +16,8 @@ package org.springframework.web.context.request.async; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.context.request.NativeWebRequest; /** diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java index 9cad8c3591..1beb9f2e60 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/StandardServletAsyncWebRequest.java @@ -33,8 +33,8 @@ import jakarta.servlet.WriteListener; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.ServletWebRequest; @@ -57,11 +57,9 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements private final List completionHandlers = new ArrayList<>(); - @Nullable - private Long timeout; + private @Nullable Long timeout; - @Nullable - private AsyncContext asyncContext; + private @Nullable AsyncContext asyncContext; private State state; @@ -259,14 +257,11 @@ public class StandardServletAsyncWebRequest extends ServletWebRequest implements */ private static final class LifecycleHttpServletResponse extends HttpServletResponseWrapper { - @Nullable - private StandardServletAsyncWebRequest asyncWebRequest; + private @Nullable StandardServletAsyncWebRequest asyncWebRequest; - @Nullable - private ServletOutputStream outputStream; + private @Nullable ServletOutputStream outputStream; - @Nullable - private PrintWriter writer; + private @Nullable PrintWriter writer; public LifecycleHttpServletResponse(HttpServletResponse response) { super(response); 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 a743844181..c948b0b9d5 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 @@ -27,10 +27,10 @@ import java.util.concurrent.atomic.AtomicReference; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -74,18 +74,15 @@ public final class WebAsyncManager { new TimeoutDeferredResultProcessingInterceptor(); - @Nullable - private AsyncWebRequest asyncWebRequest; + private @Nullable AsyncWebRequest asyncWebRequest; private AsyncTaskExecutor taskExecutor = DEFAULT_TASK_EXECUTOR; private boolean isMultipartRequestParsed; - @Nullable - private volatile Object concurrentResult = RESULT_NONE; + private volatile @Nullable Object concurrentResult = RESULT_NONE; - @Nullable - private volatile Object[] concurrentResultContext; + private volatile Object @Nullable [] concurrentResultContext; private final AtomicReference state = new AtomicReference<>(State.NOT_STARTED); @@ -123,8 +120,7 @@ public final class WebAsyncManager { * Return the current {@link AsyncWebRequest}. * @since 5.3.33 */ - @Nullable - public AsyncWebRequest getAsyncWebRequest() { + public @Nullable AsyncWebRequest getAsyncWebRequest() { return this.asyncWebRequest; } @@ -162,8 +158,7 @@ public final class WebAsyncManager { * concurrent handling raised one * @see #clearConcurrentResult() */ - @Nullable - public Object getConcurrentResult() { + public @Nullable Object getConcurrentResult() { return this.concurrentResult; } @@ -171,8 +166,7 @@ public final class WebAsyncManager { * Get the additional processing context saved at the start of concurrent handling. * @see #clearConcurrentResult() */ - @Nullable - public Object[] getConcurrentResultContext() { + public Object @Nullable [] getConcurrentResultContext() { return this.concurrentResultContext; } @@ -181,8 +175,7 @@ public final class WebAsyncManager { * @param key the key * @return the interceptor registered under that key, or {@code null} if none */ - @Nullable - public CallableProcessingInterceptor getCallableInterceptor(Object key) { + public @Nullable CallableProcessingInterceptor getCallableInterceptor(Object key) { return this.callableInterceptors.get(key); } @@ -191,8 +184,7 @@ public final class WebAsyncManager { * @param key the key * @return the interceptor registered under that key, or {@code null} if none */ - @Nullable - public DeferredResultProcessingInterceptor getDeferredResultInterceptor(Object key) { + public @Nullable 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 5b49b79d46..5d14b776ef 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 @@ -18,10 +18,11 @@ package org.springframework.web.context.request.async; import java.util.concurrent.Callable; +import org.jspecify.annotations.Nullable; + 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; @@ -38,26 +39,19 @@ public class WebAsyncTask implements BeanFactoryAware { private final Callable callable; - @Nullable - private final Long timeout; + private final @Nullable Long timeout; - @Nullable - private final AsyncTaskExecutor executor; + private final @Nullable AsyncTaskExecutor executor; - @Nullable - private final String executorName; + private final @Nullable String executorName; - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; - @Nullable - private Callable timeoutCallback; + private @Nullable Callable timeoutCallback; - @Nullable - private Callable errorCallback; + private @Nullable Callable errorCallback; - @Nullable - private Runnable completionCallback; + private @Nullable Runnable completionCallback; /** @@ -126,8 +120,7 @@ public class WebAsyncTask implements BeanFactoryAware { /** * Return the timeout value in milliseconds, or {@code null} if no timeout is set. */ - @Nullable - public Long getTimeout() { + public @Nullable Long getTimeout() { return this.timeout; } @@ -145,8 +138,7 @@ public class WebAsyncTask implements BeanFactoryAware { * Return the AsyncTaskExecutor to use for concurrent handling, * or {@code null} if none specified. */ - @Nullable - public AsyncTaskExecutor getExecutor() { + public @Nullable AsyncTaskExecutor getExecutor() { if (this.executor != null) { return this.executor; } diff --git a/spring-web/src/main/java/org/springframework/web/context/request/async/package-info.java b/spring-web/src/main/java/org/springframework/web/context/request/async/package-info.java index c9f78c659d..f53c1fd58d 100644 --- a/spring-web/src/main/java/org/springframework/web/context/request/async/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/context/request/async/package-info.java @@ -1,9 +1,7 @@ /** * Support for asynchronous request processing. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.context.request.async; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 ed3aae5f0b..bc9dfc601f 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,9 +2,7 @@ * Support for generic request context holding, in particular for * scoping of application objects per HTTP request or HTTP session. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.context.request; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java index b679c21854..7626821629 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/AbstractRefreshableWebApplicationContext.java @@ -18,13 +18,13 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.context.support.AbstractRefreshableConfigApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.lang.Nullable; import org.springframework.ui.context.Theme; import org.springframework.ui.context.ThemeSource; import org.springframework.ui.context.support.UiApplicationContextUtils; @@ -83,20 +83,16 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR implements ConfigurableWebApplicationContext, ThemeSource { /** Servlet context that this context runs in. */ - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; /** Servlet config that this context runs in, if any. */ - @Nullable - private ServletConfig servletConfig; + private @Nullable ServletConfig servletConfig; /** Namespace of this context, or {@code null} if root. */ - @Nullable - private String namespace; + private @Nullable String namespace; /** the ThemeSource for this ApplicationContext. */ - @Nullable - private ThemeSource themeSource; + private @Nullable ThemeSource themeSource; public AbstractRefreshableWebApplicationContext() { @@ -110,8 +106,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return this.servletContext; } @@ -124,8 +119,7 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { return this.servletConfig; } @@ -138,14 +132,12 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR } @Override - @Nullable - public String getNamespace() { + public @Nullable String getNamespace() { return this.namespace; } @Override - @Nullable - public String[] getConfigLocations() { + public String @Nullable [] getConfigLocations() { return super.getConfigLocations(); } @@ -216,9 +208,8 @@ public abstract class AbstractRefreshableWebApplicationContext extends AbstractR } @Override - @Nullable @Deprecated - public Theme getTheme(String themeName) { + public @Nullable Theme getTheme(String themeName) { Assert.state(this.themeSource != null, "No ThemeSource available"); return this.themeSource.getTheme(themeName); } 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 8c67326657..feee8995f4 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 @@ -20,6 +20,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.support.BeanNameGenerator; import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.context.annotation.AnnotatedBeanDefinitionReader; @@ -27,7 +29,6 @@ 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.ClassUtils; import org.springframework.util.StringUtils; @@ -99,11 +100,9 @@ import org.springframework.web.context.ContextLoader; public class AnnotationConfigWebApplicationContext extends AbstractRefreshableWebApplicationContext implements AnnotationConfigRegistry { - @Nullable - private BeanNameGenerator beanNameGenerator; + private @Nullable BeanNameGenerator beanNameGenerator; - @Nullable - private ScopeMetadataResolver scopeMetadataResolver; + private @Nullable ScopeMetadataResolver scopeMetadataResolver; private final Set> componentClasses = new LinkedHashSet<>(); @@ -125,8 +124,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() { + protected @Nullable BeanNameGenerator getBeanNameGenerator() { return this.beanNameGenerator; } @@ -145,8 +143,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() { + protected @Nullable ScopeMetadataResolver getScopeMetadataResolver() { return this.scopeMetadataResolver; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java index 55b32a46ca..766233f862 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ContextExposingHttpServletRequest.java @@ -21,8 +21,8 @@ import java.util.Set; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequestWrapper; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; @@ -38,11 +38,9 @@ public class ContextExposingHttpServletRequest extends HttpServletRequestWrapper private final WebApplicationContext webApplicationContext; - @Nullable - private final Set exposedContextBeanNames; + private final @Nullable Set exposedContextBeanNames; - @Nullable - private Set explicitAttributes; + private @Nullable Set explicitAttributes; /** @@ -81,8 +79,7 @@ public class ContextExposingHttpServletRequest extends HttpServletRequestWrapper @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { if ((this.explicitAttributes == null || !this.explicitAttributes.contains(name)) && (this.exposedContextBeanNames == null || this.exposedContextBeanNames.contains(name)) && this.webApplicationContext.containsBean(name)) { diff --git a/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java index 1c6a3dea00..2f0335dfac 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/GenericWebApplicationContext.java @@ -18,6 +18,7 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.beans.factory.support.DefaultListableBeanFactory; @@ -25,7 +26,6 @@ import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.lang.Nullable; import org.springframework.ui.context.Theme; import org.springframework.ui.context.ThemeSource; import org.springframework.ui.context.support.UiApplicationContextUtils; @@ -82,11 +82,9 @@ import org.springframework.web.context.ServletContextAware; public class GenericWebApplicationContext extends GenericApplicationContext implements ConfigurableWebApplicationContext, ThemeSource { - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; - @Nullable - private ThemeSource themeSource; + private @Nullable ThemeSource themeSource; /** @@ -142,8 +140,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return this.servletContext; } @@ -213,9 +210,8 @@ public class GenericWebApplicationContext extends GenericApplicationContext } @Override - @Nullable @Deprecated - public Theme getTheme(String themeName) { + public @Nullable Theme getTheme(String themeName) { Assert.state(this.themeSource != null, "No ThemeSource available"); return this.themeSource.getTheme(themeName); } @@ -231,8 +227,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { throw new UnsupportedOperationException( "GenericWebApplicationContext does not support getServletConfig()"); } @@ -243,8 +238,7 @@ public class GenericWebApplicationContext extends GenericApplicationContext } @Override - @Nullable - public String getNamespace() { + public @Nullable String getNamespace() { throw new UnsupportedOperationException( "GenericWebApplicationContext does not support getNamespace()"); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/GroovyWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/GroovyWebApplicationContext.java index 25610fd6a3..99b64ee047 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/GroovyWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/GroovyWebApplicationContext.java @@ -21,6 +21,7 @@ import java.io.IOException; import groovy.lang.GroovyObject; import groovy.lang.GroovySystem; import groovy.lang.MetaClass; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeanWrapperImpl; @@ -28,7 +29,6 @@ import org.springframework.beans.BeansException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.groovy.GroovyBeanDefinitionReader; import org.springframework.beans.factory.support.DefaultListableBeanFactory; -import org.springframework.lang.Nullable; /** * {@link org.springframework.web.context.WebApplicationContext} implementation which takes @@ -175,8 +175,7 @@ public class GroovyWebApplicationContext extends AbstractRefreshableWebApplicati } @Override - @Nullable - public Object getProperty(String property) { + public @Nullable Object getProperty(String property) { if (containsBean(property)) { return getBean(property); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/HttpRequestHandlerServlet.java b/spring-web/src/main/java/org/springframework/web/context/support/HttpRequestHandlerServlet.java index be1ac6857f..3e5785e51b 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/HttpRequestHandlerServlet.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/HttpRequestHandlerServlet.java @@ -22,10 +22,10 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.HttpRequestHandler; @@ -45,8 +45,7 @@ import org.springframework.web.context.WebApplicationContext; @SuppressWarnings("serial") public class HttpRequestHandlerServlet extends HttpServlet { - @Nullable - private HttpRequestHandler target; + private @Nullable HttpRequestHandler target; @Override 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 bc60bb4308..25d23d65b6 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 @@ -16,8 +16,9 @@ package org.springframework.web.context.support; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; -import org.springframework.lang.Nullable; /** * Event raised when a request is handled within an ApplicationContext. @@ -37,19 +38,16 @@ import org.springframework.lang.Nullable; public class RequestHandledEvent extends ApplicationEvent { /** Session id that applied to the request, if any. */ - @Nullable - private final String sessionId; + private final @Nullable String sessionId; /** Usually the UserPrincipal. */ - @Nullable - private final String userName; + private final @Nullable String userName; /** Request processing time. */ private final long processingTimeMillis; /** Cause of failure, if any. */ - @Nullable - private Throwable failureCause; + private @Nullable Throwable failureCause; /** @@ -96,8 +94,7 @@ public class RequestHandledEvent extends ApplicationEvent { /** * Return the id of the HTTP session, if any. */ - @Nullable - public String getSessionId() { + public @Nullable String getSessionId() { return this.sessionId; } @@ -106,8 +103,7 @@ public class RequestHandledEvent extends ApplicationEvent { * (usually the UserPrincipal). * @see jakarta.servlet.http.HttpServletRequest#getUserPrincipal() */ - @Nullable - public String getUserName() { + public @Nullable String getUserName() { return this.userName; } @@ -121,8 +117,7 @@ public class RequestHandledEvent extends ApplicationEvent { /** * Return the cause of failure, if any. */ - @Nullable - public Throwable getFailureCause() { + public @Nullable Throwable getFailureCause() { return this.failureCause; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletConfigPropertySource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletConfigPropertySource.java index 72266c0bb9..b4ddfddaed 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletConfigPropertySource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletConfigPropertySource.java @@ -17,10 +17,10 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletConfig; +import org.jspecify.annotations.Nullable; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.PropertySource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -42,8 +42,7 @@ public class ServletConfigPropertySource extends EnumerablePropertySource attributes; + private @Nullable Map attributes; /** diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java index 84f9277738..1aadb79bc0 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeFactoryBean.java @@ -17,9 +17,9 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; import org.springframework.web.context.ServletContextAware; /** @@ -44,11 +44,9 @@ import org.springframework.web.context.ServletContextAware; */ public class ServletContextAttributeFactoryBean implements FactoryBean, ServletContextAware { - @Nullable - private String attributeName; + private @Nullable String attributeName; - @Nullable - private Object attribute; + private @Nullable Object attribute; /** @@ -71,14 +69,12 @@ public class ServletContextAttributeFactoryBean implements FactoryBean, @Override - @Nullable - public Object getObject() throws Exception { + public @Nullable Object getObject() throws Exception { return this.attribute; } @Override - @Nullable - public Class getObjectType() { + public @Nullable Class getObjectType() { return (this.attribute != null ? this.attribute.getClass() : null); } 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 b4aa7b0984..b5945648fb 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 @@ -18,10 +18,10 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; 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; @@ -41,11 +41,9 @@ import org.springframework.web.context.ServletContextAware; */ public class ServletContextAwareProcessor implements BeanPostProcessor { - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; - @Nullable - private ServletConfig servletConfig; + private @Nullable ServletConfig servletConfig; /** @@ -84,8 +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() { + protected @Nullable ServletContext getServletContext() { if (this.servletContext == null && getServletConfig() != null) { return getServletConfig().getServletContext(); } @@ -97,8 +94,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 ServletConfig getServletConfig() { + protected @Nullable ServletConfig getServletConfig() { return this.servletConfig; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextParameterFactoryBean.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextParameterFactoryBean.java index c255ccbd21..70b73713d8 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextParameterFactoryBean.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextParameterFactoryBean.java @@ -17,9 +17,9 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.FactoryBean; -import org.springframework.lang.Nullable; import org.springframework.web.context.ServletContextAware; /** @@ -39,11 +39,9 @@ import org.springframework.web.context.ServletContextAware; */ public class ServletContextParameterFactoryBean implements FactoryBean, ServletContextAware { - @Nullable - private String initParamName; + private @Nullable String initParamName; - @Nullable - private String paramValue; + private @Nullable String paramValue; /** @@ -66,8 +64,7 @@ public class ServletContextParameterFactoryBean implements FactoryBean, @Override - @Nullable - public String getObject() { + public @Nullable String getObject() { return this.paramValue; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextPropertySource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextPropertySource.java index ca100504c7..d620b385a7 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextPropertySource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextPropertySource.java @@ -17,10 +17,10 @@ package org.springframework.web.context.support; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.core.env.EnumerablePropertySource; import org.springframework.core.env.PropertySource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -42,8 +42,7 @@ public class ServletContextPropertySource extends EnumerablePropertySource attrNames = sc.getAttributeNames(); 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 b7035f711f..cea2f626ce 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 @@ -19,10 +19,10 @@ package org.springframework.web.context.support; import java.io.File; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ApplicationObjectSupport; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.ServletContextAware; import org.springframework.web.context.WebApplicationContext; @@ -43,8 +43,7 @@ import org.springframework.web.util.WebUtils; */ public abstract class WebApplicationObjectSupport extends ApplicationObjectSupport implements ServletContextAware { - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; @Override @@ -105,8 +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 { + protected final @Nullable WebApplicationContext getWebApplicationContext() throws IllegalStateException { ApplicationContext ctx = getApplicationContext(); if (ctx instanceof WebApplicationContext wac) { return wac; @@ -125,8 +123,7 @@ public abstract class WebApplicationObjectSupport extends ApplicationObjectSuppo * @throws IllegalStateException if not running within a required ServletContext * @see #isContextRequired() */ - @Nullable - protected final ServletContext getServletContext() throws IllegalStateException { + protected final @Nullable 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 78999b0c42..1a3d8a2aa3 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,9 +2,7 @@ * Classes supporting the {@code org.springframework.web.context} package, * such as WebApplicationContext implementations and various utility classes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.context.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 bef29cf0e2..80ac063fa9 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 @@ -25,8 +25,9 @@ import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + 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; @@ -68,32 +69,23 @@ public class CorsConfiguration { HttpMethod.HEAD.name(), HttpMethod.POST.name()); - @Nullable - private List allowedOrigins; + private @Nullable List allowedOrigins; - @Nullable - private List allowedOriginPatterns; + private @Nullable List allowedOriginPatterns; - @Nullable - private List allowedMethods; + private @Nullable List allowedMethods; - @Nullable - private List resolvedMethods = DEFAULT_METHODS; + private @Nullable List resolvedMethods = DEFAULT_METHODS; - @Nullable - private List allowedHeaders; + private @Nullable List allowedHeaders; - @Nullable - private List exposedHeaders; + private @Nullable List exposedHeaders; - @Nullable - private Boolean allowCredentials; + private @Nullable Boolean allowCredentials; - @Nullable - private Boolean allowPrivateNetwork; + private @Nullable Boolean allowPrivateNetwork; - @Nullable - private Long maxAge; + private @Nullable Long maxAge; /** @@ -163,8 +155,7 @@ public class CorsConfiguration { /** * Return the configured origins to allow, or {@code null} if none. */ - @Nullable - public List getAllowedOrigins() { + public @Nullable List getAllowedOrigins() { return this.allowedOrigins; } @@ -231,8 +222,7 @@ public class CorsConfiguration { * Return the configured origins patterns to allow, or {@code null} if none. * @since 5.3 */ - @Nullable - public List getAllowedOriginPatterns() { + public @Nullable List getAllowedOriginPatterns() { if (this.allowedOriginPatterns == null) { return null; } @@ -330,8 +320,7 @@ public class CorsConfiguration { * @see #addAllowedMethod(HttpMethod) * @see #addAllowedMethod(String) */ - @Nullable - public List getAllowedMethods() { + public @Nullable List getAllowedMethods() { return this.allowedMethods; } @@ -387,8 +376,7 @@ public class CorsConfiguration { * @see #addAllowedHeader(String) * @see #setAllowedHeaders(List) */ - @Nullable - public List getAllowedHeaders() { + public @Nullable List getAllowedHeaders() { return this.allowedHeaders; } @@ -430,8 +418,7 @@ public class CorsConfiguration { * @see #addExposedHeader(String) * @see #setExposedHeaders(List) */ - @Nullable - public List getExposedHeaders() { + public @Nullable List getExposedHeaders() { return this.exposedHeaders; } @@ -466,8 +453,7 @@ public class CorsConfiguration { * Return the configured {@code allowCredentials} flag, or {@code null} if none. * @see #setAllowCredentials(Boolean) */ - @Nullable - public Boolean getAllowCredentials() { + public @Nullable Boolean getAllowCredentials() { return this.allowCredentials; } @@ -493,8 +479,7 @@ public class CorsConfiguration { * @since 5.3.32 * @see #setAllowPrivateNetwork(Boolean) */ - @Nullable - public Boolean getAllowPrivateNetwork() { + public @Nullable Boolean getAllowPrivateNetwork() { return this.allowPrivateNetwork; } @@ -521,8 +506,7 @@ public class CorsConfiguration { * Return the configured {@code maxAge} value, or {@code null} if none. * @see #setMaxAge(Long) */ - @Nullable - public Long getMaxAge() { + public @Nullable Long getMaxAge() { return this.maxAge; } @@ -691,8 +675,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(@Nullable String origin) { + public @Nullable String checkOrigin(@Nullable String origin) { if (!StringUtils.hasText(origin)) { return null; } @@ -727,8 +710,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(@Nullable HttpMethod requestMethod) { + public @Nullable List checkHttpMethod(@Nullable HttpMethod requestMethod) { if (requestMethod == null) { return null; } @@ -746,8 +728,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(@Nullable List requestHeaders) { + public @Nullable List checkHeaders(@Nullable 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 c2111bb5b8..e62bf5290e 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 @@ -17,8 +17,7 @@ package org.springframework.web.cors; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by classes (usually HTTP request handlers) that @@ -33,7 +32,6 @@ 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); + @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 4b19c35d96..be64e9520c 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 @@ -20,8 +20,7 @@ import java.io.IOException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A strategy that takes a request and a {@link CorsConfiguration} and updates diff --git a/spring-web/src/main/java/org/springframework/web/cors/CorsUtils.java b/spring-web/src/main/java/org/springframework/web/cors/CorsUtils.java index 842c030821..b1a46deacb 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/CorsUtils.java +++ b/spring-web/src/main/java/org/springframework/web/cors/CorsUtils.java @@ -17,10 +17,10 @@ package org.springframework.web.cors; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; diff --git a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java index 158871a196..2bbd283c09 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/DefaultCorsProcessor.java @@ -26,6 +26,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -34,7 +35,6 @@ import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -192,8 +192,7 @@ public class DefaultCorsProcessor implements CorsProcessor { * implementation simply delegates to * {@link org.springframework.web.cors.CorsConfiguration#checkOrigin(String)}. */ - @Nullable - protected String checkOrigin(CorsConfiguration config, @Nullable String requestOrigin) { + protected @Nullable String checkOrigin(CorsConfiguration config, @Nullable String requestOrigin) { return config.checkOrigin(requestOrigin); } @@ -202,13 +201,11 @@ public class DefaultCorsProcessor implements CorsProcessor { * pre-flight request. The default implementation simply delegates to * {@link org.springframework.web.cors.CorsConfiguration#checkHttpMethod(HttpMethod)}. */ - @Nullable - protected List checkMethods(CorsConfiguration config, @Nullable HttpMethod requestMethod) { + protected @Nullable List checkMethods(CorsConfiguration config, @Nullable HttpMethod requestMethod) { return config.checkHttpMethod(requestMethod); } - @Nullable - private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { + private @Nullable HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { return (isPreFlight ? request.getHeaders().getAccessControlRequestMethod() : request.getMethod()); } @@ -217,8 +214,7 @@ public class DefaultCorsProcessor implements CorsProcessor { * pre-flight request. The default implementation simply delegates to * {@link org.springframework.web.cors.CorsConfiguration#checkHeaders(List)}. */ - @Nullable - protected List checkHeaders(CorsConfiguration config, List requestHeaders) { + protected @Nullable List checkHeaders(CorsConfiguration config, List requestHeaders) { return config.checkHeaders(requestHeaders); } diff --git a/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java b/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java index ab11bae96f..a7c81d0205 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java +++ b/spring-web/src/main/java/org/springframework/web/cors/UrlBasedCorsConfigurationSource.java @@ -21,9 +21,9 @@ import java.util.LinkedHashMap; import java.util.Map; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -62,8 +62,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource private PathMatcher pathMatcher = defaultPathMatcher; - @Nullable - private String lookupPathAttributeName; + private @Nullable String lookupPathAttributeName; private boolean allowInitLookupPath = true; @@ -239,8 +238,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource @Override - @Nullable - public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { + public @Nullable CorsConfiguration getCorsConfiguration(HttpServletRequest request) { Object path = resolvePath(request); boolean isPathContainer = (path instanceof PathContainer); for (Map.Entry entry : this.corsConfigurations.entrySet()) { 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 3c92402aed..991123eb05 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,9 +2,7 @@ * Support for CORS (Cross-Origin Resource Sharing), * based on a common {@code CorsProcessor} strategy. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.cors; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 98a31159ef..0d9a13ea9f 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,7 +16,8 @@ package org.springframework.web.cors.reactive; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.ServerWebExchange; @@ -33,7 +34,6 @@ 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); + @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 c27a06575c..5a6da4d61d 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 @@ -16,7 +16,8 @@ package org.springframework.web.cors.reactive; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.ServerWebExchange; diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java index c5256f24d6..e50839398c 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/CorsUtils.java @@ -18,10 +18,11 @@ package org.springframework.web.cors.reactive; import java.net.URI; +import org.jspecify.annotations.Nullable; + 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.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; diff --git a/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java b/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java index e1d2b82a6a..369a32fd93 100644 --- a/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/cors/reactive/DefaultCorsProcessor.java @@ -21,13 +21,13 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.ServerWebExchange; @@ -189,8 +189,7 @@ public class DefaultCorsProcessor implements CorsProcessor { * implementation simply delegates to * {@link CorsConfiguration#checkOrigin(String)}. */ - @Nullable - protected String checkOrigin(CorsConfiguration config, @Nullable String requestOrigin) { + protected @Nullable String checkOrigin(CorsConfiguration config, @Nullable String requestOrigin) { return config.checkOrigin(requestOrigin); } @@ -199,13 +198,11 @@ public class DefaultCorsProcessor implements CorsProcessor { * pre-flight request. The default implementation simply delegates to * {@link CorsConfiguration#checkHttpMethod(HttpMethod)}. */ - @Nullable - protected List checkMethods(CorsConfiguration config, @Nullable HttpMethod requestMethod) { + protected @Nullable List checkMethods(CorsConfiguration config, @Nullable HttpMethod requestMethod) { return config.checkHttpMethod(requestMethod); } - @Nullable - private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { + private @Nullable HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight) { return (isPreFlight ? request.getHeaders().getAccessControlRequestMethod() : request.getMethod()); } @@ -214,8 +211,7 @@ public class DefaultCorsProcessor implements CorsProcessor { * pre-flight request. The default implementation simply delegates to * {@link CorsConfiguration#checkHeaders(List)}. */ - @Nullable - protected List checkHeaders(CorsConfiguration config, List requestHeaders) { + protected @Nullable List checkHeaders(CorsConfiguration config, List requestHeaders) { return config.checkHeaders(requestHeaders); } 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 af85fde0aa..addc771946 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 @@ -19,8 +19,9 @@ package org.springframework.web.cors.reactive; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.util.pattern.PathPattern; @@ -78,8 +79,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource } @Override - @Nullable - public CorsConfiguration getCorsConfiguration(ServerWebExchange exchange) { + public @Nullable CorsConfiguration getCorsConfiguration(ServerWebExchange exchange) { PathContainer path = exchange.getRequest().getPath().pathWithinApplication(); for (Map.Entry entry : this.corsConfigurations.entrySet()) { if (entry.getKey().matches(path)) { 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 index 0cca26c2a0..bcfc67015b 100644 --- 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 @@ -2,9 +2,7 @@ * Reactive support for CORS (Cross-Origin Resource Sharing), * based on a common {@code CorsProcessor} strategy. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.cors.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java b/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java index 190666c12a..36dcaadcfb 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/AbstractRequestLoggingFilter.java @@ -26,10 +26,10 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; 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.util.ContentCachingRequestWrapper; @@ -99,8 +99,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter private boolean includePayload = false; - @Nullable - private Predicate headerPredicate; + private @Nullable Predicate headerPredicate; private int maxPayloadLength = DEFAULT_MAX_PAYLOAD_LENGTH; @@ -198,8 +197,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter * The configured {@link #setHeaderPredicate(Predicate) headerPredicate}. * @since 5.2 */ - @Nullable - protected Predicate getHeaderPredicate() { + protected @Nullable Predicate getHeaderPredicate() { return this.headerPredicate; } @@ -378,8 +376,7 @@ public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter * {@link #isIncludePayload()} returns true. * @since 5.0.3 */ - @Nullable - protected String getMessagePayload(HttpServletRequest request) { + protected @Nullable String getMessagePayload(HttpServletRequest request) { ContentCachingRequestWrapper wrapper = WebUtils.getNativeRequest(request, ContentCachingRequestWrapper.class); if (wrapper != null) { diff --git a/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java b/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java index d217feaaf8..e710c44bdc 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/CharacterEncodingFilter.java @@ -22,8 +22,8 @@ import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -46,8 +46,7 @@ import org.springframework.util.Assert; */ public class CharacterEncodingFilter extends OncePerRequestFilter { - @Nullable - private String encoding; + private @Nullable String encoding; private boolean forceRequestEncoding = false; @@ -120,8 +119,7 @@ public class CharacterEncodingFilter extends OncePerRequestFilter { * Return the configured encoding for requests and/or responses. * @since 4.3 */ - @Nullable - public String getEncoding() { + public @Nullable String getEncoding() { return this.encoding; } 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 af17803cd1..609ad72999 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 @@ -25,9 +25,9 @@ import jakarta.servlet.FilterChain; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import org.jspecify.annotations.Nullable; 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; @@ -85,19 +85,15 @@ import org.springframework.web.context.support.WebApplicationContextUtils; */ public class DelegatingFilterProxy extends GenericFilterBean { - @Nullable - private String contextAttribute; + private @Nullable String contextAttribute; - @Nullable - private WebApplicationContext webApplicationContext; + private @Nullable WebApplicationContext webApplicationContext; - @Nullable - private String targetBeanName; + private @Nullable String targetBeanName; private boolean targetFilterLifecycle = false; - @Nullable - private volatile Filter delegate; + private volatile @Nullable Filter delegate; private final Lock delegateLock = new ReentrantLock(); @@ -182,8 +178,7 @@ public class DelegatingFilterProxy extends GenericFilterBean { * Return the name of the ServletContext attribute which should be used to retrieve the * {@link WebApplicationContext} from which to load the delegate {@link Filter} bean. */ - @Nullable - public String getContextAttribute() { + public @Nullable String getContextAttribute() { return this.contextAttribute; } @@ -200,8 +195,7 @@ public class DelegatingFilterProxy extends GenericFilterBean { /** * Return the name of the target bean in the Spring application context. */ - @Nullable - protected String getTargetBeanName() { + protected @Nullable String getTargetBeanName() { return this.targetBeanName; } @@ -303,8 +297,7 @@ public class DelegatingFilterProxy extends GenericFilterBean { * @see WebApplicationContextUtils#getWebApplicationContext(jakarta.servlet.ServletContext) * @see WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE */ - @Nullable - protected WebApplicationContext findWebApplicationContext() { + protected @Nullable WebApplicationContext findWebApplicationContext() { if (this.webApplicationContext != null) { // The user has injected a context at construction time -> use it... if (this.webApplicationContext instanceof ConfigurableApplicationContext cac && !cac.isActive()) { diff --git a/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java b/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java index bad214fb5d..d4905d12de 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/FormContentFilter.java @@ -34,13 +34,13 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequestWrapper; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpInputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.FormHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; 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.MultiValueMap; @@ -94,8 +94,7 @@ public class FormContentFilter extends OncePerRequestFilter { } } - @Nullable - private MultiValueMap parseIfNecessary(HttpServletRequest request) throws IOException { + private @Nullable MultiValueMap parseIfNecessary(HttpServletRequest request) throws IOException { if (!shouldParse(request)) { return null; } @@ -134,8 +133,7 @@ public class FormContentFilter extends OncePerRequestFilter { } @Override - @Nullable - public String getParameter(String name) { + public @Nullable String getParameter(String name) { String queryStringValue = super.getParameter(name); String formValue = this.formParams.getFirst(name); return (queryStringValue != null ? queryStringValue : formValue); @@ -161,8 +159,7 @@ public class FormContentFilter extends OncePerRequestFilter { } @Override - @Nullable - public String[] getParameterValues(String name) { + public @Nullable String[] getParameterValues(String name) { String[] parameterValues = super.getParameterValues(name); List formParam = this.formParams.get(name); if (formParam == null) { diff --git a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java index 0c2dc2a0f1..291232c6f2 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java @@ -34,12 +34,12 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.StringUtils; @@ -218,8 +218,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { // Override header accessors to not expose forwarded headers @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { if (FORWARDED_HEADER_NAMES.contains(name)) { return null; } @@ -246,18 +245,15 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { */ private static class ForwardedHeaderExtractingRequest extends ForwardedHeaderRemovingRequest { - @Nullable - private final String scheme; + private final @Nullable String scheme; private final boolean secure; - @Nullable - private final String host; + private final @Nullable String host; private final int port; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; private final ForwardedPrefixExtractor forwardedPrefixExtractor; @@ -285,14 +281,12 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { } @Override - @Nullable - public String getScheme() { + public @Nullable String getScheme() { return this.scheme; } @Override - @Nullable - public String getServerName() { + public @Nullable String getServerName() { return this.host; } @@ -322,14 +316,12 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { } @Override - @Nullable - public String getRemoteHost() { + public @Nullable String getRemoteHost() { return (this.remoteAddress != null ? this.remoteAddress.getHostString() : super.getRemoteHost()); } @Override - @Nullable - public String getRemoteAddr() { + public @Nullable String getRemoteAddr() { return (this.remoteAddress != null ? this.remoteAddress.getHostString() : super.getRemoteAddr()); } @@ -340,8 +332,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { @SuppressWarnings("DataFlowIssue") @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { if (name.equals(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE)) { return this.forwardedPrefixExtractor.getErrorRequestUri(); } @@ -363,11 +354,9 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { private String actualRequestUri; - @Nullable - private final String forwardedPrefix; + private final @Nullable String forwardedPrefix; - @Nullable - private String requestUri; + private @Nullable String requestUri; private String requestUrl; @@ -389,8 +378,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { this.requestUrl = initRequestUrl(); } - @Nullable - private static String initForwardedPrefix(HttpServletRequest request) { + private static @Nullable String initForwardedPrefix(HttpServletRequest request) { String result = null; Enumeration names = request.getHeaderNames(); while (names.hasMoreElements()) { @@ -414,8 +402,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { return null; } - @Nullable - private String initRequestUri() { + private @Nullable String initRequestUri() { if (this.forwardedPrefix != null) { return this.forwardedPrefix + UrlPathHelper.rawPathInstance.getPathWithinApplication(this.delegate.get()); @@ -455,8 +442,7 @@ public class ForwardedHeaderFilter extends OncePerRequestFilter { } } - @Nullable - public String getErrorRequestUri() { + public @Nullable String getErrorRequestUri() { HttpServletRequest request = this.delegate.get(); String requestUri = (String) request.getAttribute(WebUtils.ERROR_REQUEST_URI_ATTRIBUTE); if (this.forwardedPrefix == null || requestUri == null) { 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 6936a66c6b..df9dc0e794 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 @@ -26,6 +26,7 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeansException; @@ -42,7 +43,6 @@ 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; @@ -83,17 +83,13 @@ public abstract class GenericFilterBean implements Filter, BeanNameAware, Enviro /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private Environment environment; + private @Nullable Environment environment; - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; - @Nullable - private FilterConfig filterConfig; + private @Nullable FilterConfig filterConfig; private final Set requiredProperties = new HashSet<>(4); @@ -275,8 +271,7 @@ public abstract class GenericFilterBean implements Filter, BeanNameAware, Enviro * @return the FilterConfig instance, or {@code null} if none available * @see jakarta.servlet.GenericServlet#getServletConfig() */ - @Nullable - public FilterConfig getFilterConfig() { + public @Nullable FilterConfig getFilterConfig() { return this.filterConfig; } @@ -291,8 +286,7 @@ public abstract class GenericFilterBean implements Filter, BeanNameAware, Enviro * @see jakarta.servlet.FilterConfig#getFilterName() * @see #setBeanName */ - @Nullable - protected String getFilterName() { + protected @Nullable String getFilterName() { return (this.filterConfig != null ? this.filterConfig.getFilterName() : this.beanName); } diff --git a/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java index c28e761592..42310220d8 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java @@ -30,13 +30,13 @@ import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpStatus; import org.springframework.http.server.observation.DefaultServerRequestObservationConvention; import org.springframework.http.server.observation.ServerHttpObservationDocumentation; import org.springframework.http.server.observation.ServerRequestObservationContext; import org.springframework.http.server.observation.ServerRequestObservationConvention; -import org.springframework.lang.Nullable; /** @@ -160,13 +160,11 @@ public class ServerHttpObservationFilter extends OncePerRequestFilter { return observation; } - @Nullable - static Throwable unwrapServletException(Throwable ex) { + static @Nullable Throwable unwrapServletException(Throwable ex) { return (ex instanceof ServletException) ? ex.getCause() : ex; } - @Nullable - static Throwable fetchException(ServletRequest request) { + static @Nullable Throwable fetchException(ServletRequest request) { return (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); } diff --git a/spring-web/src/main/java/org/springframework/web/filter/UrlHandlerFilter.java b/spring-web/src/main/java/org/springframework/web/filter/UrlHandlerFilter.java index 9566a4faff..1fa8fa5e6a 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/UrlHandlerFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/UrlHandlerFilter.java @@ -29,12 +29,12 @@ import jakarta.servlet.http.HttpServletRequestWrapper; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -208,8 +208,7 @@ public final class UrlHandlerFilter extends OncePerRequestFilter { private final List pathPatterns; - @Nullable - private Consumer interceptor; + private @Nullable Consumer interceptor; private DefaultTrailingSlashSpec(String[] patterns) { this.pathPatterns = Arrays.stream(patterns) 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 d54e7e3d3f..93bf3413ed 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,9 +1,7 @@ /** * Provides generic filter base classes allowing for bean-style configuration. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.filter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/filter/reactive/UrlHandlerFilter.java b/spring-web/src/main/java/org/springframework/web/filter/reactive/UrlHandlerFilter.java index 479e9ce4d6..382cc5a603 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/reactive/UrlHandlerFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/reactive/UrlHandlerFilter.java @@ -24,6 +24,7 @@ import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -33,7 +34,6 @@ import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -183,8 +183,7 @@ public final class UrlHandlerFilter implements WebFilter { private final List pathPatterns; - @Nullable - private List>> interceptors; + private @Nullable List>> interceptors; private DefaultTrailingSlashSpec(String[] patterns) { this.pathPatterns = Arrays.stream(patterns) 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 23a7beb13a..cdcb71975d 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,9 +2,7 @@ * {@link org.springframework.web.server.WebFilter} implementations for use in * reactive web applications. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.filter.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 f80280f223..732d79e453 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 @@ -18,8 +18,7 @@ package org.springframework.web.jsf; import jakarta.faces.application.NavigationHandler; import jakarta.faces.context.FacesContext; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Base class for JSF NavigationHandler implementations that want @@ -39,8 +38,7 @@ import org.springframework.lang.Nullable; */ public abstract class DecoratingNavigationHandler extends NavigationHandler { - @Nullable - private NavigationHandler decoratedNavigationHandler; + private @Nullable NavigationHandler decoratedNavigationHandler; /** @@ -61,8 +59,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() { + public final @Nullable NavigationHandler getDecoratedNavigationHandler() { return this.decoratedNavigationHandler; } diff --git a/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java b/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java index 0e3bac26bd..bd7eb9b582 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/DelegatingNavigationHandlerProxy.java @@ -18,9 +18,9 @@ package org.springframework.web.jsf; import jakarta.faces.application.NavigationHandler; import jakarta.faces.context.FacesContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; -import org.springframework.lang.Nullable; import org.springframework.web.context.WebApplicationContext; /** @@ -79,8 +79,7 @@ public class DelegatingNavigationHandlerProxy extends NavigationHandler { */ public static final String DEFAULT_TARGET_BEAN_NAME = "jsfNavigationHandler"; - @Nullable - private NavigationHandler originalNavigationHandler; + private @Nullable NavigationHandler originalNavigationHandler; /** 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 69a7a7a59c..c0c6c1aeee 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 @@ -18,8 +18,8 @@ package org.springframework.web.jsf; import jakarta.faces.context.ExternalContext; import jakarta.faces.context.FacesContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.util.WebUtils; @@ -47,8 +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) { + public static @Nullable WebApplicationContext getWebApplicationContext(FacesContext fc) { Assert.notNull(fc, "FacesContext must not be null"); Object attr = fc.getExternalContext().getApplicationMap().get( WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); @@ -105,8 +104,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) { + public static @Nullable Object getSessionMutex(FacesContext fc) { Assert.notNull(fc, "FacesContext must not be null"); ExternalContext ec = fc.getExternalContext(); Object mutex = ec.getSessionMap().get(WebUtils.SESSION_MUTEX_ATTRIBUTE); diff --git a/spring-web/src/main/java/org/springframework/web/jsf/el/SpringBeanFacesELResolver.java b/spring-web/src/main/java/org/springframework/web/jsf/el/SpringBeanFacesELResolver.java index b28883313e..8f92b5f050 100644 --- a/spring-web/src/main/java/org/springframework/web/jsf/el/SpringBeanFacesELResolver.java +++ b/spring-web/src/main/java/org/springframework/web/jsf/el/SpringBeanFacesELResolver.java @@ -21,8 +21,8 @@ import jakarta.el.ELException; import jakarta.el.ELResolver; import jakarta.el.PropertyNotWritableException; import jakarta.faces.context.FacesContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.jsf.FacesContextUtils; @@ -69,8 +69,7 @@ import org.springframework.web.jsf.FacesContextUtils; public class SpringBeanFacesELResolver extends ELResolver { @Override - @Nullable - public Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException { + public @Nullable Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException { if (base == null) { String beanName = property.toString(); WebApplicationContext wac = getWebApplicationContext(elContext); @@ -83,8 +82,7 @@ public class SpringBeanFacesELResolver extends ELResolver { } @Override - @Nullable - public Class getType(ELContext elContext, @Nullable Object base, Object property) throws ELException { + public @Nullable Class getType(ELContext elContext, @Nullable Object base, Object property) throws ELException { if (base == null) { String beanName = property.toString(); WebApplicationContext wac = getWebApplicationContext(elContext); 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 165102f7e7..45bb32464c 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 @@ -22,9 +22,9 @@ import jakarta.el.ELResolver; import jakarta.faces.context.FacesContext; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; -import org.springframework.lang.Nullable; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.jsf.FacesContextUtils; @@ -64,8 +64,7 @@ public class WebApplicationContextFacesELResolver extends ELResolver { @Override - @Nullable - public Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException { + public @Nullable Object getValue(ELContext elContext, @Nullable Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext wac) { String beanName = property.toString(); @@ -101,8 +100,7 @@ public class WebApplicationContextFacesELResolver extends ELResolver { } @Override - @Nullable - public Class getType(ELContext elContext, @Nullable Object base, Object property) throws ELException { + public @Nullable Class getType(ELContext elContext, @Nullable Object base, Object property) throws ELException { if (base != null) { if (base instanceof WebApplicationContext wac) { String beanName = property.toString(); @@ -164,8 +162,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) { + protected @Nullable 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 2ce617b9ae..dcc9d25c1f 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,9 +2,7 @@ * ELResolvers for integrating a JSF web layer with a Spring service layer * which is hosted in a Spring root WebApplicationContext. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.jsf.el; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 53bfeb3e1a..4802b97320 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,9 +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 -@NonNullFields +@NullMarked package org.springframework.web.jsf; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java index a3b45aecbd..b3d5ec888b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java +++ b/spring-web/src/main/java/org/springframework/web/method/ControllerAdviceBean.java @@ -21,6 +21,8 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.scope.ScopedProxyUtils; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryUtils; @@ -34,7 +36,6 @@ import org.springframework.context.ConfigurableApplicationContext; import org.springframework.core.OrderComparator; import org.springframework.core.Ordered; import org.springframework.core.annotation.OrderUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -64,18 +65,15 @@ public class ControllerAdviceBean implements Ordered { * Reference to the resolved bean instance, potentially lazily retrieved * via the {@code BeanFactory}. */ - @Nullable - private Object resolvedBean; + private @Nullable Object resolvedBean; - @Nullable - private final Class beanType; + private final @Nullable Class beanType; private final HandlerTypePredicate beanTypePredicate; private final BeanFactory beanFactory; - @Nullable - private Integer order; + private @Nullable Integer order; /** @@ -174,8 +172,7 @@ public class ControllerAdviceBean implements Ordered { *

    If the bean type is a CGLIB-generated class, the original user-defined * class is returned. */ - @Nullable - public Class getBeanType() { + public @Nullable Class getBeanType() { return this.beanType; } @@ -257,8 +254,7 @@ public class ControllerAdviceBean implements Ordered { return adviceBeans; } - @Nullable - private static Class getBeanType(String beanName, BeanFactory beanFactory) { + private static @Nullable Class getBeanType(String beanName, BeanFactory beanFactory) { Class beanType = beanFactory.getType(beanName); return (beanType != null ? ClassUtils.getUserClass(beanType) : null); } 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 41a53a5e3a..1dde8abf20 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 @@ -31,6 +31,7 @@ import java.util.stream.IntStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.context.MessageSource; @@ -43,7 +44,6 @@ import org.springframework.core.annotation.MergedAnnotation; import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -75,11 +75,9 @@ public class HandlerMethod extends AnnotatedMethod { private final Object bean; - @Nullable - private final BeanFactory beanFactory; + private final @Nullable BeanFactory beanFactory; - @Nullable - private final MessageSource messageSource; + private final @Nullable MessageSource messageSource; private final Class beanType; @@ -87,14 +85,11 @@ public class HandlerMethod extends AnnotatedMethod { private final boolean validateReturnValue; - @Nullable - private HttpStatusCode responseStatus; + private @Nullable HttpStatusCode responseStatus; - @Nullable - private String responseStatusReason; + private @Nullable String responseStatusReason; - @Nullable - private HandlerMethod resolvedFromHandlerMethod; + private @Nullable HandlerMethod resolvedFromHandlerMethod; private final String description; @@ -283,8 +278,7 @@ public class HandlerMethod extends AnnotatedMethod { * @since 4.3.8 * @see ResponseStatus#code() */ - @Nullable - protected HttpStatusCode getResponseStatus() { + protected @Nullable HttpStatusCode getResponseStatus() { return this.responseStatus; } @@ -293,8 +287,7 @@ public class HandlerMethod extends AnnotatedMethod { * @since 4.3.8 * @see ResponseStatus#reason() */ - @Nullable - protected String getResponseStatusReason() { + protected @Nullable String getResponseStatusReason() { return this.responseStatusReason; } @@ -302,8 +295,7 @@ public class HandlerMethod extends AnnotatedMethod { * Return the HandlerMethod from which this HandlerMethod instance was * resolved via {@link #createWithResolvedBean()}. */ - @Nullable - public HandlerMethod getResolvedFromHandlerMethod() { + public @Nullable HandlerMethod getResolvedFromHandlerMethod() { return this.resolvedFromHandlerMethod; } diff --git a/spring-web/src/main/java/org/springframework/web/method/HandlerTypePredicate.java b/spring-web/src/main/java/org/springframework/web/method/HandlerTypePredicate.java index 427a886c62..a7f89457c9 100644 --- a/spring-web/src/main/java/org/springframework/web/method/HandlerTypePredicate.java +++ b/spring-web/src/main/java/org/springframework/web/method/HandlerTypePredicate.java @@ -25,8 +25,9 @@ import java.util.List; import java.util.Set; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; 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 d1f28393aa..ff9f48a986 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 @@ -16,9 +16,10 @@ package org.springframework.web.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.MissingRequestCookieException; import org.springframework.web.bind.ServletRequestBindingException; 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 145d108f0a..017a42c316 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 @@ -25,6 +25,7 @@ import jakarta.servlet.ServletException; import kotlin.reflect.KFunction; import kotlin.reflect.KParameter; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.ConversionNotSupportedException; @@ -34,7 +35,6 @@ import org.springframework.beans.factory.config.BeanExpressionResolver; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.KotlinDetector; 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; @@ -72,11 +72,9 @@ import org.springframework.web.method.support.ModelAndViewContainer; */ public abstract class AbstractNamedValueMethodArgumentResolver implements HandlerMethodArgumentResolver { - @Nullable - private final ConfigurableBeanFactory configurableBeanFactory; + private final @Nullable ConfigurableBeanFactory configurableBeanFactory; - @Nullable - private final BeanExpressionContext expressionContext; + private final @Nullable BeanExpressionContext expressionContext; private final Map namedValueInfoCache = new ConcurrentHashMap<>(256); @@ -100,8 +98,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle @Override - @Nullable - public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public final @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { NamedValueInfo namedValueInfo = getNamedValueInfo(parameter); @@ -194,8 +191,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle * Resolve the given annotation-specified value, * potentially containing placeholders and expressions. */ - @Nullable - private Object resolveEmbeddedValuesAndExpressions(String value) { + private @Nullable Object resolveEmbeddedValuesAndExpressions(String value) { if (this.configurableBeanFactory == null || this.expressionContext == null) { return value; } @@ -216,8 +212,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) + protected abstract @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception; /** @@ -261,8 +256,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. */ - @Nullable - private Object handleNullValue(String name, @Nullable Object value, Class paramType) { + private @Nullable Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (paramType == boolean.class) { return Boolean.FALSE; @@ -276,8 +270,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle return value; } - @Nullable - private static Object convertIfNecessary( + private static @Nullable Object convertIfNecessary( MethodParameter parameter, NativeWebRequest webRequest, WebDataBinderFactory binderFactory, NamedValueInfo namedValueInfo, @Nullable Object arg) throws Exception { @@ -325,8 +318,7 @@ public abstract class AbstractNamedValueMethodArgumentResolver implements Handle private final boolean required; - @Nullable - private final String defaultValue; + private final @Nullable String defaultValue; public NamedValueInfo(String name, boolean required, @Nullable String defaultValue) { this.name = name; 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 0d0272a373..5c8961ff5c 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 @@ -18,9 +18,9 @@ package org.springframework.web.method.annotation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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; @@ -94,8 +94,7 @@ public abstract class AbstractWebArgumentResolverAdapter implements HandlerMetho * to the method parameter. */ @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Class paramType = parameter.getParameterType(); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java index 2e727c7975..0399b22df0 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ErrorsMethodArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -49,8 +50,7 @@ public class ErrorsMethodArgumentResolver implements HandlerMethodArgumentResolv } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { 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 80d6d70bdc..0ea6217e08 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 @@ -26,12 +26,13 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ExceptionDepthComparator; import org.springframework.core.MethodIntrospector; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ConcurrentLruCache; import org.springframework.util.MimeType; @@ -160,8 +161,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) { + public @Nullable Method resolveMethod(Exception exception) { ExceptionHandlerMappingInfo mappingInfo = resolveExceptionMapping(exception, MediaType.ALL); return (mappingInfo != null) ? mappingInfo.getHandlerMethod() : null; } @@ -173,8 +173,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) { + public @Nullable Method resolveMethodByThrowable(Throwable exception) { ExceptionHandlerMappingInfo mappingInfo = resolveExceptionMapping(exception, MediaType.ALL); return (mappingInfo != null) ? mappingInfo.getHandlerMethod() : null; } @@ -188,8 +187,7 @@ public class ExceptionHandlerMethodResolver { * @return a Method to handle the exception, or {@code null} if none found * @since 6.2 */ - @Nullable - public ExceptionHandlerMappingInfo resolveExceptionMapping(Throwable exception, MediaType mediaType) { + public @Nullable ExceptionHandlerMappingInfo resolveExceptionMapping(Throwable exception, MediaType mediaType) { ExceptionHandlerMappingInfo mappingInfo = resolveExceptionMappingByExceptionType(exception.getClass(), mediaType); if (mappingInfo == null) { Throwable cause = exception.getCause(); @@ -207,8 +205,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) { + public @Nullable Method resolveMethodByExceptionType(Class exceptionType) { ExceptionHandlerMappingInfo mappingInfo = resolveExceptionMappingByExceptionType(exceptionType, MediaType.ALL); return (mappingInfo != null) ? mappingInfo.getHandlerMethod() : null; } @@ -220,8 +217,7 @@ public class ExceptionHandlerMethodResolver { * @param mediaType the media type requested by the HTTP client * @return a Method to handle the exception, or {@code null} if none found */ - @Nullable - public ExceptionHandlerMappingInfo resolveExceptionMappingByExceptionType(Class exceptionType, MediaType mediaType) { + public @Nullable ExceptionHandlerMappingInfo resolveExceptionMappingByExceptionType(Class exceptionType, MediaType mediaType) { ExceptionHandlerMappingInfo mappingInfo = this.lookupCache.get(new ExceptionMapping(exceptionType, mediaType)); return (mappingInfo != NO_MATCHING_EXCEPTION_HANDLER ? mappingInfo : null); } @@ -230,8 +226,7 @@ public class ExceptionHandlerMethodResolver { * Return the {@link Method} mapped to the given exception type, or * {@link #NO_MATCHING_EXCEPTION_HANDLER} if none. */ - @Nullable - private ExceptionHandlerMappingInfo getMappedMethod(Class exceptionType, MediaType mediaType) { + private @Nullable ExceptionHandlerMappingInfo getMappedMethod(Class exceptionType, MediaType mediaType) { List matches = new ArrayList<>(); for (ExceptionMapping mappingInfo : this.mappedMethods.keySet()) { if (mappingInfo.exceptionType().isAssignableFrom(exceptionType) && mappingInfo.mediaType().isCompatibleWith(mediaType)) { 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 70f2a06e61..3c3a120861 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 @@ -17,11 +17,11 @@ package org.springframework.web.method.annotation; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; 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.util.Assert; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.context.request.NativeWebRequest; @@ -65,8 +65,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueMet } @Override - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception { + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest webRequest) throws Exception { // No name to resolve return null; } diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidationException.java b/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidationException.java index 019576c4d1..ea7c335083 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidationException.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidationException.java @@ -21,11 +21,12 @@ import java.util.List; import java.util.Locale; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.validation.method.MethodValidationResult; import org.springframework.validation.method.ParameterErrors; diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidator.java b/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidator.java index e854fcab75..bd85cb07f9 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidator.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/HandlerMethodValidator.java @@ -20,11 +20,11 @@ import java.lang.reflect.Method; import java.util.function.Predicate; import jakarta.validation.Validator; +import org.jspecify.annotations.Nullable; import org.springframework.core.Conventions; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.lang.Nullable; import org.springframework.validation.BindingResult; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.SmartValidator; @@ -77,7 +77,7 @@ public final class HandlerMethodValidator implements MethodValidator { @Override public void applyArgumentValidation( - Object target, Method method, @Nullable MethodParameter[] parameters, + Object target, Method method, MethodParameter @Nullable [] parameters, Object[] arguments, Class[] groups) { MethodValidationResult result = validateArguments(target, method, parameters, arguments, groups); @@ -109,7 +109,7 @@ public final class HandlerMethodValidator implements MethodValidator { @Override public MethodValidationResult validateArguments( - Object target, Method method, @Nullable MethodParameter[] parameters, + Object target, Method method, MethodParameter @Nullable [] parameters, Object[] arguments, Class[] groups) { return this.validationAdapter.validateArguments(target, method, parameters, arguments, groups); @@ -139,8 +139,7 @@ public final class HandlerMethodValidator implements MethodValidator { * Validation is enabled for use via {@link ConfigurableWebBindingInitializer}, * for example in Spring MVC or WebFlux config. */ - @Nullable - public static MethodValidator from( + public static @Nullable MethodValidator from( @Nullable WebBindingInitializer initializer, @Nullable ParameterNameDiscoverer paramNameDiscoverer, Predicate modelAttributePredicate, Predicate requestParamPredicate) { @@ -162,8 +161,7 @@ public final class HandlerMethodValidator implements MethodValidator { return null; } - @Nullable - private static Validator getValidator(ConfigurableWebBindingInitializer initializer) { + private static @Nullable Validator getValidator(ConfigurableWebBindingInitializer initializer) { if (initializer.getValidator() instanceof Validator validator) { return validator; } 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 d8446a353a..60f5a01030 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 @@ -19,7 +19,8 @@ package org.springframework.web.method.annotation; import java.util.Collections; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.WebDataBinder; diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java index 8f8cb85489..2f7f803113 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MapMethodProcessor.java @@ -18,8 +18,9 @@ package org.springframework.web.method.annotation; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.web.bind.support.WebDataBinderFactory; @@ -50,8 +51,7 @@ public class MapMethodProcessor implements HandlerMethodArgumentResolver, Handle } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Assert.state(mavContainer != null, "ModelAndViewContainer is required for model exposure"); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java index 3043f33643..6a0b79ff3b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentConversionNotSupportedException.java @@ -16,9 +16,10 @@ package org.springframework.web.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.ConversionNotSupportedException; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * A ConversionNotSupportedException raised while resolving a method argument. diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java index 9f83ce09b3..b9c883c51b 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/MethodArgumentTypeMismatchException.java @@ -16,9 +16,10 @@ package org.springframework.web.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.TypeMismatchException; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * A TypeMismatchException raised while resolving a controller method argument. diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java index e8e89c3027..14814abe7f 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessor.java @@ -22,11 +22,11 @@ import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.validation.BindException; @@ -103,8 +103,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol * @throws Exception if WebDataBinder initialization fails */ @Override - @Nullable - public final Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public final @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Assert.state(mavContainer != null, "ModelAttributeMethodProcessor requires ModelAndViewContainer"); @@ -172,8 +171,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol return attribute; } - @Nullable - private static Object wrapAsOptionalIfNecessary(MethodParameter parameter, @Nullable Object target) { + private static @Nullable Object wrapAsOptionalIfNecessary(MethodParameter parameter, @Nullable Object target) { return (parameter.getParameterType() == Optional.class ? Optional.ofNullable(target) : target); } @@ -190,8 +188,7 @@ public class ModelAttributeMethodProcessor implements HandlerMethodArgumentResol * @param request the current request * @return the created model attribute, or {@code null} */ - @Nullable - protected Object createAttribute(String attributeName, MethodParameter parameter, + protected @Nullable Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { return null; diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java index d2dbe96836..ec5e2304ad 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelFactory.java @@ -26,12 +26,12 @@ import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.core.Conventions; import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java index a68931b7cb..930d52e2f2 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/ModelMethodProcessor.java @@ -16,8 +16,9 @@ package org.springframework.web.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.util.Assert; import org.springframework.web.bind.support.WebDataBinderFactory; @@ -45,8 +46,7 @@ public class ModelMethodProcessor implements HandlerMethodArgumentResolver, Hand } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Assert.state(mavContainer != null, "ModelAndViewContainer is required for model exposure"); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java index 558d2ea06e..33ec1e7398 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestHeaderMapMethodArgumentResolver.java @@ -20,9 +20,10 @@ import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestHeader; 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 bfc79c787b..45e9129ecd 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 @@ -18,9 +18,10 @@ package org.springframework.web.method.annotation; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.MissingRequestHeaderException; import org.springframework.web.bind.ServletRequestBindingException; @@ -71,8 +72,7 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueMetho } @Override - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { String[] headerValues = request.getHeaderValues(name); if (headerValues != null) { return (headerValues.length == 1 ? headerValues[0] : headerValues); diff --git a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java index 7c71280f4f..2a8990faa8 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/RequestParamMapMethodArgumentResolver.java @@ -22,10 +22,10 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; 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 921f7f656f..83f43a4c78 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 @@ -24,6 +24,7 @@ import java.util.Optional; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -31,7 +32,6 @@ 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.Assert; import org.springframework.util.StringUtils; import org.springframework.web.bind.MissingServletRequestParameterException; @@ -158,8 +158,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } @Override - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); if (servletRequest != null) { @@ -258,8 +257,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueMethod } } - @Nullable - protected String formatUriValue( + protected @Nullable String formatUriValue( @Nullable ConversionService cs, @Nullable TypeDescriptor sourceType, @Nullable Object value) { if (value == null) { 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 b9071f4484..5595c8870f 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 @@ -24,8 +24,9 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.SessionAttributes; @@ -183,8 +184,7 @@ public class SessionAttributesHandler { * @param attributeName the name of the attribute of interest * @return the attribute value, or {@code null} if none */ - @Nullable - Object retrieveAttribute(WebRequest request, String attributeName) { + @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/SessionStatusMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.java index 5676fa24be..9d577417d0 100644 --- a/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/method/annotation/SessionStatusMethodArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.support.SessionStatus; import org.springframework.web.bind.support.WebDataBinderFactory; 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 0a15dd473f..db2d623918 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,9 +1,7 @@ /** * Support classes for annotation-based handler method processing. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.method.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 772e1ec8a0..23bd6e2bf8 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,9 +2,7 @@ * Common infrastructure for handler method processing, as used by * Spring MVC's {@code org.springframework.web.servlet.mvc.method} package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.method; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/method/support/AsyncHandlerMethodReturnValueHandler.java b/spring-web/src/main/java/org/springframework/web/method/support/AsyncHandlerMethodReturnValueHandler.java index c43de97316..eceea514ed 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/AsyncHandlerMethodReturnValueHandler.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/AsyncHandlerMethodReturnValueHandler.java @@ -16,8 +16,9 @@ package org.springframework.web.method.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; /** * A return value handler that supports async types. Such return value types 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 2e2ffaf8fb..796ffdb8fa 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 @@ -23,10 +23,11 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.web.util.UriComponentsBuilder; /** 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 72b1972e1c..00e6dff711 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 @@ -16,8 +16,9 @@ package org.springframework.web.method.support; +import org.jspecify.annotations.Nullable; + 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; @@ -56,8 +57,7 @@ public interface HandlerMethodArgumentResolver { * @return the resolved argument value, or {@code null} if not resolvable * @throws Exception in case of errors with the preparation of argument values */ - @Nullable - Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception; } diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java index 4ca80dd52c..1edee89c3d 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodArgumentResolverComposite.java @@ -22,8 +22,9 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; @@ -110,8 +111,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu * @throws IllegalArgumentException if no suitable argument resolver is found */ @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { HandlerMethodArgumentResolver resolver = getArgumentResolver(parameter); @@ -126,8 +126,7 @@ public class HandlerMethodArgumentResolverComposite implements HandlerMethodArgu * Find a registered {@link HandlerMethodArgumentResolver} that supports * the given method parameter. */ - @Nullable - public HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { + public @Nullable HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter); if (result == null) { for (HandlerMethodArgumentResolver resolver : this.argumentResolvers) { diff --git a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java index 2133effcb3..6ad0a02a28 100644 --- a/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java +++ b/spring-web/src/main/java/org/springframework/web/method/support/HandlerMethodReturnValueHandler.java @@ -16,8 +16,9 @@ package org.springframework.web.method.support; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** 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 c00b7923e0..ce90637945 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 @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; /** @@ -53,8 +54,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe return getReturnValueHandler(returnType) != null; } - @Nullable - private HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { + private @Nullable HandlerMethodReturnValueHandler getReturnValueHandler(MethodParameter returnType) { for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { if (handler.supportsReturnType(returnType)) { return handler; @@ -78,8 +78,7 @@ public class HandlerMethodReturnValueHandlerComposite implements HandlerMethodRe handler.handleReturnValue(returnValue, returnType, mavContainer, webRequest); } - @Nullable - private HandlerMethodReturnValueHandler selectHandler(@Nullable Object value, MethodParameter returnType) { + private @Nullable HandlerMethodReturnValueHandler selectHandler(@Nullable Object value, MethodParameter returnType) { boolean isAsyncValue = isAsyncReturnValue(value, returnType); for (HandlerMethodReturnValueHandler handler : this.returnValueHandlers) { if (isAsyncValue && !(handler instanceof AsyncHandlerMethodReturnValueHandler)) { 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 6f14f487ae..d49a6ae66b 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 @@ -30,6 +30,7 @@ import kotlin.reflect.KType; import kotlin.reflect.full.KClasses; import kotlin.reflect.jvm.KCallablesJvm; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.publisher.SynchronousSink; @@ -39,7 +40,6 @@ import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.KotlinDetector; import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.validation.method.MethodValidator; @@ -70,11 +70,9 @@ public class InvocableHandlerMethod extends HandlerMethod { private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); - @Nullable - private WebDataBinderFactory dataBinderFactory; + private @Nullable WebDataBinderFactory dataBinderFactory; - @Nullable - private MethodValidator methodValidator; + private @Nullable MethodValidator methodValidator; private Class[] validationGroups = EMPTY_GROUPS; @@ -173,8 +171,7 @@ public class InvocableHandlerMethod extends HandlerMethod { * @see #getMethodArgumentValues * @see #doInvoke */ - @Nullable - public Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object invokeForRequest(NativeWebRequest request, @Nullable ModelAndViewContainer mavContainer, Object... providedArgs) throws Exception { Object[] args = getMethodArgumentValues(request, mavContainer, providedArgs); @@ -242,8 +239,7 @@ public class InvocableHandlerMethod extends HandlerMethod { /** * Invoke the handler method with the given argument values. */ - @Nullable - protected Object doInvoke(Object... args) throws Exception { + protected @Nullable Object doInvoke(Object... args) throws Exception { Method method = getBridgedMethod(); try { if (KotlinDetector.isKotlinReflectPresent()) { @@ -300,9 +296,8 @@ public class InvocableHandlerMethod extends HandlerMethod { */ private static class KotlinDelegate { - @Nullable @SuppressWarnings("DataFlowIssue") - public static Object invokeFunction(Method method, Object target, Object[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { + public static @Nullable Object invokeFunction(Method method, Object target, Object[] args) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { KFunction function = ReflectJvmMapping.getKotlinFunction(method); // For property accessors if (function == 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 7f2db8d3dc..bf07e9c9a0 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 @@ -20,8 +20,9 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.validation.support.BindingAwareModelMap; @@ -51,18 +52,15 @@ public class ModelAndViewContainer { private boolean ignoreDefaultModelOnRedirect = true; - @Nullable - private Object view; + private @Nullable Object view; private final ModelMap defaultModel = new BindingAwareModelMap(); - @Nullable - private ModelMap redirectModel; + private @Nullable ModelMap redirectModel; private boolean redirectModelScenario = false; - @Nullable - private HttpStatusCode status; + private @Nullable HttpStatusCode status; private final Set noBinding = new HashSet<>(4); @@ -104,8 +102,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() { + public @Nullable String getViewName() { return (this.view instanceof String viewName ? viewName : null); } @@ -121,8 +118,7 @@ public class ModelAndViewContainer { * 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 Object getView() { + public @Nullable Object getView() { return this.view; } @@ -204,8 +200,7 @@ public class ModelAndViewContainer { * Return the configured HTTP status, if any. * @since 4.3 */ - @Nullable - public HttpStatusCode getStatus() { + public @Nullable HttpStatusCode 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 4d4de4a057..6ce1127baa 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,9 +1,7 @@ /** * Generic support classes for handler method processing. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.method.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MaxUploadSizeExceededException.java b/spring-web/src/main/java/org/springframework/web/multipart/MaxUploadSizeExceededException.java index 5ccdf47278..7fc0572229 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MaxUploadSizeExceededException.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MaxUploadSizeExceededException.java @@ -16,10 +16,11 @@ package org.springframework.web.multipart; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.web.ErrorResponse; /** diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartException.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartException.java index 401cd572bd..b7e10e3ef4 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartException.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartException.java @@ -16,8 +16,9 @@ package org.springframework.web.multipart; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Exception thrown when multipart resolution fails. 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 34ad8274c2..e184f0b747 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 @@ -22,9 +22,10 @@ import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.InputStreamSource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; /** @@ -64,16 +65,14 @@ public interface MultipartFile extends InputStreamSource { * @see RFC 7578, Section 4.2 * @see Unrestricted File Upload */ - @Nullable - String getOriginalFilename(); + @Nullable String getOriginalFilename(); /** * Return the content type of the file. * @return the content type, or {@code null} if not defined * (or no file has been chosen in the multipart form) */ - @Nullable - String getContentType(); + @Nullable String getContentType(); /** * Return whether the uploaded file is empty, that is, either no file has diff --git a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java index d710062e06..13a7afff03 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/MultipartFileResource.java @@ -19,8 +19,9 @@ package org.springframework.web.multipart; import java.io.IOException; import java.io.InputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.AbstractResource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -65,8 +66,7 @@ class MultipartFileResource extends AbstractResource { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.multipartFile.getOriginalFilename(); } 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 7d2237d859..485d86e4ad 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 @@ -17,10 +17,10 @@ package org.springframework.web.multipart; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; 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 @@ -65,7 +65,6 @@ public interface MultipartHttpServletRequest extends HttpServletRequest, Multipa * then all headers are returned. Otherwise, for example, for a file upload, the * returned headers may expose a 'Content-Type' if available. */ - @Nullable - HttpHeaders getMultipartHeaders(String paramOrFileName); + @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 f5339b4716..8c1002f595 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,7 +20,8 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.MultiValueMap; /** @@ -48,8 +49,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); + @Nullable MultipartFile getFile(String name); /** * Return the contents plus description of uploaded files in this request, @@ -81,7 +81,6 @@ public interface MultipartRequest { * @return the associated content type, or {@code null} if not defined * @since 3.1 */ - @Nullable - String getMultipartContentType(String paramOrFileName); + @Nullable String getMultipartContentType(String paramOrFileName); } 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 8620295ce9..530a984363 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,9 +4,7 @@ * and a generic extension of the HttpServletRequest interface * for accessing multipart files in web application code. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.multipart; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/AbstractMultipartHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/AbstractMultipartHttpServletRequest.java index 1299f15c7f..64fdf9ee2f 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/AbstractMultipartHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/AbstractMultipartHttpServletRequest.java @@ -24,10 +24,10 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequestWrapper; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.multipart.MultipartFile; @@ -44,8 +44,7 @@ import org.springframework.web.multipart.MultipartHttpServletRequest; public abstract class AbstractMultipartHttpServletRequest extends HttpServletRequestWrapper implements MultipartHttpServletRequest { - @Nullable - private MultiValueMap multipartFiles; + private @Nullable MultiValueMap multipartFiles; /** @@ -84,8 +83,7 @@ public abstract class AbstractMultipartHttpServletRequest extends HttpServletReq } @Override - @Nullable - public MultipartFile getFile(String name) { + public @Nullable MultipartFile getFile(String name) { return getMultipartFiles().getFirst(name); } diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditor.java b/spring-web/src/main/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditor.java index 71068c2960..ad3a7fb6d8 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditor.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/ByteArrayMultipartFileEditor.java @@ -18,8 +18,9 @@ package org.springframework.web.multipart.support; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.propertyeditors.ByteArrayPropertyEditor; -import org.springframework.lang.Nullable; import org.springframework.web.multipart.MultipartFile; /** diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java index 609837234b..3789a96d19 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/DefaultMultipartHttpServletRequest.java @@ -24,9 +24,9 @@ import java.util.Map; import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.multipart.MultipartFile; @@ -45,11 +45,9 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer private static final String CONTENT_TYPE = "Content-Type"; - @Nullable - private Map multipartParameters; + private @Nullable Map multipartParameters; - @Nullable - private Map multipartParameterContentTypes; + private @Nullable Map multipartParameterContentTypes; /** @@ -78,8 +76,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer @Override - @Nullable - public String getParameter(String name) { + public @Nullable String getParameter(String name) { String[] values = getMultipartParameters().get(name); if (values != null) { return (values.length > 0 ? values[0] : null); @@ -130,8 +127,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer } @Override - @Nullable - public String getMultipartContentType(String paramOrFileName) { + public @Nullable String getMultipartContentType(String paramOrFileName) { MultipartFile file = getFile(paramOrFileName); if (file != null) { return file.getContentType(); @@ -142,8 +138,7 @@ public class DefaultMultipartHttpServletRequest extends AbstractMultipartHttpSer } @Override - @Nullable - public HttpHeaders getMultipartHeaders(String paramOrFileName) { + public @Nullable HttpHeaders getMultipartHeaders(String paramOrFileName) { String contentType = getMultipartContentType(paramOrFileName); if (contentType != null) { HttpHeaders headers = new HttpHeaders(); 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 a519cd25b2..6b14989678 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 @@ -23,10 +23,10 @@ import java.util.Locale; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -52,8 +52,7 @@ public final class MultipartResolutionDelegate { } - @Nullable - public static MultipartRequest resolveMultipartRequest(NativeWebRequest webRequest) { + public static @Nullable MultipartRequest resolveMultipartRequest(NativeWebRequest webRequest) { MultipartRequest multipartRequest = webRequest.getNativeRequest(MultipartRequest.class); if (multipartRequest != null) { return multipartRequest; @@ -91,8 +90,7 @@ public final class MultipartResolutionDelegate { (Part.class == paramType || isPartCollection(parameter) || isPartArray(parameter))); } - @Nullable - public static Object resolveMultipartArgument(String name, MethodParameter parameter, HttpServletRequest request) + public static @Nullable Object resolveMultipartArgument(String name, MethodParameter parameter, HttpServletRequest request) throws Exception { MultipartHttpServletRequest multipartRequest = @@ -169,8 +167,7 @@ public final class MultipartResolutionDelegate { return (Part.class == methodParam.getNestedParameterType().componentType()); } - @Nullable - private static Class getCollectionParameterType(MethodParameter methodParam) { + private static @Nullable Class getCollectionParameterType(MethodParameter methodParam) { Class paramType = methodParam.getNestedParameterType(); if (Collection.class == paramType || List.class.isAssignableFrom(paramType)){ Class valueType = ResolvableType.forMethodParameter(methodParam).asCollection().resolveGeneric(); diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java b/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java index 424ea4e1d6..4082d59b2a 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/RequestPartServletServerHttpRequest.java @@ -23,12 +23,12 @@ import java.nio.charset.Charset; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.web.multipart.MultipartException; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; @@ -113,8 +113,7 @@ public class RequestPartServletServerHttpRequest extends ServletServerHttpReques throw new IllegalStateException("No body available for request part '" + this.requestPartName + "'"); } - @Nullable - private Part retrieveServletPart() { + private @Nullable Part retrieveServletPart() { try { return this.multipartRequest.getPart(this.requestPartName); } 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 d2810985c2..7b7a21f5cc 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 @@ -34,10 +34,10 @@ import java.util.Set; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.FileCopyUtils; import org.springframework.util.LinkedMultiValueMap; @@ -58,8 +58,7 @@ import org.springframework.web.multipart.MultipartFile; */ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpServletRequest { - @Nullable - private Set multipartParameterNames; + private @Nullable Set multipartParameterNames; /** @@ -181,8 +180,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe } @Override - @Nullable - public String getMultipartContentType(String paramOrFileName) { + public @Nullable String getMultipartContentType(String paramOrFileName) { try { Part part = getPart(paramOrFileName); return (part != null ? part.getContentType() : null); @@ -193,8 +191,7 @@ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpSe } @Override - @Nullable - public HttpHeaders getMultipartHeaders(String paramOrFileName) { + public @Nullable HttpHeaders getMultipartHeaders(String paramOrFileName) { try { Part part = getPart(paramOrFileName); if (part != null) { diff --git a/spring-web/src/main/java/org/springframework/web/multipart/support/StringMultipartFileEditor.java b/spring-web/src/main/java/org/springframework/web/multipart/support/StringMultipartFileEditor.java index 32bb903a97..1b73bf5126 100644 --- a/spring-web/src/main/java/org/springframework/web/multipart/support/StringMultipartFileEditor.java +++ b/spring-web/src/main/java/org/springframework/web/multipart/support/StringMultipartFileEditor.java @@ -19,7 +19,8 @@ package org.springframework.web.multipart.support; import java.beans.PropertyEditorSupport; import java.io.IOException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.multipart.MultipartFile; /** @@ -33,8 +34,7 @@ import org.springframework.web.multipart.MultipartFile; */ public class StringMultipartFileEditor extends PropertyEditorSupport { - @Nullable - private final String charsetName; + private final @Nullable String charsetName; /** 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 776fdfcf0b..1a9a7a2b77 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,9 +3,7 @@ * Contains property editors for multipart files, and a Servlet filter * for multipart handling without Spring's Web MVC. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.multipart.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 dd944f1f0a..d5ad58301c 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,9 +2,7 @@ * Common, generic interfaces that define minimal boundary points * between Spring's web infrastructure and other framework modules. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/server/DefaultServerWebExchangeBuilder.java b/spring-web/src/main/java/org/springframework/web/server/DefaultServerWebExchangeBuilder.java index 69fd787779..8f7962ddc2 100644 --- a/spring-web/src/main/java/org/springframework/web/server/DefaultServerWebExchangeBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/server/DefaultServerWebExchangeBuilder.java @@ -19,11 +19,11 @@ package org.springframework.web.server; import java.security.Principal; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; 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.util.Assert; /** @@ -36,14 +36,11 @@ class DefaultServerWebExchangeBuilder implements ServerWebExchange.Builder { private final ServerWebExchange delegate; - @Nullable - private ServerHttpRequest request; + private @Nullable ServerHttpRequest request; - @Nullable - private ServerHttpResponse response; + private @Nullable ServerHttpResponse response; - @Nullable - private Mono principalMono; + private @Nullable Mono principalMono; DefaultServerWebExchangeBuilder(ServerWebExchange delegate) { @@ -89,14 +86,11 @@ class DefaultServerWebExchangeBuilder implements ServerWebExchange.Builder { */ private static class MutativeDecorator extends ServerWebExchangeDecorator { - @Nullable - private final ServerHttpRequest request; + private final @Nullable ServerHttpRequest request; - @Nullable - private final ServerHttpResponse response; + private final @Nullable ServerHttpResponse response; - @Nullable - private final Mono principalMono; + private final @Nullable Mono principalMono; public MutativeDecorator(ServerWebExchange delegate, @Nullable ServerHttpRequest request, @Nullable ServerHttpResponse response, @Nullable Mono principalMono) { diff --git a/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java b/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java index ca89460488..88e2d65e90 100644 --- a/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java +++ b/spring-web/src/main/java/org/springframework/web/server/MethodNotAllowedException.java @@ -21,10 +21,11 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; diff --git a/spring-web/src/main/java/org/springframework/web/server/PayloadTooLargeException.java b/spring-web/src/main/java/org/springframework/web/server/PayloadTooLargeException.java index 5dc9cf4127..a4bdf0ba95 100644 --- a/spring-web/src/main/java/org/springframework/web/server/PayloadTooLargeException.java +++ b/spring-web/src/main/java/org/springframework/web/server/PayloadTooLargeException.java @@ -17,8 +17,9 @@ package org.springframework.web.server; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; /** * Exception for errors that fit response status 413 (payload too large) for use in 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 23abc0fd39..c2be31ec44 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 @@ -18,11 +18,12 @@ package org.springframework.web.server; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.web.ErrorResponseException; /** @@ -37,8 +38,7 @@ import org.springframework.web.ErrorResponseException; @SuppressWarnings("serial") public class ResponseStatusException extends ErrorResponseException { - @Nullable - private final String reason; + private final @Nullable String reason; /** @@ -92,7 +92,7 @@ public class ResponseStatusException extends ErrorResponseException { */ protected ResponseStatusException( HttpStatusCode status, @Nullable String reason, @Nullable Throwable cause, - @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { super(status, ProblemDetail.forStatus(status), cause, messageDetailCode, messageDetailArguments); this.reason = reason; @@ -103,8 +103,7 @@ public class ResponseStatusException extends ErrorResponseException { /** * The reason explaining the exception (potentially {@code null} or empty). */ - @Nullable - public String getReason() { + public @Nullable 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 e079e0f2b9..e4713672c5 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,9 +18,10 @@ package org.springframework.web.server; import java.lang.reflect.Method; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; /** * Exception for an {@link HttpStatus#INTERNAL_SERVER_ERROR} that exposes extra @@ -33,11 +34,9 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ServerErrorException extends ResponseStatusException { - @Nullable - private final Method handlerMethod; + private final @Nullable Method handlerMethod; - @Nullable - private final MethodParameter parameter; + private final @Nullable MethodParameter parameter; /** @@ -74,16 +73,14 @@ public class ServerErrorException extends ResponseStatusException { * Return the handler method associated with the error, if any. * @since 5.0.5 */ - @Nullable - public Method getHandlerMethod() { + public @Nullable Method getHandlerMethod() { return this.handlerMethod; } /** * Return the specific method parameter associated with the error, if any. */ - @Nullable - public MethodParameter getMethodParameter() { + public @Nullable MethodParameter getMethodParameter() { return this.parameter; } diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java index da7a3bfb52..7515f57b7d 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchange.java @@ -22,6 +22,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; @@ -29,7 +30,6 @@ import org.springframework.context.i18n.LocaleContext; import org.springframework.http.codec.multipart.Part; 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.util.MultiValueMap; @@ -75,8 +75,7 @@ public interface ServerWebExchange { * @return the attribute value */ @SuppressWarnings("unchecked") - @Nullable - default T getAttribute(String name) { + default @Nullable T getAttribute(String name) { return (T) getAttributes().get(name); } @@ -168,8 +167,7 @@ public interface ServerWebExchange { * @since 5.0.3 * @see org.springframework.web.server.adapter.WebHttpHandlerBuilder#applicationContext(ApplicationContext) */ - @Nullable - ApplicationContext getApplicationContext(); + @Nullable ApplicationContext getApplicationContext(); /** * Returns {@code true} if the one of the {@code checkNotModified} methods diff --git a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java index b69c18599a..09b62204de 100644 --- a/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java +++ b/spring-web/src/main/java/org/springframework/web/server/ServerWebExchangeDecorator.java @@ -21,6 +21,7 @@ import java.time.Instant; import java.util.Map; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.context.ApplicationContext; @@ -28,7 +29,6 @@ import org.springframework.context.i18n.LocaleContext; import org.springframework.http.codec.multipart.Part; 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.util.MultiValueMap; @@ -94,8 +94,7 @@ public class ServerWebExchangeDecorator implements ServerWebExchange { } @Override - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return getDelegate().getApplicationContext(); } 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 e0ba0ea243..6e9c18a99e 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 @@ -16,9 +16,10 @@ package org.springframework.web.server; +import org.jspecify.annotations.Nullable; + 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 @@ -31,8 +32,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ServerWebInputException extends ResponseStatusException { - @Nullable - private final MethodParameter parameter; + private final @Nullable MethodParameter parameter; /** @@ -62,7 +62,7 @@ public class ServerWebInputException extends ResponseStatusException { * @since 6.0 */ protected ServerWebInputException(String reason, @Nullable MethodParameter parameter, @Nullable Throwable cause, - @Nullable String messageDetailCode, @Nullable Object[] messageDetailArguments) { + @Nullable String messageDetailCode, Object @Nullable [] messageDetailArguments) { super(HttpStatus.BAD_REQUEST, reason, cause, messageDetailCode, messageDetailArguments); this.parameter = parameter; @@ -72,8 +72,7 @@ public class ServerWebInputException extends ResponseStatusException { /** * Return the {@code MethodParameter} associated with this error, if any. */ - @Nullable - public MethodParameter getMethodParameter() { + public @Nullable 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 58c26a32a9..f38dd40b95 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 @@ -19,12 +19,13 @@ package org.springframework.web.server; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ResolvableType; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.ErrorResponse; @@ -41,16 +42,13 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException ErrorResponse.getDefaultDetailMessageCode(UnsupportedMediaTypeStatusException.class, "parseError"); - @Nullable - private final MediaType contentType; + private final @Nullable MediaType contentType; private final List supportedMediaTypes; - @Nullable - private final ResolvableType bodyType; + private final @Nullable ResolvableType bodyType; - @Nullable - private final HttpMethod method; + private final @Nullable HttpMethod method; /** @@ -126,8 +124,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() { + public @Nullable MediaType getContentType() { return this.contentType; } @@ -146,8 +143,7 @@ public class UnsupportedMediaTypeStatusException extends ResponseStatusException * @return the body type, or {@code null} if not available * @since 5.1 */ - @Nullable - public ResolvableType getBodyType() { + public @Nullable ResolvableType getBodyType() { return this.bodyType; } diff --git a/spring-web/src/main/java/org/springframework/web/server/WebSession.java b/spring-web/src/main/java/org/springframework/web/server/WebSession.java index cfa35d9667..fbe863831b 100644 --- a/spring-web/src/main/java/org/springframework/web/server/WebSession.java +++ b/spring-web/src/main/java/org/springframework/web/server/WebSession.java @@ -20,9 +20,9 @@ import java.time.Duration; import java.time.Instant; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -56,8 +56,7 @@ public interface WebSession { * @return the attribute value */ @SuppressWarnings("unchecked") - @Nullable - default T getAttribute(String name) { + default @Nullable T getAttribute(String name) { return (T) getAttributes().get(name); } diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java b/spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java index 0500180897..a305e1a991 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/DefaultServerWebExchange.java @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.function.Function; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -46,7 +47,6 @@ import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.reactive.AbstractServerHttpRequest; 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.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -99,15 +99,13 @@ public class DefaultServerWebExchange implements ServerWebExchange { private volatile boolean multipartRead = false; - @Nullable - private final ApplicationContext applicationContext; + private final @Nullable ApplicationContext applicationContext; private volatile boolean notModified; private Function urlTransformer = url -> url; - @Nullable - private Object logId; + private @Nullable Object logId; private String logPrefix = ""; @@ -183,8 +181,7 @@ public class DefaultServerWebExchange implements ServerWebExchange { .cache(); } - @Nullable - private static MediaType getContentType(ServerHttpRequest request) { + private static @Nullable MediaType getContentType(ServerHttpRequest request) { MediaType contentType = null; try { contentType = request.getHeaders().getContentType(); @@ -196,8 +193,7 @@ public class DefaultServerWebExchange implements ServerWebExchange { } @SuppressWarnings("unchecked") - @Nullable - private static HttpMessageReader getReader( + private static @Nullable HttpMessageReader getReader( ServerCodecConfigurer configurer, MediaType contentType, ResolvableType targetType) { HttpMessageReader result = null; @@ -278,8 +274,7 @@ public class DefaultServerWebExchange implements ServerWebExchange { } @Override - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java b/spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java index a920f17b81..0a00a58d28 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/ForwardedHeaderTransformer.java @@ -24,10 +24,11 @@ import java.util.Locale; import java.util.Set; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.http.HttpHeaders; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedCaseInsensitiveMap; import org.springframework.util.StringUtils; import org.springframework.web.util.ForwardedHeaderUtils; @@ -155,8 +156,7 @@ public class ForwardedHeaderTransformer implements Function filters = new ArrayList<>(); private final List exceptionHandlers = new ArrayList<>(); - @Nullable - private Function httpHandlerDecorator; + private @Nullable Function httpHandlerDecorator; - @Nullable - private WebSessionManager sessionManager; + private @Nullable WebSessionManager sessionManager; - @Nullable - private ServerCodecConfigurer codecConfigurer; + private @Nullable ServerCodecConfigurer codecConfigurer; - @Nullable - private LocaleContextResolver localeContextResolver; + private @Nullable LocaleContextResolver localeContextResolver; - @Nullable - private ForwardedHeaderTransformer forwardedHeaderTransformer; + private @Nullable ForwardedHeaderTransformer forwardedHeaderTransformer; - @Nullable - private ObservationRegistry observationRegistry; + private @Nullable ObservationRegistry observationRegistry; - @Nullable - private ServerRequestObservationConvention observationConvention; + private @Nullable ServerRequestObservationConvention observationConvention; /** 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 13828629a5..4795dd805c 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,9 +3,7 @@ * {@code org.springframework.http.client.reactive} reactive HTTP adapter * and {@link org.springframework.http.server.reactive.HttpHandler}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.server.adapter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/server/handler/DefaultWebFilterChain.java b/spring-web/src/main/java/org/springframework/web/server/handler/DefaultWebFilterChain.java index c255dd0688..1b52916457 100644 --- a/spring-web/src/main/java/org/springframework/web/server/handler/DefaultWebFilterChain.java +++ b/spring-web/src/main/java/org/springframework/web/server/handler/DefaultWebFilterChain.java @@ -20,9 +20,9 @@ import java.util.Collections; import java.util.List; import java.util.ListIterator; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; @@ -48,11 +48,9 @@ public class DefaultWebFilterChain implements WebFilterChain { private final WebHandler handler; - @Nullable - private final WebFilter currentFilter; + private final @Nullable WebFilter currentFilter; - @Nullable - private final DefaultWebFilterChain chain; + private final @Nullable DefaultWebFilterChain chain; /** diff --git a/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java b/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java index 70b6c38779..172fbd600d 100644 --- a/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java +++ b/spring-web/src/main/java/org/springframework/web/server/handler/ResponseStatusExceptionHandler.java @@ -18,13 +18,13 @@ package org.springframework.web.server.handler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.HttpStatusCode; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebExceptionHandler; @@ -45,8 +45,7 @@ public class ResponseStatusExceptionHandler implements WebExceptionHandler { private static final Log logger = LogFactory.getLog(ResponseStatusExceptionHandler.class); - @Nullable - private Log warnLogger; + private @Nullable Log warnLogger; /** @@ -116,8 +115,7 @@ public class ResponseStatusExceptionHandler implements WebExceptionHandler { * @return the associated HTTP status code, or {@code null} if it can't be * derived */ - @Nullable - protected HttpStatusCode determineStatus(Throwable ex) { + protected @Nullable HttpStatusCode determineStatus(Throwable ex) { if (ex instanceof ResponseStatusException responseStatusException) { return responseStatusException.getStatusCode(); } 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 25dc942f1e..5ec721b4a3 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,9 +2,7 @@ * Provides common WebHandler implementations and a * {@link org.springframework.web.server.handler.WebHandlerDecorator}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.server.handler; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolver.java b/spring-web/src/main/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolver.java index c5e990f101..67a31db6cf 100644 --- a/spring-web/src/main/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolver.java +++ b/spring-web/src/main/java/org/springframework/web/server/i18n/AcceptHeaderLocaleContextResolver.java @@ -20,10 +20,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import org.jspecify.annotations.Nullable; + import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.SimpleLocaleContext; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -48,8 +49,7 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver private final List supportedLocales = new ArrayList<>(4); - @Nullable - private Locale defaultLocale; + private @Nullable Locale defaultLocale; /** @@ -94,8 +94,7 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver * The configured default locale, if any. *

    This method may be overridden in subclasses. */ - @Nullable - public Locale getDefaultLocale() { + public @Nullable Locale getDefaultLocale() { return this.defaultLocale; } @@ -112,8 +111,7 @@ public class AcceptHeaderLocaleContextResolver implements LocaleContextResolver return new SimpleLocaleContext(resolveSupportedLocale(requestLocales)); } - @Nullable - private Locale resolveSupportedLocale(@Nullable List requestLocales) { + private @Nullable Locale resolveSupportedLocale(@Nullable List requestLocales) { if (CollectionUtils.isEmpty(requestLocales)) { return getDefaultLocale(); // may be null } diff --git a/spring-web/src/main/java/org/springframework/web/server/i18n/FixedLocaleContextResolver.java b/spring-web/src/main/java/org/springframework/web/server/i18n/FixedLocaleContextResolver.java index 4c731a4349..d6a61396c9 100644 --- a/spring-web/src/main/java/org/springframework/web/server/i18n/FixedLocaleContextResolver.java +++ b/spring-web/src/main/java/org/springframework/web/server/i18n/FixedLocaleContextResolver.java @@ -19,9 +19,10 @@ package org.springframework.web.server.i18n; import java.util.Locale; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -39,8 +40,7 @@ public class FixedLocaleContextResolver implements LocaleContextResolver { private final Locale locale; - @Nullable - private final TimeZone timeZone; + private final @Nullable TimeZone timeZone; /** @@ -79,8 +79,7 @@ public class FixedLocaleContextResolver implements LocaleContextResolver { return locale; } @Override - @Nullable - public TimeZone getTimeZone() { + public @Nullable TimeZone getTimeZone() { return timeZone; } }; diff --git a/spring-web/src/main/java/org/springframework/web/server/i18n/LocaleContextResolver.java b/spring-web/src/main/java/org/springframework/web/server/i18n/LocaleContextResolver.java index 4e4f1af23c..7f9dfc9aca 100644 --- a/spring-web/src/main/java/org/springframework/web/server/i18n/LocaleContextResolver.java +++ b/spring-web/src/main/java/org/springframework/web/server/i18n/LocaleContextResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.server.i18n; +import org.jspecify.annotations.Nullable; + import org.springframework.context.i18n.LocaleContext; -import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** diff --git a/spring-web/src/main/java/org/springframework/web/server/i18n/package-info.java b/spring-web/src/main/java/org/springframework/web/server/i18n/package-info.java index c7724d0e0b..3a20ca8bc9 100644 --- a/spring-web/src/main/java/org/springframework/web/server/i18n/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/server/i18n/package-info.java @@ -2,9 +2,7 @@ * Locale related support classes. * Provides standard LocaleContextResolver implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.server.i18n; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 603079df25..bb5149cb62 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,9 +4,7 @@ * reactive HTTP adapter layer, providing additional constructs such as * WebHandler, WebFilter, WebSession among others. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java b/spring-web/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java index df661f2e93..d2afdb7454 100644 --- a/spring-web/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java +++ b/spring-web/src/main/java/org/springframework/web/server/session/CookieWebSessionIdResolver.java @@ -21,9 +21,10 @@ import java.util.Collections; import java.util.List; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpCookie; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; @@ -41,8 +42,7 @@ public class CookieWebSessionIdResolver implements WebSessionIdResolver { private Duration cookieMaxAge = Duration.ofSeconds(-1); - @Nullable - private Consumer initializer = null; + private @Nullable Consumer initializer = null; /** 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 9df7670c70..af063ef32a 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,9 +2,7 @@ * Auxiliary interfaces and implementation classes for * {@link org.springframework.web.server.WebSession} support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.server.session; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessor.java b/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessor.java index 9839babcdf..d13bf7443d 100644 --- a/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessor.java +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessor.java @@ -19,6 +19,8 @@ package org.springframework.web.service.annotation; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.aop.framework.AopProxyUtils; import org.springframework.aot.generate.GenerationContext; import org.springframework.aot.hint.ProxyHints; @@ -28,7 +30,6 @@ import org.springframework.beans.factory.aot.BeanRegistrationCode; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.Search; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; @@ -44,9 +45,8 @@ import static org.springframework.core.annotation.MergedAnnotations.SearchStrate */ class HttpExchangeBeanRegistrationAotProcessor implements BeanRegistrationAotProcessor { - @Nullable @Override - public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { + public @Nullable BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registeredBean) { Class beanClass = registeredBean.getBeanClass(); List> exchangeInterfaces = new ArrayList<>(); Search search = MergedAnnotations.search(TYPE_HIERARCHY); diff --git a/spring-web/src/main/java/org/springframework/web/service/annotation/package-info.java b/spring-web/src/main/java/org/springframework/web/service/annotation/package-info.java index c04c6fd761..30f1b0e366 100644 --- a/spring-web/src/main/java/org/springframework/web/service/annotation/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/service/annotation/package-info.java @@ -1,9 +1,7 @@ /** * Annotations for declaring HTTP service request methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.service.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractNamedValueArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractNamedValueArgumentResolver.java index 3a967ed0c7..0a2c78ebac 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractNamedValueArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractNamedValueArgumentResolver.java @@ -25,11 +25,11 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; 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.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -49,8 +49,7 @@ public abstract class AbstractNamedValueArgumentResolver implements HttpServiceA protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private final ConversionService conversionService; + private final @Nullable ConversionService conversionService; private final Map namedValueInfoCache = new ConcurrentHashMap<>(256); @@ -102,8 +101,7 @@ public abstract class AbstractNamedValueArgumentResolver implements HttpServiceA return true; } - @Nullable - private NamedValueInfo getNamedValueInfo(MethodParameter parameter, HttpRequestValues.Metadata requestValues) { + private @Nullable NamedValueInfo getNamedValueInfo(MethodParameter parameter, HttpRequestValues.Metadata requestValues) { NamedValueInfo info = this.namedValueInfoCache.get(parameter); if (info == null) { info = createNamedValueInfo(parameter, requestValues); @@ -120,16 +118,14 @@ public abstract class AbstractNamedValueArgumentResolver implements HttpServiceA * Return information about the request value, or {@code null} if the * parameter does not represent a request value of interest. */ - @Nullable - protected abstract NamedValueInfo createNamedValueInfo(MethodParameter parameter); + protected abstract @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter); /** * Variant of {@link #createNamedValueInfo(MethodParameter)} that also provides * access to the static values set from {@code @HttpExchange} attributes. * @since 6.2 */ - @Nullable - protected NamedValueInfo createNamedValueInfo( + protected @Nullable NamedValueInfo createNamedValueInfo( MethodParameter parameter, HttpRequestValues.Metadata metadata) { return createNamedValueInfo(parameter); @@ -238,8 +234,7 @@ public abstract class AbstractNamedValueArgumentResolver implements HttpServiceA private final boolean required; - @Nullable - private final String defaultValue; + private final @Nullable String defaultValue; private final String label; diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java b/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java index a11e6f5167..184a6e4a5e 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/AbstractReactorHttpExchangeAdapter.java @@ -18,11 +18,12 @@ package org.springframework.web.service.invoker; import java.time.Duration; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -36,8 +37,7 @@ public abstract class AbstractReactorHttpExchangeAdapter implements ReactorHttpE private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); - @Nullable - private Duration blockTimeout; + private @Nullable Duration blockTimeout; /** @@ -69,8 +69,7 @@ public abstract class AbstractReactorHttpExchangeAdapter implements ReactorHttpE } @Override - @Nullable - public Duration getBlockTimeout() { + public @Nullable Duration getBlockTimeout() { return this.blockTimeout; } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java index 6b987351bd..8048042970 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/CookieValueArgumentResolver.java @@ -16,9 +16,10 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.CookieValue; /** @@ -57,8 +58,7 @@ public class CookieValueArgumentResolver extends AbstractNamedValueArgumentResol @Override - @Nullable - protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { + protected @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter) { CookieValue annot = parameter.getParameterAnnotation(CookieValue.class); return (annot == null ? null : new NamedValueInfo(annot.name(), annot.required(), annot.defaultValue(), "cookie value", true)); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpExchangeAdapter.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpExchangeAdapter.java index 8e78bbe610..368103bc71 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpExchangeAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpExchangeAdapter.java @@ -16,10 +16,11 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; /** * Contract to abstract an HTTP client from {@linkplain HttpServiceProxyFactory} @@ -58,8 +59,7 @@ public interface HttpExchangeAdapter { * @param the type the response is decoded to * @return the decoded response body. */ - @Nullable - T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference bodyType); + @Nullable T exchangeForBody(HttpRequestValues requestValues, ParameterizedTypeReference bodyType); /** * Variant of {@link #exchange(HttpRequestValues)} with additional diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpMethodArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpMethodArgumentResolver.java index 0f0258045e..cb83772ef7 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpMethodArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpMethodArgumentResolver.java @@ -20,10 +20,10 @@ import java.util.Optional; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java index 7bf09599ae..0efa005d43 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpRequestValues.java @@ -23,11 +23,12 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -52,17 +53,13 @@ public class HttpRequestValues { CollectionUtils.toMultiValueMap(Collections.emptyMap()); - @Nullable - private final HttpMethod httpMethod; + private final @Nullable HttpMethod httpMethod; - @Nullable - private final URI uri; + private final @Nullable URI uri; - @Nullable - private final UriBuilderFactory uriBuilderFactory; + private final @Nullable UriBuilderFactory uriBuilderFactory; - @Nullable - private final String uriTemplate; + private final @Nullable String uriTemplate; private final Map uriVariables; @@ -72,8 +69,7 @@ public class HttpRequestValues { private final Map attributes; - @Nullable - private final Object bodyValue; + private final @Nullable Object bodyValue; /** @@ -103,8 +99,7 @@ public class HttpRequestValues { /** * Return the HTTP method to use for the request. */ - @Nullable - public HttpMethod getHttpMethod() { + public @Nullable HttpMethod getHttpMethod() { return this.httpMethod; } @@ -114,8 +109,7 @@ public class HttpRequestValues { * the caller with the option to override the {@link #getUriTemplate() * uriTemplate} from class and method {@code HttpExchange} annotations. */ - @Nullable - public URI getUri() { + public @Nullable URI getUri() { return this.uri; } @@ -127,8 +121,7 @@ public class HttpRequestValues { * underlying client. * @since 6.1 */ - @Nullable - public UriBuilderFactory getUriBuilderFactory() { + public @Nullable UriBuilderFactory getUriBuilderFactory() { return this.uriBuilderFactory; } @@ -136,8 +129,7 @@ public class HttpRequestValues { * Return the URL template for the request. This comes from the values in * class and method {@code HttpExchange} annotations. */ - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } @@ -172,8 +164,7 @@ public class HttpRequestValues { /** * Return the request body as a value to be serialized, if set. */ - @Nullable - public Object getBodyValue() { + public @Nullable Object getBodyValue() { return this.bodyValue; } @@ -192,26 +183,22 @@ public class HttpRequestValues { /** * Return the HTTP method, if known. */ - @Nullable - HttpMethod getHttpMethod(); + @Nullable HttpMethod getHttpMethod(); /** * Return the URI template, if set already. */ - @Nullable - String getUriTemplate(); + @Nullable String getUriTemplate(); /** * Return the content type, if set already. */ - @Nullable - MediaType getContentType(); + @Nullable MediaType getContentType(); /** * Return the acceptable media types, if set already. */ - @Nullable - List getAcceptMediaTypes(); + @Nullable List getAcceptMediaTypes(); } @@ -220,38 +207,27 @@ public class HttpRequestValues { */ public static class Builder implements Metadata { - @Nullable - private HttpMethod httpMethod; + private @Nullable HttpMethod httpMethod; - @Nullable - private URI uri; + private @Nullable URI uri; - @Nullable - private UriBuilderFactory uriBuilderFactory; + private @Nullable UriBuilderFactory uriBuilderFactory; - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; - @Nullable - private Map uriVars; + private @Nullable Map uriVars; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; - @Nullable - private MultiValueMap cookies; + private @Nullable MultiValueMap cookies; - @Nullable - private MultiValueMap requestParams; + private @Nullable MultiValueMap requestParams; - @Nullable - private MultiValueMap parts; + private @Nullable MultiValueMap parts; - @Nullable - private Map attributes; + private @Nullable Map attributes; - @Nullable - private Object bodyValue; + private @Nullable Object bodyValue; /** * Set the HTTP method for the request. @@ -393,26 +369,22 @@ public class HttpRequestValues { // Implementation of {@link Metadata} methods @Override - @Nullable - public HttpMethod getHttpMethod() { + public @Nullable HttpMethod getHttpMethod() { return this.httpMethod; } @Override - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } @Override - @Nullable - public MediaType getContentType() { + public @Nullable MediaType getContentType() { return (this.headers != null ? this.headers.getContentType() : null); } @Override - @Nullable - public List getAcceptMediaTypes() { + public @Nullable List getAcceptMediaTypes() { return (this.headers != null ? this.headers.getAccept() : null); } diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceArgumentResolver.java index d9d045e9f0..e3f170a5af 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.service.annotation.HttpExchange; /** diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java index 819667c744..99844fee8f 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceMethod.java @@ -26,6 +26,7 @@ import java.util.Set; import java.util.function.Function; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -45,7 +46,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; @@ -127,8 +127,7 @@ final class HttpServiceMethod { } - @Nullable - public Object invoke(Object[] arguments) { + public @Nullable Object invoke(Object[] arguments) { HttpRequestValues.Builder requestValues = this.requestValuesInitializer.initializeRequestValuesBuilder(); applyArguments(requestValues, arguments); return this.responseFunction.execute(requestValues.build()); @@ -223,8 +222,7 @@ final class HttpServiceMethod { acceptableMediaTypes, headers, requestValuesSupplier); } - @Nullable - private static HttpMethod initHttpMethod(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation) { + private static @Nullable HttpMethod initHttpMethod(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation) { String methodLevelMethod = methodAnnotation.method(); if (StringUtils.hasText(methodLevelMethod)) { return HttpMethod.valueOf(methodLevelMethod); @@ -238,9 +236,8 @@ final class HttpServiceMethod { return null; } - @Nullable @SuppressWarnings("NullAway") - private static String initUrl( + private static @Nullable String initUrl( @Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation, @Nullable StringValueResolver embeddedValueResolver) { @@ -266,8 +263,7 @@ final class HttpServiceMethod { return (hasMethodLevelUrl ? methodLevelUrl : typeLevelUrl); } - @Nullable - private static MediaType initContentType(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation) { + private static @Nullable MediaType initContentType(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation) { String methodLevelContentType = methodAnnotation.contentType(); if (StringUtils.hasText(methodLevelContentType)) { return MediaType.parseMediaType(methodLevelContentType); @@ -281,8 +277,7 @@ final class HttpServiceMethod { return null; } - @Nullable - private static List initAccept(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation) { + private static @Nullable List initAccept(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation) { String[] methodLevelAccept = methodAnnotation.accept(); if (!ObjectUtils.isEmpty(methodLevelAccept)) { return MediaType.parseMediaTypes(List.of(methodLevelAccept)); @@ -322,8 +317,7 @@ final class HttpServiceMethod { return headers; } - @Nullable - private static MultiValueMap initHeaders(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation, + private static @Nullable MultiValueMap initHeaders(@Nullable HttpExchange typeAnnotation, HttpExchange methodAnnotation, @Nullable StringValueResolver embeddedValueResolver) { MultiValueMap methodLevelHeaders = parseHeaders(methodAnnotation.headers(), embeddedValueResolver); @@ -384,8 +378,7 @@ final class HttpServiceMethod { */ private interface ResponseFunction { - @Nullable - Object execute(HttpRequestValues requestValues); + @Nullable Object execute(HttpRequestValues requestValues); } @@ -458,8 +451,7 @@ final class HttpServiceMethod { boolean blockForOptional, @Nullable Duration blockTimeout) implements ResponseFunction { @Override - @Nullable - public Object execute(HttpRequestValues requestValues) { + public @Nullable Object execute(HttpRequestValues requestValues) { Publisher responsePublisher = this.responseFunction.apply(requestValues); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java index 863377344b..d064cafd76 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/HttpServiceProxyFactory.java @@ -26,6 +26,7 @@ import java.util.stream.Collectors; import org.aopalliance.intercept.MethodInterceptor; import org.aopalliance.intercept.MethodInvocation; +import org.jspecify.annotations.Nullable; import org.springframework.aop.framework.ProxyFactory; import org.springframework.aop.framework.ReflectiveMethodInvocation; @@ -34,7 +35,6 @@ import org.springframework.core.MethodIntrospector; import org.springframework.core.annotation.AnnotatedElementUtils; 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.util.StringValueResolver; import org.springframework.web.service.annotation.HttpExchange; @@ -58,8 +58,7 @@ public final class HttpServiceProxyFactory { private final List argumentResolvers; - @Nullable - private final StringValueResolver embeddedValueResolver; + private final @Nullable StringValueResolver embeddedValueResolver; private HttpServiceProxyFactory( @@ -123,16 +122,13 @@ public final class HttpServiceProxyFactory { */ public static final class Builder { - @Nullable - private HttpExchangeAdapter exchangeAdapter; + private @Nullable HttpExchangeAdapter exchangeAdapter; private final List customArgumentResolvers = new ArrayList<>(); - @Nullable - private ConversionService conversionService; + private @Nullable ConversionService conversionService; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private Builder() { } @@ -233,8 +229,7 @@ public final class HttpServiceProxyFactory { } @Override - @Nullable - public Object invoke(MethodInvocation invocation) throws Throwable { + public @Nullable Object invoke(MethodInvocation invocation) throws Throwable { Method method = invocation.getMethod(); HttpServiceMethod httpServiceMethod = this.httpServiceMethods.get(method); if (httpServiceMethod != null) { diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java index 668e4fd4b5..4a20a17f4d 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/PathVariableArgumentResolver.java @@ -16,9 +16,10 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.PathVariable; /** @@ -49,8 +50,7 @@ public class PathVariableArgumentResolver extends AbstractNamedValueArgumentReso @Override - @Nullable - protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { + protected @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter) { PathVariable annot = parameter.getParameterAnnotation(PathVariable.class); return (annot == null ? null : new NamedValueInfo(annot.name(), annot.required(), null, "path variable", false)); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java index de5d477f2e..b8cfdb897c 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactiveHttpRequestValues.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.ParameterizedTypeReference; @@ -27,7 +28,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.client.MultipartBodyBuilder; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.web.util.UriBuilderFactory; @@ -41,11 +41,9 @@ import org.springframework.web.util.UriBuilderFactory; */ public final class ReactiveHttpRequestValues extends HttpRequestValues { - @Nullable - private final Publisher body; + private final @Nullable Publisher body; - @Nullable - private final ParameterizedTypeReference bodyElementType; + private final @Nullable ParameterizedTypeReference bodyElementType; private ReactiveHttpRequestValues( @@ -66,16 +64,14 @@ public final class ReactiveHttpRequestValues extends HttpRequestValues { *

    This is mutually exclusive with {@link #getBodyValue()}. * Only one of the two or neither is set. */ - @Nullable - public Publisher getBodyPublisher() { + public @Nullable Publisher getBodyPublisher() { return this.body; } /** * Return the element type for a {@linkplain #getBodyPublisher() body publisher}. */ - @Nullable - public ParameterizedTypeReference getBodyPublisherElementType() { + public @Nullable ParameterizedTypeReference getBodyPublisherElementType() { return this.bodyElementType; } @@ -90,14 +86,11 @@ public final class ReactiveHttpRequestValues extends HttpRequestValues { */ public static final class Builder extends HttpRequestValues.Builder { - @Nullable - private MultipartBodyBuilder multipartBuilder; + private @Nullable MultipartBodyBuilder multipartBuilder; - @Nullable - private Publisher body; + private @Nullable Publisher body; - @Nullable - private ParameterizedTypeReference bodyElementType; + private @Nullable ParameterizedTypeReference bodyElementType; @Override public Builder setHttpMethod(HttpMethod httpMethod) { diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactorHttpExchangeAdapter.java b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactorHttpExchangeAdapter.java index 466fda215e..10752ddd6f 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/ReactorHttpExchangeAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/ReactorHttpExchangeAdapter.java @@ -18,6 +18,7 @@ package org.springframework.web.service.invoker; import java.time.Duration; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -25,7 +26,6 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; /** * Contract to abstract a reactive, HTTP client from @@ -50,8 +50,7 @@ public interface ReactorHttpExchangeAdapter extends HttpExchangeAdapter { * configuring timeout values directly on the underlying HTTP client, which * provides more control over such settings. */ - @Nullable - Duration getBlockTimeout(); + @Nullable Duration getBlockTimeout(); /** * Perform the given request, and release the response content, if any. diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java index b99f6f49b8..f5b9f8e2c3 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestAttribute; /** @@ -41,8 +42,7 @@ public class RequestAttributeArgumentResolver extends AbstractNamedValueArgument @Override - @Nullable - protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { + protected @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestAttribute annot = parameter.getParameterAnnotation(RequestAttribute.class); return (annot == null ? null : new NamedValueInfo(annot.name(), annot.required(), null, "request attribute", false)); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestBodyArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestBodyArgumentResolver.java index a84ef532ac..311a44aec9 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestBodyArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestBodyArgumentResolver.java @@ -18,11 +18,12 @@ package org.springframework.web.service.invoker; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.bind.annotation.RequestBody; @@ -41,8 +42,7 @@ public class RequestBodyArgumentResolver implements HttpServiceArgumentResolver ClassUtils.isPresent("reactor.core.publisher.Mono", RequestBodyArgumentResolver.class.getClassLoader()); - @Nullable - private final ReactiveAdapterRegistry reactiveAdapterRegistry; + private final @Nullable ReactiveAdapterRegistry reactiveAdapterRegistry; /** diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java index 40a1523de6..8df23e2f86 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestHeaderArgumentResolver.java @@ -16,9 +16,10 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestHeader; /** @@ -58,8 +59,7 @@ public class RequestHeaderArgumentResolver extends AbstractNamedValueArgumentRes @Override - @Nullable - protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { + protected @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestHeader annot = parameter.getParameterAnnotation(RequestHeader.class); return (annot == null ? null : new NamedValueInfo(annot.name(), annot.required(), annot.defaultValue(), "request header", true)); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java index 4bcf4aef77..0b995f5ad7 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestParamArgumentResolver.java @@ -16,10 +16,11 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.convert.ConversionService; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestParam; /** @@ -85,8 +86,7 @@ public class RequestParamArgumentResolver extends AbstractNamedValueArgumentReso @Override - @Nullable - protected NamedValueInfo createNamedValueInfo(MethodParameter parameter, HttpRequestValues.Metadata metadata) { + protected @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter, HttpRequestValues.Metadata metadata) { RequestParam annot = parameter.getParameterAnnotation(RequestParam.class); if (annot == null) { return null; diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java index f4173d6e06..46b09918f8 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/RequestPartArgumentResolver.java @@ -16,6 +16,7 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.MethodParameter; @@ -25,7 +26,6 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.codec.multipart.Part; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.bind.annotation.RequestPart; @@ -56,8 +56,7 @@ public class RequestPartArgumentResolver extends AbstractNamedValueArgumentResol ClassUtils.isPresent("reactor.core.publisher.Mono", RequestPartArgumentResolver.class.getClassLoader()); - @Nullable - private final ReactiveAdapterRegistry reactiveAdapterRegistry; + private final @Nullable ReactiveAdapterRegistry reactiveAdapterRegistry; /** @@ -78,8 +77,7 @@ public class RequestPartArgumentResolver extends AbstractNamedValueArgumentResol @Override - @Nullable - protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { + protected @Nullable NamedValueInfo createNamedValueInfo(MethodParameter parameter) { RequestPart annot = parameter.getParameterAnnotation(RequestPart.class); boolean isMultiPartFile = parameter.nestedIfOptional().getNestedParameterType().equals(MultipartFile.class); String label = (isMultiPartFile ? "MultipartFile" : "request part"); diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolver.java index 0c89f905e5..795c269a18 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.web.service.invoker; import java.net.URL; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.util.UriBuilderFactory; import org.springframework.web.util.UriTemplate; diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/UrlArgumentResolver.java b/spring-web/src/main/java/org/springframework/web/service/invoker/UrlArgumentResolver.java index e3840a5534..81d7114273 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/UrlArgumentResolver.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/UrlArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.web.service.invoker; import java.net.URI; import java.util.Optional; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/main/java/org/springframework/web/service/invoker/package-info.java b/spring-web/src/main/java/org/springframework/web/service/invoker/package-info.java index 9c420bbf3f..1e40eb8d0f 100644 --- a/spring-web/src/main/java/org/springframework/web/service/invoker/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/service/invoker/package-info.java @@ -2,9 +2,7 @@ * Support for creating a client proxy for an HTTP service annotated with * {@link org.springframework.web.service.annotation.HttpExchange} methods. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.service.invoker; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/service/package-info.java b/spring-web/src/main/java/org/springframework/web/service/package-info.java index 4fbe50a5af..0d90975028 100644 --- a/spring-web/src/main/java/org/springframework/web/service/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/service/package-info.java @@ -2,9 +2,7 @@ * Annotations to declare an HTTP service contract with request methods along * with a proxy factory backed by client-driven implementation. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.service; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/util/BindErrorUtils.java b/spring-web/src/main/java/org/springframework/web/util/BindErrorUtils.java index 9230d0fb0d..a485bcd82a 100644 --- a/spring-web/src/main/java/org/springframework/web/util/BindErrorUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/BindErrorUtils.java @@ -22,10 +22,11 @@ import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.support.StaticMessageSource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.validation.FieldError; @@ -115,8 +116,7 @@ public abstract class BindErrorUtils { } @Override - @Nullable - protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) { + protected @Nullable String getDefaultMessage(MessageSourceResolvable resolvable, Locale locale) { String message = super.getDefaultMessage(resolvable, locale); return (resolvable instanceof FieldError error ? error.getField() + ": " + message : message); } diff --git a/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java b/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java index fe4a465c08..ebbad60293 100644 --- a/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java +++ b/spring-web/src/main/java/org/springframework/web/util/ContentCachingRequestWrapper.java @@ -31,10 +31,10 @@ import jakarta.servlet.ReadListener; import jakarta.servlet.ServletInputStream; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequestWrapper; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.FastByteArrayOutputStream; /** @@ -58,14 +58,11 @@ public class ContentCachingRequestWrapper extends HttpServletRequestWrapper { private final FastByteArrayOutputStream cachedContent; - @Nullable - private final Integer contentCacheLimit; + private final @Nullable Integer contentCacheLimit; - @Nullable - private ServletInputStream inputStream; + private @Nullable ServletInputStream inputStream; - @Nullable - private BufferedReader reader; + private @Nullable BufferedReader reader; /** diff --git a/spring-web/src/main/java/org/springframework/web/util/ContentCachingResponseWrapper.java b/spring-web/src/main/java/org/springframework/web/util/ContentCachingResponseWrapper.java index 6f150b7547..b8511a8f8d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/ContentCachingResponseWrapper.java +++ b/spring-web/src/main/java/org/springframework/web/util/ContentCachingResponseWrapper.java @@ -30,9 +30,9 @@ import jakarta.servlet.ServletOutputStream; import jakarta.servlet.WriteListener; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.FastByteArrayOutputStream; /** @@ -51,14 +51,11 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper { private final FastByteArrayOutputStream content = new FastByteArrayOutputStream(1024); - @Nullable - private ServletOutputStream outputStream; + private @Nullable ServletOutputStream outputStream; - @Nullable - private PrintWriter writer; + private @Nullable PrintWriter writer; - @Nullable - private Integer contentLength; + private @Nullable Integer contentLength; /** @@ -202,8 +199,7 @@ public class ContentCachingResponseWrapper extends HttpServletResponseWrapper { } @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { if (this.contentLength != null && HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) { return this.contentLength.toString(); } 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 2f15c6e3d2..c334afca5c 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 @@ -20,8 +20,8 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -48,16 +48,13 @@ public class CookieGenerator { protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private String cookieName; + private @Nullable String cookieName; - @Nullable - private String cookieDomain; + private @Nullable String cookieDomain; private String cookiePath = DEFAULT_COOKIE_PATH; - @Nullable - private Integer cookieMaxAge; + private @Nullable Integer cookieMaxAge; private boolean cookieSecure = false; @@ -75,8 +72,7 @@ public class CookieGenerator { /** * Return the given name for cookies created by this generator. */ - @Nullable - public String getCookieName() { + public @Nullable String getCookieName() { return this.cookieName; } @@ -92,8 +88,7 @@ public class CookieGenerator { /** * Return the domain for cookies created by this generator, if any. */ - @Nullable - public String getCookieDomain() { + public @Nullable String getCookieDomain() { return this.cookieDomain; } @@ -127,8 +122,7 @@ public class CookieGenerator { /** * Return the maximum age for cookies created by this generator. */ - @Nullable - public Integer getCookieMaxAge() { + public @Nullable Integer getCookieMaxAge() { return this.cookieMaxAge; } diff --git a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java index 96639045e6..b49830a094 100644 --- a/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java +++ b/spring-web/src/main/java/org/springframework/web/util/DefaultUriBuilderFactory.java @@ -23,7 +23,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Optional; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -42,16 +43,13 @@ import org.springframework.util.StringUtils; */ public class DefaultUriBuilderFactory implements UriBuilderFactory { - @Nullable - private final UriComponentsBuilder baseUri; + private final @Nullable UriComponentsBuilder baseUri; - @Nullable - private UriComponentsBuilder.ParserType parserType; + private UriComponentsBuilder.@Nullable ParserType parserType; private EncodingMode encodingMode = EncodingMode.TEMPLATE_AND_VALUES; - @Nullable - private Map defaultUriVariables; + private @Nullable Map defaultUriVariables; private boolean parsePath = true; @@ -112,8 +110,7 @@ public class DefaultUriBuilderFactory implements UriBuilderFactory { * Return the configured parser type. * @since 6.2 */ - @Nullable - public UriComponentsBuilder.ParserType getParserType() { + public UriComponentsBuilder.@Nullable ParserType getParserType() { return this.parserType; } diff --git a/spring-web/src/main/java/org/springframework/web/util/ForwardedHeaderUtils.java b/spring-web/src/main/java/org/springframework/web/util/ForwardedHeaderUtils.java index fa7df6d282..84900e3374 100644 --- a/spring-web/src/main/java/org/springframework/web/util/ForwardedHeaderUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/ForwardedHeaderUtils.java @@ -21,8 +21,9 @@ import java.net.URI; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -145,8 +146,7 @@ public abstract class ForwardedHeaderUtils { * {@code null} if the headers are not present * @see RFC 7239, Section 5.2 */ - @Nullable - public static InetSocketAddress parseForwardedFor( + public static @Nullable InetSocketAddress parseForwardedFor( URI uri, HttpHeaders headers, @Nullable InetSocketAddress remoteAddress) { int port = (remoteAddress != null ? 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 3af171ebc9..02ccc8a9ca 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 @@ -29,8 +29,9 @@ import java.util.StringJoiner; import java.util.function.BiFunction; import java.util.function.UnaryOperator; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -98,14 +99,11 @@ final class HierarchicalUriComponents extends UriComponents { }; - @Nullable - private final String userInfo; + private final @Nullable String userInfo; - @Nullable - private final String host; + private final @Nullable String host; - @Nullable - private final String port; + private final @Nullable String port; private final PathComponent path; @@ -113,8 +111,7 @@ final class HierarchicalUriComponents extends UriComponents { private final EncodeState encodeState; - @Nullable - private UnaryOperator variableEncoder; + private @Nullable UnaryOperator variableEncoder; /** @@ -167,20 +164,17 @@ final class HierarchicalUriComponents extends UriComponents { // Component getters @Override - @Nullable - public String getSchemeSpecificPart() { + public @Nullable String getSchemeSpecificPart() { return null; } @Override - @Nullable - public String getUserInfo() { + public @Nullable String getUserInfo() { return this.userInfo; } @Override - @Nullable - public String getHost() { + public @Nullable String getHost() { return this.host; } @@ -202,8 +196,7 @@ final class HierarchicalUriComponents extends UriComponents { } @Override - @NonNull - public String getPath() { + public @NonNull String getPath() { return this.path.getPath(); } @@ -213,8 +206,7 @@ final class HierarchicalUriComponents extends UriComponents { } @Override - @Nullable - public String getQuery() { + public @Nullable String getQuery() { if (!this.queryParams.isEmpty()) { StringBuilder queryBuilder = new StringBuilder(); this.queryParams.forEach((name, values) -> { @@ -1094,8 +1086,7 @@ final class HierarchicalUriComponents extends UriComponents { } @Override - @Nullable - public Object getValue(@Nullable String name) { + public @Nullable Object getValue(@Nullable String name) { Object value = this.delegate.getValue(name); if (ObjectUtils.isArray(value)) { value = StringUtils.arrayToCommaDelimitedString(ObjectUtils.toObjectArray(value)); 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 d28724c27d..045379b4c5 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,7 +23,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Properties; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -122,8 +123,7 @@ class HtmlCharacterEntityReferences { /** * Return the reference mapped to the given character, or {@code null} if none found. */ - @Nullable - public String convertToReference(char character) { + public @Nullable String convertToReference(char character) { return convertToReference(character, WebUtils.DEFAULT_CHARACTER_ENCODING); } @@ -131,8 +131,7 @@ class HtmlCharacterEntityReferences { * Return the reference mapped to the given character, or {@code null} if none found. * @since 4.1.2 */ - @Nullable - public String convertToReference(char character, String encoding) { + public @Nullable String convertToReference(char character, String encoding) { if (encoding.startsWith("UTF-")){ return switch (character){ case '<' -> "<"; diff --git a/spring-web/src/main/java/org/springframework/web/util/NestedServletException.java b/spring-web/src/main/java/org/springframework/web/util/NestedServletException.java index 299b26ddff..eb05b1545d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/NestedServletException.java +++ b/spring-web/src/main/java/org/springframework/web/util/NestedServletException.java @@ -17,9 +17,9 @@ package org.springframework.web.util; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.core.NestedExceptionUtils; -import org.springframework.lang.Nullable; /** * Legacy subclass of {@link ServletException} that handles a root cause in terms diff --git a/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java b/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java index de437e6db0..c124ebbd5b 100644 --- a/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java +++ b/spring-web/src/main/java/org/springframework/web/util/OpaqueUriComponents.java @@ -23,7 +23,8 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -41,8 +42,7 @@ final class OpaqueUriComponents extends UriComponents { private static final MultiValueMap QUERY_PARAMS_NONE = new LinkedMultiValueMap<>(); - @Nullable - private final String ssp; + private final @Nullable String ssp; OpaqueUriComponents(@Nullable String scheme, @Nullable String schemeSpecificPart, @Nullable String fragment) { @@ -52,20 +52,17 @@ final class OpaqueUriComponents extends UriComponents { @Override - @Nullable - public String getSchemeSpecificPart() { + public @Nullable String getSchemeSpecificPart() { return this.ssp; } @Override - @Nullable - public String getUserInfo() { + public @Nullable String getUserInfo() { return null; } @Override - @Nullable - public String getHost() { + public @Nullable String getHost() { return null; } @@ -75,8 +72,7 @@ final class OpaqueUriComponents extends UriComponents { } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return null; } @@ -86,8 +82,7 @@ final class OpaqueUriComponents extends UriComponents { } @Override - @Nullable - public String getQuery() { + public @Nullable String getQuery() { return null; } diff --git a/spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java b/spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java index cf4e284815..e07f82923c 100644 --- a/spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java +++ b/spring-web/src/main/java/org/springframework/web/util/RfcUriParser.java @@ -20,9 +20,9 @@ import java.util.Locale; import java.util.Set; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.core.log.LogDelegateFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -386,26 +386,19 @@ abstract class RfcUriParser { private final String uri; - @Nullable - private String scheme; + private @Nullable String scheme; - @Nullable - String user; + @Nullable String user; - @Nullable - private String host; + private @Nullable String host; - @Nullable - private String path; + private @Nullable String path; - @Nullable - String port; + @Nullable String port; - @Nullable - String query; + @Nullable String query; - @Nullable - String fragment; + @Nullable String fragment; private State state = State.START; diff --git a/spring-web/src/main/java/org/springframework/web/util/ServletContextPropertyUtils.java b/spring-web/src/main/java/org/springframework/web/util/ServletContextPropertyUtils.java index 14a8e2f7b4..bd05bef73d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/ServletContextPropertyUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/ServletContextPropertyUtils.java @@ -17,8 +17,8 @@ package org.springframework.web.util; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.SystemPropertyUtils; @@ -99,8 +99,7 @@ public abstract class ServletContextPropertyUtils { } @Override - @Nullable - public String resolvePlaceholder(String placeholderName) { + public @Nullable String resolvePlaceholder(String placeholderName) { try { String propVal = this.servletContext.getInitParameter(placeholderName); if (propVal == null) { diff --git a/spring-web/src/main/java/org/springframework/web/util/ServletRequestPathUtils.java b/spring-web/src/main/java/org/springframework/web/util/ServletRequestPathUtils.java index 4c62789658..06683bdb75 100644 --- a/spring-web/src/main/java/org/springframework/web/util/ServletRequestPathUtils.java +++ b/spring-web/src/main/java/org/springframework/web/util/ServletRequestPathUtils.java @@ -24,10 +24,10 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletMapping; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.MappingMatch; +import org.jspecify.annotations.Nullable; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -256,8 +256,7 @@ public abstract class ServletRequestPathUtils { RequestPath.parse(requestUri, request.getContextPath())); } - @Nullable - private static String getServletPathPrefix(HttpServletRequest request) { + private static @Nullable String getServletPathPrefix(HttpServletRequest request) { HttpServletMapping mapping = (HttpServletMapping) request.getAttribute(RequestDispatcher.INCLUDE_MAPPING); mapping = (mapping != null ? mapping : request.getHttpServletMapping()); if (ObjectUtils.nullSafeEquals(mapping.getMappingMatch(), MappingMatch.PATH)) { 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 b468038af9..238aca79bc 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 @@ -21,7 +21,8 @@ import java.util.Collection; import java.util.Map; import java.util.Optional; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.MultiValueMap; /** 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 047a8ce09c..c8ae65a0ac 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 @@ -28,7 +28,8 @@ import java.util.function.UnaryOperator; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; @@ -51,11 +52,9 @@ public abstract class UriComponents implements Serializable { private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)\\}"); - @Nullable - private final String scheme; + private final @Nullable String scheme; - @Nullable - private final String fragment; + private final @Nullable String fragment; protected UriComponents(@Nullable String scheme, @Nullable String fragment) { @@ -69,36 +68,31 @@ public abstract class UriComponents implements Serializable { /** * Return the scheme. Can be {@code null}. */ - @Nullable - public final String getScheme() { + public final @Nullable String getScheme() { return this.scheme; } /** * Return the fragment. Can be {@code null}. */ - @Nullable - public final String getFragment() { + public final @Nullable String getFragment() { return this.fragment; } /** * Return the scheme specific part. Can be {@code null}. */ - @Nullable - public abstract String getSchemeSpecificPart(); + public abstract @Nullable String getSchemeSpecificPart(); /** * Return the user info. Can be {@code null}. */ - @Nullable - public abstract String getUserInfo(); + public abstract @Nullable String getUserInfo(); /** * Return the host. Can be {@code null}. */ - @Nullable - public abstract String getHost(); + public abstract @Nullable String getHost(); /** * Return the port. {@code -1} if no port has been set. @@ -108,8 +102,7 @@ public abstract class UriComponents implements Serializable { /** * Return the path. Can be {@code null}. */ - @Nullable - public abstract String getPath(); + public abstract @Nullable String getPath(); /** * Return the list of path segments. Empty if no path has been set. @@ -119,8 +112,7 @@ public abstract class UriComponents implements Serializable { /** * Return the query. Can be {@code null}. */ - @Nullable - public abstract String getQuery(); + public abstract @Nullable String getQuery(); /** * Return the map of query parameters. Empty if no query has been set. @@ -237,13 +229,11 @@ public abstract class UriComponents implements Serializable { // Static expansion helpers - @Nullable - static String expandUriComponent(@Nullable String source, UriTemplateVariables uriVariables) { + static @Nullable String expandUriComponent(@Nullable String source, UriTemplateVariables uriVariables) { return expandUriComponent(source, uriVariables, null); } - @Nullable - static String expandUriComponent(@Nullable String source, UriTemplateVariables uriVariables, + static @Nullable String expandUriComponent(@Nullable String source, UriTemplateVariables uriVariables, @Nullable UnaryOperator encoder) { if (source == null) { @@ -325,8 +315,7 @@ public abstract class UriComponents implements Serializable { * @param name the variable name * @return the variable value, possibly {@code null} or {@link #SKIP_VALUE} */ - @Nullable - Object getValue(@Nullable String name); + @Nullable Object getValue(@Nullable String name); } @@ -342,8 +331,7 @@ public abstract class UriComponents implements Serializable { } @Override - @Nullable - public Object getValue(@Nullable String name) { + public @Nullable Object getValue(@Nullable String name) { if (!this.uriVariables.containsKey(name)) { throw new IllegalArgumentException("Map has no value for '" + name + "'"); } @@ -364,8 +352,7 @@ public abstract class UriComponents implements Serializable { } @Override - @Nullable - public Object getValue(@Nullable String name) { + public @Nullable Object getValue(@Nullable String name) { if (!this.valueIterator.hasNext()) { throw new IllegalArgumentException("Not enough variable values available to expand '" + 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 422142082a..8aa36ccf19 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 @@ -30,7 +30,8 @@ import java.util.Optional; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -76,27 +77,21 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { private static final Object[] EMPTY_VALUES = new Object[0]; - @Nullable - private String scheme; + private @Nullable String scheme; - @Nullable - private String ssp; + private @Nullable String ssp; - @Nullable - private String userInfo; + private @Nullable String userInfo; - @Nullable - private String host; + private @Nullable String host; - @Nullable - private String port; + private @Nullable String port; private CompositePathComponentBuilder pathBuilder; private final MultiValueMap queryParams = new LinkedMultiValueMap<>(); - @Nullable - private String fragment; + private @Nullable String fragment; private final Map uriVariables = new HashMap<>(4); @@ -610,8 +605,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { return this; } - @Nullable - private String getQueryParamValue(@Nullable Object value) { + private @Nullable String getQueryParamValue(@Nullable Object value) { if (value != null) { return (value instanceof Optional optional ? optional.map(Object::toString).orElse(null) : @@ -777,8 +771,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { private interface PathComponentBuilder { - @Nullable - PathComponent build(); + @Nullable PathComponent build(); PathComponentBuilder cloneBuilder(); } @@ -819,8 +812,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { } @SuppressWarnings("unchecked") - @Nullable - private T getLastBuilder(Class builderClass) { + private @Nullable T getLastBuilder(Class builderClass) { if (!this.builders.isEmpty()) { PathComponentBuilder last = this.builders.getLast(); if (builderClass.isInstance(last)) { @@ -869,8 +861,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { } @Override - @Nullable - public PathComponent build() { + public @Nullable PathComponent build() { if (this.path.isEmpty()) { return null; } @@ -920,8 +911,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { } @Override - @Nullable - public PathComponent build() { + public @Nullable PathComponent build() { return (this.pathSegments.isEmpty() ? null : new HierarchicalUriComponents.PathSegmentComponent(this.pathSegments)); } diff --git a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java index fd011edb63..a6b622d588 100644 --- a/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java +++ b/spring-web/src/main/java/org/springframework/web/util/UriTemplate.java @@ -25,7 +25,8 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; 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 c8faec81c9..9362697bf0 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 @@ -23,7 +23,8 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -393,8 +394,7 @@ public abstract class UriUtils { * @return the extracted file extension (for example, "html") * @since 4.3.2 */ - @Nullable - public static String extractFileExtension(String path) { + public static @Nullable String extractFileExtension(String path) { int end = path.indexOf('?'); int fragmentIndex = path.indexOf('#'); if (fragmentIndex != -1 && (end == -1 || fragmentIndex < end)) { 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 c6bd2a2956..a703582515 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 @@ -29,8 +29,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.MappingMatch; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -70,8 +70,7 @@ public class UrlPathHelper { private static final Log logger = LogFactory.getLog(UrlPathHelper.class); - @Nullable - static volatile Boolean websphereComplianceFlag; + static @Nullable volatile Boolean websphereComplianceFlag; private boolean alwaysUseFullPath = false; @@ -362,8 +361,7 @@ public class UrlPathHelper { * context path and the servlet path returned by the HttpServletRequest are * stripped of semicolon content unlike the requestUri. */ - @Nullable - private String getRemainingPath(String requestUri, String mapping, boolean ignoreCase) { + private @Nullable String getRemainingPath(String requestUri, String mapping, boolean ignoreCase) { int index1 = 0; int index2 = 0; for (; (index1 < requestUri.length()) && (index2 < mapping.length()); index1++, index2++) { diff --git a/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java b/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java index dfff61eea9..b7572ce742 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java +++ b/spring-web/src/main/java/org/springframework/web/util/WebUtilRuntimeHints.java @@ -16,10 +16,11 @@ package org.springframework.web.util; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; import org.springframework.core.io.ClassPathResource; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that registers resource hints 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 b5d8fa8fc2..f5ff808548 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 @@ -34,11 +34,11 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; 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; @@ -278,8 +278,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(@Nullable ServletContext servletContext) { + public static @Nullable Boolean getDefaultHtmlEscape(@Nullable ServletContext servletContext) { if (servletContext == null) { return null; } @@ -301,8 +300,7 @@ public abstract class WebUtils { * ({@code null} = no explicit default) * @since 4.1.2 */ - @Nullable - public static Boolean getResponseEncodedHtmlEscape(@Nullable ServletContext servletContext) { + public static @Nullable Boolean getResponseEncodedHtmlEscape(@Nullable ServletContext servletContext) { if (servletContext == null) { return null; } @@ -354,8 +352,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) { + public static @Nullable String getSessionId(HttpServletRequest request) { Assert.notNull(request, "Request must not be null"); HttpSession session = request.getSession(false); return (session != null ? session.getId() : null); @@ -369,8 +366,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) { + public static @Nullable Object getSessionAttribute(HttpServletRequest request, String name) { Assert.notNull(request, "Request must not be null"); HttpSession session = request.getSession(false); return (session != null ? session.getAttribute(name) : null); @@ -455,8 +451,7 @@ public abstract class WebUtils { * of that type is available */ @SuppressWarnings("unchecked") - @Nullable - public static T getNativeRequest(ServletRequest request, @Nullable Class requiredType) { + public static @Nullable T getNativeRequest(ServletRequest request, @Nullable Class requiredType) { if (requiredType != null) { if (requiredType.isInstance(request)) { return (T) request; @@ -477,8 +472,7 @@ public abstract class WebUtils { * of that type is available */ @SuppressWarnings("unchecked") - @Nullable - public static T getNativeResponse(ServletResponse response, @Nullable Class requiredType) { + public static @Nullable T getNativeResponse(ServletResponse response, @Nullable Class requiredType) { if (requiredType != null) { if (requiredType.isInstance(response)) { return (T) response; @@ -573,8 +567,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) { + public static @Nullable Cookie getCookie(HttpServletRequest request, String name) { Assert.notNull(request, "Request must not be null"); Cookie[] cookies = request.getCookies(); if (cookies != null) { @@ -618,8 +611,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) { + public static @Nullable String findParameterValue(ServletRequest request, String name) { return findParameterValue(request.getParameterMap(), name); } @@ -646,8 +638,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) { + public static @Nullable String findParameterValue(Map parameters, String name) { // First try to get it as a normal name=value parameter Object value = parameters.get(name); if (value instanceof String[] values) { diff --git a/spring-web/src/main/java/org/springframework/web/util/WhatWgUrlParser.java b/spring-web/src/main/java/org/springframework/web/util/WhatWgUrlParser.java index 44cb470d30..cdf863701d 100644 --- a/spring-web/src/main/java/org/springframework/web/util/WhatWgUrlParser.java +++ b/spring-web/src/main/java/org/springframework/web/util/WhatWgUrlParser.java @@ -31,8 +31,8 @@ import java.util.function.IntPredicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -71,24 +71,19 @@ final class WhatWgUrlParser { private final StringBuilder input; - @Nullable - private final UrlRecord base; + private final @Nullable UrlRecord base; - @Nullable - private Charset encoding; + private @Nullable Charset encoding; - @Nullable - private final Consumer validationErrorHandler; + private final @Nullable Consumer validationErrorHandler; private int pointer; private final StringBuilder buffer; - @Nullable - private State state; + private @Nullable State state; - @Nullable - private State stateOverride; + private @Nullable State stateOverride; private boolean atSignSeen; @@ -539,8 +534,7 @@ final class WhatWgUrlParser { } } - @Nullable - private String percentEncode(int c, IntPredicate percentEncodeSet) { + private @Nullable String percentEncode(int c, IntPredicate percentEncodeSet) { if (this.encoding == null) { return null; } @@ -1723,25 +1717,19 @@ final class WhatWgUrlParser { private String scheme = ""; - @Nullable - private StringBuilder username = null; + private @Nullable StringBuilder username = null; - @Nullable - private StringBuilder password = null; + private @Nullable StringBuilder password = null; - @Nullable - private Host host = null; + private @Nullable Host host = null; - @Nullable - private Port port = null; + private @Nullable Port port = null; private Path path = new PathSegments(); - @Nullable - private StringBuilder query = null; + private @Nullable StringBuilder query = null; - @Nullable - private StringBuilder fragment = null; + private @Nullable StringBuilder fragment = null; public UrlRecord() { } @@ -1836,8 +1824,7 @@ final class WhatWgUrlParser { /** * Convenience method to return the full user info. */ - @Nullable - public String userInfo() { + public @Nullable String userInfo() { if (!includesCredentials()) { return null; } @@ -1853,8 +1840,7 @@ final class WhatWgUrlParser { * A URL’s host is {@code null} or a {@linkplain Host host}. * It is initially {@code null}. */ - @Nullable - public Host host() { + public @Nullable Host host() { return this.host; } @@ -1891,8 +1877,7 @@ final class WhatWgUrlParser { * integer, or a string containing a uri template. *

    It is initially {@code null}. */ - @Nullable - public Port port() { + public @Nullable Port port() { return this.port; } @@ -1930,8 +1915,7 @@ final class WhatWgUrlParser { * A URL’s query is either {@code null} or an ASCII string. *

    It is initially {@code null}. */ - @Nullable - public String query() { + public @Nullable String query() { return (this.query != null ? this.query.toString() : null); } @@ -1958,8 +1942,7 @@ final class WhatWgUrlParser { * other components identify. *

    It is initially {@code null}. */ - @Nullable - public String fragment() { + public @Nullable String fragment() { return (this.fragment != null ? this.fragment.toString() : null); } @@ -2916,11 +2899,9 @@ final class WhatWgUrlParser { static final class PathSegment implements Path { - @Nullable - private StringBuilder builder = null; + private @Nullable StringBuilder builder = null; - @Nullable - String segment; + @Nullable String segment; PathSegment(String segment) { this.segment = segment; 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 d5cd93f885..b36cd157b9 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 @@ -1,9 +1,7 @@ /** * Miscellaneous web utility classes, such as HTML escaping and cookie handling. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.util; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java index d02dc686cb..4d28e5d480 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/CaptureVariablePathElement.java @@ -19,8 +19,9 @@ package org.springframework.web.util.pattern; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.http.server.PathContainer.PathSegment; -import org.springframework.lang.Nullable; /** * A path element representing capturing a piece of the path as a variable. In the pattern @@ -34,8 +35,7 @@ class CaptureVariablePathElement extends PathElement { private final String variableName; - @Nullable - private final Pattern constraintPattern; + private final @Nullable Pattern constraintPattern; /** diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/InternalPathPatternParser.java b/spring-web/src/main/java/org/springframework/web/util/pattern/InternalPathPatternParser.java index 53e511ae0f..00de897de8 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/InternalPathPatternParser.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/InternalPathPatternParser.java @@ -20,7 +20,8 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.PatternSyntaxException; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.web.util.pattern.PatternParseException.PatternMessage; @@ -67,16 +68,13 @@ class InternalPathPatternParser { private int variableCaptureStart; // Variables captures in this path pattern - @Nullable - private List capturedVariableNames; + private @Nullable List capturedVariableNames; // The head of the path element chain currently being built - @Nullable - private PathElement headPE; + private @Nullable PathElement headPE; // The most recently constructed path element in the chain - @Nullable - private PathElement currentPE; + private @Nullable PathElement currentPE; /** diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathElement.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathElement.java index b9660bf338..e6a17d3150 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathElement.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathElement.java @@ -16,7 +16,8 @@ package org.springframework.web.util.pattern; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.util.pattern.PathPattern.MatchingContext; @@ -44,12 +45,10 @@ abstract class PathElement { protected final char separator; // The next path element in the chain - @Nullable - protected PathElement next; + protected @Nullable PathElement next; // The previous path element in the chain - @Nullable - protected PathElement prev; + protected @Nullable PathElement prev; /** 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 abd3157b5c..bdada06050 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 @@ -23,11 +23,12 @@ import java.util.List; import java.util.Map; import java.util.StringJoiner; +import org.jspecify.annotations.Nullable; + import org.springframework.http.server.PathContainer; import org.springframework.http.server.PathContainer.Element; import org.springframework.http.server.PathContainer.PathSegment; import org.springframework.http.server.PathContainer.Separator; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -116,8 +117,7 @@ public class PathPattern implements Comparable { private final boolean caseSensitive; /** First path element in the parsed chain of path elements for this pattern. */ - @Nullable - private final PathElement head; + private final @Nullable PathElement head; /** How many variables are captured in this pattern. */ private int capturedVariableCount; @@ -217,8 +217,7 @@ public class PathPattern implements Comparable { * @param pathContainer the candidate path to attempt to match against * @return info object with the extracted variables, or {@code null} for no match */ - @Nullable - public PathMatchInfo matchAndExtract(PathContainer pathContainer) { + public @Nullable PathMatchInfo matchAndExtract(PathContainer pathContainer) { if (this.head == null) { return (hasLength(pathContainer) && !pathContainerIsJustSeparator(pathContainer) ? null : PathMatchInfo.EMPTY); } @@ -241,8 +240,7 @@ public class PathPattern implements Comparable { * @param pathContainer the candidate path to attempt to match against * @return info object with the match result or {@code null} for no match */ - @Nullable - public PathRemainingMatchInfo matchStartOfPath(PathContainer pathContainer) { + public @Nullable PathRemainingMatchInfo matchStartOfPath(PathContainer pathContainer) { if (this.head == null) { return new PathRemainingMatchInfo(EMPTY_PATH, pathContainer); } @@ -492,8 +490,7 @@ public class PathPattern implements Comparable { return sb.toString(); } - @Nullable - PathElement getHeadSection() { + @Nullable PathElement getHeadSection() { return this.head; } @@ -647,11 +644,9 @@ public class PathPattern implements Comparable { final int pathLength; - @Nullable - private Map extractedUriVariables; + private @Nullable Map extractedUriVariables; - @Nullable - private Map> extractedMatrixVariables; + private @Nullable Map> extractedMatrixVariables; boolean extractingVariables; diff --git a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java index 740b61152d..776b5f04f7 100644 --- a/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java +++ b/spring-web/src/main/java/org/springframework/web/util/pattern/PathPatternRouteMatcher.java @@ -20,8 +20,9 @@ import java.util.Comparator; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.RouteMatcher; @@ -80,8 +81,7 @@ public class PathPatternRouteMatcher implements RouteMatcher { } @Override - @Nullable - public Map matchAndExtract(String pattern, Route route) { + public @Nullable Map matchAndExtract(String pattern, Route route) { PathPattern.PathMatchInfo info = getPathPattern(pattern).matchAndExtract(getPathContainer(route)); return info != null ? info.getUriVariables() : 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 f6a5f3fce8..4f067d584b 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 @@ -6,9 +6,7 @@ * {@link org.springframework.web.util.pattern.PathPattern org.springframework.web.util.pattern.PathPatterns} that can then be * used for matching purposes at request time. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.util.pattern; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt b/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt index a6234cfb14..cefc9542eb 100644 --- a/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt +++ b/spring-web/src/main/kotlin/org/springframework/web/client/RestOperationsExtensions.kt @@ -21,7 +21,9 @@ import org.springframework.http.HttpEntity import org.springframework.http.HttpMethod import org.springframework.http.RequestEntity import org.springframework.http.ResponseEntity +import java.lang.Class import java.net.URI +import kotlin.reflect.KClass /** * Extension for [RestOperations.getForObject] providing a `getForObject(...)` @@ -35,7 +37,7 @@ import java.net.URI */ @Throws(RestClientException::class) inline fun RestOperations.getForObject(url: String, vararg uriVariables: Any): T = - getForObject(url, T::class.java, *uriVariables) as T + getForObject(url, T::class.java as Class<*>, *uriVariables) as T /** * Extension for [RestOperations.getForObject] providing a `getForObject(...)` @@ -49,7 +51,7 @@ inline fun RestOperations.getForObject(url: String, vararg uriVariab */ @Throws(RestClientException::class) inline fun RestOperations.getForObject(url: String, uriVariables: Map): T = - getForObject(url, T::class.java, uriVariables) as T + getForObject(url, T::class.java as Class<*>, uriVariables) as T /** * Extension for [RestOperations.getForObject] providing a `getForObject(...)` @@ -63,7 +65,7 @@ inline fun RestOperations.getForObject(url: String, uriVariables: Ma */ @Throws(RestClientException::class) inline fun RestOperations.getForObject(url: URI): T = - getForObject(url, T::class.java) as T + getForObject(url, T::class.java as Class<*>) as T /** * Extension for [RestOperations.getForEntity] providing a `getForEntity(...)` @@ -74,8 +76,9 @@ inline fun RestOperations.getForObject(url: URI): T = * @author Sebastien Deleuze * @since 5.0.2 */ +@Suppress("UNCHECKED_CAST") @Throws(RestClientException::class) -inline fun RestOperations.getForEntity(url: URI): ResponseEntity = +inline fun RestOperations.getForEntity(url: URI): ResponseEntity = getForEntity(url, T::class.java) /** @@ -89,7 +92,7 @@ inline fun RestOperations.getForEntity(url: URI): ResponseEntity * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.getForEntity(url: String, vararg uriVariables: Any): ResponseEntity = +inline fun RestOperations.getForEntity(url: String, vararg uriVariables: Any): ResponseEntity = getForEntity(url, T::class.java, *uriVariables) /** @@ -102,7 +105,7 @@ inline fun RestOperations.getForEntity(url: String, vararg uriVariab * @since 5.0.2 */ @Throws(RestClientException::class) -inline fun RestOperations.getForEntity(url: String, uriVariables: Map): ResponseEntity = +inline fun RestOperations.getForEntity(url: String, uriVariables: Map): ResponseEntity = getForEntity(url, T::class.java, uriVariables) /** @@ -117,7 +120,7 @@ inline fun RestOperations.getForEntity(url: String, uriVariables: Ma @Throws(RestClientException::class) inline fun RestOperations.patchForObject(url: String, request: Any? = null, vararg uriVariables: Any): T = - patchForObject(url, request, T::class.java, *uriVariables) as T + patchForObject(url, request, T::class.java as Class<*>, *uriVariables) as T /** * Extension for [RestOperations.patchForObject] providing a `patchForObject(...)` @@ -131,7 +134,7 @@ inline fun RestOperations.patchForObject(url: String, request: Any? @Throws(RestClientException::class) inline fun RestOperations.patchForObject(url: String, request: Any? = null, uriVariables: Map): T = - patchForObject(url, request, T::class.java, uriVariables) as T + patchForObject(url, request, T::class.java as Class<*>, uriVariables) as T /** * Extension for [RestOperations.patchForObject] providing a `patchForObject(...)` @@ -144,7 +147,7 @@ inline fun RestOperations.patchForObject(url: String, request: Any? */ @Throws(RestClientException::class) inline fun RestOperations.patchForObject(url: URI, request: Any? = null): T = - patchForObject(url, request, T::class.java) as T + patchForObject(url, request, T::class.java as Class<*>) as T /** * Extension for [RestOperations.postForObject] providing a `postForObject(...)` @@ -159,7 +162,7 @@ inline fun RestOperations.patchForObject(url: URI, request: Any? = n @Throws(RestClientException::class) inline fun RestOperations.postForObject(url: String, request: Any? = null, vararg uriVariables: Any): T = - postForObject(url, request, T::class.java, *uriVariables) as T + postForObject(url, request, T::class.java as Class<*>, *uriVariables) as T /** * Extension for [RestOperations.postForObject] providing a `postForObject(...)` @@ -174,7 +177,7 @@ inline fun RestOperations.postForObject(url: String, request: Any? = @Throws(RestClientException::class) inline fun RestOperations.postForObject(url: String, request: Any? = null, uriVariables: Map): T = - postForObject(url, request, T::class.java, uriVariables) as T + postForObject(url, request, T::class.java as Class<*>, uriVariables) as T /** * Extension for [RestOperations.postForObject] providing a `postForObject(...)` @@ -188,7 +191,7 @@ inline fun RestOperations.postForObject(url: String, request: Any? = */ @Throws(RestClientException::class) inline fun RestOperations.postForObject(url: URI, request: Any? = null): T = - postForObject(url, request, T::class.java) as T + postForObject(url, request, T::class.java as Class<*>) as T /** * Extension for [RestOperations.postForEntity] providing a `postForEntity(...)` @@ -201,7 +204,7 @@ inline fun RestOperations.postForObject(url: URI, request: Any? = nu * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForEntity(url: String, request: Any? = null, +inline fun RestOperations.postForEntity(url: String, request: Any? = null, vararg uriVariables: Any): ResponseEntity = postForEntity(url, request, T::class.java, *uriVariables) @@ -216,7 +219,7 @@ inline fun RestOperations.postForEntity(url: String, request: Any? = * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForEntity(url: String, request: Any? = null, +inline fun RestOperations.postForEntity(url: String, request: Any? = null, uriVariables: Map): ResponseEntity = postForEntity(url, request, T::class.java, uriVariables) @@ -231,7 +234,7 @@ inline fun RestOperations.postForEntity(url: String, request: Any? = * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.postForEntity(url: URI, request: Any? = null): ResponseEntity = +inline fun RestOperations.postForEntity(url: URI, request: Any? = null): ResponseEntity = postForEntity(url, request, T::class.java) /** @@ -244,7 +247,7 @@ inline fun RestOperations.postForEntity(url: URI, request: Any? = nu * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.exchange(url: String, method: HttpMethod, +inline fun RestOperations.exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>? = null, vararg uriVariables: Any): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}, *uriVariables) @@ -258,7 +261,7 @@ inline fun RestOperations.exchange(url: String, method: HttpMethod, * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.exchange(url: String, method: HttpMethod, +inline fun RestOperations.exchange(url: String, method: HttpMethod, requestEntity: HttpEntity<*>? = null, uriVariables: Map): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}, uriVariables) @@ -272,7 +275,7 @@ inline fun RestOperations.exchange(url: String, method: HttpMethod, * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.exchange(url: URI, method: HttpMethod, +inline fun RestOperations.exchange(url: URI, method: HttpMethod, requestEntity: HttpEntity<*>? = null): ResponseEntity = exchange(url, method, requestEntity, object : ParameterizedTypeReference() {}) @@ -286,5 +289,5 @@ inline fun RestOperations.exchange(url: URI, method: HttpMethod, * @since 5.0 */ @Throws(RestClientException::class) -inline fun RestOperations.exchange(requestEntity: RequestEntity<*>): ResponseEntity = +inline fun RestOperations.exchange(requestEntity: RequestEntity<*>): ResponseEntity = exchange(requestEntity, object : ParameterizedTypeReference() {}) diff --git a/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java b/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java index 443cb06952..049fd5d934 100644 --- a/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java +++ b/spring-web/src/test/java/org/springframework/http/client/JdkClientHttpRequestFactoryTests.java @@ -19,6 +19,7 @@ package org.springframework.http.client; import java.io.IOException; import java.net.URI; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -26,7 +27,6 @@ import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; @@ -37,8 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ class JdkClientHttpRequestFactoryTests extends AbstractHttpRequestFactoryTests { - @Nullable - private static String originalPropertyValue; + private static @Nullable String originalPropertyValue; @BeforeAll static void setProperty() { diff --git a/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java b/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java index 209e358a52..692f06a108 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/multipart/DefaultPartHttpMessageReaderTests.java @@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Stream; import io.netty.buffer.PooledByteBufAllocator; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -48,7 +49,6 @@ import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest; import static java.nio.charset.StandardCharsets.UTF_8; diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/TypePojo.java b/spring-web/src/test/java/org/springframework/http/codec/xml/TypePojo.java index 31c3b8ab7b..466ce18325 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/TypePojo.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/TypePojo.java @@ -16,7 +16,7 @@ package org.springframework.http.codec.xml; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Arjen Poutsma diff --git a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java index d62a9ce021..8a7095fddf 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/json/MappingJackson2HttpMessageConverterTests.java @@ -39,13 +39,13 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.skyscreamer.jsonassert.JSONAssert; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.lang.Nullable; import org.springframework.web.testfixture.http.MockHttpInputMessage; import org.springframework.web.testfixture.http.MockHttpOutputMessage; diff --git a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java index 19c277a9b7..4ef209b2bd 100644 --- a/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java +++ b/spring-web/src/test/java/org/springframework/http/converter/xml/Jaxb2CollectionHttpMessageConverterTests.java @@ -28,6 +28,7 @@ import jakarta.xml.bind.annotation.XmlAttribute; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; import jakarta.xml.bind.annotation.XmlType; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -35,7 +36,6 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.http.converter.HttpMessageNotReadableException; -import org.springframework.lang.Nullable; import org.springframework.web.testfixture.http.MockHttpInputMessage; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java index e6ac7463f4..325a846411 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/ListenerReadPublisherTests.java @@ -16,6 +16,7 @@ package org.springframework.http.server.reactive; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.reactivestreams.Subscriber; @@ -103,7 +104,7 @@ class ListenerReadPublisherTests { } @Override - protected DataBuffer read() { + protected @Nullable DataBuffer read() { if (this.discardCalls != 0) { return null; } diff --git a/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java b/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java index 9ad7ee09b9..fc39bff8a1 100644 --- a/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/ErrorResponseExceptionTests.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.Locale; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.testfixture.beans.TestBean; @@ -33,7 +34,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ProblemDetail; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.BindingResult; @@ -456,7 +456,7 @@ class ErrorResponseExceptionTests { } private void assertDetailMessageCode( - ErrorResponse ex, @Nullable String suffix, @Nullable Object[] arguments) { + ErrorResponse ex, @Nullable String suffix, Object @Nullable [] arguments) { assertThat(ex.getDetailMessageCode()) .isEqualTo(ErrorResponse.getDefaultDetailMessageCode(ex.getClass(), suffix)); diff --git a/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java index d5407aa73f..2f3310af71 100644 --- a/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java +++ b/spring-web/src/test/java/org/springframework/web/bind/support/WebExchangeDataBinderTests.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -35,7 +36,6 @@ import org.springframework.http.MediaType; import org.springframework.http.codec.FormHttpMessageWriter; import org.springframework.http.codec.multipart.FilePart; import org.springframework.http.codec.multipart.MultipartHttpMessageWriter; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebExchange; @@ -334,8 +334,7 @@ class WebExchangeDataBinderTests { private final FilePart part; - @Nullable - private final FilePart nullablePart; + private final @Nullable FilePart nullablePart; MultipartDataClass(FilePart part, @Nullable FilePart nullablePart) { this.part = part; @@ -346,8 +345,7 @@ class WebExchangeDataBinderTests { return part; } - @Nullable - public FilePart getNullablePart() { + public @Nullable FilePart getNullablePart() { return nullablePart; } } diff --git a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java index fbe2f9d318..d7f3fcbfbb 100644 --- a/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/DefaultResponseErrorHandlerTests.java @@ -20,6 +20,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.net.URI; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; @@ -28,7 +29,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; import static java.nio.charset.StandardCharsets.UTF_8; diff --git a/spring-web/src/test/java/org/springframework/web/client/RestClientBuilderTests.java b/spring-web/src/test/java/org/springframework/web/client/RestClientBuilderTests.java index e328bcfb84..c06a22736f 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestClientBuilderTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestClientBuilderTests.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import org.assertj.core.api.InstanceOfAssertFactories; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.http.client.ClientHttpRequestInitializer; @@ -32,7 +33,6 @@ import org.springframework.http.client.JettyClientHttpRequestFactory; import org.springframework.http.client.support.BasicAuthenticationInterceptor; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.web.util.DefaultUriBuilderFactory; import static org.assertj.core.api.Assertions.assertThat; @@ -256,8 +256,7 @@ public class RestClientBuilderTests { ); } - @Nullable - private static Object fieldValue(String name, DefaultRestClientBuilder instance) { + private static @Nullable Object fieldValue(String name, DefaultRestClientBuilder instance) { try { Field field = DefaultRestClientBuilder.class.getDeclaredField(name); field.setAccessible(true); @@ -270,8 +269,7 @@ public class RestClientBuilderTests { } } - @Nullable - private static Object fieldValue(String name, RestClient instance) { + private static @Nullable Object fieldValue(String name, RestClient instance) { try { Field field = DefaultRestClient.class.getDeclaredField(name); field.setAccessible(true); diff --git a/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java b/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java index b8a2ad99d3..521d5e677e 100644 --- a/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/RestTemplateObservationTests.java @@ -26,6 +26,7 @@ import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationHandler; import io.micrometer.observation.tck.TestObservationRegistry; import io.micrometer.observation.tck.TestObservationRegistryAssert; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -39,7 +40,6 @@ import org.springframework.http.client.ClientHttpRequestFactory; import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.observation.ClientRequestObservationContext; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; @@ -234,8 +234,7 @@ class RestTemplateObservationTests { final TestObservationRegistry observationRegistry; - @Nullable - Observation currentObservation; + @Nullable Observation currentObservation; ObservationErrorHandler(TestObservationRegistry observationRegistry) { this.observationRegistry = observationRegistry; diff --git a/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java b/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java index 2f5e87f985..4abb8defbd 100644 --- a/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java +++ b/spring-web/src/test/java/org/springframework/web/client/support/RestClientAdapterTests.java @@ -30,6 +30,7 @@ import io.micrometer.observation.tck.TestObservationRegistry; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; @@ -37,7 +38,6 @@ import org.junit.jupiter.params.provider.MethodSource; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.CookieValue; diff --git a/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java b/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java index 7fdc186b6a..fdb076bf14 100644 --- a/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java +++ b/spring-web/src/test/java/org/springframework/web/context/request/ServletWebRequestHttpMethodsTests.java @@ -24,13 +24,13 @@ import java.time.Instant; import java.time.ZonedDateTime; import java.time.temporal.ChronoUnit; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; import org.springframework.web.testfixture.servlet.MockHttpServletResponse; diff --git a/spring-web/src/test/java/org/springframework/web/filter/UrlHandlerFilterTests.java b/spring-web/src/test/java/org/springframework/web/filter/UrlHandlerFilterTests.java index 41a4f21555..e8da060186 100644 --- a/spring-web/src/test/java/org/springframework/web/filter/UrlHandlerFilterTests.java +++ b/spring-web/src/test/java/org/springframework/web/filter/UrlHandlerFilterTests.java @@ -20,11 +20,11 @@ import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.testfixture.servlet.MockFilterChain; import org.springframework.web.testfixture.servlet.MockHttpServletRequest; diff --git a/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java b/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java index 3b5178d5b4..1909164095 100644 --- a/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java +++ b/spring-web/src/test/java/org/springframework/web/jsf/DelegatingNavigationHandlerTests.java @@ -18,11 +18,11 @@ package org.springframework.web.jsf; import jakarta.faces.application.NavigationHandler; import jakarta.faces.context.FacesContext; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.support.StaticListableBeanFactory; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java index 04e6c23155..4b3aec2f5a 100644 --- a/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/annotation/ModelAttributeMethodProcessorTests.java @@ -21,6 +21,7 @@ import java.lang.annotation.Target; import java.lang.reflect.Method; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -29,7 +30,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.SynthesizingMethodParameter; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.validation.BindingResult; import org.springframework.validation.Errors; import org.springframework.web.bind.MethodArgumentNotValidException; diff --git a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java index c14791d772..492f70e4a1 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/HandlerMethodValidationExceptionTests.java @@ -26,6 +26,7 @@ import java.util.function.Predicate; import jakarta.validation.Valid; import jakarta.validation.constraints.Size; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.beans.BeanUtils; @@ -33,7 +34,6 @@ import org.springframework.context.MessageSourceResolvable; import org.springframework.context.support.DefaultMessageSourceResolvable; import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.validation.BeanPropertyBindingResult; import org.springframework.validation.Errors; import org.springframework.validation.method.MethodValidationResult; diff --git a/spring-web/src/test/java/org/springframework/web/method/support/StubArgumentResolver.java b/spring-web/src/test/java/org/springframework/web/method/support/StubArgumentResolver.java index 52dd2fe975..e8ec8109a3 100644 --- a/spring-web/src/test/java/org/springframework/web/method/support/StubArgumentResolver.java +++ b/spring-web/src/test/java/org/springframework/web/method/support/StubArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.web.method.support; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; @@ -33,8 +34,7 @@ public class StubArgumentResolver implements HandlerMethodArgumentResolver { private final Class valueType; - @Nullable - private final Object value; + private final @Nullable Object value; private List resolvedParameters = new ArrayList<>(); diff --git a/spring-web/src/test/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessorTests.java b/spring-web/src/test/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessorTests.java index cc0960ed51..cd8e7567e0 100644 --- a/spring-web/src/test/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessorTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/annotation/HttpExchangeBeanRegistrationAotProcessorTests.java @@ -16,6 +16,7 @@ package org.springframework.web.service.annotation; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.aop.SpringProxy; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory; import org.springframework.beans.factory.support.RegisteredBean; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.core.DecoratingProxy; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.mock; @@ -67,8 +67,7 @@ class HttpExchangeBeanRegistrationAotProcessorTests { } } - @Nullable - private static BeanRegistrationAotContribution createContribution(Class beanClass) { + private static @Nullable BeanRegistrationAotContribution createContribution(Class beanClass) { DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); beanFactory.registerBeanDefinition(beanClass.getName(), new RootBeanDefinition(beanClass)); return new HttpExchangeBeanRegistrationAotProcessor() diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java index e2f87f01cc..d1be287fee 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpMethodArgumentResolverTests.java @@ -18,10 +18,10 @@ package org.springframework.web.service.invoker; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.web.service.annotation.GetExchange; import org.springframework.web.service.annotation.HttpExchange; @@ -95,8 +95,7 @@ class HttpMethodArgumentResolverTests { } - @Nullable - private HttpMethod getActualMethod() { + private @Nullable HttpMethod getActualMethod() { return this.client.getRequestValues().getHttpMethod(); } diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java index 90932f856b..804686bf0a 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/HttpServiceMethodTests.java @@ -27,6 +27,7 @@ import java.util.Optional; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Flowable; import io.reactivex.rxjava3.core.Single; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.web.service.annotation.GetExchange; import org.springframework.web.service.annotation.HttpExchange; import org.springframework.web.service.annotation.PostExchange; diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/NamedValueArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/NamedValueArgumentResolverTests.java index 4e677140b5..3e8495f608 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/NamedValueArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/NamedValueArgumentResolverTests.java @@ -27,13 +27,13 @@ import java.util.Map; import java.util.Optional; import org.apache.groovy.util.Maps; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; import org.springframework.core.annotation.AliasFor; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java index 4fdb1f08e5..3d5149ed62 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/PathVariableArgumentResolverTests.java @@ -16,9 +16,9 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.service.annotation.GetExchange; diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java index 2feaf15dce..8801672bb5 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestAttributeArgumentResolverTests.java @@ -16,9 +16,9 @@ package org.springframework.web.service.invoker; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.service.annotation.GetExchange; diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java index 3b82d00164..7c3822eb22 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/RequestBodyArgumentResolverTests.java @@ -20,12 +20,12 @@ import java.util.Optional; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Single; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; import org.springframework.core.ParameterizedTypeReference; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.service.annotation.GetExchange; @@ -168,18 +168,15 @@ class RequestBodyArgumentResolverTests { } - @Nullable - private Object getBodyValue() { + private @Nullable Object getBodyValue() { return getReactiveRequestValues().getBodyValue(); } - @Nullable - private Publisher getPublisherBody() { + private @Nullable Publisher getPublisherBody() { return getReactiveRequestValues().getBodyPublisher(); } - @Nullable - private ParameterizedTypeReference getBodyElementType() { + private @Nullable ParameterizedTypeReference getBodyElementType() { return getReactiveRequestValues().getBodyPublisherElementType(); } diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/TestExchangeAdapter.java b/spring-web/src/test/java/org/springframework/web/service/invoker/TestExchangeAdapter.java index b600d9d870..2cbe5aa2c1 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/TestExchangeAdapter.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/TestExchangeAdapter.java @@ -18,10 +18,11 @@ package org.springframework.web.service.invoker; import java.util.Collections; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import static org.assertj.core.api.Assertions.assertThat; @@ -33,14 +34,11 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class TestExchangeAdapter implements HttpExchangeAdapter { - @Nullable - private String invokedMethodName; + private @Nullable String invokedMethodName; - @Nullable - private HttpRequestValues requestValues; + private @Nullable HttpRequestValues requestValues; - @Nullable - private ParameterizedTypeReference bodyType; + private @Nullable ParameterizedTypeReference bodyType; public String getInvokedMethodName() { @@ -53,8 +51,7 @@ public class TestExchangeAdapter implements HttpExchangeAdapter { return this.requestValues; } - @Nullable - public ParameterizedTypeReference getBodyType() { + public @Nullable ParameterizedTypeReference getBodyType() { return this.bodyType; } diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolverTests.java index 36b8c9ec56..7a28a50106 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/UriBuilderFactoryArgumentResolverTests.java @@ -18,9 +18,9 @@ package org.springframework.web.service.invoker; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.web.service.annotation.GetExchange; import org.springframework.web.util.DefaultUriBuilderFactory; import org.springframework.web.util.UriBuilderFactory; diff --git a/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java b/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java index 2039e851a4..205370dfe2 100644 --- a/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java +++ b/spring-web/src/test/java/org/springframework/web/service/invoker/UrlArgumentResolverTests.java @@ -19,9 +19,9 @@ package org.springframework.web.service.invoker; import java.net.URI; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; import org.springframework.web.service.annotation.GetExchange; import static org.assertj.core.api.Assertions.assertThat; diff --git a/spring-web/src/test/java/org/springframework/web/util/WhatWgUrlParserTests.java b/spring-web/src/test/java/org/springframework/web/util/WhatWgUrlParserTests.java index 4ea6c21825..144cb4c698 100644 --- a/spring-web/src/test/java/org/springframework/web/util/WhatWgUrlParserTests.java +++ b/spring-web/src/test/java/org/springframework/web/util/WhatWgUrlParserTests.java @@ -16,10 +16,9 @@ package org.springframework.web.util; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; -import org.springframework.lang.Nullable; - import static org.assertj.core.api.Assertions.assertThat; /** diff --git a/spring-web/src/test/kotlin/org/springframework/http/ResponseEntityKotlinTests.kt b/spring-web/src/test/kotlin/org/springframework/http/ResponseEntityKotlinTests.kt index dfda75650d..6aec92f148 100644 --- a/spring-web/src/test/kotlin/org/springframework/http/ResponseEntityKotlinTests.kt +++ b/spring-web/src/test/kotlin/org/springframework/http/ResponseEntityKotlinTests.kt @@ -32,7 +32,7 @@ class ResponseEntityKotlinTests { val responseEntity = ResponseEntity.ofNullable(entity) assertThat(responseEntity).isNotNull() assertThat(responseEntity.statusCode).isEqualTo(HttpStatus.OK) - assertThat(responseEntity.body as Int).isEqualTo(entity) + assertThat(responseEntity.body).isEqualTo(entity) } @Test diff --git a/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt b/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt index 6bcd605b3c..78e2d4d008 100644 --- a/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt +++ b/spring-web/src/test/kotlin/org/springframework/web/client/RestOperationsExtensionsTests.kt @@ -20,6 +20,7 @@ import io.mockk.every import io.mockk.mockk import io.mockk.verify import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import org.springframework.core.ParameterizedTypeReference import org.springframework.http.* @@ -269,6 +270,7 @@ class RestOperationsExtensionsTests { } @Test + @Disabled("May require Kotlin 2") // TODO Enable after Kotlin 2 upgrade fun `RestOperations are available`() { val extensions = Class.forName("org.springframework.web.client.RestOperationsExtensionsKt") ReflectionUtils.doWithMethods(RestOperations::class.java) { method -> @@ -277,7 +279,9 @@ class RestOperationsExtensionsTests { val parameters = mutableListOf>(RestOperations::class.java).apply { addAll(method.parameterTypes.filter { it != kClass.java }) } val f = extensions.getDeclaredMethod(method.name, *parameters.toTypedArray()).kotlinFunction!! assertThat(f.typeParameters.size).isEqualTo(1) - assertThat(f.typeParameters[0].upperBounds).isEqualTo(listOf(Any::class.createType(nullable = true))) + val type = f.typeParameters[0].upperBounds.first() + assertThat(type.classifier).isEqualTo(Any::class) + assertThat(type.isMarkedNullable).isTrue() } } } diff --git a/spring-web/src/test/kotlin/org/springframework/web/client/support/KotlinRestTemplateHttpServiceProxyTests.kt b/spring-web/src/test/kotlin/org/springframework/web/client/support/KotlinRestTemplateHttpServiceProxyTests.kt index d427b89565..e093df1d9f 100644 --- a/spring-web/src/test/kotlin/org/springframework/web/client/support/KotlinRestTemplateHttpServiceProxyTests.kt +++ b/spring-web/src/test/kotlin/org/springframework/web/client/support/KotlinRestTemplateHttpServiceProxyTests.kt @@ -25,7 +25,6 @@ import org.junit.jupiter.api.Test import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ResponseEntity -import org.springframework.lang.Nullable import org.springframework.util.LinkedMultiValueMap import org.springframework.util.MultiValueMap import org.springframework.web.bind.annotation.* @@ -259,7 +258,7 @@ class KotlinRestTemplateHttpServiceProxyTests { fun getRequestWithPathVariable(@PathVariable id: String): ResponseEntity @GetExchange("/test/{id}") - fun getRequestWithDynamicUri(@Nullable uri: URI, @PathVariable id: String): Optional + fun getRequestWithDynamicUri(uri: URI?, @PathVariable id: String): Optional @PostExchange("/test") fun postRequestWithHeader(@RequestHeader("testHeaderName") testHeader: String, diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/MockClientHttpRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/MockClientHttpRequest.java index 1cf6a68e59..a7010b22ee 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/MockClientHttpRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/MockClientHttpRequest.java @@ -21,10 +21,11 @@ import java.net.URI; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; + 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; import org.springframework.web.testfixture.http.MockHttpOutputMessage; import org.springframework.web.util.UriComponentsBuilder; @@ -43,13 +44,11 @@ public class MockClientHttpRequest extends MockHttpOutputMessage implements Clie private URI uri; - @Nullable - private ClientHttpResponse clientHttpResponse; + private @Nullable ClientHttpResponse clientHttpResponse; private boolean executed = false; - @Nullable - Map attributes; + @Nullable Map attributes; /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/package-info.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/package-info.java index d153421f5c..c0b011a841 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/package-info.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/package-info.java @@ -1,9 +1,7 @@ /** * Contains mock request and response types for the imperative HTTP client */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.testfixture.http.client; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/package-info.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/package-info.java index 68dbdb5832..8e7f2e318b 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/package-info.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/client/reactive/package-info.java @@ -1,9 +1,7 @@ /** * Contains mock request and response types for the reactive HTTP client */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.testfixture.http.client.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java index d3c62d711e..4bd546ace4 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/MockServerHttpRequest.java @@ -26,6 +26,7 @@ import java.util.List; import java.util.Locale; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -38,7 +39,6 @@ import org.springframework.http.HttpRange; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.AbstractServerHttpRequest; import org.springframework.http.server.reactive.SslInfo; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MimeType; @@ -57,14 +57,11 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { private final MultiValueMap cookies; - @Nullable - private final InetSocketAddress localAddress; + private final @Nullable InetSocketAddress localAddress; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; - @Nullable - private final SslInfo sslInfo; + private final @Nullable SslInfo sslInfo; private final Flux body; @@ -83,20 +80,17 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { @Override - @Nullable - public InetSocketAddress getLocalAddress() { + public @Nullable InetSocketAddress getLocalAddress() { return this.localAddress; } @Override - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.remoteAddress; } @Override - @Nullable - protected SslInfo initSslInfo() { + protected @Nullable SslInfo initSslInfo() { return this.sslInfo; } @@ -422,8 +416,7 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { private final URI url; - @Nullable - private String contextPath; + private @Nullable String contextPath; private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance(); @@ -431,14 +424,11 @@ public final class MockServerHttpRequest extends AbstractServerHttpRequest { private final MultiValueMap cookies = new LinkedMultiValueMap<>(); - @Nullable - private InetSocketAddress remoteAddress; + private @Nullable InetSocketAddress remoteAddress; - @Nullable - private InetSocketAddress localAddress; + private @Nullable InetSocketAddress localAddress; - @Nullable - private SslInfo sslInfo; + private @Nullable SslInfo sslInfo; DefaultBodyBuilder(HttpMethod method, URI url) { this.method = method; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/package-info.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/package-info.java index cc95fcf042..2240283cbe 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/package-info.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/http/server/reactive/package-info.java @@ -1,9 +1,7 @@ /** * For @NonNull annotations on implementation classes */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.testfixture.http.server.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java index abd6b2c051..61cd92370d 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/method/ResolvableMethod.java @@ -32,6 +32,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.cglib.core.SpringNamingPolicy; import org.springframework.cglib.proxy.Callback; @@ -47,7 +48,6 @@ import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; 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.Assert; @@ -617,12 +617,10 @@ public class ResolvableMethod { private static class MethodInvocationInterceptor implements MethodInterceptor, InvocationHandler { - @Nullable - private Method invokedMethod; + private @Nullable Method invokedMethod; @Override - @Nullable - public Object intercept(Object object, Method method, @Nullable Object[] args, @Nullable MethodProxy proxy) { + public @Nullable Object intercept(Object object, Method method, Object @Nullable [] args, @Nullable MethodProxy proxy) { if (ReflectionUtils.isObjectMethod(method)) { return ReflectionUtils.invokeMethod(method, object, args); } @@ -633,13 +631,11 @@ public class ResolvableMethod { } @Override - @Nullable - public Object invoke(Object proxy, Method method, @Nullable Object[] args) { + public @Nullable Object invoke(Object proxy, Method method, Object @Nullable [] args) { return intercept(proxy, method, args, null); } - @Nullable - Method getInvokedMethod() { + @Nullable Method getInvokedMethod() { return this.invokedMethod; } } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockServerWebExchange.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockServerWebExchange.java index 82635bd181..3ede08c4d0 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockServerWebExchange.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockServerWebExchange.java @@ -16,10 +16,10 @@ package org.springframework.web.testfixture.server; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.web.server.WebSession; import org.springframework.web.server.adapter.DefaultServerWebExchange; import org.springframework.web.server.i18n.AcceptHeaderLocaleContextResolver; @@ -99,8 +99,7 @@ public final class MockServerWebExchange extends DefaultServerWebExchange { private final MockServerHttpRequest request; - @Nullable - private WebSessionManager sessionManager; + private @Nullable WebSessionManager sessionManager; public Builder(MockServerHttpRequest request) { diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockWebSession.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockWebSession.java index 689418372f..73f127234a 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockWebSession.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/MockWebSession.java @@ -21,9 +21,9 @@ import java.time.Duration; import java.time.Instant; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.WebSession; import org.springframework.web.server.session.InMemoryWebSessionStore; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/package-info.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/package-info.java index 54867a2423..1646b7468f 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/package-info.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/server/package-info.java @@ -1,9 +1,7 @@ /** * For @NonNull annotations on implementation classes */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.testfixture.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/HeaderValueHolder.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/HeaderValueHolder.java index c1659d97cd..3416aadf69 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/HeaderValueHolder.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/HeaderValueHolder.java @@ -21,7 +21,8 @@ import java.util.Collections; import java.util.LinkedList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; /** @@ -63,13 +64,11 @@ class HeaderValueHolder { return this.values.stream().map(Object::toString).toList(); } - @Nullable - Object getValue() { + @Nullable Object getValue() { return (!this.values.isEmpty() ? this.values.get(0) : null); } - @Nullable - String getStringValue() { + @Nullable String getStringValue() { return (!this.values.isEmpty() ? String.valueOf(this.values.get(0)) : null); } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockAsyncContext.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockAsyncContext.java index f01b2b7411..d403c7424a 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockAsyncContext.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockAsyncContext.java @@ -29,9 +29,9 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.util.WebUtils; @@ -45,13 +45,11 @@ public class MockAsyncContext implements AsyncContext { private final HttpServletRequest request; - @Nullable - private final HttpServletResponse response; + private final @Nullable HttpServletResponse response; private final List listeners = new ArrayList<>(); - @Nullable - private String dispatchedPath; + private @Nullable String dispatchedPath; private long timeout = 10 * 1000L; @@ -82,8 +80,7 @@ public class MockAsyncContext implements AsyncContext { } @Override - @Nullable - public ServletResponse getResponse() { + public @Nullable ServletResponse getResponse() { return this.response; } @@ -110,8 +107,7 @@ public class MockAsyncContext implements AsyncContext { } } - @Nullable - public String getDispatchedPath() { + public @Nullable String getDispatchedPath() { return this.dispatchedPath; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockBodyContent.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockBodyContent.java index 63b566828f..9e068196df 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockBodyContent.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockBodyContent.java @@ -24,8 +24,7 @@ import java.io.Writer; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.JspWriter; import jakarta.servlet.jsp.tagext.BodyContent; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of the {@link jakarta.servlet.jsp.tagext.BodyContent} class. diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java index 9d01ad1c6d..73053568d3 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockCookie.java @@ -21,9 +21,9 @@ import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import jakarta.servlet.http.Cookie; +import org.jspecify.annotations.Nullable; import org.springframework.core.style.ToStringCreator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -54,8 +54,7 @@ public class MockCookie extends Cookie { private static final String EXPIRES = "Expires"; - @Nullable - private ZonedDateTime expires; + private @Nullable ZonedDateTime expires; /** @@ -81,8 +80,7 @@ public class MockCookie extends Cookie { * @return the "Expires" attribute for this cookie, or {@code null} if not set * @since 5.1.11 */ - @Nullable - public ZonedDateTime getExpires() { + public @Nullable ZonedDateTime getExpires() { return this.expires; } @@ -101,8 +99,7 @@ public class MockCookie extends Cookie { * Get the "SameSite" attribute for this cookie. * @return the "SameSite" attribute for this cookie, or {@code null} if not set */ - @Nullable - public String getSameSite() { + public @Nullable String getSameSite() { return getAttribute(SAME_SITE); } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java index 03ed3b0d3e..b42d4fe7df 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterChain.java @@ -28,8 +28,8 @@ import jakarta.servlet.Servlet; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -50,16 +50,13 @@ import org.springframework.util.ObjectUtils; */ public class MockFilterChain implements FilterChain { - @Nullable - private ServletRequest request; + private @Nullable ServletRequest request; - @Nullable - private ServletResponse response; + private @Nullable ServletResponse response; private final List filters; - @Nullable - private Iterator iterator; + private @Nullable Iterator iterator; /** @@ -100,16 +97,14 @@ public class MockFilterChain implements FilterChain { /** * Return the request that {@link #doFilter} has been called with. */ - @Nullable - public ServletRequest getRequest() { + public @Nullable ServletRequest getRequest() { return this.request; } /** * Return the response that {@link #doFilter} has been called with. */ - @Nullable - public ServletResponse getResponse() { + public @Nullable ServletResponse getResponse() { return this.response; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterConfig.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterConfig.java index 931f043df5..5589bb5cd4 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterConfig.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterConfig.java @@ -23,8 +23,8 @@ import java.util.Map; import jakarta.servlet.FilterConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterRegistration.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterRegistration.java index 9a165b1a95..3ef3ce9590 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterRegistration.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockFilterRegistration.java @@ -29,8 +29,7 @@ import java.util.Set; import jakarta.servlet.DispatcherType; import jakarta.servlet.FilterRegistration; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of {@link FilterRegistration}. @@ -68,9 +67,8 @@ public class MockFilterRegistration implements FilterRegistration.Dynamic { return this.name; } - @Nullable @Override - public String getClassName() { + public @Nullable String getClassName() { return this.className; } @@ -79,9 +77,8 @@ public class MockFilterRegistration implements FilterRegistration.Dynamic { return (this.initParameters.putIfAbsent(name, value) != null); } - @Nullable @Override - public String getInitParameter(String name) { + public @Nullable String getInitParameter(String name) { return this.initParameters.get(name); } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletMapping.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletMapping.java index b24ed628e5..3a919cb765 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletMapping.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletMapping.java @@ -18,8 +18,7 @@ package org.springframework.web.testfixture.servlet; import jakarta.servlet.http.HttpServletMapping; import jakarta.servlet.http.MappingMatch; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of {@link HttpServletMapping}. @@ -35,8 +34,7 @@ public class MockHttpServletMapping implements HttpServletMapping { private final String servletName; - @Nullable - private final MappingMatch mappingMatch; + private final @Nullable MappingMatch mappingMatch; public MockHttpServletMapping( @@ -65,8 +63,7 @@ public class MockHttpServletMapping implements HttpServletMapping { } @Override - @Nullable - public MappingMatch getMappingMatch() { + public @Nullable MappingMatch getMappingMatch() { return this.mappingMatch; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java index c909946b92..28424e4150 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletRequest.java @@ -62,10 +62,10 @@ import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpUpgradeHandler; import jakarta.servlet.http.MappingMatch; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; 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; @@ -170,20 +170,15 @@ public class MockHttpServletRequest implements HttpServletRequest { private final Map attributes = new LinkedHashMap<>(); - @Nullable - private String characterEncoding; + private @Nullable String characterEncoding; - @Nullable - private byte[] content; + private byte @Nullable [] content; - @Nullable - private String contentType; + private @Nullable String contentType; - @Nullable - private ServletInputStream inputStream; + private @Nullable ServletInputStream inputStream; - @Nullable - private BufferedReader reader; + private @Nullable BufferedReader reader; private final Map parameters = new LinkedHashMap<>(16); @@ -216,8 +211,7 @@ public class MockHttpServletRequest implements HttpServletRequest { private boolean asyncSupported = false; - @Nullable - private MockAsyncContext asyncContext; + private @Nullable MockAsyncContext asyncContext; private DispatcherType dispatcherType = DispatcherType.REQUEST; @@ -226,46 +220,35 @@ public class MockHttpServletRequest implements HttpServletRequest { // HttpServletRequest properties // --------------------------------------------------------------------- - @Nullable - private String authType; + private @Nullable String authType; - @Nullable - private Cookie[] cookies; + private @Nullable Cookie[] cookies; private final Map headers = new LinkedCaseInsensitiveMap<>(); - @Nullable - private String method; + private @Nullable String method; - @Nullable - private String pathInfo; + private @Nullable String pathInfo; private String contextPath = ""; - @Nullable - private String queryString; + private @Nullable String queryString; - @Nullable - private String remoteUser; + private @Nullable String remoteUser; private final Set userRoles = new HashSet<>(); - @Nullable - private Principal userPrincipal; + private @Nullable Principal userPrincipal; - @Nullable - private String requestedSessionId; + private @Nullable String requestedSessionId; - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; - @Nullable - private String requestURI; + private @Nullable String requestURI; private String servletPath = ""; - @Nullable - private HttpSession session; + private @Nullable HttpSession session; private boolean requestedSessionIdValid = true; @@ -275,8 +258,7 @@ public class MockHttpServletRequest implements HttpServletRequest { private final MultiValueMap parts = new LinkedMultiValueMap<>(); - @Nullable - private HttpServletMapping httpServletMapping; + private @Nullable HttpServletMapping httpServletMapping; // --------------------------------------------------------------------- @@ -385,8 +367,7 @@ public class MockHttpServletRequest implements HttpServletRequest { // --------------------------------------------------------------------- @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { checkActive(); return this.attributes.get(name); } @@ -398,8 +379,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getCharacterEncoding() { + public @Nullable String getCharacterEncoding() { return this.characterEncoding; } @@ -428,7 +408,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #getContentAsByteArray() * @see #getContentAsString() */ - public void setContent(@Nullable byte[] content) { + public void setContent(byte @Nullable [] content) { this.content = content; this.inputStream = null; this.reader = null; @@ -441,8 +421,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setContent(byte[]) * @see #getContentAsString() */ - @Nullable - public byte[] getContentAsByteArray() { + public byte @Nullable [] getContentAsByteArray() { return this.content; } @@ -457,8 +436,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * @see #setCharacterEncoding(String) * @see #getContentAsByteArray() */ - @Nullable - public String getContentAsString() throws IllegalStateException, UnsupportedEncodingException { + public @Nullable String getContentAsString() throws IllegalStateException, UnsupportedEncodingException { Assert.state(this.characterEncoding != null, "Cannot get content as a String for a null character encoding. " + "Consider setting the characterEncoding in the request."); @@ -501,8 +479,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -627,8 +604,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getParameter(String name) { + public @Nullable String getParameter(String name) { Assert.notNull(name, "Parameter name must not be null"); String[] arr = this.parameters.get(name); return (arr != null && arr.length > 0 ? arr[0] : null); @@ -640,8 +616,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String[] getParameterValues(String name) { + public @Nullable String[] getParameterValues(String name) { Assert.notNull(name, "Parameter name must not be null"); return this.parameters.get(name); } @@ -964,8 +939,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public AsyncContext getAsyncContext() { + public @Nullable AsyncContext getAsyncContext() { return this.asyncContext; } @@ -1020,8 +994,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getAuthType() { + public @Nullable String getAuthType() { return this.authType; } @@ -1042,8 +1015,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public Cookie[] getCookies() { + public @Nullable Cookie[] getCookies() { return this.cookies; } @@ -1165,8 +1137,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { HeaderValueHolder header = this.headers.get(name); return (header != null ? header.getStringValue() : null); } @@ -1206,8 +1177,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getMethod() { + public @Nullable String getMethod() { return this.method; } @@ -1216,14 +1186,12 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getPathInfo() { + public @Nullable String getPathInfo() { return this.pathInfo; } @Override - @Nullable - public String getPathTranslated() { + public @Nullable String getPathTranslated() { return (this.pathInfo != null ? this.servletContext.getRealPath(this.pathInfo) : null); } @@ -1241,8 +1209,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getQueryString() { + public @Nullable String getQueryString() { return this.queryString; } @@ -1251,8 +1218,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getRemoteUser() { + public @Nullable String getRemoteUser() { return this.remoteUser; } @@ -1272,8 +1238,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public Principal getUserPrincipal() { + public @Nullable Principal getUserPrincipal() { return this.userPrincipal; } @@ -1282,8 +1247,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getRequestedSessionId() { + public @Nullable String getRequestedSessionId() { return this.requestedSessionId; } @@ -1300,8 +1264,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * Return the original URI template used to prepare the request, if any. * @since 6.2 */ - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } @@ -1310,8 +1273,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public String getRequestURI() { + public @Nullable String getRequestURI() { return this.requestURI; } @@ -1350,8 +1312,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public HttpSession getSession(boolean create) { + public @Nullable HttpSession getSession(boolean create) { checkActive(); // Reset session if invalidated. if (this.session instanceof MockHttpSession mockSession && mockSession.isInvalid()) { @@ -1365,8 +1326,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public HttpSession getSession() { + public @Nullable HttpSession getSession() { return getSession(true); } @@ -1434,8 +1394,7 @@ public class MockHttpServletRequest implements HttpServletRequest { } @Override - @Nullable - public Part getPart(String name) throws IOException, ServletException { + public @Nullable Part getPart(String name) throws IOException, ServletException { return this.parts.getFirst(name); } @@ -1465,8 +1424,7 @@ public class MockHttpServletRequest implements HttpServletRequest { * This helps {@link org.springframework.web.util.ServletRequestPathUtils} * to take into account the Servlet path when parsing the requestURI. */ - @Nullable - private MappingMatch determineMappingMatch() { + private @Nullable MappingMatch determineMappingMatch() { if (StringUtils.hasText(this.requestURI) && StringUtils.hasText(this.servletPath)) { String path = UrlPathHelper.defaultInstance.getRequestUri(this); String prefix = this.contextPath + this.servletPath; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java index c51560554e..fe31513e9c 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java @@ -43,10 +43,10 @@ import java.util.TimeZone; import jakarta.servlet.ServletOutputStream; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; 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; @@ -99,13 +99,11 @@ public class MockHttpServletResponse implements HttpServletResponse { private final ServletOutputStream outputStream = new ResponseServletOutputStream(this.content); - @Nullable - private PrintWriter writer; + private @Nullable PrintWriter writer; private long contentLength = 0; - @Nullable - private String contentType; + private @Nullable String contentType; private int bufferSize = 4096; @@ -124,16 +122,14 @@ public class MockHttpServletResponse implements HttpServletResponse { private int status = HttpServletResponse.SC_OK; - @Nullable - private String errorMessage; + private @Nullable String errorMessage; //--------------------------------------------------------------------- // Properties for MockRequestDispatcher //--------------------------------------------------------------------- - @Nullable - private String forwardedUrl; + private @Nullable String forwardedUrl; private final List includedUrls = new ArrayList<>(); @@ -372,8 +368,7 @@ public class MockHttpServletResponse implements HttpServletResponse { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -510,8 +505,7 @@ public class MockHttpServletResponse implements HttpServletResponse { return this.cookies.toArray(new Cookie[0]); } - @Nullable - public Cookie getCookie(String name) { + public @Nullable Cookie getCookie(String name) { Assert.notNull(name, "Cookie name must not be null"); for (Cookie cookie : this.cookies) { if (name.equals(cookie.getName())) { @@ -546,8 +540,7 @@ public class MockHttpServletResponse implements HttpServletResponse { * @see HttpServletResponse#getHeader(String) */ @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { HeaderValueHolder header = this.headers.get(name); return (header != null ? header.getStringValue() : null); } @@ -577,8 +570,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) { + public @Nullable Object getHeaderValue(String name) { HeaderValueHolder header = this.headers.get(name); return (header != null ? header.getValue() : null); } @@ -649,8 +641,7 @@ public class MockHttpServletResponse implements HttpServletResponse { setCommitted(true); } - @Nullable - public String getRedirectedUrl() { + public @Nullable String getRedirectedUrl() { return getHeader(HttpHeaders.LOCATION); } @@ -807,8 +798,7 @@ public class MockHttpServletResponse implements HttpServletResponse { /** * Return the error message used when calling {@link HttpServletResponse#sendError(int, String)}. */ - @Nullable - public String getErrorMessage() { + public @Nullable String getErrorMessage() { return this.errorMessage; } @@ -821,8 +811,7 @@ public class MockHttpServletResponse implements HttpServletResponse { this.forwardedUrl = forwardedUrl; } - @Nullable - public String getForwardedUrl() { + public @Nullable String getForwardedUrl() { return this.forwardedUrl; } @@ -833,8 +822,7 @@ public class MockHttpServletResponse implements HttpServletResponse { } } - @Nullable - public String getIncludedUrl() { + public @Nullable String getIncludedUrl() { int count = this.includedUrls.size(); Assert.state(count <= 1, () -> "More than 1 URL included - check getIncludedUrls instead: " + this.includedUrls); diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpSession.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpSession.java index 0ec6fae4b8..f497369558 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpSession.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpSession.java @@ -29,8 +29,8 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpSessionBindingEvent; import jakarta.servlet.http.HttpSessionBindingListener; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockJspWriter.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockJspWriter.java index 86c62131e8..d0d905167a 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockJspWriter.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockJspWriter.java @@ -22,8 +22,7 @@ import java.io.Writer; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.JspWriter; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of the {@link jakarta.servlet.jsp.JspWriter} class. @@ -36,8 +35,7 @@ public class MockJspWriter extends JspWriter { private final HttpServletResponse response; - @Nullable - private PrintWriter targetWriter; + private @Nullable PrintWriter targetWriter; /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java index 849731ac5a..3a55a9c504 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartFile.java @@ -21,8 +21,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import org.springframework.lang.NonNull; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.NonNull; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.web.multipart.MultipartFile; @@ -45,8 +46,7 @@ public class MockMultipartFile implements MultipartFile { private final String originalFilename; - @Nullable - private final String contentType; + private final @Nullable String contentType; private final byte[] content; @@ -56,7 +56,7 @@ public class MockMultipartFile implements MultipartFile { * @param name the name of the file * @param content the content of the file */ - public MockMultipartFile(String name, @Nullable byte[] content) { + public MockMultipartFile(String name, byte @Nullable [] content) { this(name, "", null, content); } @@ -78,7 +78,7 @@ public class MockMultipartFile implements MultipartFile { * @param content the content of the file */ public MockMultipartFile( - String name, @Nullable String originalFilename, @Nullable String contentType, @Nullable byte[] content) { + String name, @Nullable String originalFilename, @Nullable String contentType, byte @Nullable [] content) { Assert.hasLength(name, "Name must not be empty"); this.name = name; @@ -109,14 +109,12 @@ public class MockMultipartFile implements MultipartFile { } @Override - @NonNull - public String getOriginalFilename() { + public @NonNull String getOriginalFilename() { return this.originalFilename; } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartHttpServletRequest.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartHttpServletRequest.java index 24d2b464b5..a7c0c8b9af 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartHttpServletRequest.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockMultipartHttpServletRequest.java @@ -28,10 +28,10 @@ import java.util.Objects; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; 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; diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPageContext.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPageContext.java index 6476710dad..d6fab65d89 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPageContext.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPageContext.java @@ -36,8 +36,8 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.jsp.JspWriter; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -63,8 +63,7 @@ public class MockPageContext extends PageContext { private final Map attributes = new LinkedHashMap<>(); - @Nullable - private JspWriter out; + private @Nullable JspWriter out; /** @@ -163,15 +162,13 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); return this.attributes.get(name); } @Override - @Nullable - public Object getAttribute(String name, int scope) { + public @Nullable Object getAttribute(String name, int scope) { Assert.notNull(name, "Attribute name must not be null"); return switch (scope) { case PAGE_SCOPE -> getAttribute(name); @@ -186,8 +183,7 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public Object findAttribute(String name) { + public @Nullable Object findAttribute(String name) { Object value = getAttribute(name); if (value == null) { value = getAttribute(name, REQUEST_SCOPE); @@ -268,8 +264,7 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public ELContext getELContext() { + public @Nullable ELContext getELContext() { return null; } @@ -294,8 +289,7 @@ public class MockPageContext extends PageContext { } @Override - @Nullable - public Exception getException() { + public @Nullable Exception getException() { return null; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPart.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPart.java index 82688a6f78..99715488dc 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPart.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockPart.java @@ -23,10 +23,10 @@ import java.util.Collection; import java.util.Collections; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,8 +42,7 @@ public class MockPart implements Part { private final String name; - @Nullable - private final String filename; + private final @Nullable String filename; private final byte[] content; @@ -54,7 +53,7 @@ public class MockPart implements Part { * Constructor for a part with a name and content only. * @see #getHeaders() */ - public MockPart(String name, @Nullable byte[] content) { + public MockPart(String name, byte @Nullable [] content) { this(name, null, content); } @@ -62,7 +61,7 @@ public class MockPart implements Part { * Constructor for a part with a name, filename, and content. * @see #getHeaders() */ - public MockPart(String name, @Nullable String filename, @Nullable byte[] content) { + public MockPart(String name, @Nullable String filename, byte @Nullable [] content) { this(name, filename, content, null); } @@ -71,7 +70,7 @@ public class MockPart implements Part { * @since 6.1.2 * @see #getHeaders() */ - public MockPart(String name, @Nullable String filename, @Nullable byte[] content, @Nullable MediaType contentType) { + public MockPart(String name, @Nullable String filename, byte @Nullable [] content, @Nullable MediaType contentType) { Assert.hasLength(name, "'name' must not be empty"); this.name = name; this.filename = filename; @@ -87,14 +86,12 @@ public class MockPart implements Part { } @Override - @Nullable - public String getSubmittedFileName() { + public @Nullable String getSubmittedFileName() { return this.filename; } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { MediaType contentType = this.headers.getContentType(); return (contentType != null ? contentType.toString() : null); } @@ -120,8 +117,7 @@ public class MockPart implements Part { } @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { return this.headers.getFirst(name); } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletConfig.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletConfig.java index 17f4541a13..33a970cbe4 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletConfig.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletConfig.java @@ -23,8 +23,8 @@ import java.util.Map; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletContext.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletContext.java index c7f6f28149..32bff6a2d0 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletContext.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockServletContext.java @@ -43,13 +43,13 @@ import jakarta.servlet.SessionTrackingMode; import jakarta.servlet.descriptor.JspConfigDescriptor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.DefaultResourceLoader; 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.CollectionUtils; @@ -132,18 +132,15 @@ public class MockServletContext implements ServletContext { private final Set declaredRoles = new LinkedHashSet<>(); - @Nullable - private Set sessionTrackingModes; + private @Nullable Set sessionTrackingModes; private final SessionCookieConfig sessionCookieConfig = new MockSessionCookieConfig(); private int sessionTimeout; - @Nullable - private String requestCharacterEncoding; + private @Nullable String requestCharacterEncoding; - @Nullable - private String responseCharacterEncoding; + private @Nullable String responseCharacterEncoding; private final Map filterRegistrations = new LinkedHashMap<>(); @@ -226,8 +223,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public ServletContext getContext(String contextPath) { + public @Nullable ServletContext getContext(String contextPath) { if (this.contextPath.equals(contextPath)) { return this; } @@ -271,8 +267,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public String getMimeType(String filePath) { + public @Nullable String getMimeType(String filePath) { String extension = StringUtils.getFilenameExtension(filePath); if (this.mimeTypes.containsKey(extension)) { return this.mimeTypes.get(extension).toString(); @@ -295,8 +290,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public Set getResourcePaths(String path) { + public @Nullable Set getResourcePaths(String path) { String actualPath = (path.endsWith("/") ? path : path + "/"); String resourceLocation = getResourceLocation(actualPath); Resource resource = null; @@ -327,8 +321,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public URL getResource(String path) throws MalformedURLException { + public @Nullable URL getResource(String path) throws MalformedURLException { String resourceLocation = getResourceLocation(path); Resource resource = null; try { @@ -351,8 +344,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public InputStream getResourceAsStream(String path) { + public @Nullable InputStream getResourceAsStream(String path) { String resourceLocation = getResourceLocation(path); Resource resource = null; try { @@ -379,8 +371,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public RequestDispatcher getNamedDispatcher(String path) { + public @Nullable RequestDispatcher getNamedDispatcher(String path) { return this.namedRequestDispatchers.get(path); } @@ -446,8 +437,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public String getRealPath(String path) { + public @Nullable String getRealPath(String path) { String resourceLocation = getResourceLocation(path); Resource resource = null; try { @@ -469,8 +459,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public String getInitParameter(String name) { + public @Nullable String getInitParameter(String name) { Assert.notNull(name, "Parameter name must not be null"); return this.initParameters.get(name); } @@ -496,8 +485,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { Assert.notNull(name, "Attribute name must not be null"); return this.attributes.get(name); } @@ -534,8 +522,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -590,8 +577,7 @@ public class MockServletContext implements ServletContext { } @Override // on Servlet 4.0 - @Nullable - public String getRequestCharacterEncoding() { + public @Nullable String getRequestCharacterEncoding() { return this.requestCharacterEncoding; } @@ -601,8 +587,7 @@ public class MockServletContext implements ServletContext { } @Override // on Servlet 4.0 - @Nullable - public String getResponseCharacterEncoding() { + public @Nullable String getResponseCharacterEncoding() { return this.responseCharacterEncoding; } @@ -615,8 +600,7 @@ public class MockServletContext implements ServletContext { } @Override - @Nullable - public FilterRegistration getFilterRegistration(String filterName) { + public @Nullable FilterRegistration getFilterRegistration(String filterName) { return this.filterRegistrations.get(filterName); } @@ -665,8 +649,7 @@ public class MockServletContext implements ServletContext { * @see jakarta.servlet.ServletContext#getServletRegistration(java.lang.String) */ @Override - @Nullable - public ServletRegistration getServletRegistration(String servletName) { + public @Nullable ServletRegistration getServletRegistration(String servletName) { return null; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockSessionCookieConfig.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockSessionCookieConfig.java index 07a76626b2..2aed89467e 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockSessionCookieConfig.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockSessionCookieConfig.java @@ -21,8 +21,7 @@ import java.util.LinkedHashMap; import java.util.Map; import jakarta.servlet.SessionCookieConfig; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Mock implementation of the {@link jakarta.servlet.SessionCookieConfig} interface. @@ -33,17 +32,13 @@ import org.springframework.lang.Nullable; */ public class MockSessionCookieConfig implements SessionCookieConfig { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String domain; + private @Nullable String domain; - @Nullable - private String path; + private @Nullable String path; - @Nullable - private String comment; + private @Nullable String comment; private boolean httpOnly; @@ -60,8 +55,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -71,8 +65,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getDomain() { + public @Nullable String getDomain() { return this.domain; } @@ -82,8 +75,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.path; } @@ -95,8 +87,7 @@ public class MockSessionCookieConfig implements SessionCookieConfig { @SuppressWarnings("removal") @Override - @Nullable - public String getComment() { + public @Nullable String getComment() { return this.comment; } diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java index 1b54587e56..8a1432bb0b 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/PassThroughFilterChain.java @@ -24,8 +24,8 @@ import jakarta.servlet.Servlet; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -42,14 +42,11 @@ import org.springframework.util.Assert; */ public class PassThroughFilterChain implements FilterChain { - @Nullable - private Filter filter; + private @Nullable Filter filter; - @Nullable - private FilterChain nextFilterChain; + private @Nullable FilterChain nextFilterChain; - @Nullable - private Servlet servlet; + private @Nullable Servlet servlet; /** diff --git a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java index 9350b3060b..97a38a8585 100644 --- a/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java +++ b/spring-web/src/testFixtures/java/org/springframework/web/testfixture/xml/Pojo.java @@ -17,8 +17,7 @@ package org.springframework.web.testfixture.xml; import jakarta.xml.bind.annotation.XmlRootElement; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Sebastien Deleuze 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 6f9a4b95a5..3826346d33 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 @@ -20,11 +20,12 @@ import java.lang.annotation.Annotation; import java.util.Collection; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.DataBinder; @@ -52,8 +53,7 @@ import org.springframework.web.server.ServerWebExchange; */ public class BindingContext { - @Nullable - private final WebBindingInitializer initializer; + private final @Nullable WebBindingInitializer initializer; private final Model model = new BindingAwareConcurrentModel(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java index 996c672c00..cda5cdfb30 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java @@ -21,6 +21,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -29,7 +30,6 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.cors.reactive.CorsUtils; import org.springframework.web.cors.reactive.PreFlightRequestHandler; @@ -71,14 +71,11 @@ import org.springframework.web.server.adapter.WebHttpHandlerBuilder; */ public class DispatcherHandler implements WebHandler, PreFlightRequestHandler, ApplicationContextAware { - @Nullable - private List handlerMappings; + private @Nullable List handlerMappings; - @Nullable - private List handlerAdapters; + private @Nullable List handlerAdapters; - @Nullable - private List resultHandlers; + private @Nullable List resultHandlers; /** @@ -105,8 +102,7 @@ public class DispatcherHandler implements WebHandler, PreFlightRequestHandler, A * prior to {@link #setApplicationContext(ApplicationContext)}. * @return immutable list with the configured mappings or {@code null} */ - @Nullable - public final List getHandlerMappings() { + public final @Nullable List getHandlerMappings() { return this.handlerMappings; } 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 c9a970fbaf..a4f4ac6691 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 @@ -16,9 +16,10 @@ package org.springframework.web.reactive; +import org.jspecify.annotations.Nullable; + 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; @@ -32,15 +33,13 @@ public class HandlerResult { private final Object handler; - @Nullable - private final Object returnValue; + private final @Nullable Object returnValue; private final ResolvableType returnType; private final BindingContext bindingContext; - @Nullable - private DispatchExceptionHandler exceptionHandler; + private @Nullable DispatchExceptionHandler exceptionHandler; /** @@ -82,8 +81,7 @@ public class HandlerResult { /** * Return the value returned from the handler, if any. */ - @Nullable - public Object getReturnValue() { + public @Nullable Object getReturnValue() { return this.returnValue; } @@ -137,8 +135,7 @@ public class HandlerResult { * configured} exception handler. * @since 6.0 */ - @Nullable - public DispatchExceptionHandler getExceptionHandler() { + public @Nullable DispatchExceptionHandler getExceptionHandler() { return this.exceptionHandler; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java index b74cc841f9..e4e6126116 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/accept/RequestedContentTypeResolverBuilder.java @@ -24,8 +24,9 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * Builder for a composite {@link RequestedContentTypeResolver} that delegates @@ -115,8 +116,7 @@ public class RequestedContentTypeResolverBuilder { private final Map mediaTypes = new HashMap<>(); - @Nullable - private String parameterName; + private @Nullable String parameterName; /** * Configure a mapping between a lookup key (extracted from a query 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 a9693904f1..c37fb6c233 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,9 +3,7 @@ * strategy and implementations to resolve the requested content type for a * given request. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.accept; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/BlockingExecutionConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/BlockingExecutionConfigurer.java index ca56c99549..8fb2e2ddc8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/BlockingExecutionConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/BlockingExecutionConfigurer.java @@ -18,8 +18,9 @@ package org.springframework.web.reactive.config; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.AsyncTaskExecutor; -import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; /** @@ -30,11 +31,9 @@ import org.springframework.web.method.HandlerMethod; */ public class BlockingExecutionConfigurer { - @Nullable - private AsyncTaskExecutor executor; + private @Nullable AsyncTaskExecutor executor; - @Nullable - private Predicate blockingControllerMethodPredicate; + private @Nullable Predicate blockingControllerMethodPredicate; /** @@ -63,13 +62,11 @@ public class BlockingExecutionConfigurer { } - @Nullable - protected AsyncTaskExecutor getExecutor() { + protected @Nullable AsyncTaskExecutor getExecutor() { return this.executor; } - @Nullable - protected Predicate getBlockingControllerMethodPredicate() { + protected @Nullable Predicate getBlockingControllerMethodPredicate() { return this.blockingControllerMethodPredicate; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java index bc7ca8d50f..e2aaa147bb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/DelegatingWebFluxConfiguration.java @@ -18,11 +18,12 @@ package org.springframework.web.reactive.config; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; 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; @@ -65,15 +66,13 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport } @Override - @Nullable - protected Validator getValidator() { + protected @Nullable Validator getValidator() { Validator validator = this.configurers.getValidator(); return (validator != null ? validator : super.getValidator()); } @Override - @Nullable - protected MessageCodesResolver getMessageCodesResolver() { + protected @Nullable MessageCodesResolver getMessageCodesResolver() { MessageCodesResolver messageCodesResolver = this.configurers.getMessageCodesResolver(); return (messageCodesResolver != null ? messageCodesResolver : super.getMessageCodesResolver()); } @@ -120,8 +119,7 @@ public class DelegatingWebFluxConfiguration extends WebFluxConfigurationSupport } @Override - @Nullable - protected WebSocketService getWebSocketService() { + protected @Nullable WebSocketService getWebSocketService() { WebSocketService service = this.configurers.getWebSocketService(); return (service != null ? service : super.getWebSocketService()); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java index 58cc38a744..e0fce27ff1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/PathMatchConfigurer.java @@ -20,7 +20,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Assist with configuring {@code HandlerMapping}'s with path matching options. @@ -31,11 +31,9 @@ import org.springframework.lang.Nullable; */ public class PathMatchConfigurer { - @Nullable - private Boolean caseSensitiveMatch; + private @Nullable Boolean caseSensitiveMatch; - @Nullable - private Map>> pathPrefixes; + private @Nullable Map>> pathPrefixes; /** @@ -68,13 +66,11 @@ public class PathMatchConfigurer { } - @Nullable - protected Boolean isUseCaseSensitiveMatch() { + protected @Nullable Boolean isUseCaseSensitiveMatch() { return this.caseSensitiveMatch; } - @Nullable - protected Map>> getPathPrefixes() { + protected @Nullable Map>> getPathPrefixes() { return this.pathPrefixes; } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceChainRegistration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceChainRegistration.java index fe7318feb0..b152d5fe0b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceChainRegistration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceChainRegistration.java @@ -19,9 +19,10 @@ package org.springframework.web.reactive.config; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.concurrent.ConcurrentMapCache; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.reactive.resource.CachingResourceResolver; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistration.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistration.java index c68e0bd816..137b7b1b9f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistration.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ResourceHandlerRegistration.java @@ -23,13 +23,14 @@ import java.util.List; import java.util.Map; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; import org.springframework.http.CacheControl; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.resource.ResourceWebHandler; import org.springframework.web.server.ServerWebExchange; @@ -48,21 +49,17 @@ public class ResourceHandlerRegistration { private final List locationValues = new ArrayList<>(); - @Nullable - private CacheControl cacheControl; + private @Nullable CacheControl cacheControl; - @Nullable - private ResourceChainRegistration resourceChainRegistration; + private @Nullable ResourceChainRegistration resourceChainRegistration; private boolean useLastModified = true; - @Nullable - private Function etagGenerator; + private @Nullable Function etagGenerator; private boolean optimizeLocations = false; - @Nullable - private Map mediaTypes; + private @Nullable Map mediaTypes; 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 a84fdcc6aa..39d34aadde 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 @@ -22,10 +22,11 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanInitializationException; import org.springframework.core.Ordered; import org.springframework.core.io.ResourceLoader; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.handler.AbstractUrlHandlerMapping; import org.springframework.web.reactive.handler.SimpleUrlHandlerMapping; import org.springframework.web.reactive.resource.ResourceTransformer; @@ -63,8 +64,7 @@ public class ResourceHandlerRegistry { private int order = Ordered.LOWEST_PRECEDENCE - 1; - @Nullable - private ResourceUrlProvider resourceUrlProvider; + private @Nullable ResourceUrlProvider resourceUrlProvider; /** @@ -130,8 +130,7 @@ public class ResourceHandlerRegistry { * Return a handler mapping with the mapped resource handlers; or {@code null} in case * of no registrations. */ - @Nullable - protected AbstractUrlHandlerMapping getHandlerMapping() { + protected @Nullable AbstractUrlHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty()) { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java index 9b603e0637..26bb76b492 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/config/ViewResolverRegistry.java @@ -20,11 +20,12 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ApplicationContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.reactive.result.view.HttpMessageWriterView; import org.springframework.web.reactive.result.view.UrlBasedViewResolver; @@ -49,15 +50,13 @@ import org.springframework.web.reactive.result.view.script.ScriptTemplateViewRes */ public class ViewResolverRegistry { - @Nullable - private final ApplicationContext applicationContext; + private final @Nullable ApplicationContext applicationContext; private final List viewResolvers = new ArrayList<>(4); private final List defaultViews = new ArrayList<>(4); - @Nullable - private Integer order; + private @Nullable Integer order; public ViewResolverRegistry(@Nullable ApplicationContext applicationContext) { 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 57b71e8a99..025979f0d6 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 @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.BeanInitializationException; @@ -38,7 +39,6 @@ import org.springframework.format.FormatterRegistry; import org.springframework.format.support.DefaultFormattingConversionService; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.validation.Errors; @@ -91,23 +91,17 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { ClassUtils.isPresent("jakarta.validation.Validator", WebFluxConfigurationSupport.class.getClassLoader()); - @Nullable - private Map corsConfigurations; + private @Nullable Map corsConfigurations; - @Nullable - private PathMatchConfigurer pathMatchConfigurer; + private @Nullable PathMatchConfigurer pathMatchConfigurer; - @Nullable - private BlockingExecutionConfigurer blockingExecutionConfigurer; + private @Nullable BlockingExecutionConfigurer blockingExecutionConfigurer; - @Nullable - private List errorResponseInterceptors; + private @Nullable List errorResponseInterceptors; - @Nullable - private ViewResolverRegistry viewResolverRegistry; + private @Nullable ViewResolverRegistry viewResolverRegistry; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; @Override @@ -120,8 +114,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { } } - @Nullable - public final ApplicationContext getApplicationContext() { + public final @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -419,16 +412,14 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { /** * Override this method to provide a custom {@link Validator}. */ - @Nullable - protected Validator getValidator() { + protected @Nullable Validator getValidator() { return null; } /** * Override this method to provide a custom {@link MessageCodesResolver}. */ - @Nullable - protected MessageCodesResolver getMessageCodesResolver() { + protected @Nullable MessageCodesResolver getMessageCodesResolver() { return null; } @@ -488,8 +479,7 @@ public class WebFluxConfigurationSupport implements ApplicationContextAware { return service; } - @Nullable - protected WebSocketService getWebSocketService() { + protected @Nullable WebSocketService getWebSocketService() { 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 01f244cfff..af14b1f434 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 @@ -18,11 +18,12 @@ package org.springframework.web.reactive.config; import java.util.List; +import org.jspecify.annotations.Nullable; + 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.ErrorResponse; @@ -74,8 +75,7 @@ public interface WebFluxConfigurer { *

    The configured validator is used for validating annotated controller * method arguments. */ - @Nullable - default Validator getValidator() { + default @Nullable Validator getValidator() { return null; } @@ -84,8 +84,7 @@ public interface WebFluxConfigurer { * annotated controller method arguments instead of the one created by * default in {@link org.springframework.validation.DataBinder}. */ - @Nullable - default MessageCodesResolver getMessageCodesResolver() { + default @Nullable MessageCodesResolver getMessageCodesResolver() { return null; } @@ -170,8 +169,7 @@ public interface WebFluxConfigurer { * {@link org.springframework.web.reactive.socket.server.RequestUpgradeStrategy}. * @since 5.3 */ - @Nullable - default WebSocketService getWebSocketService() { + default @Nullable WebSocketService getWebSocketService() { 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 e8efac6cfd..8c72207226 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 @@ -21,9 +21,10 @@ import java.util.List; import java.util.Objects; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + 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; @@ -62,14 +63,12 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer { } @Override - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return createSingleBean(WebFluxConfigurer::getValidator, Validator.class); } @Override - @Nullable - public MessageCodesResolver getMessageCodesResolver() { + public @Nullable MessageCodesResolver getMessageCodesResolver() { return createSingleBean(WebFluxConfigurer::getMessageCodesResolver, MessageCodesResolver.class); } @@ -115,14 +114,12 @@ public class WebFluxConfigurerComposite implements WebFluxConfigurer { this.delegates.forEach(delegate -> delegate.addResourceHandlers(registry)); } - @Nullable @Override - public WebSocketService getWebSocketService() { + public @Nullable WebSocketService getWebSocketService() { return createSingleBean(WebFluxConfigurer::getWebSocketService, WebSocketService.class); } - @Nullable - private T createSingleBean(Function factory, Class beanType) { + private @Nullable T createSingleBean(Function factory, Class beanType) { List result = this.delegates.stream().map(factory).filter(Objects::nonNull).toList(); if (result.isEmpty()) { return null; 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 9722fd8a14..9b5d36a81f 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,9 +1,7 @@ /** * Spring WebFlux configuration infrastructure. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java index 96fac2afbf..205f6bd3b6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/BodyInserters.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.concurrent.Executor; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -40,7 +41,6 @@ import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ServerSentEvent; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; 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 8c863c567e..3709a0b96d 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 @@ -19,10 +19,11 @@ package org.springframework.web.reactive.function; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; import org.springframework.core.ResolvableType; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * Exception thrown to indicate that a {@code Content-Type} is not supported. @@ -33,13 +34,11 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class UnsupportedMediaTypeException extends NestedRuntimeException { - @Nullable - private final MediaType contentType; + private final @Nullable MediaType contentType; private final List supportedMediaTypes; - @Nullable - private final ResolvableType bodyType; + private final @Nullable ResolvableType bodyType; /** @@ -82,8 +81,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() { + public @Nullable MediaType getContentType() { return this.contentType; } @@ -102,8 +100,7 @@ public class UnsupportedMediaTypeException extends NestedRuntimeException { * @return the body type, or {@code null} if not available * @since 5.1 */ - @Nullable - public ResolvableType getBodyType() { + public @Nullable ResolvableType getBodyType() { return this.bodyType; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java index 5c24b2ab30..c21e47d0d5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequest.java @@ -21,6 +21,7 @@ import java.util.Map; import java.util.Optional; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -28,7 +29,6 @@ import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.client.reactive.ClientHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.reactive.function.BodyInserter; @@ -99,8 +99,7 @@ public interface ClientRequest { * Return consumer(s) configured to access to the {@link ClientHttpRequest}. * @since 5.3 */ - @Nullable - Consumer httpRequest(); + @Nullable Consumer httpRequest(); /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequestObservationContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequestObservationContext.java index 434ca9f140..6a3992a01e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequestObservationContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ClientRequestObservationContext.java @@ -17,8 +17,7 @@ package org.springframework.web.reactive.function.client; import io.micrometer.observation.transport.RequestReplySenderContext; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Context that holds information for metadata collection during the @@ -33,13 +32,11 @@ import org.springframework.lang.Nullable; */ public class ClientRequestObservationContext extends RequestReplySenderContext { - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; private boolean aborted; - @Nullable - private ClientRequest request; + private @Nullable ClientRequest request; /** @@ -54,7 +51,7 @@ public class ClientRequestObservationContext extends RequestReplySenderContext headers.set(name, value)); } @@ -71,8 +68,7 @@ public class ClientRequestObservationContext extends RequestReplySenderContext body = BodyInserters.empty(); - @Nullable - private Consumer httpRequestConsumer; + private @Nullable Consumer httpRequestConsumer; public DefaultClientRequestBuilder(ClientRequest other) { @@ -190,8 +189,7 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { private final Map attributes; - @Nullable - private final Consumer httpRequestConsumer; + private final @Nullable Consumer httpRequestConsumer; private final String logPrefix; @@ -242,8 +240,7 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { } @Override - @Nullable - public Consumer httpRequest() { + public @Nullable Consumer httpRequest() { return this.httpRequestConsumer; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestObservationConvention.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestObservationConvention.java index 62f5d1287d..d7a3f6c001 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestObservationConvention.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestObservationConvention.java @@ -22,10 +22,10 @@ import java.util.regex.Pattern; import io.micrometer.common.KeyValue; import io.micrometer.common.KeyValues; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.reactive.function.client.ClientHttpObservationDocumentation.HighCardinalityKeyNames; import org.springframework.web.reactive.function.client.ClientHttpObservationDocumentation.LowCardinalityKeyNames; @@ -90,8 +90,7 @@ public class DefaultClientRequestObservationConvention implements ClientRequestO } @Override - @Nullable - public String getContextualName(ClientRequestObservationContext context) { + public @Nullable String getContextualName(ClientRequestObservationContext context) { ClientRequest request = context.getRequest(); return (request != null ? "http " + request.method().name().toLowerCase(Locale.ROOT) : null); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java index 6d8c2bfd25..907d394190 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponse.java @@ -25,6 +25,7 @@ import java.util.OptionalLong; import java.util.function.Function; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -46,7 +47,6 @@ import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.codec.DecoderHttpMessageReader; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeType; import org.springframework.util.MultiValueMap; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java index 0a49c08971..00075c8db4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientResponseBuilder.java @@ -23,6 +23,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import org.springframework.core.io.buffer.DataBuffer; @@ -35,7 +36,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; 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; @@ -79,16 +79,13 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder { private HttpStatusCode statusCode = HttpStatus.OK; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; - @Nullable - private MultiValueMap cookies; + private @Nullable MultiValueMap cookies; private Flux body = Flux.empty(); - @Nullable - private ClientResponse originalResponse; + private @Nullable ClientResponse originalResponse; private HttpRequest request; @@ -228,16 +225,13 @@ final class DefaultClientResponseBuilder implements ClientResponse.Builder { private final HttpStatusCode statusCode; - @Nullable - private final HttpHeaders headers; + private final @Nullable HttpHeaders headers; - @Nullable - private final MultiValueMap cookies; + private final @Nullable MultiValueMap cookies; private final Flux body; - @Nullable - private final ClientResponse originalResponse; + private final @Nullable ClientResponse originalResponse; BuiltClientHttpResponse(HttpStatusCode statusCode, @Nullable HttpHeaders headers, 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 443ba3018f..08109bf3ae 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 @@ -34,6 +34,7 @@ import java.util.function.Predicate; import io.micrometer.observation.Observation; import io.micrometer.observation.ObservationRegistry; import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -48,7 +49,6 @@ 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; @@ -83,26 +83,21 @@ final class DefaultWebClient implements WebClient { private final ExchangeFunction exchangeFunction; - @Nullable - private final ExchangeFilterFunction filterFunctions; + private final @Nullable ExchangeFilterFunction filterFunctions; private final UriBuilderFactory uriBuilderFactory; - @Nullable - private final HttpHeaders defaultHeaders; + private final @Nullable HttpHeaders defaultHeaders; - @Nullable - private final MultiValueMap defaultCookies; + private final @Nullable MultiValueMap defaultCookies; - @Nullable - private final Consumer> defaultRequest; + private final @Nullable Consumer> defaultRequest; private final List defaultStatusHandlers; private final ObservationRegistry observationRegistry; - @Nullable - private final ClientRequestObservationConvention observationConvention; + private final @Nullable ClientRequestObservationConvention observationConvention; private final DefaultWebClientBuilder builder; @@ -202,25 +197,19 @@ final class DefaultWebClient implements WebClient { private final HttpMethod httpMethod; - @Nullable - private URI uri; + private @Nullable URI uri; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; - @Nullable - private MultiValueMap cookies; + private @Nullable MultiValueMap cookies; - @Nullable - private BodyInserter inserter; + private @Nullable BodyInserter inserter; private final Map attributes = new LinkedHashMap<>(4); - @Nullable - private Function contextModifier; + private @Nullable Function contextModifier; - @Nullable - private Consumer httpRequestConsumer; + private @Nullable Consumer httpRequestConsumer; DefaultRequestBodyUriSpec(HttpMethod httpMethod) { this.httpMethod = httpMethod; @@ -684,8 +673,7 @@ final class DefaultWebClient implements WebClient { return t -> response.createException().flatMap(ex -> Mono.error(ex.initCause(t))); } - @Nullable - private Mono applyStatusHandlers(ClientResponse response) { + private @Nullable Mono applyStatusHandlers(ClientResponse response) { HttpStatusCode statusCode = response.statusCode(); for (StatusHandler handler : this.statusHandlers) { if (handler.test(statusCode)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java index b67ace1c82..867bc97e54 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultWebClientBuilder.java @@ -26,6 +26,7 @@ import java.util.function.Function; import java.util.function.Predicate; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; @@ -37,7 +38,6 @@ import org.springframework.http.client.reactive.JettyClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.client.reactive.ReactorNetty2ClientHttpConnector; import org.springframework.http.codec.ClientCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; @@ -74,46 +74,33 @@ final class DefaultWebClientBuilder implements WebClient.Builder { } - @Nullable - private String baseUrl; + private @Nullable String baseUrl; - @Nullable - private Map defaultUriVariables; + private @Nullable Map defaultUriVariables; - @Nullable - private UriBuilderFactory uriBuilderFactory; + private @Nullable UriBuilderFactory uriBuilderFactory; - @Nullable - private HttpHeaders defaultHeaders; + private @Nullable HttpHeaders defaultHeaders; - @Nullable - private MultiValueMap defaultCookies; + private @Nullable MultiValueMap defaultCookies; - @Nullable - private Consumer> defaultRequest; + private @Nullable Consumer> defaultRequest; - @Nullable - private Map, Function>> statusHandlers; + private @Nullable Map, Function>> statusHandlers; - @Nullable - private List filters; + private @Nullable List filters; - @Nullable - private ClientHttpConnector connector; + private @Nullable ClientHttpConnector connector; - @Nullable - private ExchangeStrategies strategies; + private @Nullable ExchangeStrategies strategies; - @Nullable - private List> strategiesConfigurers; + private @Nullable List> strategiesConfigurers; - @Nullable - private ExchangeFunction exchangeFunction; + private @Nullable ExchangeFunction exchangeFunction; private ObservationRegistry observationRegistry = ObservationRegistry.NOOP; - @Nullable - private ClientRequestObservationConvention observationConvention; + private @Nullable ClientRequestObservationConvention observationConvention; public DefaultWebClientBuilder() { @@ -368,8 +355,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder { return factory; } - @Nullable - private HttpHeaders copyDefaultHeaders() { + private @Nullable HttpHeaders copyDefaultHeaders() { if (this.defaultHeaders == null) { return null; } @@ -378,8 +364,7 @@ final class DefaultWebClientBuilder implements WebClient.Builder { return HttpHeaders.readOnlyHttpHeaders(headers); } - @Nullable - private MultiValueMap copyDefaultCookies() { + private @Nullable MultiValueMap copyDefaultCookies() { if (this.defaultCookies == null) { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java index 351348431b..991485f5e1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFilterFunctions.java @@ -22,12 +22,12 @@ import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/UnknownHttpStatusCodeException.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/UnknownHttpStatusCodeException.java index 34bc91483d..a3f92b7096 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/UnknownHttpStatusCodeException.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/UnknownHttpStatusCodeException.java @@ -18,10 +18,11 @@ package org.springframework.web.reactive.function.client; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; /** * Exception thrown when an unknown (or custom) HTTP status code is received. diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientException.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientException.java index afbd03701a..36a2f30674 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientException.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientException.java @@ -16,8 +16,9 @@ package org.springframework.web.reactive.function.client; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Abstract base class for exception published by {@link WebClient} in case of errors. diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java index 6188c45a20..9e08f919e7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/WebClientResponseException.java @@ -22,13 +22,14 @@ import java.util.List; import java.util.Map; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpRequest; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -52,15 +53,12 @@ public class WebClientResponseException extends WebClientException { private final HttpHeaders headers; - @Nullable @SuppressWarnings("serial") - private final Charset responseCharset; + private final @Nullable Charset responseCharset; - @Nullable - private final transient HttpRequest request; + private final transient @Nullable HttpRequest request; - @Nullable - private transient Function bodyDecodeFunction; + private transient @Nullable Function bodyDecodeFunction; /** @@ -69,7 +67,7 @@ public class WebClientResponseException extends WebClientException { */ public WebClientResponseException( int statusCode, String statusText, @Nullable HttpHeaders headers, - @Nullable byte[] body, @Nullable Charset charset) { + byte @Nullable [] body, @Nullable Charset charset) { this(statusCode, statusText, headers, body, charset, null); } @@ -80,7 +78,7 @@ public class WebClientResponseException extends WebClientException { */ public WebClientResponseException( int status, String reasonPhrase, @Nullable HttpHeaders headers, - @Nullable byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) { + byte @Nullable [] body, @Nullable Charset charset, @Nullable HttpRequest request) { this(HttpStatusCode.valueOf(status), reasonPhrase, headers, body, charset, request); } @@ -91,7 +89,7 @@ public class WebClientResponseException extends WebClientException { */ public WebClientResponseException( HttpStatusCode statusCode, String reasonPhrase, @Nullable HttpHeaders headers, - @Nullable byte[] body, @Nullable Charset charset, @Nullable HttpRequest request) { + byte @Nullable [] body, @Nullable Charset charset, @Nullable HttpRequest request) { this(initMessage(statusCode, reasonPhrase, request), statusCode, reasonPhrase, headers, body, charset, request); @@ -107,7 +105,7 @@ public class WebClientResponseException extends WebClientException { */ public WebClientResponseException( String message, int statusCode, String statusText, - @Nullable HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset) { + @Nullable HttpHeaders headers, byte @Nullable [] responseBody, @Nullable Charset charset) { this(message, statusCode, statusText, headers, responseBody, charset, null); } @@ -118,7 +116,7 @@ public class WebClientResponseException extends WebClientException { */ public WebClientResponseException( String message, int statusCode, String statusText, - @Nullable HttpHeaders headers, @Nullable byte[] responseBody, @Nullable Charset charset, + @Nullable HttpHeaders headers, byte @Nullable [] responseBody, @Nullable Charset charset, @Nullable HttpRequest request) { this(message, HttpStatusCode.valueOf(statusCode), statusText, headers, responseBody, charset, request); @@ -130,7 +128,7 @@ public class WebClientResponseException extends WebClientException { */ public WebClientResponseException( String message, HttpStatusCode statusCode, String statusText, @Nullable HttpHeaders headers, - @Nullable byte[] responseBody, @Nullable Charset charset, @Nullable HttpRequest request) { + byte @Nullable [] responseBody, @Nullable Charset charset, @Nullable HttpRequest request) { super(message); @@ -232,8 +230,7 @@ public class WebClientResponseException extends WebClientException { * @throws org.springframework.core.codec.DecodingException if decoding fails * @since 6.0 */ - @Nullable - public E getResponseBodyAs(Class targetType) { + public @Nullable E getResponseBodyAs(Class targetType) { return decodeBody(ResolvableType.forClass(targetType)); } @@ -241,14 +238,12 @@ public class WebClientResponseException extends WebClientException { * Variant of {@link #getResponseBodyAs(Class)} with {@link ParameterizedTypeReference}. * @since 6.0 */ - @Nullable - public E getResponseBodyAs(ParameterizedTypeReference targetType) { + public @Nullable E getResponseBodyAs(ParameterizedTypeReference targetType) { return decodeBody(ResolvableType.forType(targetType.getType())); } @SuppressWarnings("unchecked") - @Nullable - private E decodeBody(ResolvableType targetType) { + private @Nullable E decodeBody(ResolvableType targetType) { Assert.state(this.bodyDecodeFunction != null, "Decoder function not set"); return (E) this.bodyDecodeFunction.apply(targetType); } @@ -257,8 +252,7 @@ public class WebClientResponseException extends WebClientException { * Return the corresponding request. * @since 5.1.4 */ - @Nullable - public HttpRequest getRequest() { + public @Nullable HttpRequest getRequest() { return this.request; } 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 7c67791d7c..7455d3e6ea 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,9 +3,7 @@ * that builds on top of the * {@code org.springframework.http.client.reactive} reactive HTTP adapter layer. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.function.client; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/package-info.java index f1df06d388..4fb639d019 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/support/package-info.java @@ -2,9 +2,7 @@ * Classes supporting the {@code org.springframework.web.reactive.function.client} package. * Contains a {@code ClientResponse} wrapper to adapt a request. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.function.client.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 b7ef8b31ba..8e0e49a849 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,9 +1,7 @@ /** * Provides a foundation for both the reactive client and server subpackages. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.function; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java index a947d25d1b..c7913692f4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultRenderingResponseBuilder.java @@ -26,6 +26,7 @@ import java.util.Map; import java.util.function.Consumer; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -36,7 +37,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java index c2ba3a9ff5..caf09e15bc 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequest.java @@ -30,6 +30,7 @@ import java.util.OptionalLong; import java.util.function.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -50,7 +51,6 @@ import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.RequestPath; 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.util.MultiValueMap; import org.springframework.validation.BindException; @@ -337,8 +337,7 @@ class DefaultServerRequest implements ServerRequest { } @Override - @Nullable - public InetSocketAddress host() { + public @Nullable InetSocketAddress host() { return this.httpHeaders.getHost(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java index 11c9795251..d26c440bc5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerRequestBuilder.java @@ -28,6 +28,7 @@ import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -48,7 +49,6 @@ import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.RequestPath; 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.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -75,8 +75,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { private URI uri; - @Nullable - private String contextPath; + private @Nullable String contextPath; private final HttpHeaders headers = new HttpHeaders(); @@ -428,9 +427,8 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { return this.delegate.getLocaleContext(); } - @Nullable @Override - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.delegate.getApplicationContext(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java index 684bd49e98..d2736b05ff 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/DefaultServerResponseBuilder.java @@ -31,6 +31,7 @@ import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -90,7 +91,8 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { @Override - public ServerResponse.BodyBuilder header(String headerName, String... headerValues) { + @SuppressWarnings("NullAway") // TODO NullAway bug potentially due to the recursive generic type + public ServerResponse.BodyBuilder header(String headerName, @Nullable String... headerValues) { Assert.notNull(headerName, "HeaderName must not be null"); for (String headerValue : headerValues) { this.headers.add(headerName, headerValue); 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 3b51db3698..61e50cf04a 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 @@ -20,12 +20,12 @@ import java.util.Collection; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java index 157a360aa7..a3b9e46a0f 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/RequestPredicates.java @@ -34,6 +34,7 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -47,7 +48,6 @@ import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeTypeUtils; @@ -481,8 +481,8 @@ public abstract class RequestPredicates { private final boolean value; - @Nullable - private final Consumer> modifyAttributes; + + private final @Nullable Consumer> modifyAttributes; private Result(boolean value, @Nullable Consumer> modifyAttributes) { @@ -820,8 +820,7 @@ public abstract class RequestPredicates { private final Predicate extensionPredicate; - @Nullable - private final String extension; + private final @Nullable String extension; public PathExtensionPredicate(Predicate extensionPredicate) { Assert.notNull(extensionPredicate, "Predicate must not be null"); @@ -870,8 +869,7 @@ public abstract class RequestPredicates { private final Predicate valuePredicate; - @Nullable - private final String value; + private final @Nullable String value; public QueryParamPredicate(String name, Predicate valuePredicate) { Assert.notNull(name, "Name must not be null"); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ResourceHandlerFunction.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ResourceHandlerFunction.java index 2fa724917d..56ea5b1fb7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ResourceHandlerFunction.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ResourceHandlerFunction.java @@ -25,13 +25,13 @@ import java.net.URL; import java.util.Set; import java.util.function.BiConsumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.function.BodyInserters; /** @@ -137,8 +137,7 @@ class ResourceHandlerFunction implements HandlerFunction { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.delegate.getFilename(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java index af3ebeaa17..2cf587fdab 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerRequest.java @@ -28,6 +28,7 @@ import java.util.Optional; import java.util.OptionalLong; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -44,7 +45,6 @@ import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -498,8 +498,7 @@ public interface ServerRequest { * {@linkplain InetSocketAddress#getPort() port} in the returned address will * be {@code 0}. */ - @Nullable - InetSocketAddress host(); + @Nullable InetSocketAddress host(); /** * Get the value of the {@code Range} header. @@ -520,8 +519,7 @@ public interface ServerRequest { * @param headerName the header name * @since 5.2.5 */ - @Nullable - default String firstHeader(String headerName) { + default @Nullable String firstHeader(String headerName) { List list = header(headerName); return list.isEmpty() ? null : list.get(0); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java index d71fa7d8e1..3baf0dcc87 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/ServerResponse.java @@ -26,6 +26,7 @@ import java.util.Set; import java.util.function.BiFunction; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -234,7 +235,7 @@ public interface ServerResponse { * @return this builder * @see HttpHeaders#add(String, String) */ - B header(String headerName, String... headerValues); + B header(String headerName, @Nullable String... headerValues); /** * Manipulate this response's headers with the given consumer. The 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 0fc2f21a0d..7d6ae45324 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,9 +1,7 @@ /** * Provides the types that make up Spring's functional web framework for Reactive environments. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.function.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java index 4848a636bf..5e03a488f8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/RouterFunctionMapping.java @@ -21,13 +21,13 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.InitializingBean; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.reactive.function.server.HandlerFunction; import org.springframework.web.reactive.function.server.RouterFunction; @@ -50,8 +50,7 @@ import org.springframework.web.util.pattern.PathPattern; */ public class RouterFunctionMapping extends AbstractHandlerMapping implements InitializingBean { - @Nullable - private RouterFunction routerFunction; + private @Nullable RouterFunction routerFunction; private List> messageReaders = Collections.emptyList(); @@ -81,8 +80,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini * prior to {@link #afterPropertiesSet()}. * @return the router function or {@code null} */ - @Nullable - public RouterFunction getRouterFunction() { + public @Nullable RouterFunction getRouterFunction() { return this.routerFunction; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java index ba5ff5f6e4..1d9fc1f365 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/server/support/ServerRequestWrapper.java @@ -27,6 +27,7 @@ import java.util.Optional; import java.util.OptionalLong; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -41,7 +42,6 @@ import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.WebDataBinder; @@ -284,8 +284,7 @@ public class ServerRequestWrapper implements ServerRequest { } @Override - @Nullable - public InetSocketAddress host() { + public @Nullable InetSocketAddress host() { return this.headers.host(); } 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 2f4f6d6504..12193ec76b 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,9 +4,7 @@ * a {@code HandlerResultHandler} that supports {@code ServerResponse}s, and * a {@code ServerRequest} wrapper to adapt a request. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.function.server.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c179d49e33..6cccb413cd 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 @@ -19,6 +19,7 @@ package org.springframework.web.reactive.handler; import java.util.Map; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.BeanNameAware; @@ -26,7 +27,6 @@ import org.springframework.context.support.ApplicationObjectSupport; import org.springframework.core.Ordered; import org.springframework.core.log.LogDelegateFactory; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.reactive.CorsConfigurationSource; @@ -60,15 +60,13 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport private final PathPatternParser patternParser = new PathPatternParser(); - @Nullable - private CorsConfigurationSource corsConfigurationSource; + private @Nullable CorsConfigurationSource corsConfigurationSource; private CorsProcessor corsProcessor = new DefaultCorsProcessor(); private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered - @Nullable - private String beanName; + private @Nullable String beanName; /** @@ -214,8 +212,7 @@ public abstract class AbstractHandlerMapping extends ApplicationObjectSupport * @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) { + protected @Nullable CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) { if (handler instanceof CorsConfigurationSource ccs) { return ccs.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 01263e6050..14d5f7a606 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 @@ -23,12 +23,12 @@ import java.util.List; import java.util.Map; import java.util.function.BiPredicate; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.BeansException; import org.springframework.http.server.PathContainer; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.util.pattern.PathPattern; @@ -59,8 +59,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping { private final Map handlerMap = new LinkedHashMap<>(); - @Nullable - private BiPredicate handlerPredicate; + private @Nullable BiPredicate handlerPredicate; /** @@ -127,9 +126,8 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping { * @return the associated handler instance, or {@code null} if not found * @see org.springframework.web.util.pattern.PathPattern */ - @Nullable @SuppressWarnings("removal") - protected Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception { + protected @Nullable Object lookupHandler(PathContainer lookupPath, ServerWebExchange exchange) throws Exception { List matches = null; for (PathPattern pattern : this.handlerMap.keySet()) { if (pattern.matches(lookupPath)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java index 3583410aa4..3315fa1308 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/handler/WebFluxResponseStatusExceptionHandler.java @@ -16,9 +16,10 @@ package org.springframework.web.reactive.handler; +import org.jspecify.annotations.Nullable; + import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.server.handler.ResponseStatusExceptionHandler; @@ -39,8 +40,7 @@ import org.springframework.web.server.handler.ResponseStatusExceptionHandler; public class WebFluxResponseStatusExceptionHandler extends ResponseStatusExceptionHandler { @Override - @Nullable - protected HttpStatusCode determineStatus(Throwable ex) { + protected @Nullable HttpStatusCode determineStatus(Throwable ex) { HttpStatusCode statusCode = super.determineStatus(ex); if (statusCode == null) { ResponseStatus ann = AnnotatedElementUtils.findMergedAnnotation(ex.getClass(), ResponseStatus.class); 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 061a4179c4..0f2ef3cf58 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,9 +1,7 @@ /** * Provides HandlerMapping implementations including abstract base classes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.handler; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 549793e0e9..fa38c269a4 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,9 +9,7 @@ * routing and handling. The module also contains a functional, reactive * {@code WebClient} as well as client and server, reactive WebSocket support. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractFileNameVersionStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractFileNameVersionStrategy.java index 04e347b4de..c7d6724edb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractFileNameVersionStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractFileNameVersionStrategy.java @@ -21,8 +21,8 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -41,8 +41,7 @@ public abstract class AbstractFileNameVersionStrategy implements VersionStrategy @Override - @Nullable - public String extractVersion(String requestPath) { + public @Nullable String extractVersion(String requestPath) { Matcher matcher = pattern.matcher(requestPath); if (matcher.find()) { String match = matcher.group(1); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java index 6542ad3042..718ab55248 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractPrefixVersionStrategy.java @@ -18,8 +18,8 @@ package org.springframework.web.reactive.resource; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -45,8 +45,7 @@ public abstract class AbstractPrefixVersionStrategy implements VersionStrategy { @Override - @Nullable - public String extractVersion(String requestPath) { + public @Nullable String extractVersion(String requestPath) { return (requestPath.startsWith(this.prefix) ? this.prefix : null); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractResourceResolver.java index c862345a2c..ed100ad7a7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/AbstractResourceResolver.java @@ -20,10 +20,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java index 6903e989cd..d57c890ca1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CachingResourceResolver.java @@ -23,12 +23,12 @@ import java.util.List; import java.util.Locale; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -132,8 +132,7 @@ public class CachingResourceResolver extends AbstractResourceResolver { return RESOLVED_RESOURCE_CACHE_KEY_PREFIX + requestPath; } - @Nullable - private String getContentCodingKey(ServerWebExchange exchange) { + private @Nullable String getContentCodingKey(ServerWebExchange exchange) { String header = exchange.getRequest().getHeaders().getFirst("Accept-Encoding"); if (!StringUtils.hasText(header)) { return null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java index e95c23b682..38aef72854 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/CssLinkResourceTransformer.java @@ -28,6 +28,7 @@ import java.util.TreeSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -35,7 +36,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; 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 be05220f93..233d91ab42 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 @@ -21,10 +21,10 @@ import java.util.Collections; import java.util.List; import java.util.ListIterator; +import org.jspecify.annotations.Nullable; 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; @@ -36,11 +36,9 @@ import org.springframework.web.server.ServerWebExchange; */ class DefaultResourceResolverChain implements ResourceResolverChain { - @Nullable - private final ResourceResolver resolver; + private final @Nullable ResourceResolver resolver; - @Nullable - private final ResourceResolverChain nextChain; + private final @Nullable ResourceResolverChain nextChain; public DefaultResourceResolverChain(@Nullable List resolvers) { 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 dc79e5d6aa..1b1969831c 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 @@ -21,10 +21,10 @@ import java.util.Collections; import java.util.List; import java.util.ListIterator; +import org.jspecify.annotations.Nullable; 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; @@ -38,11 +38,9 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain { private final ResourceResolverChain resolverChain; - @Nullable - private final ResourceTransformer transformer; + private final @Nullable ResourceTransformer transformer; - @Nullable - private final ResourceTransformerChain nextChain; + private final @Nullable ResourceTransformerChain nextChain; public DefaultResourceTransformerChain( diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java index 8750d24197..6f6b2cadfb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/EncodedResourceResolver.java @@ -31,13 +31,13 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; 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.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -166,8 +166,7 @@ public class EncodedResourceResolver extends AbstractResourceResolver { }); } - @Nullable - private String getAcceptEncoding(ServerWebExchange exchange) { + private @Nullable String getAcceptEncoding(ServerWebExchange exchange) { ServerHttpRequest request = exchange.getRequest(); String header = request.getHeaders().getFirst(HttpHeaders.ACCEPT_ENCODING); return (header != null ? header.toLowerCase(Locale.ROOT) : null); @@ -277,8 +276,7 @@ public class EncodedResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.original.getFilename(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/LiteWebJarsResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/LiteWebJarsResourceResolver.java index d396dbccc7..9aa045bbf4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/LiteWebJarsResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/LiteWebJarsResourceResolver.java @@ -18,11 +18,11 @@ package org.springframework.web.reactive.resource; import java.util.List; +import org.jspecify.annotations.Nullable; import org.webjars.WebJarVersionLocator; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** @@ -98,8 +98,7 @@ public class LiteWebJarsResourceResolver extends AbstractResourceResolver { })); } - @Nullable - protected String findWebJarResourcePath(String path) { + protected @Nullable String findWebJarResourcePath(String path) { int endOffset = path.indexOf('/', 1); if (endOffset != -1) { int startOffset = (path.startsWith("/") ? 1 : 0); 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 946be62489..f6d0d023fe 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 @@ -20,12 +20,12 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; import org.springframework.core.log.LogFormatUtils; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -42,8 +42,7 @@ import org.springframework.web.server.ServerWebExchange; */ public class PathResourceResolver extends AbstractResourceResolver { - @Nullable - private Resource[] allowedLocations; + private Resource @Nullable [] allowedLocations; /** @@ -61,12 +60,11 @@ public class PathResourceResolver extends AbstractResourceResolver { * to match its list of locations. * @param locations the list of allowed locations */ - public void setAllowedLocations(@Nullable Resource... locations) { + public void setAllowedLocations(Resource @Nullable ... locations) { this.allowedLocations = locations; } - @Nullable - public Resource[] getAllowedLocations() { + public Resource @Nullable [] getAllowedLocations() { return this.allowedLocations; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java index ca1b2a2d60..a7104a8c13 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceHandlerUtils.java @@ -22,12 +22,12 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.core.log.LogFormatUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolver.java index 610e052a78..1b9b80c823 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolver.java @@ -18,11 +18,11 @@ package org.springframework.web.reactive.resource; import java.util.List; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolverChain.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolverChain.java index 53f3fe4991..ad15a8e835 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolverChain.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceResolverChain.java @@ -18,10 +18,10 @@ package org.springframework.web.reactive.resource; import java.util.List; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.web.server.ServerWebExchange; /** 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 22d4a8114f..fe704a7471 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 @@ -18,10 +18,10 @@ package org.springframework.web.reactive.resource; import java.util.Collections; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -35,8 +35,7 @@ import org.springframework.web.server.ServerWebExchange; */ public abstract class ResourceTransformerSupport implements ResourceTransformer { - @Nullable - private ResourceUrlProvider resourceUrlProvider; + private @Nullable ResourceUrlProvider resourceUrlProvider; /** @@ -53,8 +52,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer /** * Return the configured {@code ResourceUrlProvider}. */ - @Nullable - public ResourceUrlProvider getResourceUrlProvider() { + public @Nullable ResourceUrlProvider getResourceUrlProvider() { return this.resourceUrlProvider; } 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 c03b6f7808..cf1140f075 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 @@ -23,6 +23,7 @@ import java.util.Map; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.BeansException; @@ -32,7 +33,6 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.http.server.PathContainer; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.HandlerMapping; import org.springframework.web.reactive.handler.AbstractUrlHandlerMapping; import org.springframework.web.server.ServerWebExchange; @@ -57,8 +57,7 @@ public class ResourceUrlProvider implements ApplicationListener handlerMap = new LinkedHashMap<>(); - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; @Override 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 cd624891b5..9ca35449c5 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 @@ -29,6 +29,7 @@ import java.util.function.Function; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.InitializingBean; @@ -43,7 +44,6 @@ import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; import org.springframework.http.codec.ResourceHttpMessageWriter; import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -90,8 +90,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { private static final Log logger = LogFactory.getLog(ResourceWebHandler.class); - @Nullable - private ResourceLoader resourceLoader; + private @Nullable ResourceLoader resourceLoader; private final List locationValues = new ArrayList<>(4); @@ -103,25 +102,19 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { private final List resourceTransformers = new ArrayList<>(4); - @Nullable - private ResourceResolverChain resolverChain; + private @Nullable ResourceResolverChain resolverChain; - @Nullable - private ResourceTransformerChain transformerChain; + private @Nullable ResourceTransformerChain transformerChain; - @Nullable - private CacheControl cacheControl; + private @Nullable CacheControl cacheControl; - @Nullable - private ResourceHttpMessageWriter resourceHttpMessageWriter; + private @Nullable ResourceHttpMessageWriter resourceHttpMessageWriter; - @Nullable - private Map mediaTypes; + private @Nullable Map mediaTypes; private boolean useLastModified = true; - @Nullable - private Function etagGenerator; + private @Nullable Function etagGenerator; private boolean optimizeLocations = false; @@ -235,8 +228,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { /** * Return the configured resource message writer. */ - @Nullable - public ResourceHttpMessageWriter getResourceHttpMessageWriter() { + public @Nullable ResourceHttpMessageWriter getResourceHttpMessageWriter() { return this.resourceHttpMessageWriter; } @@ -252,8 +244,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { * Return the {@link org.springframework.http.CacheControl} instance to build * the Cache-Control HTTP response header. */ - @Nullable - public CacheControl getCacheControl() { + public @Nullable CacheControl getCacheControl() { return this.cacheControl; } @@ -296,8 +287,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { * @return the HTTP ETag generator function * @since 6.1 */ - @Nullable - public Function getEtagGenerator() { + public @Nullable Function getEtagGenerator() { return this.etagGenerator; } @@ -525,8 +515,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean { return false; } - @Nullable - private MediaType getMediaType(Resource resource) { + private @Nullable MediaType getMediaType(Resource resource) { MediaType mediaType = null; String filename = resource.getFilename(); if (!CollectionUtils.isEmpty(this.mediaTypes)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/TransformedResource.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/TransformedResource.java index 220dd7b56d..82dfb6c1b3 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/TransformedResource.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/TransformedResource.java @@ -18,9 +18,10 @@ package org.springframework.web.reactive.resource; import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * An extension of {@link ByteArrayResource} that a {@link ResourceTransformer} @@ -32,8 +33,7 @@ import org.springframework.lang.Nullable; */ public class TransformedResource extends ByteArrayResource { - @Nullable - private final String filename; + private final @Nullable String filename; private final long lastModified; @@ -52,8 +52,7 @@ public class TransformedResource extends ByteArrayResource { @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.filename; } 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 7bf4af1c68..f17c620709 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 @@ -30,12 +30,12 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; 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; @@ -220,8 +220,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) { + protected @Nullable VersionStrategy getStrategyForPath(String requestPath) { String path = "/".concat(requestPath); List matchingPatterns = new ArrayList<>(); for (String pattern : this.versionStrategyMap.keySet()) { @@ -320,8 +319,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.original.getFilename(); } 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 f7269bc176..6904d5d0ee 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 @@ -16,10 +16,10 @@ package org.springframework.web.reactive.resource; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * A strategy to determine the version of a static resource and to apply and/or @@ -37,8 +37,7 @@ public interface VersionStrategy { * @param requestPath the request path to check * @return the version string or {@code null} if none was found */ - @Nullable - String extractVersion(String requestPath); + @Nullable String extractVersion(String requestPath); /** * Remove the version from the request path. It is assumed that the given 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 b5baa18e0a..5236d580a5 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,9 +1,7 @@ /** * Support classes for serving static resources. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.resource; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 24d176948b..e0be343103 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 @@ -24,12 +24,12 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; 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.util.MimeTypeUtils; import org.springframework.web.reactive.HandlerMapping; @@ -104,8 +104,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} if none */ - @Nullable - protected ReactiveAdapter getAdapter(HandlerResult result) { + protected @Nullable ReactiveAdapter getAdapter(HandlerResult result) { return getAdapterRegistry().getAdapter(result.getReturnType().resolve(), result.getReturnValue()); } @@ -116,8 +115,7 @@ public abstract class HandlerResultHandlerSupport implements Ordered { * @param producibleTypesSupplier the media types producible for the request * @return the selected media type, or {@code null} if none */ - @Nullable - protected MediaType selectMediaType(ServerWebExchange exchange, Supplier> producibleTypesSupplier) { + protected @Nullable MediaType selectMediaType(ServerWebExchange exchange, Supplier> producibleTypesSupplier) { return selectMediaType(exchange, producibleTypesSupplier, getAcceptableTypes(exchange)); } @@ -125,8 +123,7 @@ public abstract class HandlerResultHandlerSupport implements Ordered { * Variant of {@link #selectMediaType(ServerWebExchange, Supplier)} with a * given list of requested (acceptable) media types. */ - @Nullable - protected MediaType selectMediaType( + protected @Nullable MediaType selectMediaType( ServerWebExchange exchange, Supplier> producibleTypesSupplier, List acceptableTypes) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java index 88d304374d..9989fb486e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractMediaTypeExpression.java @@ -18,8 +18,9 @@ package org.springframework.web.reactive.result.condition; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.server.NotAcceptableStatusException; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractNameValueExpression.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractNameValueExpression.java index 69739fea40..5a7d97ceb2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractNameValueExpression.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractNameValueExpression.java @@ -18,7 +18,8 @@ package org.springframework.web.reactive.result.condition; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; import org.springframework.web.server.ServerWebExchange; @@ -35,8 +36,7 @@ abstract class AbstractNameValueExpression implements NameValueExpression protected final String name; - @Nullable - protected final T value; + protected final @Nullable T value; protected final boolean isNegated; @@ -62,8 +62,7 @@ abstract class AbstractNameValueExpression implements NameValueExpression } @Override - @Nullable - public T getValue() { + public @Nullable T getValue() { return this.value; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java index 0f87326390..4b54f2d511 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/AbstractRequestCondition.java @@ -19,7 +19,7 @@ package org.springframework.web.reactive.result.condition; import java.util.Collection; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A base class for {@link RequestCondition} types providing implementations of 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 40e56fb979..364a4493a4 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,7 +21,8 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.server.ServerWebExchange; @@ -143,8 +144,7 @@ public class CompositeRequestCondition extends AbstractRequestConditionAn empty {@code CompositeRequestCondition} matches to all requests. */ @Override - @Nullable - public CompositeRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable CompositeRequestCondition getMatchingCondition(ServerWebExchange exchange) { if (isEmpty()) { return this; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java index 29e8a774ed..fa70667f82 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ConsumesRequestCondition.java @@ -23,11 +23,12 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -75,14 +76,14 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition 1) { Collections.sort(this.expressions); } } - private static List parseExpressions(@Nullable String[] consumes, @Nullable String[] headers) { + private static List parseExpressions(String @Nullable [] consumes, String @Nullable [] headers) { Set result = null; if (!ObjectUtils.isEmpty(headers)) { for (String header : headers) { @@ -194,8 +195,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition getMatchingExpressions(ServerWebExchange exchange) { + private @Nullable List getMatchingExpressions(ServerWebExchange exchange) { List result = null; for (ConsumeMediaTypeExpression expression : this.expressions) { if (expression.match(exchange)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/HeadersRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/HeadersRequestCondition.java index d1135f3e37..1e8c1a95c2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/HeadersRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/HeadersRequestCondition.java @@ -21,7 +21,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMapping; @@ -120,8 +121,7 @@ public final class HeadersRequestCondition extends AbstractRequestCondition { String getName(); - @Nullable - T getValue(); + @Nullable T getValue(); boolean isNegated(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ParamsRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ParamsRequestCondition.java index 8304a87ab5..487e73b4ec 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ParamsRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ParamsRequestCondition.java @@ -21,7 +21,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMapping; @@ -103,8 +104,7 @@ public final class ParamsRequestCondition extends AbstractRequestCondition matches = getMatchingPatterns(exchange); return (matches != null ? new PatternsRequestCondition(matches) : null); } - @Nullable - private SortedSet getMatchingPatterns(ServerWebExchange exchange) { + private @Nullable SortedSet getMatchingPatterns(ServerWebExchange exchange) { PathContainer lookupPath = exchange.getRequest().getPath().pathWithinApplication(); TreeSet result = null; for (PathPattern pattern : this.patterns) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java index 3d51b46b6c..91431651f8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/ProducesRequestCondition.java @@ -22,8 +22,9 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeType; import org.springframework.util.ObjectUtils; @@ -81,7 +82,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition 1) { @@ -102,7 +103,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition parseExpressions(@Nullable String[] produces, @Nullable String[] headers) { + private List parseExpressions(String @Nullable [] produces, String @Nullable [] headers) { Set result = null; if (!ObjectUtils.isEmpty(headers)) { for (String header : headers) { @@ -193,8 +194,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition getMatchingExpressions(ServerWebExchange exchange) { + private @Nullable List getMatchingExpressions(ServerWebExchange exchange) { List result = null; for (ProduceMediaTypeExpression expression : this.expressions) { if (expression.match(exchange)) { 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 d42758de5d..8dfb620782 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,7 +16,8 @@ package org.springframework.web.reactive.result.condition; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.server.ServerWebExchange; /** @@ -55,8 +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); + @Nullable T getMatchingCondition(ServerWebExchange exchange); /** * Compare this condition to another condition in the context of 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 d255935135..1288b867af 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,7 +19,8 @@ package org.springframework.web.reactive.result.condition; import java.util.Collection; import java.util.Collections; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.server.ServerWebExchange; /** @@ -38,8 +39,7 @@ import org.springframework.web.server.ServerWebExchange; */ public final class RequestConditionHolder extends AbstractRequestCondition { - @Nullable - private final RequestCondition condition; + private final @Nullable RequestCondition condition; /** @@ -55,8 +55,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition getCondition() { + public @Nullable RequestCondition getCondition() { return this.condition; } @@ -99,8 +98,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition extends AbstractHandlerMap /** * Extract and return the CORS configuration for the mapping. */ - @Nullable - protected CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) { + protected @Nullable CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) { return null; } @@ -317,8 +316,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @see #handleMatch * @see #handleNoMatch */ - @Nullable - protected HandlerMethod lookupHandlerMethod(ServerWebExchange exchange) throws Exception { + protected @Nullable HandlerMethod lookupHandlerMethod(ServerWebExchange exchange) throws Exception { List matches = new ArrayList<>(); List directPathMatches = this.mappingRegistry.getMappingsByDirectPath(exchange); if (directPathMatches != null) { @@ -389,8 +387,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, ServerWebExchange exchange) throws Exception { + protected @Nullable HandlerMethod handleNoMatch(Set mappings, ServerWebExchange exchange) throws Exception { return null; } @@ -401,8 +398,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } @Override - @Nullable - protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) { + protected @Nullable CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchange exchange) { CorsConfiguration corsConfig = super.getCorsConfiguration(handler, exchange); if (handler instanceof HandlerMethod handlerMethod) { if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) { @@ -432,8 +428,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); + protected abstract @Nullable T getMappingForMethod(Method method, Class handlerType); /** * Return the request mapping paths that are not patterns. @@ -450,8 +445,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); + protected abstract @Nullable T getMatchingMapping(T mapping, ServerWebExchange exchange); /** * Return a comparator for sorting matching mappings. @@ -491,8 +485,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * @since 5.3 * @see #acquireReadLock() */ - @Nullable - public List getMappingsByDirectPath(ServerWebExchange exchange) { + public @Nullable List getMappingsByDirectPath(ServerWebExchange exchange) { String path = exchange.getRequest().getPath().pathWithinApplication().value(); return this.pathLookup.get(path); } @@ -500,8 +493,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Return CORS configuration. Thread-safe for concurrent use. */ - @Nullable - public CorsConfiguration getCorsConfiguration(HandlerMethod handlerMethod) { + public @Nullable CorsConfiguration getCorsConfiguration(HandlerMethod handlerMethod) { HandlerMethod original = handlerMethod.getResolvedFromHandlerMethod(); return this.corsLookup.get(original != null ? original : handlerMethod); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java index 351badb98e..1bb79e4c66 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/HandlerMethodArgumentResolverComposite.java @@ -22,10 +22,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebExchange; @@ -123,8 +123,7 @@ class HandlerMethodArgumentResolverComposite implements HandlerMethodArgumentRes * Find a registered {@link HandlerMethodArgumentResolver} that supports * the given method parameter. */ - @Nullable - private HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { + private @Nullable HandlerMethodArgumentResolver getArgumentResolver(MethodParameter parameter) { HandlerMethodArgumentResolver result = this.argumentResolverCache.get(parameter); if (result == null) { for (HandlerMethodArgumentResolver methodArgumentResolver : this.argumentResolvers) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java index 836a775308..f6bc3fb54c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/InvocableHandlerMethod.java @@ -35,6 +35,7 @@ import kotlin.reflect.KType; import kotlin.reflect.full.KClasses; import kotlin.reflect.jvm.KCallablesJvm; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.publisher.SynchronousSink; import reactor.core.scheduler.Scheduler; @@ -49,7 +50,6 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpStatusCode; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.lang.Contract; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.validation.method.MethodValidator; @@ -89,13 +89,11 @@ public class InvocableHandlerMethod extends HandlerMethod { private ReactiveAdapterRegistry reactiveAdapterRegistry = ReactiveAdapterRegistry.getSharedInstance(); - @Nullable - private MethodValidator methodValidator; + private @Nullable MethodValidator methodValidator; private Class[] validationGroups = EMPTY_GROUPS; - @Nullable - private Scheduler invocationScheduler; + private @Nullable Scheduler invocationScheduler; /** @@ -182,7 +180,7 @@ public class InvocableHandlerMethod extends HandlerMethod { */ @SuppressWarnings({"unchecked", "NullAway"}) public Mono invoke( - ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { + ServerWebExchange exchange, BindingContext bindingContext, @Nullable Object... providedArgs) { return getMethodArgumentValuesOnScheduler(exchange, bindingContext, providedArgs).flatMap(args -> { if (shouldValidateArguments() && this.methodValidator != null) { @@ -237,13 +235,13 @@ public class InvocableHandlerMethod extends HandlerMethod { } private Mono getMethodArgumentValuesOnScheduler( - ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { + ServerWebExchange exchange, BindingContext bindingContext, @Nullable Object... providedArgs) { Mono argumentValuesMono = getMethodArgumentValues(exchange, bindingContext, providedArgs); return this.invocationScheduler != null ? argumentValuesMono.publishOn(this.invocationScheduler) : argumentValuesMono; } private Mono getMethodArgumentValues( - ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { + ServerWebExchange exchange, BindingContext bindingContext, @Nullable Object... providedArgs) { MethodParameter[] parameters = getMethodParameters(); if (ObjectUtils.isEmpty(parameters)) { @@ -323,9 +321,8 @@ public class InvocableHandlerMethod extends HandlerMethod { // Copy of CoWebFilter.COROUTINE_CONTEXT_ATTRIBUTE value to avoid compilation errors in Eclipse private static final String COROUTINE_CONTEXT_ATTRIBUTE = "org.springframework.web.server.CoWebFilter.context"; - @Nullable @SuppressWarnings("DataFlowIssue") - public static Object invokeFunction(Method method, Object target, Object[] args, boolean isSuspendingFunction, + public static @Nullable Object invokeFunction(Method method, Object target, Object[] args, boolean isSuspendingFunction, ServerWebExchange exchange) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { if (isSuspendingFunction) { 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 2f3124288a..3d28c33b27 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 @@ -21,7 +21,8 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMethod; @@ -70,8 +71,7 @@ public final class RequestMappingInfo implements RequestCondition getCustomCondition() { + public @Nullable RequestCondition getCustomCondition() { return this.customConditionHolder.getCondition(); } @@ -243,8 +241,7 @@ public final class RequestMappingInfo implements RequestCondition customCondition; + private @Nullable RequestCondition customCondition; private BuilderConfiguration options = new BuilderConfiguration(); @@ -618,11 +607,9 @@ public final class RequestMappingInfo implements RequestCondition infos, + protected @Nullable HandlerMethod handleNoMatch(Set infos, ServerWebExchange exchange) throws Exception { if (CollectionUtils.isEmpty(infos)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java index f6d7c162df..32d7e51fde 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncHandlerMethodArgumentResolver.java @@ -16,10 +16,10 @@ package org.springframework.web.reactive.result.method; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebExchange; @@ -51,8 +51,7 @@ public interface SyncHandlerMethodArgumentResolver extends HandlerMethodArgument * @param exchange the current exchange * @return the resolved value, if any */ - @Nullable - Object resolveArgumentValue( + @Nullable Object resolveArgumentValue( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java index fc82786fde..a7d164f58e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/SyncInvocableHandlerMethod.java @@ -21,9 +21,10 @@ import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.jspecify.annotations.Nullable; + import org.springframework.core.DefaultParameterNameDiscoverer; import org.springframework.core.ParameterNameDiscoverer; -import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.HandlerResult; @@ -96,8 +97,7 @@ public class SyncInvocableHandlerMethod extends HandlerMethod { * @return a Mono with a {@link HandlerResult}. * @throws ServerErrorException if method argument resolution or method invocation fails */ - @Nullable - public HandlerResult invokeForHandlerResult(ServerWebExchange exchange, + public @Nullable HandlerResult invokeForHandlerResult(ServerWebExchange exchange, BindingContext bindingContext, Object... providedArgs) { CompletableFuture future = 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 f728423709..776c400be4 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 @@ -22,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -44,7 +45,6 @@ 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.ValidationAnnotationUtils; @@ -260,8 +260,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) { + private Object @Nullable [] extractValidationHints(MethodParameter parameter) { Annotation[] annotations = parameter.getParameterAnnotations(); for (Annotation ann : annotations) { Object[] hints = ValidationAnnotationUtils.determineValidationHints(ann); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java index 763e8db287..af7436a8e1 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/AbstractMessageWriterResultHandler.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -37,7 +38,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ProblemDetail; import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.CollectionUtils; 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 25b177af66..0f79892096 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 @@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentHashMap; import kotlin.reflect.KFunction; import kotlin.reflect.KParameter; import kotlin.reflect.jvm.ReflectJvmMapping; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.BeanUtils; @@ -35,7 +36,6 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.KotlinDetector; 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; @@ -69,11 +69,9 @@ import org.springframework.web.server.ServerWebInputException; */ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodArgumentResolverSupport { - @Nullable - private final ConfigurableBeanFactory configurableBeanFactory; + private final @Nullable ConfigurableBeanFactory configurableBeanFactory; - @Nullable - private final BeanExpressionContext expressionContext; + private final @Nullable BeanExpressionContext expressionContext; private final Map namedValueInfoCache = new ConcurrentHashMap<>(256); @@ -167,8 +165,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr * Resolve the given annotation-specified value, * potentially containing placeholders and expressions. */ - @Nullable - private Object resolveEmbeddedValuesAndExpressions(String value) { + private @Nullable Object resolveEmbeddedValuesAndExpressions(String value) { if (this.configurableBeanFactory == null || this.expressionContext == null) { return value; } @@ -193,8 +190,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr /** * Apply type conversion if necessary. */ - @Nullable - private Object applyConversion(@Nullable Object value, NamedValueInfo namedValueInfo, MethodParameter parameter, + private @Nullable Object applyConversion(@Nullable Object value, NamedValueInfo namedValueInfo, MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { WebDataBinder binder = bindingContext.createDataBinder(exchange, namedValueInfo.name); @@ -277,8 +273,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. */ - @Nullable - private Object handleNullValue(String name, @Nullable Object value, Class paramType) { + private @Nullable Object handleNullValue(String name, @Nullable Object value, Class paramType) { if (value == null) { if (paramType == boolean.class) { return Boolean.FALSE; @@ -317,8 +312,7 @@ public abstract class AbstractNamedValueArgumentResolver extends HandlerMethodAr private final boolean required; - @Nullable - private final String defaultValue; + private final @Nullable String defaultValue; public NamedValueInfo(String name, boolean required, @Nullable String defaultValue) { this.name = name; 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 1344d0bd3e..7806237ee8 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 @@ -16,12 +16,12 @@ package org.springframework.web.reactive.result.method.annotation; +import org.jspecify.annotations.Nullable; 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; @@ -80,7 +80,6 @@ public abstract class AbstractNamedValueSyncArgumentResolver extends AbstractNam /** * Actually resolve the value synchronously. */ - @Nullable - protected abstract Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange); + protected abstract @Nullable Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java index d4011e05a8..58698d4be0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ControllerMethodResolver.java @@ -28,6 +28,7 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.scheduler.Scheduler; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; @@ -40,7 +41,6 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.http.MediaType; import org.springframework.http.codec.HttpMessageReader; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils.MethodFilter; @@ -112,14 +112,11 @@ class ControllerMethodResolver { private final RequestedContentTypeResolver contentTypeResolver; - @Nullable - private final Scheduler invocationScheduler; + private final @Nullable Scheduler invocationScheduler; - @Nullable - private final Predicate blockingMethodPredicate; + private final @Nullable Predicate blockingMethodPredicate; - @Nullable - private final MethodValidator methodValidator; + private final @Nullable MethodValidator methodValidator; private final Map, Set> initBinderMethodCache = new ConcurrentHashMap<>(64); @@ -313,8 +310,7 @@ class ControllerMethodResolver { * blocking by the underlying blocking method predicate, or null if no * particular scheduler should be used for this method invocation. */ - @Nullable - public Scheduler getSchedulerFor(HandlerMethod handlerMethod) { + public @Nullable Scheduler getSchedulerFor(HandlerMethod handlerMethod) { if (this.invocationScheduler != null) { Assert.state(this.blockingMethodPredicate != null, "Expected HandlerMethod Predicate"); if (this.blockingMethodPredicate.test(handlerMethod)) { @@ -412,9 +408,8 @@ class ControllerMethodResolver { * @param handlerMethod the controller method that raised the exception, * or if {@code null}, check only {@code @ControllerAdvice} classes. */ - @Nullable @SuppressWarnings("NullAway") - public InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, ServerWebExchange exchange, @Nullable HandlerMethod handlerMethod) { + public @Nullable InvocableHandlerMethod getExceptionHandlerMethod(Throwable ex, ServerWebExchange exchange, @Nullable HandlerMethod handlerMethod) { Class handlerType = (handlerMethod != null ? handlerMethod.getBeanType() : null); List requestedMediaTypes = List.of(MediaType.ALL); 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 75c84dee3a..09355c28e1 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 @@ -16,11 +16,12 @@ package org.springframework.web.reactive.result.method.annotation; +import org.jspecify.annotations.Nullable; + 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.util.Assert; import org.springframework.web.bind.annotation.CookieValue; import org.springframework.web.server.MissingRequestValueException; @@ -65,8 +66,7 @@ public class CookieValueMethodArgumentResolver extends AbstractNamedValueSyncArg } @Override - @Nullable - protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { HttpCookie cookie = exchange.getRequest().getCookies().getFirst(name); Class paramType = parameter.getNestedParameterType(); if (HttpCookie.class.isAssignableFrom(paramType)) { 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 1355c52575..a233da8077 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 @@ -16,11 +16,12 @@ package org.springframework.web.reactive.result.method.annotation; +import org.jspecify.annotations.Nullable; + 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.util.Assert; import org.springframework.web.server.ServerWebExchange; @@ -63,8 +64,7 @@ public class ExpressionValueMethodArgumentResolver extends AbstractNamedValueSyn } @Override - @Nullable - protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { // No name to resolve return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java index ec3f998573..a018372462 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ExtendedWebExchangeDataBinder.java @@ -21,10 +21,10 @@ import java.util.Map; import java.util.Set; import java.util.function.Predicate; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.support.WebExchangeDataBinder; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityMethodArgumentResolver.java index 5d9c8fc57a..9e8b728ac8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/HttpEntityMethodArgumentResolver.java @@ -18,6 +18,7 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.List; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.MethodParameter; @@ -26,7 +27,6 @@ import org.springframework.http.HttpEntity; import org.springframework.http.RequestEntity; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebExchange; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java index c8d67038c6..aac2b708b3 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/InitBinderBindingContext.java @@ -18,8 +18,9 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.InitBinder; @@ -47,8 +48,7 @@ class InitBinderBindingContext extends BindingContext { private final SessionStatus sessionStatus = new SimpleSessionStatus(); - @Nullable - private Runnable saveModelOperation; + private @Nullable Runnable saveModelOperation; InitBinderBindingContext( diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java index a9d179d0aa..d4cd791082 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMapMethodArgumentResolver.java @@ -19,10 +19,11 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -63,9 +64,8 @@ public class MatrixVariableMapMethodArgumentResolver extends HandlerMethodArgume (ann, type) -> (Map.class.isAssignableFrom(type) && !StringUtils.hasText(ann.name()))); } - @Nullable @Override - public Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext, + public @Nullable Object resolveArgumentValue(MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { Map> matrixVariables = diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java index 0722365347..083c83c39c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/MatrixVariableMethodArgumentResolver.java @@ -20,10 +20,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -71,9 +72,8 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueSync return new MatrixVariableNamedValueInfo(ann); } - @Nullable @Override - protected Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter param, ServerWebExchange exchange) { Map> pathParameters = exchange.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE); if (CollectionUtils.isEmpty(pathParameters)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java index b45c3ba0da..d9ea3ddb07 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ModelAttributeMethodArgumentResolver.java @@ -19,6 +19,7 @@ package org.springframework.web.reactive.result.method.annotation; import java.lang.annotation.Annotation; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; @@ -29,7 +30,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; @@ -173,8 +173,7 @@ public class ModelAttributeMethodArgumentResolver extends HandlerMethodArgumentR } } - @Nullable - private Object removeReactiveAttribute(String name, Model model) { + private @Nullable Object removeReactiveAttribute(String name, Model model) { for (Map.Entry entry : model.asMap().entrySet()) { if (entry.getKey().startsWith(name)) { ReactiveAdapter adapter = getAdapterRegistry().getAdapter(null, entry.getValue()); 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 c3c493ebe9..67c99bd117 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 @@ -19,11 +19,12 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.Assert; import org.springframework.util.StringUtils; @@ -85,8 +86,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueSyncAr } @Override - @Nullable - protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { String attributeName = HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE; return exchange.getAttributeOrDefault(attributeName, Collections.emptyMap()).get(name); } 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 537e565828..be8d1ff797 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 @@ -16,13 +16,13 @@ package org.springframework.web.reactive.result.method.annotation; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.annotation.RequestAttribute; import org.springframework.web.bind.annotation.ValueConstants; @@ -66,8 +66,7 @@ public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueSy } @Override - @Nullable - protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { Object value = exchange.getAttribute(name); ReactiveAdapter toAdapter = getAdapterRegistry().getAdapter(parameter.getParameterType()); if (toAdapter != null) { 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 5a2250c8d0..c4b3205368 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 @@ -19,11 +19,12 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.util.Assert; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.server.MissingRequestValueException; @@ -78,8 +79,7 @@ public class RequestHeaderMethodArgumentResolver extends AbstractNamedValueSyncA } @Override - @Nullable - protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { List headerValues = exchange.getRequest().getHeaders().get(name); Object result = null; if (headerValues != null) { 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 071ddc37c8..bc857a5aee 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 @@ -24,6 +24,7 @@ import java.util.function.Predicate; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; import reactor.core.scheduler.Schedulers; @@ -36,7 +37,6 @@ import org.springframework.core.KotlinDetector; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.ServerCodecConfigurer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.support.WebBindingInitializer; @@ -79,31 +79,23 @@ public class RequestMappingHandlerAdapter private List> messageReaders = Collections.emptyList(); - @Nullable - private WebBindingInitializer webBindingInitializer; + private @Nullable WebBindingInitializer webBindingInitializer; - @Nullable - private ArgumentResolverConfigurer argumentResolverConfigurer; + private @Nullable ArgumentResolverConfigurer argumentResolverConfigurer; private RequestedContentTypeResolver contentTypeResolver = new RequestedContentTypeResolverBuilder().build(); - @Nullable - private Scheduler scheduler; + private @Nullable Scheduler scheduler; - @Nullable - private Predicate blockingMethodPredicate; + private @Nullable Predicate blockingMethodPredicate; - @Nullable - private ReactiveAdapterRegistry reactiveAdapterRegistry; + private @Nullable ReactiveAdapterRegistry reactiveAdapterRegistry; - @Nullable - private ConfigurableApplicationContext applicationContext; + private @Nullable ConfigurableApplicationContext applicationContext; - @Nullable - private ControllerMethodResolver methodResolver; + private @Nullable ControllerMethodResolver methodResolver; - @Nullable - private ModelInitializer modelInitializer; + private @Nullable ModelInitializer modelInitializer; /** @@ -133,8 +125,7 @@ public class RequestMappingHandlerAdapter /** * Return the configured WebBindingInitializer, or {@code null} if none. */ - @Nullable - public WebBindingInitializer getWebBindingInitializer() { + public @Nullable WebBindingInitializer getWebBindingInitializer() { return this.webBindingInitializer; } @@ -148,8 +139,7 @@ public class RequestMappingHandlerAdapter /** * Return the configured resolvers for controller method arguments. */ - @Nullable - public ArgumentResolverConfigurer getArgumentResolverConfigurer() { + public @Nullable ArgumentResolverConfigurer getArgumentResolverConfigurer() { return this.argumentResolverConfigurer; } @@ -207,8 +197,7 @@ public class RequestMappingHandlerAdapter /** * Return the configured registry for adapting reactive types. */ - @Nullable - public ReactiveAdapterRegistry getReactiveAdapterRegistry() { + public @Nullable ReactiveAdapterRegistry getReactiveAdapterRegistry() { return this.reactiveAdapterRegistry; } 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 6cce38b7e5..b722b92149 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 @@ -27,6 +27,8 @@ import java.util.Map; import java.util.function.Predicate; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; + import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.MergedAnnotation; @@ -34,7 +36,6 @@ import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.RepeatableContainers; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -77,8 +78,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi private RequestedContentTypeResolver contentTypeResolver = new RequestedContentTypeResolverBuilder().build(); - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration(); @@ -160,8 +160,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @see #getCustomTypeCondition(Class) */ @Override - @Nullable - protected RequestMappingInfo getMappingForMethod(Method method, Class handlerType) { + protected @Nullable RequestMappingInfo getMappingForMethod(Method method, Class handlerType) { RequestMappingInfo info = createRequestMappingInfo(method); if (info != null) { RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType); @@ -186,8 +185,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi return info; } - @Nullable - private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { + private @Nullable RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { RequestMappingInfo requestMappingInfo = null; RequestCondition customCondition = (element instanceof Class clazz ? getCustomTypeCondition(clazz) : getCustomMethodCondition((Method) element)); @@ -233,8 +231,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @return the condition, or {@code null} */ @SuppressWarnings("UnusedParameters") - @Nullable - protected RequestCondition getCustomTypeCondition(Class handlerType) { + protected @Nullable RequestCondition getCustomTypeCondition(Class handlerType) { return null; } @@ -252,8 +249,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @return the condition, or {@code null} */ @SuppressWarnings("UnusedParameters") - @Nullable - protected RequestCondition getCustomMethodCondition(Method method) { + protected @Nullable RequestCondition getCustomMethodCondition(Method method) { return null; } @@ -358,8 +354,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi } @Override - @Nullable - protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { + protected @Nullable CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { HandlerMethod handlerMethod = createHandlerMethod(handler, method); Class beanType = handlerMethod.getBeanType(); CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class); 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 17c6a868d0..b2f977dfcd 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 @@ -19,12 +19,13 @@ package org.springframework.web.reactive.result.method.annotation; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanUtils; 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; @@ -98,8 +99,7 @@ public class RequestParamMethodArgumentResolver extends AbstractNamedValueSyncAr } @Override - @Nullable - protected Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { + protected @Nullable Object resolveNamedValue(String name, MethodParameter parameter, ServerWebExchange exchange) { Object result = null; List paramValues = exchange.getRequest().getQueryParams().get(name); if (paramValues == null) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java index 8cdf713595..059bce4da5 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestPartMethodArgumentResolver.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.multipart.Part; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestPart; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java index ff34740788..4ba05d2174 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityExceptionHandler.java @@ -20,6 +20,7 @@ import java.util.Locale; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.context.MessageSource; @@ -29,7 +30,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.ProblemDetail; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.validation.method.MethodValidationException; import org.springframework.web.ErrorResponse; import org.springframework.web.ErrorResponseException; @@ -69,8 +69,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private MessageSource messageSource; + private @Nullable MessageSource messageSource; @Override @@ -82,8 +81,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * Get the {@link MessageSource} that this exception handler uses. * @since 6.0.3 */ - @Nullable - protected MessageSource getMessageSource() { + protected @Nullable MessageSource getMessageSource() { return this.messageSource; } @@ -361,7 +359,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa */ protected ProblemDetail createProblemDetail( Exception ex, HttpStatusCode status, String defaultDetail, @Nullable String detailMessageCode, - @Nullable Object[] detailMessageArguments, ServerWebExchange exchange) { + Object @Nullable [] detailMessageArguments, ServerWebExchange exchange) { ErrorResponse.Builder builder = ErrorResponse.builder(ex, status, defaultDetail); if (detailMessageCode != null) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java index 3d91c62a7d..1961429a1d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ResponseEntityResultHandler.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.KotlinDetector; @@ -36,7 +37,6 @@ import org.springframework.http.ProblemDetail; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.http.codec.HttpMessageWriter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.ErrorResponse; import org.springframework.web.reactive.HandlerResult; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeMethodArgumentResolver.java index 3231b4a87e..f648bb21b8 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/ServerWebExchangeMethodArgumentResolver.java @@ -21,6 +21,8 @@ import java.time.ZoneId; import java.util.Locale; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; import org.springframework.core.MethodParameter; @@ -28,7 +30,6 @@ import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpMethod; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.result.method.HandlerMethodArgumentResolverSupport; import org.springframework.web.reactive.result.method.SyncHandlerMethodArgumentResolver; @@ -80,8 +81,7 @@ public class ServerWebExchangeMethodArgumentResolver extends HandlerMethodArgume } @Override - @Nullable - public Object resolveArgumentValue( + public @Nullable Object resolveArgumentValue( MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { Class paramType = methodParameter.getParameterType(); @@ -122,8 +122,7 @@ public class ServerWebExchangeMethodArgumentResolver extends HandlerMethodArgume } } - @Nullable - private TimeZone getTimeZone(LocaleContext localeContext) { + private @Nullable TimeZone getTimeZone(LocaleContext localeContext) { TimeZone timeZone = null; if (localeContext instanceof TimeZoneAwareLocaleContext timeZoneAwareLocaleContext) { timeZone = timeZoneAwareLocaleContext.getTimeZone(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java index 5a9d37d89d..c2d1f90b80 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/SessionStatusMethodArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.reactive.result.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.support.SessionStatus; import org.springframework.web.reactive.BindingContext; @@ -38,9 +39,8 @@ public class SessionStatusMethodArgumentResolver implements SyncHandlerMethodArg return SessionStatus.class == parameter.getParameterType(); } - @Nullable @Override - public Object resolveArgumentValue( + public @Nullable Object resolveArgumentValue( MethodParameter parameter, BindingContext bindingContext, ServerWebExchange exchange) { Assert.isInstanceOf(InitBinderBindingContext.class, bindingContext); 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 01e8df69bd..4fc8082a2e 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,9 +1,7 @@ /** * Infrastructure for annotation-based handler method processing. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result.method.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 e5bbb0c703..eb754679b3 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,9 +1,7 @@ /** * Infrastructure for handler method processing. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result.method; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 be6787715f..3f89955b0a 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,9 +4,7 @@ * {@code WebHandler}. Includes the handling of handler result values — * for example, {@code @ResponseBody}, view resolution, and so on. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractUrlBasedView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractUrlBasedView.java index b290d59649..e459c767b4 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractUrlBasedView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/AbstractUrlBasedView.java @@ -18,10 +18,10 @@ package org.springframework.web.reactive.result.view; import java.util.Locale; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * Abstract base class for URL-based views. Provides a consistent way of @@ -32,8 +32,7 @@ import org.springframework.lang.Nullable; */ public abstract class AbstractUrlBasedView extends AbstractView implements InitializingBean { - @Nullable - private String url; + private @Nullable String url; /** @@ -61,8 +60,7 @@ public abstract class AbstractUrlBasedView extends AbstractView implements Initi /** * Return the URL of the resource that this view wraps. */ - @Nullable - public String getUrl() { + public @Nullable String getUrl() { return this.url; } 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 cd761d5bdb..6a5353bb46 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 @@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -37,7 +38,6 @@ import org.springframework.context.ApplicationContextAware; 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.validation.BindingResult; import org.springframework.web.reactive.BindingContext; @@ -65,14 +65,11 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo private Charset defaultCharset = StandardCharsets.UTF_8; - @Nullable - private String requestContextAttribute; + private @Nullable String requestContextAttribute; - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; public AbstractView() { @@ -132,8 +129,7 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo /** * Get the name of the {@code RequestContext} attribute for this view, if any. */ - @Nullable - public String getRequestContextAttribute() { + public @Nullable String getRequestContextAttribute() { return this.requestContextAttribute; } @@ -150,8 +146,7 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo * Get the view's name. *

    Should never be {@code null} if the view was correctly configured. */ - @Nullable - public String getBeanName() { + public @Nullable String getBeanName() { return this.beanName; } @@ -160,8 +155,7 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -315,8 +309,7 @@ public abstract class AbstractView implements View, BeanNameAware, ApplicationCo * @return the {@code RequestDataValueProcessor}, or {@code null} if there is * none in the application context */ - @Nullable - protected RequestDataValueProcessor getRequestDataValueProcessor() { + protected @Nullable RequestDataValueProcessor getRequestDataValueProcessor() { ApplicationContext context = getApplicationContext(); if (context != null && context.containsBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME)) { return context.getBean(REQUEST_DATA_VALUE_PROCESSOR_BEAN_NAME, RequestDataValueProcessor.class); 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 a244a33cb4..27267b4cea 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 @@ -20,10 +20,11 @@ import java.beans.PropertyEditor; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.context.NoSuchMessageException; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; @@ -53,34 +54,25 @@ public class BindStatus { private final boolean htmlEscape; - @Nullable - private final String expression; + private final @Nullable String expression; - @Nullable - private final Errors errors; + private final @Nullable Errors errors; private final String[] errorCodes; - @Nullable - private String[] errorMessages; + private String @Nullable [] errorMessages; - @Nullable - private List objectErrors; + private @Nullable List objectErrors; - @Nullable - private Object value; + private @Nullable Object value; - @Nullable - private Class valueType; + private @Nullable Class valueType; - @Nullable - private Object actualValue; + private @Nullable Object actualValue; - @Nullable - private PropertyEditor editor; + private @Nullable PropertyEditor editor; - @Nullable - private BindingResult bindingResult; + private @Nullable BindingResult bindingResult; /** @@ -195,8 +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() { + public @Nullable String getExpression() { return this.expression; } @@ -206,8 +197,7 @@ public class BindStatus { *

    This value will be an HTML-escaped String if the original value * already was a String. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } @@ -216,8 +206,7 @@ public class BindStatus { * '{@code getValue().getClass()}' since '{@code getValue()}' may * return '{@code null}'. */ - @Nullable - public Class getValueType() { + public @Nullable Class getValueType() { return this.valueType; } @@ -225,8 +214,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() { + public @Nullable Object getActualValue() { return this.actualValue; } @@ -321,8 +309,7 @@ public class BindStatus { * @return the current Errors instance, or {@code null} if none * @see org.springframework.validation.BindingResult */ - @Nullable - public Errors getErrors() { + public @Nullable Errors getErrors() { return this.errors; } @@ -331,8 +318,7 @@ public class BindStatus { * is currently bound to. * @return the current PropertyEditor, or {@code null} if none */ - @Nullable - public PropertyEditor getEditor() { + public @Nullable PropertyEditor getEditor() { return this.editor; } @@ -342,8 +328,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) { + public @Nullable 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/DefaultFragmentsRenderingBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultFragmentsRenderingBuilder.java index cbdb6c9dd4..86c79e8350 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultFragmentsRenderingBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultFragmentsRenderingBuilder.java @@ -22,12 +22,12 @@ import java.util.Collection; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; /** * Default implementation of {@link FragmentsRendering.Builder}. @@ -37,17 +37,13 @@ import org.springframework.lang.Nullable; */ class DefaultFragmentsRenderingBuilder implements FragmentsRendering.Builder { - @Nullable - private Collection fragmentsCollection; + private @Nullable Collection fragmentsCollection; - @Nullable - private final Flux fragmentsFlux; + private final @Nullable Flux fragmentsFlux; - @Nullable - private HttpStatusCode status; + private @Nullable HttpStatusCode status; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; DefaultFragmentsRenderingBuilder() { this.fragmentsCollection = null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRendering.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRendering.java index 82d139630a..7b6ef2c3d7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRendering.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRendering.java @@ -19,9 +19,10 @@ package org.springframework.web.reactive.result.view; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; /** @@ -39,8 +40,7 @@ class DefaultRendering implements Rendering { private final Map model; - @Nullable - private final HttpStatusCode status; + private final @Nullable HttpStatusCode status; private final HttpHeaders headers; @@ -54,8 +54,7 @@ class DefaultRendering implements Rendering { @Override - @Nullable - public Object view() { + public @Nullable Object view() { return this.view; } @@ -65,8 +64,7 @@ class DefaultRendering implements Rendering { } @Override - @Nullable - public HttpStatusCode status() { + public @Nullable HttpStatusCode status() { return this.status; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRenderingBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRenderingBuilder.java index 84a264a504..267e91cd06 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRenderingBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/DefaultRenderingBuilder.java @@ -19,9 +19,10 @@ package org.springframework.web.reactive.result.view; import java.util.Arrays; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.ui.ExtendedModelMap; import org.springframework.ui.Model; import org.springframework.util.Assert; @@ -36,14 +37,11 @@ class DefaultRenderingBuilder implements Rendering.RedirectBuilder { private final Object view; - @Nullable - private Model model; + private @Nullable Model model; - @Nullable - private HttpStatusCode status; + private @Nullable HttpStatusCode status; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; DefaultRenderingBuilder(Object view) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Fragment.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Fragment.java index f999f5ae32..c7a49a8274 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Fragment.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/Fragment.java @@ -20,7 +20,8 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.Model; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -34,14 +35,11 @@ import org.springframework.util.CollectionUtils; */ public final class Fragment { - @Nullable - private final String viewName; + private final @Nullable String viewName; - @Nullable - private final View view; + private final @Nullable View view; - @Nullable - private Map model; + private @Nullable Map model; private Fragment(@Nullable String viewName, @Nullable View view, @Nullable Map model) { @@ -61,8 +59,7 @@ public final class Fragment { /** * Return the view name of the Fragment, or {@code null} if not set. */ - @Nullable - public String viewName() { + public @Nullable String viewName() { return this.viewName; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/FragmentsRendering.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/FragmentsRendering.java index 2767146268..d2a5f196b9 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/FragmentsRendering.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/FragmentsRendering.java @@ -20,6 +20,7 @@ import java.util.Collection; import java.util.Map; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -27,7 +28,6 @@ import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -50,8 +50,7 @@ public interface FragmentsRendering { /** * Return the HTTP status to set the response to. */ - @Nullable - HttpStatusCode status(); + @Nullable HttpStatusCode status(); /** * Return headers to add to the response. 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 4833987a91..8b80773a27 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 @@ -22,6 +22,7 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -31,7 +32,6 @@ import org.springframework.core.codec.Hints; 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,8 +120,7 @@ public class HttpMessageWriterView implements View { return (value != null ? write(value, contentType, exchange) : exchange.getResponse().setComplete()); } - @Nullable - private Object getObjectToRender(@Nullable Map model) { + private @Nullable Object getObjectToRender(@Nullable Map model) { if (model == null) { return null; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java index 1ffcdd33ef..5390a0e2da 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java @@ -24,6 +24,7 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.HttpStatus; @@ -31,7 +32,6 @@ import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; 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.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -63,8 +63,7 @@ public class RedirectView extends AbstractUrlBasedView { private boolean propagateQuery = false; - @Nullable - private String[] hosts; + private String @Nullable [] hosts; /** @@ -148,15 +147,14 @@ public class RedirectView extends AbstractUrlBasedView { *

    If not set (the default) all redirect URLs are encoded. * @param hosts one or more application hosts */ - public void setHosts(@Nullable String... hosts) { + public void setHosts(String @Nullable ... hosts) { this.hosts = hosts; } /** * Return the configured application hosts. */ - @Nullable - public String[] getHosts() { + public String @Nullable [] getHosts() { return this.hosts; } 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 73c1b6451a..f0f039317b 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 @@ -19,9 +19,10 @@ package org.springframework.web.reactive.result.view; import java.util.Collection; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; /** @@ -46,8 +47,7 @@ public interface Rendering { /** * Return the selected {@link String} view name or {@link View} object. */ - @Nullable - Object view(); + @Nullable Object view(); /** * Return attributes to add to the model. @@ -57,8 +57,7 @@ public interface Rendering { /** * Return the HTTP status to set the response to. */ - @Nullable - HttpStatusCode status(); + @Nullable HttpStatusCode status(); /** * Return headers to add to the response. 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 a98a911dd0..6e69490e43 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 @@ -22,13 +22,14 @@ import java.util.Locale; import java.util.Map; import java.util.TimeZone; +import org.jspecify.annotations.Nullable; + import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; import org.springframework.context.NoSuchMessageException; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; import org.springframework.http.server.reactive.ServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.validation.BindException; @@ -65,14 +66,11 @@ public class RequestContext { private TimeZone timeZone; - @Nullable - private Boolean defaultHtmlEscape; + private @Nullable Boolean defaultHtmlEscape; - @Nullable - private Map errorsMap; + private @Nullable Map errorsMap; - @Nullable - private final RequestDataValueProcessor dataValueProcessor; + private final @Nullable RequestDataValueProcessor dataValueProcessor; public RequestContext(ServerWebExchange exchange, Map model, MessageSource messageSource) { @@ -116,8 +114,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() { + public @Nullable Map getModel() { return this.model; } @@ -172,8 +169,7 @@ public class RequestContext { * specified and an explicit value. * @return whether default HTML escaping is enabled (null = no explicit default) */ - @Nullable - public Boolean getDefaultHtmlEscape() { + public @Nullable Boolean getDefaultHtmlEscape() { return this.defaultHtmlEscape; } @@ -181,8 +177,7 @@ public class RequestContext { * Return the {@link RequestDataValueProcessor} instance to apply to in form * tag libraries and to redirect URLs. */ - @Nullable - public RequestDataValueProcessor getRequestDataValueProcessor() { + public @Nullable RequestDataValueProcessor getRequestDataValueProcessor() { return this.dataValueProcessor; } @@ -256,7 +251,7 @@ public class RequestContext { * @param defaultMessage the String to return if the lookup fails * @return the message */ - public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { + public String getMessage(String code, Object @Nullable [] args, String defaultMessage) { return getMessage(code, args, defaultMessage, isDefaultHtmlEscape()); } @@ -279,7 +274,7 @@ public class RequestContext { * @param htmlEscape if the message should be HTML-escaped * @return the message */ - public String getMessage(String code, @Nullable Object[] args, String defaultMessage, boolean htmlEscape) { + public String getMessage(String code, Object @Nullable [] args, String defaultMessage, boolean htmlEscape) { String msg = this.messageSource.getMessage(code, args, defaultMessage, this.locale); if (msg == null) { return ""; @@ -304,7 +299,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args) throws NoSuchMessageException { return getMessage(code, args, isDefaultHtmlEscape()); } @@ -327,7 +322,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, @Nullable Object[] args, boolean htmlEscape) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args, boolean htmlEscape) throws NoSuchMessageException { String msg = this.messageSource.getMessage(code, args, this.locale); return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg); } @@ -360,8 +355,7 @@ public class RequestContext { * @param name the name of the bind object * @return the Errors instance, or {@code null} if not found */ - @Nullable - public Errors getErrors(String name) { + public @Nullable Errors getErrors(String name) { return getErrors(name, isDefaultHtmlEscape()); } @@ -371,8 +365,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) { + public @Nullable Errors getErrors(String name, boolean htmlEscape) { if (this.errorsMap == null) { this.errorsMap = new HashMap<>(); } @@ -407,8 +400,7 @@ public class RequestContext { * @return the model object */ @SuppressWarnings("unchecked") - @Nullable - protected T getModelObject(String modelName) { + protected @Nullable T getModelObject(String modelName) { T modelObject = (T) this.model.get(modelName); if (modelObject == null) { modelObject = this.exchange.getAttribute(modelName); 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 fee25884cd..d9962f607d 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 @@ -18,7 +18,8 @@ package org.springframework.web.reactive.result.view; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.server.ServerWebExchange; /** @@ -63,8 +64,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); + @Nullable Map getExtraHiddenFields(ServerWebExchange exchange); /** * Invoked when a URL is about to be rendered or redirected to. 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 d4eaab48cd..d1b0c0d8be 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 @@ -19,13 +19,13 @@ package org.springframework.web.reactive.result.view; import java.util.Locale; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.PatternMatchUtils; @@ -74,23 +74,19 @@ public class UrlBasedViewResolver extends ViewResolverSupport public static final String REDIRECT_URL_PREFIX = "redirect:"; - @Nullable - private Class viewClass; + private @Nullable Class viewClass; private String prefix = ""; private String suffix = ""; - @Nullable - private String[] viewNames; + private String @Nullable [] viewNames; private Function redirectViewProvider = RedirectView::new; - @Nullable - private String requestContextAttribute; + private @Nullable String requestContextAttribute; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; /** @@ -114,8 +110,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport * Return the view class to be used to create views. * @see #setViewClass */ - @Nullable - protected Class getViewClass() { + protected @Nullable Class getViewClass() { return this.viewClass; } @@ -153,7 +148,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport * 'my*', '*Report' and '*Repo*' will all match the view name 'myReport'. * @see #canHandle */ - public void setViewNames(@Nullable String... viewNames) { + public void setViewNames(String @Nullable ... viewNames) { this.viewNames = viewNames; } @@ -161,8 +156,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport * Return the view names (or name patterns) that can be handled by this * {@link ViewResolver}. */ - @Nullable - protected String[] getViewNames() { + protected String @Nullable [] getViewNames() { return this.viewNames; } @@ -186,8 +180,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport /** * Return the name of the {@link RequestContext} attribute for all views, if any. */ - @Nullable - protected String getRequestContextAttribute() { + protected @Nullable String getRequestContextAttribute() { return this.requestContextAttribute; } @@ -208,8 +201,7 @@ public class UrlBasedViewResolver extends ViewResolverSupport * Return the containing {@code ApplicationContext}, if any. * @see #setApplicationContext */ - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } 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 28cd9075de..c31fa3b23f 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 @@ -20,10 +20,10 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; 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; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java index b8d558e5fd..a574679df6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandler.java @@ -26,6 +26,7 @@ import java.util.Locale; import java.util.Map; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -49,7 +50,6 @@ import org.springframework.http.codec.ServerSentEvent; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -463,11 +463,9 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp */ private static class BodySavingResponse extends ServerHttpResponseDecorator { - @Nullable - private Flux bodyFlux; + private @Nullable Flux bodyFlux; - @Nullable - private HttpHeaders headers; + private @Nullable HttpHeaders headers; BodySavingResponse(ServerHttpResponse delegate) { super(delegate); @@ -553,8 +551,7 @@ public class ViewResolutionResultHandler extends HandlerResultHandlerSupport imp exchange.getResponse().getHeaders().setContentType(mediaType); } - @Nullable - private Charset getCharset(ServerHttpRequest request) { + private @Nullable Charset getCharset(ServerHttpRequest request) { for (MediaType mediaType : request.getHeaders().getAccept()) { if (mediaType.isCompatibleWith(MediaType.TEXT_EVENT_STREAM)) { if (mediaType.getCharset() != null) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerConfigurer.java index 1a28ff3e89..c35676e21b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerConfigurer.java @@ -24,10 +24,10 @@ import freemarker.cache.ClassTemplateLoader; import freemarker.cache.TemplateLoader; import freemarker.template.Configuration; import freemarker.template.TemplateException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ResourceLoaderAware; -import org.springframework.lang.Nullable; import org.springframework.ui.freemarker.FreeMarkerConfigurationFactory; import org.springframework.util.Assert; @@ -64,8 +64,7 @@ import org.springframework.util.Assert; public class FreeMarkerConfigurer extends FreeMarkerConfigurationFactory implements FreeMarkerConfig, InitializingBean, ResourceLoaderAware { - @Nullable - private Configuration configuration; + private @Nullable Configuration configuration; public FreeMarkerConfigurer() { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java index 1c5ec18756..0f1001e93c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/freemarker/FreeMarkerView.java @@ -35,6 +35,7 @@ import freemarker.template.SimpleHash; import freemarker.template.Template; import freemarker.template.TemplateException; import freemarker.template.Version; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.scheduler.Schedulers; @@ -46,7 +47,6 @@ import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.FastByteArrayOutputStream; import org.springframework.util.MimeType; @@ -109,11 +109,9 @@ public class FreeMarkerView extends AbstractUrlBasedView { public static final String SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE = "springMacroRequestContext"; - @Nullable - private Configuration configuration; + private @Nullable Configuration configuration; - @Nullable - private String encoding; + private @Nullable String encoding; private boolean exposeSpringMacroHelpers = true; @@ -131,8 +129,7 @@ public class FreeMarkerView extends AbstractUrlBasedView { /** * Get the FreeMarker {@link Configuration} used by this view. */ - @Nullable - protected Configuration getConfiguration() { + protected @Nullable Configuration getConfiguration() { return this.configuration; } @@ -193,8 +190,7 @@ public class FreeMarkerView extends AbstractUrlBasedView { * determine the encoding. * @see #setEncoding(String) */ - @Nullable - protected String getEncoding() { + protected @Nullable String getEncoding() { return this.encoding; } 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 b46c377026..88b22891df 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,9 +4,7 @@ * as Spring web view technology. * Contains a View implementation for FreeMarker templates. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result.view.freemarker; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 bb7678f221..dc78f0cc34 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,9 +1,7 @@ /** * Support for result handling through view resolution. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result.view; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfig.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfig.java index 219125b9cd..9d284b14ed 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfig.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfig.java @@ -22,7 +22,7 @@ import java.util.function.Supplier; import javax.script.Bindings; import javax.script.ScriptEngine; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that configure and manage a @@ -37,58 +37,49 @@ public interface ScriptTemplateConfig { /** * Return the {@link ScriptEngine} to use by the views. */ - @Nullable - ScriptEngine getEngine(); + @Nullable ScriptEngine getEngine(); /** * Return the engine supplier that will be used to instantiate the {@link ScriptEngine}. * @since 5.2 */ - @Nullable - Supplier getEngineSupplier(); + @Nullable Supplier getEngineSupplier(); /** * Return the engine name that will be used to instantiate the {@link ScriptEngine}. */ - @Nullable - String getEngineName(); + @Nullable String getEngineName(); /** * Return whether to use a shared engine for all threads or whether to create * thread-local engine instances for each thread. */ - @Nullable - Boolean isSharedEngine(); + @Nullable Boolean isSharedEngine(); /** * Return the scripts to be loaded by the script engine (library or user provided). */ - @Nullable - String[] getScripts(); + String @Nullable [] getScripts(); /** * Return the object where the render function belongs (optional). */ - @Nullable - String getRenderObject(); + @Nullable String getRenderObject(); /** * Return the render function name (optional). If not specified, the script templates * will be evaluated with {@link ScriptEngine#eval(String, Bindings)}. */ - @Nullable - String getRenderFunction(); + @Nullable String getRenderFunction(); /** * Return the charset used to read script and template files. */ - @Nullable - Charset getCharset(); + @Nullable Charset getCharset(); /** * Return the resource loader path(s) via a Spring resource location. */ - @Nullable - String getResourceLoaderPath(); + @Nullable String getResourceLoaderPath(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfigurer.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfigurer.java index 936e4cb6c3..8d0db53d4e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfigurer.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/view/script/ScriptTemplateConfigurer.java @@ -22,7 +22,7 @@ import java.util.function.Supplier; import javax.script.Bindings; import javax.script.ScriptEngine; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * An implementation of the Spring WebFlux {@link ScriptTemplateConfig} for @@ -51,32 +51,23 @@ import org.springframework.lang.Nullable; */ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { - @Nullable - private ScriptEngine engine; + private @Nullable ScriptEngine engine; - @Nullable - private Supplier engineSupplier; + private @Nullable Supplier engineSupplier; - @Nullable - private String engineName; + private @Nullable String engineName; - @Nullable - private Boolean sharedEngine; + private @Nullable Boolean sharedEngine; - @Nullable - private String[] scripts; + private String @Nullable [] scripts; - @Nullable - private String renderObject; + private @Nullable String renderObject; - @Nullable - private String renderFunction; + private @Nullable String renderFunction; - @Nullable - private Charset charset; + private @Nullable Charset charset; - @Nullable - private String resourceLoaderPath; + private @Nullable String resourceLoaderPath; /** @@ -109,8 +100,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public ScriptEngine getEngine() { + public @Nullable ScriptEngine getEngine() { return this.engine; } @@ -128,8 +118,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public Supplier getEngineSupplier() { + public @Nullable Supplier getEngineSupplier() { return this.engineSupplier; } @@ -145,8 +134,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public String getEngineName() { + public @Nullable String getEngineName() { return this.engineName; } @@ -167,8 +155,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public Boolean isSharedEngine() { + public @Nullable Boolean isSharedEngine() { return this.sharedEngine; } @@ -183,13 +170,12 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { * @see #setResourceLoaderPath * @see WebJars */ - public void setScripts(@Nullable String... scriptNames) { + public void setScripts(String @Nullable ... scriptNames) { this.scripts = scriptNames; } @Override - @Nullable - public String[] getScripts() { + public String @Nullable [] getScripts() { return this.scripts; } @@ -203,8 +189,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public String getRenderObject() { + public @Nullable String getRenderObject() { return this.renderObject; } @@ -224,8 +209,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public String getRenderFunction() { + public @Nullable String getRenderFunction() { return this.renderFunction; } @@ -238,8 +222,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public Charset getCharset() { + public @Nullable Charset getCharset() { return this.charset; } @@ -256,8 +239,7 @@ public class ScriptTemplateConfigurer implements ScriptTemplateConfig { } @Override - @Nullable - public String getResourceLoaderPath() { + public @Nullable String getResourceLoaderPath() { return this.resourceLoaderPath; } 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 415b126475..554cb91fa5 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 @@ -30,6 +30,7 @@ import javax.script.ScriptEngineManager; import javax.script.ScriptException; import javax.script.SimpleBindings; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.beans.BeansException; @@ -40,7 +41,6 @@ import org.springframework.context.ApplicationContextException; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.core.io.Resource; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.scripting.support.StandardScriptEvalException; import org.springframework.scripting.support.StandardScriptUtils; import org.springframework.util.Assert; @@ -73,32 +73,23 @@ public class ScriptTemplateView extends AbstractUrlBasedView { private static final String DEFAULT_RESOURCE_LOADER_PATH = "classpath:"; - @Nullable - private ScriptEngine engine; + private @Nullable ScriptEngine engine; - @Nullable - private Supplier engineSupplier; + private @Nullable Supplier engineSupplier; - @Nullable - private String engineName; + private @Nullable String engineName; - @Nullable - private Boolean sharedEngine; + private @Nullable Boolean sharedEngine; - @Nullable - private String[] scripts; + private String @Nullable [] scripts; - @Nullable - private String renderObject; + private @Nullable String renderObject; - @Nullable - private String renderFunction; + private @Nullable String renderFunction; - @Nullable - private String[] resourceLoaderPaths; + private String @Nullable [] resourceLoaderPaths; - @Nullable - private volatile ScriptEngineManager scriptEngineManager; + private volatile @Nullable ScriptEngineManager scriptEngineManager; /** @@ -305,8 +296,7 @@ public class ScriptTemplateView extends AbstractUrlBasedView { } } - @Nullable - protected Resource getResource(String location) { + protected @Nullable Resource getResource(String location) { if (this.resourceLoaderPaths != null) { for (String path : this.resourceLoaderPaths) { Resource resource = obtainApplicationContext().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 49c5ceb7dc..e8b98ae065 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 @@ -2,9 +2,7 @@ * Support classes for views based on the JSR-223 script engine abstraction. * Contains a {@code View} implementation for scripted templates. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result.view.script; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d9ad00c8d1..6069a76b00 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 @@ -18,7 +18,8 @@ package org.springframework.web.reactive.socket; import java.util.Objects; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -138,8 +139,7 @@ public final class CloseStatus { private final int code; - @Nullable - private final String reason; + private final @Nullable String reason; /** @@ -172,8 +172,7 @@ public final class CloseStatus { /** * Return the reason, or {@code null} if none. */ - @Nullable - public String getReason() { + public @Nullable 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 a12a667a31..f2f9d0c540 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,11 +22,11 @@ import java.security.Principal; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; 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.MultiValueMap; @@ -53,16 +53,13 @@ public class HandshakeInfo { private final MultiValueMap cookies; - @Nullable - private final String protocol; + private final @Nullable String protocol; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; private final Map attributes; - @Nullable - private final String logPrefix; + private final @Nullable String logPrefix; /** @@ -169,8 +166,7 @@ public class HandshakeInfo { * @see * https://tools.ietf.org/html/rfc6455#section-1.9 */ - @Nullable - public String getSubProtocol() { + public @Nullable String getSubProtocol() { return this.protocol; } @@ -179,8 +175,7 @@ public class HandshakeInfo { * request came from. For a client session, it is {@code null}. * @since 5.1 */ - @Nullable - public InetSocketAddress getRemoteAddress() { + public @Nullable InetSocketAddress getRemoteAddress() { return this.remoteAddress; } @@ -197,8 +192,7 @@ public class HandshakeInfo { * @return a log prefix, or {@code null} if not specified * @since 5.1 */ - @Nullable - public String getLogPrefix() { + public @Nullable String getLogPrefix() { return this.logPrefix; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketMessage.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketMessage.java index 052f47f09a..00593dab86 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketMessage.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/WebSocketMessage.java @@ -19,10 +19,11 @@ package org.springframework.web.reactive.socket; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferUtils; import org.springframework.core.io.buffer.Netty5DataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; @@ -46,8 +47,7 @@ public class WebSocketMessage { private final DataBuffer payload; - @Nullable - private final Object nativeMessage; + private final @Nullable Object nativeMessage; /** @@ -99,9 +99,8 @@ public class WebSocketMessage { * @return the underlying message, or {@code null} * @since 5.3 */ - @Nullable @SuppressWarnings("unchecked") - public T getNativeMessage() { + public @Nullable T getNativeMessage() { return (T) this.nativeMessage; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java index 29508c33aa..0cf87fdb6d 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/AbstractListenerWebSocketSession.java @@ -20,6 +20,7 @@ import java.io.IOException; import java.util.Queue; import java.util.concurrent.atomic.AtomicBoolean; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -31,7 +32,6 @@ import reactor.util.concurrent.Queues; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.server.reactive.AbstractListenerReadPublisher; import org.springframework.http.server.reactive.AbstractListenerWriteProcessor; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.CloseStatus; import org.springframework.web.reactive.socket.HandshakeInfo; @@ -63,13 +63,11 @@ public abstract class AbstractListenerWebSocketSession extends AbstractWebSoc private static final int RECEIVE_BUFFER_SIZE = 8192; - @Nullable - private final Sinks.Empty handlerCompletionSink; + private final Sinks.@Nullable Empty handlerCompletionSink; private final WebSocketReceivePublisher receivePublisher; - @Nullable - private volatile WebSocketSendProcessor sendProcessor; + private volatile @Nullable WebSocketSendProcessor sendProcessor; private final AtomicBoolean sendCalled = new AtomicBoolean(); @@ -96,7 +94,7 @@ public abstract class AbstractListenerWebSocketSession extends AbstractWebSoc * communicate the end of handling. */ public AbstractListenerWebSocketSession(T delegate, String id, HandshakeInfo info, - DataBufferFactory bufferFactory, @Nullable Sinks.Empty handlerCompletionSink) { + DataBufferFactory bufferFactory, Sinks.@Nullable Empty handlerCompletionSink) { super(delegate, id, info, bufferFactory); this.receivePublisher = new WebSocketReceivePublisher(); @@ -272,8 +270,7 @@ public abstract class AbstractListenerWebSocketSession extends AbstractWebSoc } @Override - @Nullable - protected WebSocketMessage read() { + protected @Nullable WebSocketMessage read() { return (WebSocketMessage) this.pendingMessages.poll(); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketHandlerAdapter.java index 3668683944..9a915d333a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketHandlerAdapter.java @@ -25,11 +25,11 @@ import java.util.function.IntPredicate; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.websocket.api.Callback; import org.eclipse.jetty.websocket.api.Session; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.buffer.CloseableDataBuffer; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.CloseStatus; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -50,8 +50,7 @@ public class JettyWebSocketHandlerAdapter implements Session.Listener { private final Function sessionFactory; - @Nullable - private JettyWebSocketSession delegateSession; + private @Nullable JettyWebSocketSession delegateSession; public JettyWebSocketHandlerAdapter(WebSocketHandler handler, diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketSession.java index 35aeac20a8..4943bb546e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/JettyWebSocketSession.java @@ -26,6 +26,7 @@ import org.eclipse.jetty.util.IteratingCallback; import org.eclipse.jetty.websocket.api.Callback; import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.StatusCode; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.FluxSink; @@ -34,7 +35,6 @@ import reactor.core.publisher.Sinks; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.reactive.socket.CloseStatus; @@ -62,18 +62,16 @@ public class JettyWebSocketSession extends AbstractWebSocketSession { private boolean awaitingMessage = false; - @Nullable - private FluxSink sink; + private @Nullable FluxSink sink; - @Nullable - private final Sinks.Empty handlerCompletionSink; + private final Sinks.@Nullable Empty handlerCompletionSink; public JettyWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory) { this(session, info, factory, null); } public JettyWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory, - @Nullable Sinks.Empty completionSink) { + Sinks.@Nullable Empty completionSink) { super(session, ObjectUtils.getIdentityHexString(session), info, factory); this.handlerCompletionSink = completionSink; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketHandlerAdapter.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketHandlerAdapter.java index 43ca7f12b3..b578f6df39 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketHandlerAdapter.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketHandlerAdapter.java @@ -25,9 +25,9 @@ import jakarta.websocket.Endpoint; import jakarta.websocket.EndpointConfig; import jakarta.websocket.PongMessage; import jakarta.websocket.Session; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.buffer.DataBuffer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.CloseStatus; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -50,8 +50,7 @@ public class StandardWebSocketHandlerAdapter extends Endpoint { private final Function sessionFactory; - @Nullable - private StandardWebSocketSession delegateSession; + private @Nullable StandardWebSocketSession delegateSession; public StandardWebSocketHandlerAdapter(WebSocketHandler handler, diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketSession.java index 9849ab587e..87df9aa5bd 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/StandardWebSocketSession.java @@ -26,12 +26,12 @@ import jakarta.websocket.RemoteEndpoint; import jakarta.websocket.SendHandler; import jakarta.websocket.SendResult; import jakarta.websocket.Session; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.CloseStatus; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketMessage; @@ -52,7 +52,7 @@ public class StandardWebSocketSession extends AbstractListenerWebSocketSession completionSink) { + Sinks.@Nullable Empty completionSink) { super(session, session.getId(), info, factory, completionSink); } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/UndertowWebSocketSession.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/UndertowWebSocketSession.java index b80d4c1e3b..79de37d710 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/UndertowWebSocketSession.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/adapter/UndertowWebSocketSession.java @@ -24,13 +24,13 @@ import io.undertow.websockets.core.CloseMessage; import io.undertow.websockets.core.WebSocketCallback; import io.undertow.websockets.core.WebSocketChannel; import io.undertow.websockets.core.WebSockets; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DataBufferUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.reactive.socket.CloseStatus; import org.springframework.web.reactive.socket.HandshakeInfo; @@ -52,7 +52,7 @@ public class UndertowWebSocketSession extends AbstractListenerWebSocketSession completionSink) { + DataBufferFactory factory, Sinks.@Nullable Empty completionSink) { super(channel, ObjectUtils.getIdentityHexString(channel), info, factory, completionSink); suspendReceiving(); 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 825473c9bb..c37715865d 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,9 +1,7 @@ /** * Classes adapting Spring's Reactive WebSocket API to and from WebSocket runtimes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.socket.adapter; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/JettyWebSocketClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/JettyWebSocketClient.java index c3eebb65bf..d0b6f352ff 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/JettyWebSocketClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/JettyWebSocketClient.java @@ -27,13 +27,13 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.websocket.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.client.JettyUpgradeListener; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.core.publisher.Sinks; import org.springframework.context.Lifecycle; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.adapter.JettyWebSocketHandlerAdapter; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java index fd9680781c..ff3df926b7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNetty2WebSocketClient.java @@ -21,6 +21,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.netty5.http.client.HttpClient; import reactor.netty5.http.client.WebsocketClientSpec; @@ -28,7 +29,6 @@ import reactor.netty5.http.websocket.WebsocketInbound; import org.springframework.core.io.buffer.Netty5DataBufferFactory; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.reactive.socket.HandshakeInfo; @@ -53,8 +53,7 @@ public class ReactorNetty2WebSocketClient implements WebSocketClient { private final Supplier specBuilderSupplier; - @Nullable - private Boolean handlePing; + private @Nullable Boolean handlePing; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java index 844853a04d..2fbabf926a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/ReactorNettyWebSocketClient.java @@ -21,6 +21,7 @@ import java.util.function.Supplier; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.WebsocketClientSpec; @@ -28,7 +29,6 @@ import reactor.netty.http.websocket.WebsocketInbound; import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.reactive.socket.HandshakeInfo; @@ -51,11 +51,9 @@ public class ReactorNettyWebSocketClient implements WebSocketClient { private final Supplier specBuilderSupplier; - @Nullable - private Integer maxFramePayloadLength; + private @Nullable Integer maxFramePayloadLength; - @Nullable - private Boolean handlePing; + private @Nullable Boolean handlePing; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/UndertowWebSocketClient.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/UndertowWebSocketClient.java index e9ed39e863..8b68b19c8b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/UndertowWebSocketClient.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/client/UndertowWebSocketClient.java @@ -30,6 +30,7 @@ import io.undertow.websockets.client.WebSocketClientNegotiation; import io.undertow.websockets.core.WebSocketChannel; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.xnio.IoFuture; import org.xnio.XnioWorker; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import reactor.core.publisher.Sinks; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -226,8 +226,7 @@ public class UndertowWebSocketClient implements WebSocketClient { private final HttpHeaders responseHeaders = new HttpHeaders(); - @Nullable - private final WebSocketClientNegotiation delegate; + private final @Nullable WebSocketClientNegotiation delegate; public DefaultNegotiation(List protocols, HttpHeaders requestHeaders, ConnectionBuilder connectionBuilder) { 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 e6087f8b24..b5d57aefeb 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,9 +1,7 @@ /** * Client support for WebSocket interactions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.socket.client; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d45db5f96c..8343b6aa2b 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,9 +1,7 @@ /** * Abstractions and support classes for reactive WebSocket interactions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.socket; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 09ed240398..45242be902 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 @@ -18,11 +18,11 @@ package org.springframework.web.reactive.socket.server; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; 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.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.server.ServerWebExchange; 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 3e9b796483..350ade5a22 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,9 +1,7 @@ /** * Server support for WebSocket interactions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.socket.server; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d6c4940d9f..072a006a68 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 java.util.stream.Collectors; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.context.Lifecycle; @@ -34,7 +35,6 @@ import org.springframework.http.HttpCookie; 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.MultiValueMap; @@ -102,8 +102,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { private final RequestUpgradeStrategy upgradeStrategy; - @Nullable - private Predicate sessionAttributePredicate; + private @Nullable Predicate sessionAttributePredicate; private volatile boolean running; @@ -150,8 +149,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { * attributes from {@code WebSession} attributes. * @since 5.1 */ - @Nullable - public Predicate getSessionAttributePredicate() { + public @Nullable Predicate getSessionAttributePredicate() { return this.sessionAttributePredicate; } @@ -230,8 +228,7 @@ public class HandshakeWebSocketService implements WebSocketService, Lifecycle { return Mono.error(new ServerWebInputException(reason)); } - @Nullable - private String selectProtocol(HttpHeaders headers, WebSocketHandler handler) { + private @Nullable String selectProtocol(HttpHeaders headers, WebSocketHandler handler) { String protocolHeader = headers.getFirst(SEC_WEBSOCKET_PROTOCOL); if (protocolHeader != null) { List supportedProtocols = handler.getSubProtocols(); diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java index d931aa3ea2..c9b852588a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceRuntimeHints.java @@ -16,10 +16,11 @@ package org.springframework.web.reactive.socket.server.support; +import org.jspecify.annotations.Nullable; + import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; import org.springframework.aot.hint.RuntimeHintsRegistrar; -import org.springframework.lang.Nullable; /** * {@link RuntimeHintsRegistrar} implementation that registers reflection hints 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 e9455e38ec..e0b4e4e006 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,9 +1,7 @@ /** * Server-side support classes for WebSocket requests. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.socket.server.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyCoreRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyCoreRequestUpgradeStrategy.java index 94701d3bf0..4f201f591c 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyCoreRequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyCoreRequestUpgradeStrategy.java @@ -28,6 +28,7 @@ import org.eclipse.jetty.websocket.api.Configurable; import org.eclipse.jetty.websocket.api.exceptions.WebSocketException; import org.eclipse.jetty.websocket.server.ServerWebSocketContainer; import org.eclipse.jetty.websocket.server.WebSocketCreator; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferFactory; @@ -35,7 +36,6 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler; @@ -53,11 +53,9 @@ import org.springframework.web.server.ServerWebExchange; */ public class JettyCoreRequestUpgradeStrategy implements RequestUpgradeStrategy { - @Nullable - private Consumer webSocketConfigurer; + private @Nullable Consumer webSocketConfigurer; - @Nullable - private ServerWebSocketContainer serverContainer; + private @Nullable ServerWebSocketContainer serverContainer; /** * Add a callback to configure WebSocket server parameters on diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java index 46d8b70903..2922852716 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/JettyRequestUpgradeStrategy.java @@ -25,6 +25,7 @@ import jakarta.servlet.http.HttpServletResponse; import org.eclipse.jetty.ee10.websocket.server.JettyWebSocketCreator; import org.eclipse.jetty.ee10.websocket.server.JettyWebSocketServerContainer; import org.eclipse.jetty.websocket.api.Configurable; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferFactory; @@ -32,7 +33,6 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler; @@ -49,11 +49,9 @@ import org.springframework.web.server.ServerWebExchange; */ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy { - @Nullable - private Consumer webSocketConfigurer; + private @Nullable Consumer webSocketConfigurer; - @Nullable - private JettyWebSocketServerContainer serverContainer; + private @Nullable JettyWebSocketServerContainer serverContainer; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java index 52b85838de..c9eb17d4bb 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNetty2RequestUpgradeStrategy.java @@ -19,6 +19,7 @@ package org.springframework.web.reactive.socket.server.upgrade; import java.net.URI; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.netty5.http.server.HttpServerResponse; import reactor.netty5.http.server.WebsocketServerSpec; @@ -26,7 +27,6 @@ import reactor.netty5.http.server.WebsocketServerSpec; import org.springframework.core.io.buffer.Netty5DataBufferFactory; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java index a7ac18a564..7a2f84bdc7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/ReactorNettyRequestUpgradeStrategy.java @@ -19,6 +19,7 @@ package org.springframework.web.reactive.socket.server.upgrade; import java.net.URI; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.netty.http.server.HttpServerResponse; import reactor.netty.http.server.WebsocketServerSpec; @@ -26,7 +27,6 @@ import reactor.netty.http.server.WebsocketServerSpec; import org.springframework.core.io.buffer.NettyDataBufferFactory; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -44,11 +44,9 @@ public class ReactorNettyRequestUpgradeStrategy implements RequestUpgradeStrateg private final Supplier specBuilderSupplier; - @Nullable - private Integer maxFramePayloadLength; + private @Nullable Integer maxFramePayloadLength; - @Nullable - private Boolean handlePing; + private @Nullable Boolean handlePing; /** diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/StandardWebSocketUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/StandardWebSocketUpgradeStrategy.java index d5341505e0..f29254b030 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/StandardWebSocketUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/StandardWebSocketUpgradeStrategy.java @@ -25,6 +25,7 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.websocket.Endpoint; import jakarta.websocket.server.ServerContainer; import jakarta.websocket.server.ServerEndpointConfig; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferFactory; @@ -32,7 +33,6 @@ import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; import org.springframework.http.server.reactive.ServerHttpResponse; import org.springframework.http.server.reactive.ServerHttpResponseDecorator; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; @@ -60,20 +60,15 @@ public class StandardWebSocketUpgradeStrategy implements RequestUpgradeStrategy private static final String SERVER_CONTAINER_ATTR = "jakarta.websocket.server.ServerContainer"; - @Nullable - private Long asyncSendTimeout; + private @Nullable Long asyncSendTimeout; - @Nullable - private Long maxSessionIdleTimeout; + private @Nullable Long maxSessionIdleTimeout; - @Nullable - private Integer maxTextMessageBufferSize; + private @Nullable Integer maxTextMessageBufferSize; - @Nullable - private Integer maxBinaryMessageBufferSize; + private @Nullable Integer maxBinaryMessageBufferSize; - @Nullable - private ServerContainer serverContainer; + private @Nullable ServerContainer serverContainer; /** @@ -84,8 +79,7 @@ public class StandardWebSocketUpgradeStrategy implements RequestUpgradeStrategy this.asyncSendTimeout = timeoutInMillis; } - @Nullable - public Long getAsyncSendTimeout() { + public @Nullable Long getAsyncSendTimeout() { return this.asyncSendTimeout; } @@ -97,8 +91,7 @@ public class StandardWebSocketUpgradeStrategy implements RequestUpgradeStrategy this.maxSessionIdleTimeout = timeoutInMillis; } - @Nullable - public Long getMaxSessionIdleTimeout() { + public @Nullable Long getMaxSessionIdleTimeout() { return this.maxSessionIdleTimeout; } @@ -110,8 +103,7 @@ public class StandardWebSocketUpgradeStrategy implements RequestUpgradeStrategy this.maxTextMessageBufferSize = bufferSize; } - @Nullable - public Integer getMaxTextMessageBufferSize() { + public @Nullable Integer getMaxTextMessageBufferSize() { return this.maxTextMessageBufferSize; } @@ -123,8 +115,7 @@ public class StandardWebSocketUpgradeStrategy implements RequestUpgradeStrategy this.maxBinaryMessageBufferSize = bufferSize; } - @Nullable - public Integer getMaxBinaryMessageBufferSize() { + public @Nullable Integer getMaxBinaryMessageBufferSize() { return this.maxBinaryMessageBufferSize; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/UndertowRequestUpgradeStrategy.java b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/UndertowRequestUpgradeStrategy.java index 60f3742318..7fc2863544 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/UndertowRequestUpgradeStrategy.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/upgrade/UndertowRequestUpgradeStrategy.java @@ -28,11 +28,11 @@ import io.undertow.websockets.core.WebSocketChannel; import io.undertow.websockets.core.protocol.Handshake; import io.undertow.websockets.core.protocol.version13.Hybi13Handshake; import io.undertow.websockets.spi.WebSocketHttpExchange; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBufferFactory; import org.springframework.http.server.reactive.ServerHttpRequestDecorator; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.adapter.ContextWebSocketHandler; 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 13b172cb23..93229dff74 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,9 +2,7 @@ * Holds implementations of * {@link org.springframework.web.reactive.socket.server.RequestUpgradeStrategy}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.socket.server.upgrade; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt index 9d5d5ef69f..c09cab647e 100644 --- a/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt +++ b/spring-webflux/src/main/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensions.kt @@ -172,7 +172,7 @@ fun ServerRequest.attributeOrNull(name: String): Any? = attributes()[name] */ fun ServerRequest.queryParamOrNull(name: String): String? { val queryParamValues = queryParams()[name] - return if (queryParamValues.isNullOrEmpty()) null else queryParamValues[0] ?: "" + return if (queryParamValues.isNullOrEmpty()) null else queryParamValues[0] } /** diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java index aeadb7de41..411d955c3c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/config/WebFluxConfigurationSupportTests.java @@ -24,6 +24,7 @@ import java.util.Map; import com.google.protobuf.Message; import jakarta.xml.bind.annotation.XmlRootElement; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import org.springframework.context.ApplicationContext; @@ -43,7 +44,6 @@ import org.springframework.http.codec.ServerCodecConfigurer; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.http.codec.xml.Jaxb2XmlDecoder; import org.springframework.http.codec.xml.Jaxb2XmlEncoder; -import org.springframework.lang.Nullable; import org.springframework.util.MimeType; import org.springframework.util.MimeTypeUtils; import org.springframework.util.MultiValueMap; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java index a40bc25e6f..d6f9a24dad 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/DefaultClientResponseTests.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.OptionalLong; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -47,7 +48,6 @@ import org.springframework.http.ResponseEntity; import org.springframework.http.client.reactive.ClientHttpResponse; import org.springframework.http.codec.DecoderHttpMessageReader; import org.springframework.http.codec.json.Jackson2JsonDecoder; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -72,8 +72,7 @@ class DefaultClientResponseTests { private final ExchangeStrategies mockExchangeStrategies = mock(); - @Nullable - private HttpRequest httpRequest = null; + private @Nullable HttpRequest httpRequest = null; private DefaultClientResponse defaultClientResponse; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/WebClientAdapterTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/WebClientAdapterTests.java index 5ee065af5a..9579267f94 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/WebClientAdapterTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/client/support/WebClientAdapterTests.java @@ -27,6 +27,7 @@ import java.util.function.Consumer; import okhttp3.mockwebserver.MockResponse; import okhttp3.mockwebserver.MockWebServer; import okhttp3.mockwebserver.RecordedRequest; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,7 +35,6 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.PathVariable; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/AttributesTestVisitor.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/AttributesTestVisitor.java index fad717537a..5a6d5215e3 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/AttributesTestVisitor.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/AttributesTestVisitor.java @@ -25,10 +25,10 @@ import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * @author Arjen Poutsma @@ -37,8 +37,7 @@ class AttributesTestVisitor implements RouterFunctions.Visitor { private Deque> nestedAttributes = new LinkedList<>(); - @Nullable - private Map attributes; + private @Nullable Map attributes; private List>> routerFunctionsAttributes = new LinkedList<>(); diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java index 524b4d6a3f..1854d5fb45 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/BindingFunctionIntegrationTests.java @@ -19,10 +19,10 @@ package org.springframework.web.reactive.function.server; import java.time.Duration; import java.util.Objects; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClientResponseException; import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer; @@ -164,14 +164,11 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT @SuppressWarnings("unused") private static final class PropertyInjection { - @Nullable - private String foo; + private @Nullable String foo; - @Nullable - private String bar; + private @Nullable String bar; - @Nullable - public String getFoo() { + public @Nullable String getFoo() { return this.foo; } @@ -179,8 +176,7 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT this.foo = foo; } - @Nullable - public String getBar() { + public @Nullable String getBar() { return this.bar; } @@ -199,8 +195,7 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT private final String foo; - @Nullable - private String bar; + private @Nullable String bar; public MixedInjection(String foo) { this.foo = foo; @@ -210,8 +205,7 @@ class BindingFunctionIntegrationTests extends AbstractRouterFunctionIntegrationT return this.foo; } - @Nullable - public String getBar() { + public @Nullable String getBar() { return this.bar; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java index 1282a1cd97..f32f87799d 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DefaultServerRequestTests.java @@ -35,6 +35,7 @@ import java.util.Map; import java.util.OptionalLong; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -59,7 +60,6 @@ import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.json.Jackson2JsonDecoder; import org.springframework.http.codec.multipart.FormFieldPart; import org.springframework.http.codec.multipart.Part; -import org.springframework.lang.Nullable; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.server.ServerWebInputException; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java index e56acf391b..439e536fb1 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/DispatcherHandlerIntegrationTests.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -32,7 +33,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/LocaleContextResolverIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/LocaleContextResolverIntegrationTests.java index b5a4e2bd4e..cf33c04155 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/LocaleContextResolverIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/LocaleContextResolverIntegrationTests.java @@ -21,13 +21,13 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.result.view.View; import org.springframework.web.reactive.result.view.ViewResolver; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java index 6d9d35cee9..0657ac57a8 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/NestedRouteIntegrationTests.java @@ -18,13 +18,13 @@ package org.springframework.web.reactive.function.server; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.web.client.RestTemplate; import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer; import org.springframework.web.util.pattern.PathPattern; @@ -164,8 +164,7 @@ class NestedRouteIntegrationTests extends AbstractRouterFunctionIntegrationTests return ServerResponse.ok().body(responseBody, String.class); } - @Nullable - private PathPattern matchingPattern(ServerRequest request) { + private @Nullable PathPattern matchingPattern(ServerRequest request) { return (PathPattern) request.attributes().get(RouterFunctions.MATCHING_PATTERN_ATTRIBUTE); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java index b3e73b53e7..d827147e8c 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/PublisherHandlerFunctionIntegrationTests.java @@ -20,6 +20,7 @@ import java.net.URI; import java.util.List; import java.util.Objects; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -28,7 +29,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.web.client.RestTemplate; import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RenderingResponseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RenderingResponseIntegrationTests.java index 32064132e0..9ff5771663 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RenderingResponseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/RenderingResponseIntegrationTests.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.io.buffer.DataBuffer; @@ -29,7 +30,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.client.RestTemplate; import org.springframework.web.reactive.result.view.View; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java index b1a25abaac..59305159d3 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/function/server/SseHandlerFunctionIntegrationTests.java @@ -19,6 +19,7 @@ package org.springframework.web.reactive.function.server; import java.time.Duration; import java.util.Objects; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -26,7 +27,6 @@ import reactor.test.StepVerifier; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.MediaType; import org.springframework.http.codec.ServerSentEvent; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.testfixture.http.server.reactive.bootstrap.HttpServer; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java index c906010880..dc68f85190 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/InvocableHandlerMethodTests.java @@ -23,6 +23,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -34,7 +35,6 @@ import org.springframework.core.io.buffer.DataBuffer; import org.springframework.core.io.buffer.DefaultDataBufferFactory; import org.springframework.http.HttpStatus; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.reactive.BindingContext; import org.springframework.web.reactive.HandlerResult; @@ -237,8 +237,7 @@ class InvocableHandlerMethodTests { } - @Nullable - private HandlerResult invokeForResult(Object handler, Method method, Object... providedArgs) { + private @Nullable HandlerResult invokeForResult(Object handler, Method method, Object... providedArgs) { return invoke(handler, method, providedArgs).block(Duration.ofSeconds(5)); } @@ -331,8 +330,7 @@ class InvocableHandlerMethodTests { .thenEmpty(Mono.defer(() -> exchange.getResponse().writeWith(getBody("body")))); } - @Nullable - String notModified(ServerWebExchange exchange) { + @Nullable String notModified(ServerWebExchange exchange) { if (exchange.checkNotModified(Instant.ofEpochMilli(1000 * 1000))) { return null; } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java index 0ba5b8ef59..bbb0b7c764 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java @@ -27,6 +27,7 @@ import java.util.Map; import java.util.Set; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java index 8de93c7e67..1814c8d4d5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/JacksonStreamingIntegrationTests.java @@ -19,6 +19,7 @@ package org.springframework.web.reactive.result.method.annotation; import java.time.Duration; import java.util.Objects; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; @@ -27,7 +28,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.MediaType; import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.reactive.DispatcherHandler; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java index ecc6a7b186..c37dc1fd66 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/MessageReaderArgumentResolverTests.java @@ -32,6 +32,7 @@ import io.reactivex.rxjava3.core.Maybe; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; import jakarta.xml.bind.annotation.XmlRootElement; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; @@ -45,7 +46,6 @@ import org.springframework.http.MediaType; import org.springframework.http.codec.DecoderHttpMessageReader; import org.springframework.http.codec.HttpMessageReader; import org.springframework.http.codec.json.Jackson2JsonDecoder; -import org.springframework.lang.Nullable; import org.springframework.validation.Errors; import org.springframework.validation.Validator; import org.springframework.validation.annotation.Validated; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java index 7cf05e598f..c73ee362c5 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ModelInitializerTests.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Map; import io.reactivex.rxjava3.core.Single; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -31,7 +32,6 @@ import org.springframework.context.support.StaticApplicationContext; import org.springframework.core.MethodIntrospector; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.util.ReflectionUtils; import org.springframework.validation.Validator; @@ -222,8 +222,7 @@ class ModelInitializerTests { @SessionAttributes({"bean", "missing-bean"}) private static class TestController { - @Nullable - private Validator validator; + private @Nullable Validator validator; void setValidator(Validator validator) { diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java index f5f2ff938f..3180154ef7 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestMappingMessageConversionIntegrationTests.java @@ -32,6 +32,7 @@ import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; import jakarta.xml.bind.annotation.XmlElement; import jakarta.xml.bind.annotation.XmlRootElement; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -51,7 +52,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.http.codec.json.Jackson2JsonEncoder; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java index 2b5a1a8db6..f7d507ee39 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/RequestParamMethodArgumentResolverTests.java @@ -20,6 +20,7 @@ import java.time.Duration; import java.util.Map; import java.util.Optional; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -28,7 +29,6 @@ import reactor.test.StepVerifier; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; import org.springframework.format.support.DefaultFormattingConversionService; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.reactive.BindingContext; @@ -213,8 +213,7 @@ class RequestParamMethodArgumentResolverTests { } - @Nullable - private Object resolve(MethodParameter parameter, ServerWebExchange exchange) { + private @Nullable Object resolve(MethodParameter parameter, ServerWebExchange exchange) { return this.resolver.resolveArgument(parameter, this.bindContext, exchange).block(Duration.ZERO); } diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java index 0643f334a4..e125c63912 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/ResponseBodyResultHandlerTests.java @@ -23,6 +23,7 @@ import java.util.List; import io.reactivex.rxjava3.core.Completable; import io.reactivex.rxjava3.core.Single; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; @@ -38,7 +39,6 @@ import org.springframework.http.codec.HttpMessageWriter; import org.springframework.http.codec.ResourceHttpMessageWriter; import org.springframework.http.codec.json.Jackson2JsonEncoder; import org.springframework.http.codec.xml.Jaxb2XmlEncoder; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java index 76dd1ecbfb..d35863b46e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/method/annotation/SseIntegrationTests.java @@ -24,6 +24,7 @@ import java.time.Duration; import java.util.Objects; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -43,7 +44,6 @@ import org.springframework.http.client.reactive.JettyClientHttpConnector; import org.springframework.http.client.reactive.ReactorClientHttpConnector; import org.springframework.http.codec.ServerSentEvent; import org.springframework.http.server.reactive.HttpHandler; -import org.springframework.lang.Nullable; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java index 3c2d42c4eb..62140c9c19 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/AbstractViewTests.java @@ -23,6 +23,7 @@ import java.util.Map; import io.reactivex.rxjava3.core.Observable; import io.reactivex.rxjava3.core.Single; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -30,7 +31,6 @@ import reactor.test.StepVerifier; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.validation.BindingResult; import org.springframework.web.reactive.BindingContext; import org.springframework.web.server.ServerWebExchange; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java index bf0e326396..d5ff504864 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/LocaleContextResolverIntegrationTests.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; @@ -31,7 +32,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.reactive.config.ViewResolverRegistry; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java index bc4249cb62..aa11826642 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/result/view/ViewResolutionResultHandlerTests.java @@ -28,6 +28,7 @@ import java.util.Map; import java.util.TreeMap; import io.reactivex.rxjava3.core.Completable; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -43,7 +44,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.codec.ServerSentEvent; import org.springframework.http.server.reactive.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.ui.ConcurrentModel; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; diff --git a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java index 20cd2a36e8..3c0f20248e 100644 --- a/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java +++ b/spring-webflux/src/test/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketServiceTests.java @@ -20,10 +20,10 @@ import java.util.Arrays; import java.util.Map; import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; import org.junit.jupiter.api.Test; import reactor.core.publisher.Mono; -import org.springframework.lang.Nullable; import org.springframework.web.reactive.socket.HandshakeInfo; import org.springframework.web.reactive.socket.WebSocketHandler; import org.springframework.web.reactive.socket.server.RequestUpgradeStrategy; diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt index 8211dbb7ca..5e1673ab8a 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/client/WebClientExtensionsTests.kt @@ -129,7 +129,7 @@ class WebClientExtensionsTests { @Test fun `awaitExchangeOrNull returning null`() { val foo = mockk() - every { requestBodySpec.exchangeToMono(any>>()) } returns Mono.empty() + every { requestBodySpec.exchangeToMono(any>>()) } returns Mono.empty() runBlocking { assertThat(requestBodySpec.awaitExchangeOrNull { foo }).isEqualTo(null) } diff --git a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt index 4e8df421a5..1d65b07550 100644 --- a/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt +++ b/spring-webflux/src/test/kotlin/org/springframework/web/reactive/function/server/ServerRequestExtensionsTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -180,13 +180,6 @@ class ServerRequestExtensionsTests { verify { request.queryParams() } } - @Test - fun `queryParamOrNull with null value`() { - every { request.queryParams() } returns CollectionUtils.toMultiValueMap(mapOf("foo" to listOf(null))) - assertThat(request.queryParamOrNull("foo")).isEqualTo("") - verify { request.queryParams() } - } - @Test fun `queryParamOrNull with null`() { every { request.queryParams() } returns CollectionUtils.toMultiValueMap(mapOf("foo" to listOf("bar"))) 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 affb7ab913..110d817693 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 @@ -37,6 +37,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanInitializationException; @@ -52,7 +53,6 @@ import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.server.RequestPath; import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.web.context.WebApplicationContext; @@ -289,8 +289,7 @@ public class DispatcherServlet extends FrameworkServlet { protected static final Log pageNotFoundLogger = LogFactory.getLog(PAGE_NOT_FOUND_LOG_CATEGORY); /** Store default strategy implementations. */ - @Nullable - private static Properties defaultStrategies; + private static @Nullable Properties defaultStrategies; /** Detect all HandlerMappings or just expect "handlerMapping" bean?. */ private boolean detectAllHandlerMappings = true; @@ -308,41 +307,32 @@ public class DispatcherServlet extends FrameworkServlet { private boolean cleanupAfterInclude = true; /** MultipartResolver used by this servlet. */ - @Nullable - private MultipartResolver multipartResolver; + private @Nullable MultipartResolver multipartResolver; /** LocaleResolver used by this servlet. */ - @Nullable - private LocaleResolver localeResolver; + private @Nullable LocaleResolver localeResolver; /** ThemeResolver used by this servlet. */ @Deprecated - @Nullable - private ThemeResolver themeResolver; + private @Nullable ThemeResolver themeResolver; /** List of HandlerMappings used by this servlet. */ - @Nullable - private List handlerMappings; + private @Nullable List handlerMappings; /** List of HandlerAdapters used by this servlet. */ - @Nullable - private List handlerAdapters; + private @Nullable List handlerAdapters; /** List of HandlerExceptionResolvers used by this servlet. */ - @Nullable - private List handlerExceptionResolvers; + private @Nullable List handlerExceptionResolvers; /** RequestToViewNameTranslator used by this servlet. */ - @Nullable - private RequestToViewNameTranslator viewNameTranslator; + private @Nullable RequestToViewNameTranslator viewNameTranslator; /** FlashMapManager used by this servlet. */ - @Nullable - private FlashMapManager flashMapManager; + private @Nullable FlashMapManager flashMapManager; /** List of ViewResolvers used by this servlet. */ - @Nullable - private List viewResolvers; + private @Nullable List viewResolvers; private boolean parseRequestPath; @@ -791,8 +781,7 @@ public class DispatcherServlet extends FrameworkServlet { * @see #getWebApplicationContext() */ @Deprecated - @Nullable - public final org.springframework.ui.context.ThemeSource getThemeSource() { + public final org.springframework.ui.context.@Nullable ThemeSource getThemeSource() { return (getWebApplicationContext() instanceof org.springframework.ui.context.ThemeSource themeSource ? themeSource : null); } @@ -802,8 +791,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() { + public final @Nullable MultipartResolver getMultipartResolver() { return this.multipartResolver; } @@ -817,8 +805,7 @@ public class DispatcherServlet extends FrameworkServlet { * if not initialized yet * @since 5.0 */ - @Nullable - public final List getHandlerMappings() { + public final @Nullable List getHandlerMappings() { return (this.handlerMappings != null ? Collections.unmodifiableList(this.handlerMappings) : null); } @@ -1253,8 +1240,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 { + protected @Nullable HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { if (this.handlerMappings != null) { for (HandlerMapping mapping : this.handlerMappings) { HandlerExecutionChain handler = mapping.getHandler(request); @@ -1307,8 +1293,7 @@ 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, + protected @Nullable ModelAndView processHandlerException(HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) throws Exception { // Success and error responses may use different content types @@ -1420,8 +1405,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 { + protected @Nullable String getDefaultViewName(HttpServletRequest request) throws Exception { return (this.viewNameTranslator != null ? this.viewNameTranslator.getViewName(request) : null); } @@ -1439,15 +1423,13 @@ public class DispatcherServlet extends FrameworkServlet { * (typically in case of problems creating an actual View object) * @see ViewResolver#resolveViewName */ - @Nullable - protected View resolveViewName(String viewName, @Nullable Map model, + protected @Nullable View resolveViewName(String viewName, @Nullable Map model, Locale locale, HttpServletRequest request) throws Exception { return resolveViewNameInternal(viewName, locale); } - @Nullable - private View resolveViewNameInternal(String viewName, Locale locale) throws Exception { + private @Nullable View resolveViewNameInternal(String viewName, Locale locale) throws Exception { if (this.viewResolvers != null) { for (ViewResolver viewResolver : this.viewResolvers) { View view = viewResolver.resolveViewName(viewName, locale); 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 146034ed4f..4ca1870aa7 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,7 +18,8 @@ package org.springframework.web.servlet; import java.util.HashMap; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.util.ObjectUtils; @@ -49,8 +50,7 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public final class FlashMap extends HashMap implements Comparable { - @Nullable - private String targetRequestPath; + private @Nullable String targetRequestPath; private final MultiValueMap targetRequestParams = new LinkedMultiValueMap<>(3); @@ -69,8 +69,7 @@ public final class FlashMap extends HashMap implements Comparabl /** * Return the target URL path (or {@code null} if none specified). */ - @Nullable - public String getTargetRequestPath() { + public @Nullable 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 921e1d8e7b..3959397945 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 @@ -18,8 +18,7 @@ package org.springframework.web.servlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A strategy interface for retrieving and saving FlashMap instances. @@ -42,8 +41,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); + @Nullable FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response); /** * Save the given FlashMap, in some underlying storage and set the start 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 1d73bb25f5..b2334dcae7 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 @@ -31,6 +31,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationContext; @@ -50,7 +51,6 @@ import org.springframework.core.env.ConfigurableEnvironment; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -176,31 +176,26 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic /** ServletContext attribute to find the WebApplicationContext in. */ - @Nullable - private String contextAttribute; + private @Nullable String contextAttribute; /** WebApplicationContext implementation class to create. */ private Class contextClass = DEFAULT_CONTEXT_CLASS; /** WebApplicationContext id to assign. */ - @Nullable - private String contextId; + private @Nullable String contextId; /** Namespace for this servlet. */ - @Nullable - private String namespace; + private @Nullable String namespace; /** Explicit context config location. */ - @Nullable - private String contextConfigLocation; + private @Nullable String contextConfigLocation; /** Actual ApplicationContextInitializer instances to apply to the context. */ private final List> contextInitializers = new ArrayList<>(); /** Comma-delimited ApplicationContextInitializer class names set through init param. */ - @Nullable - private String contextInitializerClasses; + private @Nullable String contextInitializerClasses; /** Should we publish the context as a ServletContext attribute?. */ private boolean publishContext = true; @@ -221,8 +216,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic private boolean enableLoggingRequestDetails = false; /** WebApplicationContext for this servlet. */ - @Nullable - private WebApplicationContext webApplicationContext; + private @Nullable WebApplicationContext webApplicationContext; /** If the WebApplicationContext was injected via {@link #setApplicationContext}. */ private boolean webApplicationContextInjected = false; @@ -311,8 +305,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * Return the name of the ServletContext attribute which should be used to retrieve the * {@link WebApplicationContext} that this servlet is supposed to use. */ - @Nullable - public String getContextAttribute() { + public @Nullable String getContextAttribute() { return this.contextAttribute; } @@ -347,8 +340,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic /** * Return the custom WebApplicationContext id, if any. */ - @Nullable - public String getContextId() { + public @Nullable String getContextId() { return this.contextId; } @@ -380,8 +372,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic /** * Return the explicit context config location, if any. */ - @Nullable - public String getContextConfigLocation() { + public @Nullable String getContextConfigLocation() { return this.contextConfigLocation; } @@ -392,7 +383,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @see #applyInitializers */ @SuppressWarnings("unchecked") - public void setContextInitializers(@Nullable ApplicationContextInitializer... initializers) { + public void setContextInitializers(ApplicationContextInitializer @Nullable ... initializers) { if (initializers != null) { for (ApplicationContextInitializer initializer : initializers) { this.contextInitializers.add((ApplicationContextInitializer) initializer); @@ -623,8 +614,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() { + protected @Nullable WebApplicationContext findWebApplicationContext() { String attrName = getContextAttribute(); if (attrName == null) { return null; @@ -805,8 +795,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic /** * Return this servlet's WebApplicationContext. */ - @Nullable - public final WebApplicationContext getWebApplicationContext() { + public final @Nullable WebApplicationContext getWebApplicationContext() { return this.webApplicationContext; } @@ -1039,8 +1028,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) { + protected @Nullable LocaleContext buildLocaleContext(HttpServletRequest request) { return new SimpleLocaleContext(request.getLocale()); } @@ -1055,8 +1043,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, + protected @Nullable ServletRequestAttributes buildRequestAttributes(HttpServletRequest request, @Nullable HttpServletResponse response, @Nullable RequestAttributes previousAttributes) { if (previousAttributes == null || previousAttributes instanceof ServletRequestAttributes) { @@ -1162,8 +1149,7 @@ public abstract class FrameworkServlet extends HttpServletBean implements Applic * @return the username, or {@code null} if none found * @see jakarta.servlet.http.HttpServletRequest#getUserPrincipal() */ - @Nullable - protected String getUsernameForRequest(HttpServletRequest request) { + protected @Nullable 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 68ae2011c5..31b8176ce6 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 @@ -18,8 +18,7 @@ package org.springframework.web.servlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * MVC framework SPI, allowing parameterization of the core MVC workflow. @@ -74,8 +73,7 @@ public interface HandlerAdapter { * model data, or {@code null} if the request has been handled directly * @throws Exception in case of errors */ - @Nullable - ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; + @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception; /** * Same contract as for HttpServlet's {@code getLastModified} method. 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 e6f446bb7c..77f0a39cac 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 @@ -18,8 +18,7 @@ package org.springframework.web.servlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that can resolve exceptions thrown during @@ -49,8 +48,7 @@ public interface HandlerExceptionResolver { * @return a corresponding {@code ModelAndView} to forward to, * or {@code null} for default processing in the resolution chain */ - @Nullable - ModelAndView resolveException( + @Nullable ModelAndView resolveException( 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 f90bf35cc0..f41caf6eb5 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 @@ -25,8 +25,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -62,7 +62,7 @@ public class HandlerExecutionChain { * @param interceptors the array of interceptors to apply * (in the given order) before the handler itself executes */ - public HandlerExecutionChain(Object handler, @Nullable HandlerInterceptor... interceptors) { + public HandlerExecutionChain(Object handler, HandlerInterceptor @Nullable ... interceptors) { this(handler, (interceptors != null ? Arrays.asList(interceptors) : Collections.emptyList())); } @@ -118,8 +118,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() { + public HandlerInterceptor @Nullable [] getInterceptors() { return (!this.interceptorList.isEmpty() ? this.interceptorList.toArray(new HandlerInterceptor[0]) : null); } 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 976fb2bdf8..0b63d8b148 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 @@ -18,8 +18,8 @@ package org.springframework.web.servlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; /** 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 081f677aeb..6520ddd7ee 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,8 +18,7 @@ package org.springframework.web.servlet; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that define a mapping between @@ -167,7 +166,6 @@ 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; + @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 1d4766cab3..69d50e34cb 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 @@ -25,6 +25,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.BeansException; @@ -39,7 +40,6 @@ 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; @@ -84,8 +84,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment /** Logger available to subclasses. */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private ConfigurableEnvironment environment; + private @Nullable ConfigurableEnvironment environment; private final Set requiredProperties = new HashSet<>(4); @@ -196,8 +195,7 @@ public abstract class HttpServletBean extends HttpServlet implements Environment * @see #getServletConfig() */ @Override - @Nullable - public String getServletName() { + public @Nullable String getServletName() { return (getServletConfig() != null ? getServletConfig().getServletName() : 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 4331c017f8..c990b8066c 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 @@ -20,10 +20,10 @@ import java.util.Locale; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.SimpleLocaleContext; -import org.springframework.lang.Nullable; /** * Extension of {@link LocaleResolver} that adds support for a rich locale context 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 b4519563d6..a9d94bd665 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 @@ -20,8 +20,7 @@ import java.util.Locale; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface for web-based locale resolution strategies that allows for 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 1de142487b..754685bbb9 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 @@ -18,8 +18,9 @@ package org.springframework.web.servlet; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.CollectionUtils; @@ -47,16 +48,13 @@ import org.springframework.util.CollectionUtils; public class ModelAndView { /** View instance or view name String. */ - @Nullable - private Object view; + private @Nullable Object view; /** Model Map. */ - @Nullable - private ModelMap model; + private @Nullable ModelMap model; /** Optional HTTP status for the response. */ - @Nullable - private HttpStatusCode status; + private @Nullable HttpStatusCode status; /** Indicates whether this instance has been cleared with a call to {@link #clear()}. */ private boolean cleared = false; @@ -193,8 +191,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() { + public @Nullable String getViewName() { return (this.view instanceof String name ? name : null); } @@ -210,8 +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() { + public @Nullable View getView() { return (this.view instanceof View v ? v : null); } @@ -236,8 +232,7 @@ public class ModelAndView { * Return the model map. May return {@code null}. * Called by DispatcherServlet for evaluation of the model. */ - @Nullable - protected Map getModelInternal() { + protected @Nullable Map getModelInternal() { return this.model; } @@ -272,8 +267,7 @@ public class ModelAndView { * Return the configured HTTP status for the response, if any. * @since 4.3 */ - @Nullable - public HttpStatusCode getStatus() { + public @Nullable HttpStatusCode 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 df95379987..83b61ec0bd 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 @@ -17,8 +17,7 @@ package org.springframework.web.servlet; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Strategy interface for translating an incoming @@ -38,7 +37,6 @@ 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; + @Nullable String getViewName(HttpServletRequest request) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java index e3bcf3db17..566a39e8f6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/ThemeResolver.java @@ -18,8 +18,7 @@ package org.springframework.web.servlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface for web-based theme resolution strategies that allows for 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 3d8bb3c369..6ec59da725 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 @@ -20,8 +20,7 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * MVC View for a web interaction. Implementations are responsible for rendering @@ -78,8 +77,7 @@ public interface View { * @return the content type String (optionally including a character set), * or {@code null} if not predetermined */ - @Nullable - default String getContentType() { + default @Nullable String getContentType() { return null; } 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 4f797a2523..f4d3627b40 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,7 +18,7 @@ package org.springframework.web.servlet; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by objects that can resolve views by name. @@ -52,7 +52,6 @@ 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; + @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 d251860861..4444ee1d8b 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 @@ -22,6 +22,7 @@ import java.util.Properties; import com.fasterxml.jackson.dataformat.cbor.CBORFactory; import com.fasterxml.jackson.dataformat.smile.SmileFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.FactoryBean; @@ -57,7 +58,6 @@ 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.yaml.MappingJackson2YamlHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.xml.DomUtils; @@ -196,8 +196,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext context) { + public @Nullable BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); XmlReaderContext readerContext = context.getReaderContext(); @@ -363,8 +362,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return conversionServiceRef; } - @Nullable - private RuntimeBeanReference getValidator(Element element, @Nullable Object source, ParserContext context) { + private @Nullable RuntimeBeanReference getValidator(Element element, @Nullable Object source, ParserContext context) { if (element.hasAttribute("validator")) { return new RuntimeBeanReference(element.getAttribute("validator")); } @@ -466,8 +464,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return defaultMediaTypes; } - @Nullable - private RuntimeBeanReference getMessageCodesResolver(Element element) { + private @Nullable RuntimeBeanReference getMessageCodesResolver(Element element) { if (element.hasAttribute("message-codes-resolver")) { return new RuntimeBeanReference(element.getAttribute("message-codes-resolver")); } @@ -476,14 +473,12 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { } } - @Nullable - private String getAsyncTimeout(Element element) { + private @Nullable String getAsyncTimeout(Element element) { Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support"); return (asyncElement != null ? asyncElement.getAttribute("default-timeout") : null); } - @Nullable - private RuntimeBeanReference getAsyncExecutor(Element element) { + private @Nullable RuntimeBeanReference getAsyncExecutor(Element element) { Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support"); if (asyncElement != null && asyncElement.hasAttribute("task-executor")) { return new RuntimeBeanReference(asyncElement.getAttribute("task-executor")); @@ -512,8 +507,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return interceptors; } - @Nullable - private ManagedList getArgumentResolvers(Element element, ParserContext context) { + private @Nullable ManagedList getArgumentResolvers(Element element, ParserContext context) { Element resolversElement = DomUtils.getChildElementByTagName(element, "argument-resolvers"); if (resolversElement != null) { ManagedList resolvers = extractBeanSubElements(resolversElement, context); @@ -541,8 +535,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { return result; } - @Nullable - private ManagedList getReturnValueHandlers(Element element, ParserContext context) { + private @Nullable ManagedList getReturnValueHandlers(Element element, ParserContext context) { Element handlers = DomUtils.getChildElementByTagName(element, "return-value-handlers"); return (handlers != null ? extractBeanSubElements(handlers, context) : null); } @@ -660,14 +653,11 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { static class CompositeUriComponentsContributorFactoryBean implements FactoryBean, InitializingBean { - @Nullable - private RequestMappingHandlerAdapter handlerAdapter; + private @Nullable RequestMappingHandlerAdapter handlerAdapter; - @Nullable - private ConversionService conversionService; + private @Nullable ConversionService conversionService; - @Nullable - private CompositeUriComponentsContributor uriComponentsContributor; + private @Nullable CompositeUriComponentsContributor uriComponentsContributor; public void setHandlerAdapter(RequestMappingHandlerAdapter handlerAdapter) { this.handlerAdapter = handlerAdapter; @@ -685,8 +675,7 @@ class AnnotationDrivenBeanDefinitionParser implements BeanDefinitionParser { } @Override - @Nullable - public CompositeUriComponentsContributor getObject() { + public @Nullable CompositeUriComponentsContributor getObject() { return this.uriComponentsContributor; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/CorsBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/CorsBeanDefinitionParser.java index 670becc7d8..790e75dd7b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/CorsBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/CorsBeanDefinitionParser.java @@ -21,12 +21,12 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; 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; import org.springframework.web.cors.CorsConfiguration; @@ -43,8 +43,7 @@ import org.springframework.web.cors.CorsConfiguration; public class CorsBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { Map corsConfigurations = new LinkedHashMap<>(); List mappings = DomUtils.getChildElementsByTagName(element, "mapping"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/DefaultServletHandlerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/DefaultServletHandlerBeanDefinitionParser.java index 385c1010e1..a80fa756a6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/DefaultServletHandlerBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/DefaultServletHandlerBeanDefinitionParser.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.config; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -26,7 +27,6 @@ import org.springframework.beans.factory.support.ManagedMap; 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.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter; @@ -45,8 +45,7 @@ import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler class DefaultServletHandlerBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); String defaultServletName = element.getAttribute("default-servlet-name"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/InterceptorsBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/InterceptorsBeanDefinitionParser.java index 2777141be1..c95522a097 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/InterceptorsBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/InterceptorsBeanDefinitionParser.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.config; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -28,7 +29,6 @@ import org.springframework.beans.factory.support.ManagedList; 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.xml.DomUtils; import org.springframework.web.servlet.handler.MappedInterceptor; @@ -42,8 +42,7 @@ import org.springframework.web.servlet.handler.MappedInterceptor; class InterceptorsBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext context) { + public @Nullable BeanDefinition parse(Element element, ParserContext context) { context.pushContainingComponent( new CompositeComponentDefinition(element.getTagName(), context.extractSource(element))); 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 e68be743bd..b21c1b801f 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 @@ -19,6 +19,8 @@ package org.springframework.web.servlet.config; import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.RuntimeBeanReference; @@ -26,7 +28,6 @@ import org.springframework.beans.factory.parsing.BeanComponentDefinition; import org.springframework.beans.factory.support.BeanDefinitionRegistry; 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.Assert; import org.springframework.util.PathMatcher; @@ -114,8 +115,7 @@ public abstract class MvcNamespaceUtils { * Return the {@link PathMatcher} bean definition if it has been registered * in the context as an alias with its well-known name, or {@code null}. */ - @Nullable - static RuntimeBeanReference getCustomPathMatcher(ParserContext context) { + static @Nullable RuntimeBeanReference getCustomPathMatcher(ParserContext context) { if(context.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME)) { return new RuntimeBeanReference(PATH_MATCHER_BEAN_NAME); } @@ -154,8 +154,7 @@ public abstract class MvcNamespaceUtils { * Return the {@link PathPatternParser} bean definition if it has been registered * in the context as an alias with its well-known name, or {@code null}. */ - @Nullable - static RuntimeBeanReference getCustomPatternParser(ParserContext context) { + static @Nullable RuntimeBeanReference getCustomPatternParser(ParserContext context) { if (context.getRegistry().isAlias(PATTERN_PARSER_BEAN_NAME)) { return new RuntimeBeanReference(PATTERN_PARSER_BEAN_NAME); } @@ -356,8 +355,7 @@ public abstract class MvcNamespaceUtils { * with the {@code annotation-driven} element. * @return a bean definition, bean reference, or {@code null} if none defined */ - @Nullable - public static Object getContentNegotiationManager(ParserContext context) { + public static @Nullable Object getContentNegotiationManager(ParserContext context) { String name = AnnotationDrivenBeanDefinitionParser.HANDLER_MAPPING_BEAN_NAME; if (context.getRegistry().containsBeanDefinition(name)) { BeanDefinition handlerMappingBeanDef = context.getRegistry().getBeanDefinition(name); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java index 8828c103e3..68276f51b6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java @@ -19,6 +19,7 @@ package org.springframework.web.servlet.config; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.MutablePropertyValues; @@ -34,7 +35,6 @@ import org.springframework.beans.factory.xml.ParserContext; import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.core.Ordered; import org.springframework.http.CacheControl; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; @@ -86,8 +86,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext context) { + public @Nullable BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); registerUrlProvider(context, source); @@ -154,8 +153,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser { } } - @Nullable - private String registerResourceHandler(ParserContext context, Element element, + private @Nullable String registerResourceHandler(ParserContext context, Element element, RuntimeBeanReference pathHelperRef, @Nullable Object source) { String locationAttr = element.getAttribute("location"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java index 5964af08ad..a84f8dc177 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewControllerBeanDefinitionParser.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.config; import java.util.Map; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.factory.config.BeanDefinition; @@ -28,7 +29,6 @@ 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.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; @@ -60,9 +60,8 @@ class ViewControllerBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable @SuppressWarnings("unchecked") - public BeanDefinition parse(Element element, ParserContext parserContext) { + public @Nullable BeanDefinition parse(Element element, ParserContext parserContext) { Object source = parserContext.extractSource(element); // Register SimpleUrlHandlerMapping for view controllers diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java index 775107950e..251550bf2e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/ViewResolversBeanDefinitionParser.java @@ -18,6 +18,7 @@ package org.springframework.web.servlet.config; import java.util.List; +import org.jspecify.annotations.Nullable; import org.w3c.dom.Element; import org.springframework.beans.MutablePropertyValues; @@ -29,7 +30,6 @@ import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.xml.BeanDefinitionParser; import org.springframework.beans.factory.xml.ParserContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.xml.DomUtils; import org.springframework.web.servlet.view.BeanNameViewResolver; import org.springframework.web.servlet.view.ContentNegotiatingViewResolver; @@ -69,8 +69,7 @@ public class ViewResolversBeanDefinitionParser implements BeanDefinitionParser { @Override - @Nullable - public BeanDefinition parse(Element element, ParserContext context) { + public @Nullable BeanDefinition parse(Element element, ParserContext context) { Object source = context.extractSource(element); context.pushContainingComponent(new CompositeComponentDefinition(element.getTagName(), source)); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java index bdccde02a8..a45b99bfcf 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/AsyncSupportConfigurer.java @@ -21,8 +21,9 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable; +import org.jspecify.annotations.Nullable; + import org.springframework.core.task.AsyncTaskExecutor; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.async.CallableProcessingInterceptor; import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.DeferredResultProcessingInterceptor; @@ -35,11 +36,9 @@ import org.springframework.web.context.request.async.DeferredResultProcessingInt */ public class AsyncSupportConfigurer { - @Nullable - private AsyncTaskExecutor taskExecutor; + private @Nullable AsyncTaskExecutor taskExecutor; - @Nullable - private Long timeout; + private @Nullable Long timeout; private final List callableInterceptors = new ArrayList<>(); @@ -101,13 +100,11 @@ public class AsyncSupportConfigurer { } - @Nullable - protected AsyncTaskExecutor getTaskExecutor() { + protected @Nullable AsyncTaskExecutor getTaskExecutor() { return this.taskExecutor; } - @Nullable - protected Long getTimeout() { + protected @Nullable Long getTimeout() { return this.timeout; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java index a13d9855ac..b5fd713086 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ContentNegotiationConfigurer.java @@ -22,10 +22,10 @@ import java.util.List; import java.util.Map; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; -import org.springframework.lang.Nullable; import org.springframework.web.accept.ContentNegotiationManager; import org.springframework.web.accept.ContentNegotiationManagerFactoryBean; import org.springframework.web.accept.ContentNegotiationStrategy; 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 9279901135..6858cb9d9a 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 @@ -19,9 +19,9 @@ package org.springframework.web.servlet.config.annotation; import java.util.Collections; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; @@ -46,8 +46,7 @@ public class DefaultServletHandlerConfigurer { private final ServletContext servletContext; - @Nullable - private DefaultServletHttpRequestHandler handler; + private @Nullable DefaultServletHttpRequestHandler handler; /** @@ -93,8 +92,7 @@ public class DefaultServletHandlerConfigurer { * enabled. * @since 4.3.12 */ - @Nullable - protected SimpleUrlHandlerMapping buildHandlerMapping() { + protected @Nullable SimpleUrlHandlerMapping buildHandlerMapping() { if (this.handler == null) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java index 457ce6b291..1e49d23974 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.java @@ -18,11 +18,12 @@ package org.springframework.web.servlet.config.annotation; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.Validator; @@ -140,14 +141,12 @@ public class DelegatingWebMvcConfiguration extends WebMvcConfigurationSupport { } @Override - @Nullable - protected Validator getValidator() { + protected @Nullable Validator getValidator() { return this.configurers.getValidator(); } @Override - @Nullable - protected MessageCodesResolver getMessageCodesResolver() { + protected @Nullable MessageCodesResolver getMessageCodesResolver() { return this.configurers.getMessageCodesResolver(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java index ee758ceaf4..af3e7280bc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/InterceptorRegistration.java @@ -20,7 +20,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; @@ -41,14 +42,11 @@ public class InterceptorRegistration { private final HandlerInterceptor interceptor; - @Nullable - private List includePatterns; + private @Nullable List includePatterns; - @Nullable - private List excludePatterns; + private @Nullable List excludePatterns; - @Nullable - private PathMatcher pathMatcher; + private @Nullable PathMatcher pathMatcher; private int order = 0; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java index 239dbe3e12..24c73e6b11 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/PathMatchConfigurer.java @@ -20,7 +20,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.function.Predicate; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher; import org.springframework.web.util.UrlPathHelper; @@ -45,26 +46,19 @@ public class PathMatchConfigurer { private boolean preferPathMatcher = false; - @Nullable - private PathPatternParser patternParser; + private @Nullable PathPatternParser patternParser; - @Nullable - private Map>> pathPrefixes; + private @Nullable Map>> pathPrefixes; - @Nullable - private UrlPathHelper urlPathHelper; + private @Nullable UrlPathHelper urlPathHelper; - @Nullable - private PathMatcher pathMatcher; + private @Nullable PathMatcher pathMatcher; - @Nullable - private PathPatternParser defaultPatternParser; + private @Nullable PathPatternParser defaultPatternParser; - @Nullable - private UrlPathHelper defaultUrlPathHelper; + private @Nullable UrlPathHelper defaultUrlPathHelper; - @Nullable - private PathMatcher defaultPathMatcher; + private @Nullable PathMatcher defaultPathMatcher; /** @@ -158,23 +152,19 @@ public class PathMatchConfigurer { * Return the {@link PathPatternParser} to use, if configured. * @since 5.3 */ - @Nullable - public PathPatternParser getPatternParser() { + public @Nullable PathPatternParser getPatternParser() { return this.patternParser; } - @Nullable - protected Map>> getPathPrefixes() { + protected @Nullable Map>> getPathPrefixes() { return this.pathPrefixes; } - @Nullable - public UrlPathHelper getUrlPathHelper() { + public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } - @Nullable - public PathMatcher getPathMatcher() { + public @Nullable PathMatcher getPathMatcher() { return this.pathMatcher; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java index 45621534c9..f21b5f88aa 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/RedirectViewControllerRegistration.java @@ -16,9 +16,10 @@ package org.springframework.web.servlet.config.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.mvc.ParameterizableViewController; import org.springframework.web.servlet.view.RedirectView; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java index 894692fbcb..354173487f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java @@ -19,9 +19,10 @@ package org.springframework.web.servlet.config.annotation; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.cache.concurrent.ConcurrentMapCache; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.servlet.resource.CachingResourceResolver; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistration.java index 2b0e1fe0ac..07d5312c9f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceHandlerRegistration.java @@ -21,10 +21,11 @@ import java.util.Arrays; import java.util.List; import java.util.function.Function; +import org.jspecify.annotations.Nullable; + import org.springframework.cache.Cache; import org.springframework.core.io.Resource; import org.springframework.http.CacheControl; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.servlet.resource.PathResourceResolver; @@ -46,19 +47,15 @@ public class ResourceHandlerRegistration { private final List locationsResources = new ArrayList<>(); - @Nullable - private Integer cachePeriod; + private @Nullable Integer cachePeriod; - @Nullable - private CacheControl cacheControl; + private @Nullable CacheControl cacheControl; - @Nullable - private ResourceChainRegistration resourceChainRegistration; + private @Nullable ResourceChainRegistration resourceChainRegistration; private boolean useLastModified = true; - @Nullable - private Function etagGenerator; + private @Nullable Function etagGenerator; private boolean optimizeLocations = false; 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 99e132ab1a..9bb9d4f25d 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 @@ -23,11 +23,11 @@ import java.util.List; import java.util.Map; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ApplicationContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.web.HttpRequestHandler; @@ -66,8 +66,7 @@ public class ResourceHandlerRegistry { private final ApplicationContext applicationContext; - @Nullable - private final UrlPathHelper pathHelper; + private final @Nullable UrlPathHelper pathHelper; private final List registrations = new ArrayList<>(); @@ -154,8 +153,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() { + protected @Nullable AbstractHandlerMapping getHandlerMapping() { if (this.registrations.isEmpty()) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistration.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistration.java index 42dd2ef1a7..a4fc13ddad 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistration.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewControllerRegistration.java @@ -16,9 +16,10 @@ package org.springframework.web.servlet.config.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.RequestToViewNameTranslator; import org.springframework.web.servlet.mvc.ParameterizableViewController; 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 9189a8b1a5..8d0a45465a 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 @@ -21,9 +21,10 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationContext; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; import org.springframework.web.util.pattern.PathPattern; @@ -38,8 +39,7 @@ import org.springframework.web.util.pattern.PathPattern; */ public class ViewControllerRegistry { - @Nullable - private final ApplicationContext applicationContext; + private final @Nullable ApplicationContext applicationContext; private final List registrations = new ArrayList<>(4); @@ -128,8 +128,7 @@ public class ViewControllerRegistry { * controller mappings, or {@code null} for no registrations. * @since 4.3.12 */ - @Nullable - protected SimpleUrlHandlerMapping buildHandlerMapping() { + protected @Nullable SimpleUrlHandlerMapping buildHandlerMapping() { if (this.registrations.isEmpty() && this.redirectRegistrations.isEmpty()) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java index aabe17b822..707c039538 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ViewResolverRegistry.java @@ -21,11 +21,12 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.context.ApplicationContext; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.accept.ContentNegotiationManager; @@ -52,19 +53,15 @@ import org.springframework.web.servlet.view.script.ScriptTemplateViewResolver; */ public class ViewResolverRegistry { - @Nullable private final ContentNegotiationManager contentNegotiationManager; - @Nullable - private final ApplicationContext applicationContext; + private final @Nullable ApplicationContext applicationContext; - @Nullable - private ContentNegotiatingViewResolver contentNegotiatingResolver; + private @Nullable ContentNegotiatingViewResolver contentNegotiatingResolver; private final List viewResolvers = new ArrayList<>(4); - @Nullable - private Integer order; + private @Nullable Integer order; /** 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 4b3e18e1ec..aa4888cb45 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 @@ -24,6 +24,7 @@ import java.util.Locale; import java.util.Map; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.BeanInitializationException; @@ -59,7 +60,6 @@ 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.yaml.MappingJackson2YamlHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -233,38 +233,27 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv } - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; - @Nullable - private List interceptors; + private @Nullable List interceptors; - @Nullable - private PathMatchConfigurer pathMatchConfigurer; + private @Nullable PathMatchConfigurer pathMatchConfigurer; - @Nullable - private ContentNegotiationManager contentNegotiationManager; + private @Nullable ContentNegotiationManager contentNegotiationManager; - @Nullable - private List argumentResolvers; + private @Nullable List argumentResolvers; - @Nullable - private List returnValueHandlers; + private @Nullable List returnValueHandlers; - @Nullable - private List> messageConverters; + private @Nullable List> messageConverters; - @Nullable - private List errorResponseInterceptors; + private @Nullable List errorResponseInterceptors; - @Nullable - private Map corsConfigurations; + private @Nullable Map corsConfigurations; - @Nullable - private AsyncSupportConfigurer asyncSupportConfigurer; + private @Nullable AsyncSupportConfigurer asyncSupportConfigurer; /** @@ -279,8 +268,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * Return the associated Spring {@link ApplicationContext}. * @since 4.2 */ - @Nullable - public final ApplicationContext getApplicationContext() { + public final @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -297,8 +285,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * Return the associated {@link jakarta.servlet.ServletContext}. * @since 4.2 */ - @Nullable - public final ServletContext getServletContext() { + public final @Nullable ServletContext getServletContext() { return this.servletContext; } @@ -475,8 +462,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * {@link #addViewControllers}. */ @Bean - @Nullable - public HandlerMapping viewControllerHandlerMapping( + public @Nullable HandlerMapping viewControllerHandlerMapping( @Qualifier("mvcConversionService") FormattingConversionService conversionService, @Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) { @@ -569,8 +555,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * {@link #addResourceHandlers}. */ @Bean - @Nullable - public HandlerMapping resourceHandlerMapping( + public @Nullable HandlerMapping resourceHandlerMapping( @Qualifier("mvcContentNegotiationManager") ContentNegotiationManager contentNegotiationManager, @Qualifier("mvcConversionService") FormattingConversionService conversionService, @Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) { @@ -614,8 +599,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv * override {@link #configureDefaultServletHandling}. */ @Bean - @Nullable - public HandlerMapping defaultServletHandlerMapping() { + public @Nullable HandlerMapping defaultServletHandlerMapping() { Assert.state(this.servletContext != null, "No ServletContext set"); DefaultServletHandlerConfigurer configurer = new DefaultServletHandlerConfigurer(this.servletContext); configureDefaultServletHandling(configurer); @@ -716,8 +700,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv /** * Override this method to provide a custom {@link MessageCodesResolver}. */ - @Nullable - protected MessageCodesResolver getMessageCodesResolver() { + protected @Nullable MessageCodesResolver getMessageCodesResolver() { return null; } @@ -770,8 +753,7 @@ public class WebMvcConfigurationSupport implements ApplicationContextAware, Serv /** * Override this method to provide a custom {@link Validator}. */ - @Nullable - protected Validator getValidator() { + protected @Nullable 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 d55fcba9e0..afa3ab093a 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 @@ -18,11 +18,12 @@ package org.springframework.web.servlet.config.annotation; import java.util.List; +import org.jspecify.annotations.Nullable; + 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.ErrorResponse; @@ -238,8 +239,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() { + default @Nullable Validator getValidator() { return null; } @@ -248,8 +248,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() { + default @Nullable MessageCodesResolver getMessageCodesResolver() { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java index 9e58fb1627..e093d6770b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/WebMvcConfigurerComposite.java @@ -19,9 +19,10 @@ package org.springframework.web.servlet.config.annotation; import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.format.FormatterRegistry; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.validation.MessageCodesResolver; import org.springframework.validation.Validator; @@ -168,8 +169,7 @@ class WebMvcConfigurerComposite implements WebMvcConfigurer { } @Override - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { Validator selected = null; for (WebMvcConfigurer configurer : this.delegates) { Validator validator = configurer.getValidator(); @@ -185,8 +185,7 @@ class WebMvcConfigurerComposite implements WebMvcConfigurer { } @Override - @Nullable - public MessageCodesResolver getMessageCodesResolver() { + public @Nullable MessageCodesResolver getMessageCodesResolver() { MessageCodesResolver selected = null; for (WebMvcConfigurer configurer : this.delegates) { MessageCodesResolver messageCodesResolver = configurer.getMessageCodesResolver(); 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 8d9339ca55..ae5e1672e8 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,9 +1,7 @@ /** * Annotation-based setup for Spring MVC. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.config.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 45180017f3..85e32d51c9 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,9 +1,7 @@ /** * Defines the XML configuration namespace for Spring MVC. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.config; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AbstractServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AbstractServerResponse.java index 599e0df674..d2288fc3f3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AbstractServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AbstractServerResponse.java @@ -24,11 +24,11 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -76,8 +76,7 @@ abstract class AbstractServerResponse extends ErrorHandlingServerResponse { } @Override - @Nullable - public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, + public @Nullable ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) throws ServletException, IOException { try { @@ -128,8 +127,7 @@ abstract class AbstractServerResponse extends ErrorHandlingServerResponse { .forEach(servletResponse::addCookie); } - @Nullable - protected abstract ModelAndView writeToInternal( + protected abstract @Nullable ModelAndView writeToInternal( HttpServletRequest request, HttpServletResponse response, Context context) throws Exception; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AsyncServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AsyncServerResponse.java index ade8870faa..b1fdb56df6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AsyncServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/AsyncServerResponse.java @@ -20,11 +20,11 @@ import java.time.Duration; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.ReactiveAdapter; import org.springframework.core.ReactiveAdapterRegistry; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/CompletedAsyncServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/CompletedAsyncServerResponse.java index ba0c211999..fee9e4e9f9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/CompletedAsyncServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/CompletedAsyncServerResponse.java @@ -22,10 +22,10 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.web.servlet.ModelAndView; @@ -68,8 +68,7 @@ final class CompletedAsyncServerResponse implements AsyncServerResponse { } @Override - @Nullable - public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) + public @Nullable ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) throws ServletException, IOException { return this.serverResponse.writeTo(request, response, context); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java index 86a1c93177..09b818fcbe 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultAsyncServerResponse.java @@ -29,10 +29,10 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.MultiValueMap; import org.springframework.web.context.request.async.AsyncWebRequest; @@ -54,8 +54,7 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple private final CompletableFuture futureResponse; - @Nullable - private final Duration timeout; + private final @Nullable Duration timeout; DefaultAsyncServerResponse(CompletableFuture futureResponse, @Nullable Duration timeout) { @@ -105,8 +104,7 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple } @Override - @Nullable - public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) + public @Nullable ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) throws ServletException, IOException { writeAsync(request, response, createDeferredResult(request)); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilder.java index 88ff2c4fb1..c205da6543 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultEntityResponseBuilder.java @@ -34,6 +34,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -57,7 +58,6 @@ import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.SmartHttpMessageConverter; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -260,8 +260,7 @@ final class DefaultEntityResponseBuilder implements EntityResponse.Builder } @Override - @Nullable - protected ModelAndView writeToInternal(HttpServletRequest servletRequest, + protected @Nullable ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Context context) throws ServletException, IOException { @@ -322,8 +321,7 @@ final class DefaultEntityResponseBuilder implements EntityResponse.Builder throw new HttpMediaTypeNotAcceptableException(producibleMediaTypes); } - @Nullable - private static MediaType getContentType(HttpServletResponse response) { + private static @Nullable MediaType getContentType(HttpServletResponse response) { try { return MediaType.parseMediaType(response.getContentType()).removeQualityValue(); } @@ -367,8 +365,7 @@ final class DefaultEntityResponseBuilder implements EntityResponse.Builder } @Override - @Nullable - protected ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, + protected @Nullable ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Context context) throws ServletException, IOException { DeferredResult deferredResult = createDeferredResult(servletRequest, servletResponse, context); @@ -421,8 +418,7 @@ final class DefaultEntityResponseBuilder implements EntityResponse.Builder } @Override - @Nullable - protected ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, + protected @Nullable ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Context context) throws ServletException, IOException { DeferredResult deferredResult = new DeferredResult<>(); @@ -443,8 +439,7 @@ final class DefaultEntityResponseBuilder implements EntityResponse.Builder private final DeferredResult deferredResult; - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; public DeferredResultSubscriber(HttpServletRequest servletRequest, diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultRenderingResponseBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultRenderingResponseBuilder.java index 45f92fbc1a..69f6358914 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultRenderingResponseBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultRenderingResponseBuilder.java @@ -26,12 +26,12 @@ import java.util.function.Consumer; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.Conventions; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java index 0723b6cdab..2e168c72c4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequest.java @@ -49,6 +49,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; @@ -61,7 +62,6 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.SmartHttpMessageConverter; import org.springframework.http.server.RequestPath; 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; @@ -101,8 +101,7 @@ class DefaultServerRequest implements ServerRequest { private final Map attributes; - @Nullable - private MultiValueMap parts; + private @Nullable MultiValueMap parts; public DefaultServerRequest(HttpServletRequest servletRequest, List> messageConverters) { @@ -385,8 +384,7 @@ class DefaultServerRequest implements ServerRequest { } @Override - @Nullable - public InetSocketAddress host() { + public @Nullable InetSocketAddress host() { return this.httpHeaders.getHost(); } @@ -637,8 +635,7 @@ class DefaultServerRequest implements ServerRequest { } @Override - @Nullable - public String getHeader(String name) { + public @Nullable String getHeader(String name) { return this.headers.getFirst(name); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java index 0434008117..920ab58fa6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerRequestBuilder.java @@ -40,6 +40,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.ResolvableType; @@ -50,7 +51,6 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.GenericHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.SmartHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -86,8 +86,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { private final MultiValueMap params = new LinkedMultiValueMap<>(); - @Nullable - private InetSocketAddress remoteAddress; + private @Nullable InetSocketAddress remoteAddress; private byte[] body = new byte[0]; @@ -228,8 +227,7 @@ class DefaultServerRequestBuilder implements ServerRequest.Builder { private final MultiValueMap params; - @Nullable - private final InetSocketAddress remoteAddress; + private final @Nullable InetSocketAddress remoteAddress; public BuiltServerRequest(HttpServletRequest servletRequest, HttpMethod method, URI uri, HttpHeaders headers, MultiValueMap cookies, diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerResponseBuilder.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerResponseBuilder.java index 72c32d308f..03c60af202 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerResponseBuilder.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/DefaultServerResponseBuilder.java @@ -28,6 +28,7 @@ import java.util.function.Consumer; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.CacheControl; @@ -35,7 +36,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; @@ -69,7 +69,8 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { } @Override - public ServerResponse.BodyBuilder header(String headerName, String... headerValues) { + @SuppressWarnings("NullAway") // TODO NullAway bug potentially due to the recursive generic type + public ServerResponse.BodyBuilder header(String headerName, @Nullable String... headerValues) { Assert.notNull(headerName, "HeaderName must not be null"); for (String headerValue : headerValues) { this.headers.add(headerName, headerValue); @@ -227,8 +228,7 @@ class DefaultServerResponseBuilder implements ServerResponse.BodyBuilder { } @Override - @Nullable - protected ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, + protected @Nullable ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, Context context) throws Exception { return this.writeFunction.write(request, response); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ErrorHandlingServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ErrorHandlingServerResponse.java index 81d9a19254..ed1784443a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ErrorHandlingServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ErrorHandlingServerResponse.java @@ -27,8 +27,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.ModelAndView; @@ -52,8 +52,7 @@ abstract class ErrorHandlingServerResponse implements ServerResponse { this.errorHandlers.add(new ErrorHandler<>(predicate, errorHandler)); } - @Nullable - protected final ModelAndView handleError(Throwable t, HttpServletRequest servletRequest, + protected final @Nullable ModelAndView handleError(Throwable t, HttpServletRequest servletRequest, HttpServletResponse servletResponse, Context context) throws ServletException, IOException { ServerResponse serverResponse = errorResponse(t, servletRequest); @@ -71,8 +70,7 @@ abstract class ErrorHandlingServerResponse implements ServerResponse { } } - @Nullable - protected final ServerResponse errorResponse(Throwable t, HttpServletRequest servletRequest) { + protected final @Nullable ServerResponse errorResponse(Throwable t, HttpServletRequest servletRequest) { for (ErrorHandler errorHandler : this.errorHandlers) { if (errorHandler.test(t)) { ServerRequest serverRequest = (ServerRequest) diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RenderingResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RenderingResponse.java index 446dba2cfe..1d5990ca3a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RenderingResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RenderingResponse.java @@ -21,10 +21,10 @@ import java.util.Map; import java.util.function.Consumer; import jakarta.servlet.http.Cookie; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java index aa71230ed3..28152fe85b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/RequestPredicates.java @@ -40,6 +40,7 @@ import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.Part; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.http.HttpHeaders; @@ -48,7 +49,6 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MimeTypeUtils; @@ -479,8 +479,8 @@ public abstract class RequestPredicates { private final boolean value; - @Nullable - private final Consumer> modifyAttributes; + + private final @Nullable Consumer> modifyAttributes; private Result(boolean value, @Nullable Consumer> modifyAttributes) { @@ -818,8 +818,7 @@ public abstract class RequestPredicates { private final Predicate extensionPredicate; - @Nullable - private final String extension; + private final @Nullable String extension; public PathExtensionPredicate(Predicate extensionPredicate) { Assert.notNull(extensionPredicate, "Predicate must not be null"); @@ -868,8 +867,7 @@ public abstract class RequestPredicates { private final Predicate valuePredicate; - @Nullable - private final String value; + private final @Nullable String value; public ParamPredicate(String name, Predicate valuePredicate) { Assert.notNull(name, "Name must not be null"); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ResourceHandlerFunction.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ResourceHandlerFunction.java index 3ee4a3df60..86ccce7dec 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ResourceHandlerFunction.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ResourceHandlerFunction.java @@ -25,11 +25,12 @@ import java.net.URL; import java.util.Set; import java.util.function.BiConsumer; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; -import org.springframework.lang.Nullable; /** * Resource-based implementation of {@link HandlerFunction}. @@ -130,8 +131,7 @@ class ResourceHandlerFunction implements HandlerFunction { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.delegate.getFilename(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java index 01ac4ad96d..77a2e072be 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerRequest.java @@ -34,6 +34,7 @@ import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.Part; +import org.jspecify.annotations.Nullable; import org.springframework.core.ParameterizedTypeReference; import org.springframework.core.io.buffer.DataBuffer; @@ -44,7 +45,6 @@ import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.PathContainer; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -445,8 +445,7 @@ public interface ServerRequest { * {@linkplain InetSocketAddress#getPort() port} in the returned address will * be {@code 0}. */ - @Nullable - InetSocketAddress host(); + @Nullable InetSocketAddress host(); /** * Get the value of the {@code Range} header. @@ -467,8 +466,7 @@ public interface ServerRequest { * @param headerName the header name * @since 5.2.5 */ - @Nullable - default String firstHeader(String headerName) { + default @Nullable String firstHeader(String headerName) { List list = header(headerName); return list.isEmpty() ? null : list.get(0); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerResponse.java index 7d40395bf7..101fde0877 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/ServerResponse.java @@ -33,6 +33,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.springframework.core.ParameterizedTypeReference; @@ -44,7 +45,6 @@ import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.MultiValueMap; import org.springframework.web.ErrorResponse; import org.springframework.web.servlet.ModelAndView; @@ -82,8 +82,7 @@ public interface ServerResponse { * @param context the context to use when writing * @return a {@code ModelAndView} to render, or {@code null} if handled directly */ - @Nullable - ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) + @Nullable ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context) throws ServletException, IOException; @@ -335,7 +334,7 @@ public interface ServerResponse { * @return this builder * @see HttpHeaders#add(String, String) */ - B header(String headerName, String... headerValues); + B header(String headerName, @Nullable String... headerValues); /** * Manipulate this response's headers with the given consumer. The @@ -466,8 +465,7 @@ public interface ServerResponse { * @return a {@code ModelAndView} to render, or {@code null} if handled directly * @throws Exception in case of Servlet errors */ - @Nullable - ModelAndView write(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception; + @Nullable ModelAndView write(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java index 38d5cc8ff0..9f8f87b5e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java @@ -28,6 +28,7 @@ import jakarta.servlet.ServletException; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.CacheControl; import org.springframework.http.HttpHeaders; @@ -37,7 +38,6 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.DelegatingServerHttpResponse; import org.springframework.http.server.ServerHttpResponse; 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.MultiValueMap; @@ -56,8 +56,7 @@ final class SseServerResponse extends AbstractServerResponse { private final Consumer sseConsumer; - @Nullable - private final Duration timeout; + private final @Nullable Duration timeout; private SseServerResponse(Consumer sseConsumer, @Nullable Duration timeout) { @@ -78,9 +77,8 @@ final class SseServerResponse extends AbstractServerResponse { } - @Nullable @Override - protected ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, + protected @Nullable ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, Context context) throws ServletException, IOException { DeferredResult result; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/StreamingServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/StreamingServerResponse.java index ee4f2001a8..0621a4770a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/StreamingServerResponse.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/StreamingServerResponse.java @@ -25,6 +25,7 @@ import java.util.function.Consumer; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; @@ -33,7 +34,6 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.DelegatingServerHttpResponse; import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MultiValueMap; import org.springframework.web.context.request.async.DeferredResult; @@ -48,8 +48,7 @@ final class StreamingServerResponse extends AbstractServerResponse { private final Consumer streamConsumer; - @Nullable - private final Duration timeout; + private final @Nullable Duration timeout; private StreamingServerResponse(HttpStatusCode statusCode, HttpHeaders headers, MultiValueMap cookies, Consumer streamConsumer, @Nullable Duration timeout) { @@ -67,9 +66,8 @@ final class StreamingServerResponse extends AbstractServerResponse { return new StreamingServerResponse(statusCode, headers, cookies, streamConsumer, timeout); } - @Nullable @Override - protected ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, Context context) throws Exception { + protected @Nullable ModelAndView writeToInternal(HttpServletRequest request, HttpServletResponse response, Context context) throws Exception { DeferredResult result; if (this.timeout != null) { result = new DeferredResult<>(this.timeout.toMillis()); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/package-info.java index f50375d311..4a4ac6ed1d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/package-info.java @@ -1,9 +1,7 @@ /** * Provides the types that make up Spring's functional web framework for Servlet environments. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.function; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java index d3e59c7277..5cd02df8c2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/HandlerFunctionAdapter.java @@ -23,11 +23,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.Ordered; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.async.AsyncWebRequest; import org.springframework.web.context.request.async.WebAsyncManager; @@ -51,8 +51,7 @@ public class HandlerFunctionAdapter implements HandlerAdapter, Ordered { private int order = Ordered.LOWEST_PRECEDENCE; - @Nullable - private Long asyncRequestTimeout; + private @Nullable Long asyncRequestTimeout; /** * Specify the order value for this HandlerAdapter bean. @@ -88,9 +87,8 @@ public class HandlerFunctionAdapter implements HandlerAdapter, Ordered { return handler instanceof HandlerFunction; } - @Nullable @Override - public ModelAndView handle(HttpServletRequest servletRequest, + public @Nullable ModelAndView handle(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Object handler) throws Exception { @@ -149,8 +147,7 @@ public class HandlerFunctionAdapter implements HandlerAdapter, Ordered { return serverRequest; } - @Nullable - private ServerResponse handleAsync(WebAsyncManager asyncManager) throws Exception { + private @Nullable ServerResponse handleAsync(WebAsyncManager asyncManager) throws Exception { Object result = asyncManager.getConcurrentResult(); asyncManager.clearConcurrentResult(); LogFormatUtils.traceDebug(logger, traceOn -> { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java index 751a2d4522..d93579a219 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/RouterFunctionMapping.java @@ -22,6 +22,7 @@ import java.util.List; import java.util.stream.Collectors; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; @@ -29,7 +30,6 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.filter.ServerHttpObservationFilter; import org.springframework.web.servlet.function.HandlerFunction; @@ -57,8 +57,7 @@ import org.springframework.web.util.pattern.PathPatternParser; */ public class RouterFunctionMapping extends AbstractHandlerMapping implements InitializingBean, MatchableHandlerMapping { - @Nullable - private RouterFunction routerFunction; + private @Nullable RouterFunction routerFunction; private List> messageConverters = Collections.emptyList(); @@ -98,8 +97,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini * prior to {@link #afterPropertiesSet()}. * @return the router function or {@code null} */ - @Nullable - public RouterFunction getRouterFunction() { + public @Nullable RouterFunction getRouterFunction() { return this.routerFunction; } @@ -197,8 +195,7 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini @Override - @Nullable - protected Object getHandlerInternal(HttpServletRequest servletRequest) throws Exception { + protected @Nullable Object getHandlerInternal(HttpServletRequest servletRequest) throws Exception { if (this.routerFunction != null) { ServerRequest request = ServerRequest.create(servletRequest, this.messageConverters); HandlerFunction handlerFunction = this.routerFunction.route(request).orElse(null); @@ -225,9 +222,8 @@ public class RouterFunctionMapping extends AbstractHandlerMapping implements Ini servletRequest.setAttribute(RouterFunctions.REQUEST_ATTRIBUTE, request); } - @Nullable @Override - public RequestMatchResult match(HttpServletRequest request, String pattern) { + public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { throw new UnsupportedOperationException("This HandlerMapping uses PathPatterns"); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/package-info.java index a41208ab31..66f37f53e3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/support/package-info.java @@ -3,9 +3,7 @@ * Contains a {@code HandlerAdapter} that supports {@code HandlerFunction}s, * and a {@code HandlerMapping} that supports {@code RouterFunction}s. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.function.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 a8ccaf220f..1071b7ffb8 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 @@ -23,10 +23,10 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.Ordered; import org.springframework.core.log.LogFormatUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerExceptionResolver; @@ -61,17 +61,13 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti private int order = Ordered.LOWEST_PRECEDENCE; - @Nullable - private Predicate mappedHandlerPredicate; + private @Nullable Predicate mappedHandlerPredicate; - @Nullable - private Set mappedHandlers; + private @Nullable Set mappedHandlers; - @Nullable - private Class[] mappedHandlerClasses; + private Class @Nullable [] mappedHandlerClasses; - @Nullable - private Log warnLogger; + private @Nullable Log warnLogger; private boolean preventResponseCaching = false; @@ -134,8 +130,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * Return the {@link #setMappedHandlerClasses(Class[]) configured} mapped * handler classes. */ - @Nullable - protected Class[] getMappedHandlerClasses() { + protected Class @Nullable [] getMappedHandlerClasses() { return this.mappedHandlerClasses; } @@ -173,8 +168,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * to the {@link #doResolveException} template method. */ @Override - @Nullable - public ModelAndView resolveException( + public @Nullable ModelAndView resolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { if (shouldApplyTo(request, handler)) { @@ -305,8 +299,7 @@ public abstract class AbstractHandlerExceptionResolver implements HandlerExcepti * @return a corresponding {@code ModelAndView} to forward to, * or {@code null} for default processing in the resolution chain */ - @Nullable - protected abstract ModelAndView doResolveException( + protected abstract @Nullable ModelAndView doResolveException( HttpServletRequest request, 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 9eeb49d8ef..3011964738 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 @@ -26,6 +26,7 @@ import jakarta.servlet.DispatcherType; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactoryUtils; @@ -33,7 +34,6 @@ import org.springframework.beans.factory.BeanNameAware; import org.springframework.core.Ordered; import org.springframework.core.log.LogDelegateFactory; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -88,11 +88,9 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport LogDelegateFactory.getHiddenLog(HandlerMapping.class.getName() + ".Mappings"); - @Nullable - private Object defaultHandler; + private @Nullable Object defaultHandler; - @Nullable - private PathPatternParser patternParser = new PathPatternParser(); + private @Nullable PathPatternParser patternParser = new PathPatternParser(); private UrlPathHelper urlPathHelper = new UrlPathHelper(); @@ -102,15 +100,13 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport private final List adaptedInterceptors = new ArrayList<>(); - @Nullable - private CorsConfigurationSource corsConfigurationSource; + private @Nullable CorsConfigurationSource corsConfigurationSource; private CorsProcessor corsProcessor = new DefaultCorsProcessor(); private int order = Ordered.LOWEST_PRECEDENCE; // default: same as non-Ordered - @Nullable - private String beanName; + private @Nullable String beanName; /** @@ -126,8 +122,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * Return the default handler for this handler mapping, * or {@code null} if none. */ - @Nullable - public Object getDefaultHandler() { + public @Nullable Object getDefaultHandler() { return this.defaultHandler; } @@ -173,8 +168,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * String pattern matching with {@link AntPathMatcher} is enabled instead. * @since 5.3 */ - @Nullable - public PathPatternParser getPatternParser() { + public @Nullable PathPatternParser getPatternParser() { return this.patternParser; } @@ -288,8 +282,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * or more specifically before * {@link org.springframework.context.ApplicationContextAware#setApplicationContext}. */ - @Nullable - public final HandlerInterceptor[] getAdaptedInterceptors() { + public final HandlerInterceptor @Nullable [] getAdaptedInterceptors() { return (!this.adaptedInterceptors.isEmpty() ? this.adaptedInterceptors.toArray(new HandlerInterceptor[0]) : null); } @@ -298,8 +291,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() { + protected final MappedInterceptor @Nullable [] getMappedInterceptors() { List mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size()); for (HandlerInterceptor interceptor : this.adaptedInterceptors) { if (interceptor instanceof MappedInterceptor mappedInterceptor) { @@ -360,8 +352,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * configured} {@code CorsConfigurationSource}, if any. * @since 5.3 */ - @Nullable - public CorsConfigurationSource getCorsConfigurationSource() { + public @Nullable CorsConfigurationSource getCorsConfigurationSource() { return this.corsConfigurationSource; } @@ -504,8 +495,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @see #getHandlerInternal */ @Override - @Nullable - public final HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { + public final @Nullable HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { Object handler = getHandlerInternal(request); if (handler == null) { handler = getDefaultHandler(); @@ -566,8 +556,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; + protected abstract @Nullable Object getHandlerInternal(HttpServletRequest request) throws Exception; /** * Initialize the path to use for request mapping. @@ -656,8 +645,7 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport * @return the CORS configuration for the handler, or {@code null} if none * @since 4.2 */ - @Nullable - protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) { + protected @Nullable CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) { Object resolvedHandler = handler; if (handler instanceof HandlerExecutionChain handlerExecutionChain) { resolvedHandler = handlerExecutionChain.getHandler(); @@ -694,16 +682,14 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport private class CorsInterceptor implements HandlerInterceptor, CorsConfigurationSource { - @Nullable - private final CorsConfiguration config; + private final @Nullable CorsConfiguration config; public CorsInterceptor(@Nullable CorsConfiguration config) { this.config = config; } @Override - @Nullable - public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { + public @Nullable CorsConfiguration getCorsConfiguration(HttpServletRequest request) { return this.config; } 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 0c5b53e904..e6bb1e9639 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 @@ -18,8 +18,8 @@ package org.springframework.web.servlet.handler; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.ModelAndView; @@ -65,8 +65,7 @@ public abstract class AbstractHandlerMethodExceptionResolver extends AbstractHan } @Override - @Nullable - protected final ModelAndView doResolveException( + protected final @Nullable ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { HandlerMethod handlerMethod = (handler instanceof HandlerMethod hm ? hm : null); @@ -87,8 +86,7 @@ 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( + protected abstract @Nullable ModelAndView doResolveHandlerMethodException( 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 62caefd2f1..930f94fc58 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 @@ -34,12 +34,12 @@ import java.util.stream.Collectors; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; 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; @@ -95,8 +95,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap private boolean detectHandlerMethodsInAncestorContexts = false; - @Nullable - private HandlerMethodMappingNamingStrategy namingStrategy; + private @Nullable HandlerMethodMappingNamingStrategy namingStrategy; private final MappingRegistry mappingRegistry = new MappingRegistry(); @@ -136,8 +135,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap /** * Return the configured naming strategy or {@code null}. */ - @Nullable - public HandlerMethodMappingNamingStrategy getNamingStrategy() { + public @Nullable HandlerMethodMappingNamingStrategy getNamingStrategy() { return this.namingStrategy; } @@ -162,8 +160,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) { + public @Nullable List getHandlerMethodsForMappingName(String mappingName) { return this.mappingRegistry.getHandlerMethodsByMappingName(mappingName); } @@ -350,8 +347,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) { + protected @Nullable CorsConfiguration initCorsConfiguration(Object handler, Method method, T mapping) { return null; } @@ -374,8 +370,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * Look up a handler method for the given request. */ @Override - @Nullable - protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { + protected @Nullable HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { String lookupPath = initLookupPath(request); this.mappingRegistry.acquireReadLock(); try { @@ -396,8 +391,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 { + protected @Nullable HandlerMethod lookupHandlerMethod(String lookupPath, HttpServletRequest request) throws Exception { List matches = new ArrayList<>(); List directPathMatches = this.mappingRegistry.getMappingsByDirectPath(lookupPath); if (directPathMatches != null) { @@ -469,8 +463,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) + protected @Nullable HandlerMethod handleNoMatch(Set mappings, String lookupPath, HttpServletRequest request) throws Exception { return null; @@ -484,8 +477,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap } @Override - @Nullable - protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) { + protected @Nullable CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequest request) { CorsConfiguration corsConfig = super.getCorsConfiguration(handler, request); if (handler instanceof HandlerMethod handlerMethod) { if (handlerMethod.equals(PREFLIGHT_AMBIGUOUS_MATCH)) { @@ -517,8 +509,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); + protected abstract @Nullable T getMappingForMethod(Method method, Class handlerType); /** * Extract and return the URL paths contained in the supplied mapping. @@ -552,8 +543,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); + protected abstract @Nullable T getMatchingMapping(T mapping, HttpServletRequest request); /** * Return a comparator for sorting matching mappings. @@ -594,24 +584,21 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap * Return matches for the given URL path. Not thread-safe. * @see #acquireReadLock() */ - @Nullable - public List getMappingsByDirectPath(String urlPath) { + public @Nullable List getMappingsByDirectPath(String urlPath) { return this.pathLookup.get(urlPath); } /** * Return handler methods by mapping name. Thread-safe for concurrent use. */ - @Nullable - public List getHandlerMethodsByMappingName(String mappingName) { + public @Nullable List getHandlerMethodsByMappingName(String mappingName) { return this.nameLookup.get(mappingName); } /** * Return CORS configuration. Thread-safe for concurrent use. */ - @Nullable - public CorsConfiguration getCorsConfiguration(HandlerMethod handlerMethod) { + public @Nullable CorsConfiguration getCorsConfiguration(HandlerMethod handlerMethod) { HandlerMethod original = handlerMethod.getResolvedFromHandlerMethod(); return this.corsLookup.get(original != null ? original : handlerMethod); } @@ -754,8 +741,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap private final Set directPaths; - @Nullable - private final String mappingName; + private final @Nullable String mappingName; private final boolean corsConfig; @@ -783,8 +769,7 @@ public abstract class AbstractHandlerMethodMapping extends AbstractHandlerMap return this.directPaths; } - @Nullable - public String getMappingName() { + public @Nullable String getMappingName() { return this.mappingName; } 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 93aeaef853..586db1c0e5 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 @@ -25,11 +25,11 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -63,8 +63,7 @@ import org.springframework.web.util.pattern.PathPatternParser; */ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping implements MatchableHandlerMapping { - @Nullable - private Object rootHandler; + private @Nullable Object rootHandler; private boolean lazyInitHandlers = false; @@ -94,8 +93,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() { + public @Nullable Object getRootHandler() { return this.rootHandler; } @@ -232,8 +230,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 { + protected @Nullable Object getHandlerInternal(HttpServletRequest request) throws Exception { String lookupPath = initLookupPath(request); Object handler; if (usesPathPatterns()) { @@ -274,9 +271,8 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * @return a matching handler, or {@code null} if not found * @since 5.3 */ - @Nullable @SuppressWarnings("NullAway") - protected Object lookupHandler( + protected @Nullable Object lookupHandler( RequestPath path, String lookupPath, HttpServletRequest request) throws Exception { Object handler = getDirectMatch(lookupPath, request); @@ -323,8 +319,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i * @see #exposePathWithinMapping * @see AntPathMatcher */ - @Nullable - protected Object lookupHandler(String lookupPath, HttpServletRequest request) throws Exception { + protected @Nullable Object lookupHandler(String lookupPath, HttpServletRequest request) throws Exception { Object handler = getDirectMatch(lookupPath, request); if (handler != null) { return handler; @@ -385,8 +380,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i return null; } - @Nullable - private Object getDirectMatch(String urlPath, HttpServletRequest request) throws Exception { + private @Nullable Object getDirectMatch(String urlPath, HttpServletRequest request) throws Exception { Object handler = this.handlerMap.get(urlPath); if (handler != null) { // Bean name or resolved handler? @@ -459,8 +453,7 @@ public abstract class AbstractUrlHandlerMapping extends AbstractHandlerMapping i } @Override - @Nullable - public RequestMatchResult match(HttpServletRequest request, String pattern) { + public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { Assert.state(getPatternParser() == null, "This HandlerMapping uses PathPatterns."); String lookupPath = UrlPathHelper.getResolvedLookupPath(request); if (getPathMatcher().match(pattern, lookupPath)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java index fbc49d5edb..089e63d4a1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerExceptionResolverComposite.java @@ -21,9 +21,9 @@ import java.util.List; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerExceptionResolver; import org.springframework.web.servlet.ModelAndView; @@ -36,8 +36,7 @@ import org.springframework.web.servlet.ModelAndView; */ public class HandlerExceptionResolverComposite implements HandlerExceptionResolver, Ordered { - @Nullable - private List resolvers; + private @Nullable List resolvers; private int order = Ordered.LOWEST_PRECEDENCE; @@ -71,8 +70,7 @@ public class HandlerExceptionResolverComposite implements HandlerExceptionResolv *

    The first one to return a {@link ModelAndView} wins. Otherwise {@code null} is returned. */ @Override - @Nullable - public ModelAndView resolveException( + public @Nullable ModelAndView resolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { if (this.resolvers != null) { 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 7aafffc98a..d6067631e9 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 @@ -36,6 +36,7 @@ import jakarta.servlet.http.HttpServletRequestWrapper; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactoryUtils; import org.springframework.beans.factory.InitializingBean; @@ -47,7 +48,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.io.support.PropertiesLoaderUtils; import org.springframework.http.server.RequestPath; import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -100,11 +100,9 @@ public class HandlerMappingIntrospector HandlerMappingIntrospector.class.getName() + ".CachedResult"; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; - @Nullable - private List handlerMappings; + private @Nullable List handlerMappings; private Map pathPatternMappings = Collections.emptyMap(); @@ -257,8 +255,7 @@ public class HandlerMappingIntrospector * @return the previous {@link CachedResult}, if there is one from a parent dispatch * @since 6.0.14 */ - @Nullable - public CachedResult setCache(HttpServletRequest request) { + public @Nullable CachedResult setCache(HttpServletRequest request) { CachedResult previous = (CachedResult) request.getAttribute(CACHED_RESULT_ATTRIBUTE); if (previous == null || !previous.matches(request)) { HttpServletRequest wrapped = new AttributesPreservingRequest(request); @@ -310,8 +307,7 @@ public class HandlerMappingIntrospector * instance of {@link MatchableHandlerMapping} * @throws Exception if any of the HandlerMapping's raise an exception */ - @Nullable - public MatchableHandlerMapping getMatchableHandlerMapping(HttpServletRequest request) throws Exception { + public @Nullable MatchableHandlerMapping getMatchableHandlerMapping(HttpServletRequest request) throws Exception { CachedResult result = CachedResult.getResultFor(request); if (result != null) { return result.getHandlerMapping(); @@ -338,8 +334,7 @@ public class HandlerMappingIntrospector } @Override - @Nullable - public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { + public @Nullable CorsConfiguration getCorsConfiguration(HttpServletRequest request) { CachedResult result = CachedResult.getResultFor(request); if (result != null) { return result.getCorsConfig(); @@ -357,8 +352,7 @@ public class HandlerMappingIntrospector } } - @Nullable - private static CorsConfiguration getCorsConfiguration(HandlerExecutionChain chain, HttpServletRequest request) { + private static @Nullable CorsConfiguration getCorsConfiguration(HandlerExecutionChain chain, HttpServletRequest request) { for (HandlerInterceptor interceptor : chain.getInterceptorList()) { if (interceptor instanceof CorsConfigurationSource source) { return source.getCorsConfiguration(request); @@ -370,8 +364,7 @@ public class HandlerMappingIntrospector return null; } - @Nullable - private T doWithHandlerMapping( + private @Nullable T doWithHandlerMapping( HttpServletRequest request, boolean ignoreException, BiFunction extractor) throws Exception { @@ -421,17 +414,13 @@ public class HandlerMappingIntrospector private final String requestURI; - @Nullable - private final MatchableHandlerMapping handlerMapping; + private final @Nullable MatchableHandlerMapping handlerMapping; - @Nullable - private final CorsConfiguration corsConfig; + private final @Nullable CorsConfiguration corsConfig; - @Nullable - private final Exception failure; + private final @Nullable Exception failure; - @Nullable - private final IllegalStateException corsConfigFailure; + private final @Nullable IllegalStateException corsConfigFailure; private CachedResult(HttpServletRequest request, @Nullable MatchableHandlerMapping mapping, @Nullable CorsConfiguration config, @@ -450,16 +439,14 @@ public class HandlerMappingIntrospector this.requestURI.equals(request.getRequestURI())); } - @Nullable - public MatchableHandlerMapping getHandlerMapping() throws Exception { + public @Nullable MatchableHandlerMapping getHandlerMapping() throws Exception { if (this.failure != null) { throw this.failure; } return this.handlerMapping; } - @Nullable - public CorsConfiguration getCorsConfig() { + public @Nullable CorsConfiguration getCorsConfig() { if (this.corsConfigFailure != null) { throw this.corsConfigFailure; } @@ -475,8 +462,7 @@ public class HandlerMappingIntrospector /** * Return a {@link CachedResult} that matches the given request. */ - @Nullable - public static CachedResult getResultFor(HttpServletRequest request) { + public static @Nullable CachedResult getResultFor(HttpServletRequest request) { CachedResult result = (CachedResult) request.getAttribute(CACHED_RESULT_ATTRIBUTE); return (result != null && result.matches(request) ? result : null); } @@ -548,8 +534,7 @@ public class HandlerMappingIntrospector } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { return this.attributes.get(name); } @@ -581,14 +566,12 @@ public class HandlerMappingIntrospector } @Override - @Nullable - public PathPatternParser getPatternParser() { + public @Nullable PathPatternParser getPatternParser() { return this.delegate.getPatternParser(); } - @Nullable @Override - public RequestMatchResult match(HttpServletRequest request, String pattern) { + public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { pattern = initFullPathPattern(pattern); Object previousPath = request.getAttribute(this.pathAttributeName); request.setAttribute(this.pathAttributeName, this.lookupPath); @@ -605,9 +588,8 @@ public class HandlerMappingIntrospector return parser.initFullPathPattern(pattern); } - @Nullable @Override - public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { + public @Nullable HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { return this.delegate.getHandler(request); } } 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 39eaefd7db..c459672779 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 @@ -20,9 +20,9 @@ import java.util.Arrays; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.ObjectUtils; import org.springframework.util.PathMatcher; @@ -63,11 +63,9 @@ public final class MappedInterceptor implements HandlerInterceptor { private static final PathMatcher defaultPathMatcher = new AntPathMatcher(); - @Nullable - private final PatternAdapter[] includePatterns; + private final PatternAdapter @Nullable [] includePatterns; - @Nullable - private final PatternAdapter[] excludePatterns; + private final PatternAdapter @Nullable [] excludePatterns; private PathMatcher pathMatcher = defaultPathMatcher; @@ -85,7 +83,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * when not provided, {@link PathPatternParser#defaultInstance} is used. * @since 5.3 */ - public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, + public MappedInterceptor(String @Nullable [] includePatterns, String @Nullable [] excludePatterns, HandlerInterceptor interceptor, @Nullable PathPatternParser parser) { this.includePatterns = PatternAdapter.initPatterns(includePatterns, parser); @@ -99,7 +97,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * {@link #MappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)} * with include patterns only. */ - public MappedInterceptor(@Nullable String[] includePatterns, HandlerInterceptor interceptor) { + public MappedInterceptor(String @Nullable [] includePatterns, HandlerInterceptor interceptor) { this(includePatterns, null, interceptor); } @@ -108,7 +106,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * {@link #MappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)} * without a provided parser. */ - public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, + public MappedInterceptor(String @Nullable [] includePatterns, String @Nullable [] excludePatterns, HandlerInterceptor interceptor) { this(includePatterns, excludePatterns, interceptor, null); @@ -119,7 +117,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * {@link #MappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)} * with a {@link WebRequestInterceptor} as the target. */ - public MappedInterceptor(@Nullable String[] includePatterns, WebRequestInterceptor interceptor) { + public MappedInterceptor(String @Nullable [] includePatterns, WebRequestInterceptor interceptor) { this(includePatterns, null, interceptor); } @@ -128,7 +126,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * {@link #MappedInterceptor(String[], String[], HandlerInterceptor, PathPatternParser)} * with a {@link WebRequestInterceptor} as the target. */ - public MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, + public MappedInterceptor(String @Nullable [] includePatterns, String @Nullable [] excludePatterns, WebRequestInterceptor interceptor) { this(includePatterns, excludePatterns, new WebRequestHandlerInterceptorAdapter(interceptor)); @@ -140,8 +138,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * @since 6.1 * @see #getExcludePathPatterns() */ - @Nullable - public String[] getIncludePathPatterns() { + public String @Nullable [] getIncludePathPatterns() { return (!ObjectUtils.isEmpty(this.includePatterns) ? Arrays.stream(this.includePatterns).map(PatternAdapter::getPatternString).toArray(String[]::new) : null); @@ -152,8 +149,7 @@ public final class MappedInterceptor implements HandlerInterceptor { * @since 6.1 * @see #getIncludePathPatterns() */ - @Nullable - public String[] getExcludePathPatterns() { + public String @Nullable [] getExcludePathPatterns() { return (!ObjectUtils.isEmpty(this.excludePatterns) ? Arrays.stream(this.excludePatterns).map(PatternAdapter::getPatternString).toArray(String[]::new) : null); @@ -284,8 +280,7 @@ public final class MappedInterceptor implements HandlerInterceptor { private final String patternString; - @Nullable - private final PathPattern pathPattern; + private final @Nullable PathPattern pathPattern; public PatternAdapter(String pattern, @Nullable PathPatternParser parser) { @@ -293,8 +288,7 @@ public final class MappedInterceptor implements HandlerInterceptor { this.pathPattern = initPathPattern(pattern, parser); } - @Nullable - private static PathPattern initPathPattern(String pattern, @Nullable PathPatternParser parser) { + private static @Nullable PathPattern initPathPattern(String pattern, @Nullable PathPatternParser parser) { try { return (parser != null ? parser : PathPatternParser.defaultInstance).parse(pattern); } @@ -319,9 +313,8 @@ public final class MappedInterceptor implements HandlerInterceptor { return pathMatcher.match(this.patternString, (String) path); } - @Nullable - public static PatternAdapter[] initPatterns( - @Nullable String[] patterns, @Nullable PathPatternParser parser) { + public static PatternAdapter @Nullable [] initPatterns( + String @Nullable [] patterns, @Nullable PathPatternParser parser) { if (ObjectUtils.isEmpty(patterns)) { return null; 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 27ce57380c..0fcf32a92a 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 @@ -17,8 +17,8 @@ package org.springframework.web.servlet.handler; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.util.pattern.PathPatternParser; @@ -38,8 +38,7 @@ public interface MatchableHandlerMapping extends HandlerMapping { * case pre-parsed patterns are used. * @since 5.3 */ - @Nullable - default PathPatternParser getPatternParser() { + default @Nullable PathPatternParser getPatternParser() { return null; } @@ -51,7 +50,6 @@ 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); + @Nullable RequestMatchResult match(HttpServletRequest request, String pattern); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java index 5df30cbc55..18541f2e59 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/PathPatternMatchableHandlerMapping.java @@ -20,9 +20,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.HandlerExecutionChain; import org.springframework.web.util.ServletRequestPathUtils; @@ -56,9 +56,8 @@ class PathPatternMatchableHandlerMapping implements MatchableHandlerMapping { this.parser = delegate.getPatternParser(); } - @Nullable @Override - public RequestMatchResult match(HttpServletRequest request, String pattern) { + public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { PathPattern pathPattern = this.pathPatternCache.computeIfAbsent(pattern, value -> { Assert.state(this.pathPatternCache.size() < MAX_PATTERNS, "Max size for pattern cache exceeded."); return this.parser.parse(pattern); @@ -67,9 +66,8 @@ class PathPatternMatchableHandlerMapping implements MatchableHandlerMapping { return (pathPattern.matches(path) ? new RequestMatchResult(pathPattern, path) : null); } - @Nullable @Override - public HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { + public @Nullable HandlerExecutionChain getHandler(HttpServletRequest request) throws Exception { return this.delegate.getHandler(request); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java index 328a0e4e0f..96b1aaef46 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/RequestMatchResult.java @@ -18,8 +18,9 @@ package org.springframework.web.servlet.handler; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.PathMatcher; import org.springframework.web.util.pattern.PathPattern; @@ -34,21 +35,16 @@ import org.springframework.web.util.pattern.PathPattern; */ public class RequestMatchResult { - @Nullable - private final PathPattern pathPattern; + private final @Nullable PathPattern pathPattern; - @Nullable - private final PathContainer lookupPathContainer; + private final @Nullable PathContainer lookupPathContainer; - @Nullable - private final String pattern; + private final @Nullable String pattern; - @Nullable - private final String lookupPath; + private final @Nullable String lookupPath; - @Nullable - private final PathMatcher pathMatcher; + private final @Nullable PathMatcher pathMatcher; /** 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 d60f8603bb..75eac84e83 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 @@ -24,8 +24,8 @@ import java.util.Properties; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.WebUtils; @@ -49,22 +49,17 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso public static final String DEFAULT_EXCEPTION_ATTRIBUTE = "exception"; - @Nullable - private Properties exceptionMappings; + private @Nullable Properties exceptionMappings; - @Nullable - private Class[] excludedExceptions; + private Class @Nullable [] excludedExceptions; - @Nullable - private String defaultErrorView; + private @Nullable String defaultErrorView; - @Nullable - private Integer defaultStatusCode; + private @Nullable Integer defaultStatusCode; private final Map statusCodes = new HashMap<>(); - @Nullable - private String exceptionAttribute = DEFAULT_EXCEPTION_ATTRIBUTE; + private @Nullable String exceptionAttribute = DEFAULT_EXCEPTION_ATTRIBUTE; /** @@ -181,8 +176,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * or {@code null} for default processing in the resolution chain */ @Override - @Nullable - protected ModelAndView doResolveException( + protected @Nullable ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { // Expose ModelAndView for chosen error view. @@ -210,8 +204,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) { + protected @Nullable String determineViewName(Exception ex, HttpServletRequest request) { String viewName = null; if (this.excludedExceptions != null) { for (Class excludedEx : this.excludedExceptions) { @@ -241,8 +234,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) { + protected @Nullable String findMatchingViewName(Properties exceptionMappings, Exception ex) { String viewName = null; String dominantMapping = null; int deepest = Integer.MAX_VALUE; @@ -296,8 +288,7 @@ public class SimpleMappingExceptionResolver extends AbstractHandlerExceptionReso * @see #setDefaultStatusCode * @see #applyStatusCodeIfPossible */ - @Nullable - protected Integer determineStatusCode(HttpServletRequest request, String viewName) { + protected @Nullable 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/SimpleServletHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java index 1656888444..522a8f934a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletHandlerAdapter.java @@ -19,8 +19,8 @@ package org.springframework.web.servlet.handler; import jakarta.servlet.Servlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.ModelAndView; @@ -60,8 +60,7 @@ public class SimpleServletHandlerAdapter implements HandlerAdapter { } @Override - @Nullable - public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) + public @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { ((Servlet) handler).service(request, response); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java index e16ea6957a..314cc1508e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/SimpleServletPostProcessor.java @@ -23,11 +23,11 @@ import jakarta.servlet.Servlet; import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanInitializationException; import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; -import org.springframework.lang.Nullable; import org.springframework.web.context.ServletConfigAware; import org.springframework.web.context.ServletContextAware; @@ -70,11 +70,9 @@ public class SimpleServletPostProcessor implements private boolean useSharedServletConfig = true; - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; - @Nullable - private ServletConfig servletConfig; + private @Nullable ServletConfig servletConfig; /** @@ -143,8 +141,7 @@ public class SimpleServletPostProcessor implements private final String servletName; - @Nullable - private final ServletContext servletContext; + private final @Nullable ServletContext servletContext; public DelegatingServletConfig(String servletName, @Nullable ServletContext servletContext) { this.servletName = servletName; @@ -157,14 +154,12 @@ public class SimpleServletPostProcessor implements } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return this.servletContext; } @Override - @Nullable - public String getInitParameter(String paramName) { + public @Nullable String getInitParameter(String paramName) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/UserRoleAuthorizationInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/UserRoleAuthorizationInterceptor.java index 90d1209c9b..a35824aa43 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/UserRoleAuthorizationInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/UserRoleAuthorizationInterceptor.java @@ -21,8 +21,8 @@ import java.io.IOException; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerInterceptor; /** @@ -35,8 +35,7 @@ import org.springframework.web.servlet.HandlerInterceptor; */ public class UserRoleAuthorizationInterceptor implements HandlerInterceptor { - @Nullable - private String[] authorizedRoles; + private String @Nullable [] authorizedRoles; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java index 80ff163790..4d2e8ab8b8 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/WebRequestHandlerInterceptorAdapter.java @@ -18,8 +18,8 @@ package org.springframework.web.servlet.handler; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.AsyncWebRequestInterceptor; import org.springframework.web.context.request.WebRequestInterceptor; 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 6574f474fd..104e7f6bb3 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,9 +2,7 @@ * Provides standard HandlerMapping implementations, * including abstract base classes for custom implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.handler; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 0b07bc682f..6be42b7c14 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 @@ -18,7 +18,8 @@ package org.springframework.web.servlet.i18n; import java.util.TimeZone; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.servlet.LocaleContextResolver; /** @@ -34,8 +35,7 @@ import org.springframework.web.servlet.LocaleContextResolver; */ public abstract class AbstractLocaleContextResolver extends AbstractLocaleResolver implements LocaleContextResolver { - @Nullable - private TimeZone defaultTimeZone; + private @Nullable TimeZone defaultTimeZone; /** @@ -50,8 +50,7 @@ public abstract class AbstractLocaleContextResolver extends AbstractLocaleResolv * Get the default {@link TimeZone} that this resolver is supposed to fall * back to, if any. */ - @Nullable - public TimeZone getDefaultTimeZone() { + public @Nullable 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 c851ed18e0..90b31fc5c3 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,7 +18,8 @@ package org.springframework.web.servlet.i18n; import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.servlet.LocaleResolver; /** @@ -32,8 +33,7 @@ import org.springframework.web.servlet.LocaleResolver; */ public abstract class AbstractLocaleResolver implements LocaleResolver { - @Nullable - private Locale defaultLocale; + private @Nullable Locale defaultLocale; /** @@ -48,8 +48,7 @@ public abstract class AbstractLocaleResolver implements LocaleResolver { * Get the default {@link Locale} that this resolver is supposed to fall back * to, if any. */ - @Nullable - protected Locale getDefaultLocale() { + protected @Nullable 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 c0021688f7..a348c50973 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,8 +23,8 @@ import java.util.Locale; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.servlet.LocaleResolver; @@ -100,8 +100,7 @@ public class AcceptHeaderLocaleResolver extends AbstractLocaleResolver { return (defaultLocale != null ? defaultLocale : requestLocale); } - @Nullable - private Locale findSupportedLocale(HttpServletRequest request, List supportedLocales) { + private @Nullable Locale findSupportedLocale(HttpServletRequest request, List supportedLocales) { Enumeration requestLocales = request.getLocales(); Locale languageMatch = null; 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 a14e8bd3eb..32c3c1bab8 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 @@ -26,12 +26,12 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseCookie; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.servlet.LocaleResolver; @@ -297,13 +297,11 @@ public class CookieLocaleResolver extends AbstractLocaleContextResolver { parseLocaleCookieIfNecessary(request); return new TimeZoneAwareLocaleContext() { @Override - @Nullable - public Locale getLocale() { + public @Nullable Locale getLocale() { return (Locale) request.getAttribute(LOCALE_REQUEST_ATTRIBUTE_NAME); } @Override - @Nullable - public TimeZone getTimeZone() { + public @Nullable TimeZone getTimeZone() { return (TimeZone) request.getAttribute(TIME_ZONE_REQUEST_ATTRIBUTE_NAME); } }; @@ -395,8 +393,7 @@ public class CookieLocaleResolver extends AbstractLocaleContextResolver { * @since 4.3 * @see StringUtils#parseLocale(String) */ - @Nullable - protected Locale parseLocaleValue(String localeValue) { + protected @Nullable Locale parseLocaleValue(String localeValue) { return StringUtils.parseLocale(localeValue); } @@ -442,8 +439,7 @@ public class CookieLocaleResolver extends AbstractLocaleContextResolver { * @deprecated as of 6.0, in favor of {@link #setDefaultTimeZoneFunction(Function)} */ @Deprecated(since = "6.0") - @Nullable - protected TimeZone determineDefaultTimeZone(HttpServletRequest request) { + protected @Nullable TimeZone determineDefaultTimeZone(HttpServletRequest request) { return this.defaultTimeZoneFunction.apply(request); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/FixedLocaleResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/FixedLocaleResolver.java index 0493116788..49070e82cb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/FixedLocaleResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/FixedLocaleResolver.java @@ -21,10 +21,10 @@ import java.util.TimeZone; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; -import org.springframework.lang.Nullable; /** * {@link org.springframework.web.servlet.LocaleResolver} implementation @@ -83,13 +83,11 @@ public class FixedLocaleResolver extends AbstractLocaleContextResolver { public LocaleContext resolveLocaleContext(HttpServletRequest request) { return new TimeZoneAwareLocaleContext() { @Override - @Nullable - public Locale getLocale() { + public @Nullable Locale getLocale() { return getDefaultLocale(); } @Override - @Nullable - public TimeZone getTimeZone() { + public @Nullable TimeZone getTimeZone() { return getDefaultTimeZone(); } }; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java index 93996c9b94..1b267fb736 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/i18n/LocaleChangeInterceptor.java @@ -23,8 +23,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerInterceptor; @@ -52,8 +52,7 @@ public class LocaleChangeInterceptor implements HandlerInterceptor { private String paramName = DEFAULT_PARAM_NAME; - @Nullable - private String[] httpMethods; + private String @Nullable [] httpMethods; private boolean ignoreInvalidLocale = false; @@ -79,7 +78,7 @@ public class LocaleChangeInterceptor implements HandlerInterceptor { * @param httpMethods the methods * @since 4.2 */ - public void setHttpMethods(@Nullable String... httpMethods) { + public void setHttpMethods(String @Nullable ... httpMethods) { this.httpMethods = httpMethods; } @@ -87,8 +86,7 @@ public class LocaleChangeInterceptor implements HandlerInterceptor { * Return the configured HTTP methods. * @since 4.2 */ - @Nullable - public String[] getHttpMethods() { + public String @Nullable [] getHttpMethods() { return this.httpMethods; } @@ -161,8 +159,7 @@ public class LocaleChangeInterceptor implements HandlerInterceptor { * @return the corresponding {@code Locale} instance * @since 4.3 */ - @Nullable - protected Locale parseLocaleValue(String localeValue) { + protected @Nullable Locale parseLocaleValue(String localeValue) { return StringUtils.parseLocale(localeValue); } 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 b1bff28629..61865b6845 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 @@ -22,10 +22,10 @@ import java.util.function.Function; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.util.WebUtils; @@ -167,8 +167,7 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver { return locale; } @Override - @Nullable - public TimeZone getTimeZone() { + public @Nullable TimeZone getTimeZone() { TimeZone timeZone = (TimeZone) WebUtils.getSessionAttribute(request, timeZoneAttributeName); if (timeZone == null) { timeZone = defaultTimeZoneFunction.apply(request); @@ -224,8 +223,7 @@ public class SessionLocaleResolver extends AbstractLocaleContextResolver { * @deprecated as of 6.0, in favor of {@link #setDefaultTimeZoneFunction(Function)} */ @Deprecated(since = "6.0") - @Nullable - protected TimeZone determineDefaultTimeZone(HttpServletRequest request) { + protected @Nullable TimeZone determineDefaultTimeZone(HttpServletRequest request) { return this.defaultTimeZoneFunction.apply(request); } 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 5a2290e8be..424fcde3be 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,9 +3,7 @@ * Provides standard LocaleResolver implementations, * and a HandlerInterceptor for locale changes. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.i18n; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 5576d0c7ee..4e0f204a76 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 @@ -19,10 +19,10 @@ package org.springframework.web.servlet.mvc; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; 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; @@ -151,8 +151,7 @@ public abstract class AbstractController extends WebContentGenerator implements @Override - @Nullable - public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) + public @Nullable ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { if (HttpMethod.OPTIONS.matches(request.getMethod())) { @@ -183,8 +182,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) + protected abstract @Nullable 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 cc37288772..d63c706f34 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 @@ -18,8 +18,8 @@ package org.springframework.web.servlet.mvc; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; /** @@ -121,7 +121,6 @@ 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; + @Nullable ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java index 835b7581f7..a7217f9433 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/HttpRequestHandlerAdapter.java @@ -18,8 +18,8 @@ package org.springframework.web.servlet.mvc; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.HttpRequestHandler; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.ModelAndView; @@ -45,8 +45,7 @@ public class HttpRequestHandlerAdapter implements HandlerAdapter { } @Override - @Nullable - public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) + public @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { ((HttpRequestHandler) handler).handleRequest(request, response); 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 2ecea3ad62..2e39fbb329 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 @@ -18,11 +18,11 @@ package org.springframework.web.servlet.mvc; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.View; import org.springframework.web.servlet.support.RequestContextUtils; @@ -39,11 +39,9 @@ import org.springframework.web.servlet.support.RequestContextUtils; */ public class ParameterizableViewController extends AbstractController { - @Nullable - private Object view; + private @Nullable Object view; - @Nullable - private HttpStatusCode statusCode; + private @Nullable HttpStatusCode statusCode; private boolean statusOnly; @@ -66,8 +64,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() { + public @Nullable String getViewName() { if (this.view instanceof String viewName) { if (getStatusCode() != null && getStatusCode().is3xxRedirection()) { return viewName.startsWith("redirect:") ? viewName : "redirect:" + viewName; @@ -93,8 +90,7 @@ public class ParameterizableViewController extends AbstractController { * to be resolved by the DispatcherServlet via a ViewResolver. * @since 4.1 */ - @Nullable - public View getView() { + public @Nullable View getView() { return (this.view instanceof View v ? v : null); } @@ -117,8 +113,7 @@ public class ParameterizableViewController extends AbstractController { * Return the configured HTTP status code or {@code null}. * @since 4.1 */ - @Nullable - public HttpStatusCode getStatusCode() { + public @Nullable HttpStatusCode getStatusCode() { return this.statusCode; } @@ -149,8 +144,7 @@ public class ParameterizableViewController extends AbstractController { * @see #getViewName() */ @Override - @Nullable - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) + protected @Nullable ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String viewName = getViewName(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java index 9d3516cfcf..f8210e2909 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletForwardingController.java @@ -21,9 +21,9 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanNameAware; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.util.WebUtils; @@ -88,11 +88,9 @@ import org.springframework.web.util.WebUtils; */ public class ServletForwardingController extends AbstractController implements BeanNameAware { - @Nullable - private String servletName; + private @Nullable String servletName; - @Nullable - private String beanName; + private @Nullable String beanName; public ServletForwardingController() { @@ -119,8 +117,7 @@ public class ServletForwardingController extends AbstractController implements B @Override - @Nullable - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) + protected @Nullable ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ServletContext servletContext = getServletContext(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java index 699138de92..1268989c66 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/ServletWrappingController.java @@ -24,11 +24,11 @@ import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanNameAware; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ReflectionUtils; import org.springframework.web.servlet.ModelAndView; @@ -86,19 +86,15 @@ import org.springframework.web.servlet.ModelAndView; public class ServletWrappingController extends AbstractController implements BeanNameAware, InitializingBean, DisposableBean { - @Nullable - private Class servletClass; + private @Nullable Class servletClass; - @Nullable - private String servletName; + private @Nullable String servletName; private Properties initParameters = new Properties(); - @Nullable - private String beanName; + private @Nullable String beanName; - @Nullable - private Servlet servletInstance; + private @Nullable Servlet servletInstance; public ServletWrappingController() { @@ -159,8 +155,7 @@ public class ServletWrappingController extends AbstractController * @see jakarta.servlet.Servlet#service(jakarta.servlet.ServletRequest, jakarta.servlet.ServletResponse) */ @Override - @Nullable - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) + protected @Nullable ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Assert.state(this.servletInstance != null, "No Servlet instance"); @@ -189,14 +184,12 @@ public class ServletWrappingController extends AbstractController private class DelegatingServletConfig implements ServletConfig { @Override - @Nullable - public String getServletName() { + public @Nullable String getServletName() { return servletName; } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return ServletWrappingController.this.getServletContext(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java index 58e4a57375..f24ae82e9c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/SimpleControllerHandlerAdapter.java @@ -18,8 +18,8 @@ package org.springframework.web.servlet.mvc; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.ModelAndView; @@ -44,8 +44,7 @@ public class SimpleControllerHandlerAdapter implements HandlerAdapter { } @Override - @Nullable - public ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) + public @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return ((Controller) handler).handleRequest(request, response); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/UrlFilenameViewController.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/UrlFilenameViewController.java index fc026104af..4a84992e46 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/UrlFilenameViewController.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/UrlFilenameViewController.java @@ -20,8 +20,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.util.ServletRequestPathUtils; 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 0ed4a41c55..6526fed409 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 @@ -25,10 +25,10 @@ import jakarta.servlet.ServletException; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.CacheControl; import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -250,8 +250,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @return the matched {@code CacheControl}, or {@code null} if no match * @since 5.3 */ - @Nullable - protected CacheControl lookupCacheControl(PathContainer path) { + protected @Nullable CacheControl lookupCacheControl(PathContainer path) { for (Map.Entry entry : this.cacheControlMappings.entrySet()) { if (entry.getKey().matches(path)) { return entry.getValue(); @@ -267,8 +266,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @param lookupPath the path to match to * @return the matched {@code CacheControl}, or {@code null} if no match */ - @Nullable - protected CacheControl lookupCacheControl(String lookupPath) { + protected @Nullable CacheControl lookupCacheControl(String lookupPath) { for (Map.Entry entry : this.cacheControlMappings.entrySet()) { if (this.pathMatcher.match(entry.getKey().getPatternString(), lookupPath)) { return entry.getValue(); @@ -284,8 +282,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @return the matched cacheSeconds, or {@code null} if there is no match * @since 5.3 */ - @Nullable - protected Integer lookupCacheSeconds(PathContainer path) { + protected @Nullable Integer lookupCacheSeconds(PathContainer path) { for (Map.Entry entry : this.cacheMappings.entrySet()) { if (entry.getKey().matches(path)) { return entry.getValue(); @@ -301,8 +298,7 @@ public class WebContentInterceptor extends WebContentGenerator implements Handle * @param lookupPath the path to match to * @return the matched cacheSeconds, or {@code null} if there is no match */ - @Nullable - protected Integer lookupCacheSeconds(String lookupPath) { + protected @Nullable Integer lookupCacheSeconds(String lookupPath) { for (Map.Entry entry : this.cacheMappings.entrySet()) { if (this.pathMatcher.match(entry.getKey().getPatternString(), lookupPath)) { return entry.getValue(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java index f162fcda12..f3b8a643c4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/annotation/ModelAndViewResolver.java @@ -18,7 +18,8 @@ package org.springframework.web.servlet.mvc.annotation; import java.lang.reflect.Method; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.ExtendedModelMap; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.servlet.ModelAndView; 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 ed9790a2df..2dd54673b0 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 @@ -20,12 +20,12 @@ import java.io.IOException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; 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; @@ -56,8 +56,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver; */ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware { - @Nullable - private MessageSource messageSource; + private @Nullable MessageSource messageSource; @Override @@ -67,8 +66,7 @@ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionRes @Override - @Nullable - protected ModelAndView doResolveException( + protected @Nullable ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { try { 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 54698d04e4..862b463ffe 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,9 +1,7 @@ /** * Support package for annotation-based Servlet MVC controllers. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.mvc.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java index f13fdccd2d..3b5d024bf6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractMediaTypeExpression.java @@ -18,8 +18,9 @@ package org.springframework.web.servlet.mvc.condition; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java index 9beb44238b..6b1578e174 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractNameValueExpression.java @@ -19,8 +19,8 @@ package org.springframework.web.servlet.mvc.condition; import java.util.Locale; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; /** @@ -37,8 +37,7 @@ abstract class AbstractNameValueExpression implements NameValueExpression protected final String name; - @Nullable - protected final T value; + protected final @Nullable T value; protected final boolean isNegated; @@ -64,8 +63,7 @@ abstract class AbstractNameValueExpression implements NameValueExpression } @Override - @Nullable - public T getValue() { + public @Nullable T getValue() { return this.value; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java index 1dbf485356..1c00dc4d86 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/AbstractRequestCondition.java @@ -19,7 +19,7 @@ package org.springframework.web.servlet.mvc.condition; import java.util.Collection; import java.util.StringJoiner; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A base class for {@link RequestCondition} types providing implementations of 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 aaa8d5f040..337db1c0c0 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 @@ -22,8 +22,8 @@ import java.util.Collections; import java.util.List; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; @@ -144,8 +144,7 @@ public class CompositeRequestCondition extends AbstractRequestConditionAn empty {@code CompositeRequestCondition} matches to all requests. */ @Override - @Nullable - public CompositeRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable CompositeRequestCondition getMatchingCondition(HttpServletRequest request) { if (isEmpty()) { return this; } 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 d4a455b623..628ca0d711 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 @@ -24,11 +24,11 @@ import java.util.List; import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpHeaders; import org.springframework.http.InvalidMediaTypeException; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -76,14 +76,14 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition 1) { Collections.sort(this.expressions); } } - private static List parseExpressions(@Nullable String[] consumes, @Nullable String[] headers) { + private static List parseExpressions(String @Nullable [] consumes, String @Nullable [] headers) { Set result = null; if (!ObjectUtils.isEmpty(headers)) { for (String header : headers) { @@ -196,8 +196,7 @@ public final class ConsumesRequestCondition extends AbstractRequestCondition getMatchingExpressions(MediaType contentType) { + private @Nullable List getMatchingExpressions(MediaType contentType) { List result = null; for (ConsumeMediaTypeExpression expression : this.expressions) { if (expression.match(contentType)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java index 4e14f65feb..c479aca074 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/HeadersRequestCondition.java @@ -22,8 +22,8 @@ import java.util.LinkedHashSet; import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMapping; @@ -122,8 +122,7 @@ public final class HeadersRequestCondition extends AbstractRequestCondition { String getName(); - @Nullable - T getValue(); + @Nullable T getValue(); boolean isNegated(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java index fec74254fd..e9e47e7b78 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ParamsRequestCondition.java @@ -23,8 +23,8 @@ import java.util.LinkedHashSet; import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMapping; @@ -107,8 +107,7 @@ public final class ParamsRequestCondition extends AbstractRequestCondition matches = getMatchingPatterns(path); return (matches != null ? new PathPatternsRequestCondition(matches) : null); } - @Nullable - private SortedSet getMatchingPatterns(PathContainer path) { + private @Nullable SortedSet getMatchingPatterns(PathContainer path) { TreeSet result = null; for (PathPattern pattern : this.patterns) { if (pattern.matches(path)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java index 7c7596fe52..66ae0f79c6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PatternsRequestCondition.java @@ -27,8 +27,8 @@ import java.util.List; import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -202,8 +202,7 @@ public class PatternsRequestCondition extends AbstractRequestCondition matches = getMatchingPatterns(lookupPath); return !matches.isEmpty() ? new PatternsRequestCondition(new LinkedHashSet<>(matches), this) : null; @@ -235,8 +234,7 @@ public class PatternsRequestCondition extends AbstractRequestCondition parseExpressions(@Nullable String[] produces, @Nullable String[] headers) { + private List parseExpressions(String @Nullable [] produces, String @Nullable [] headers) { Set result = null; if (!ObjectUtils.isEmpty(headers)) { for (String header : headers) { @@ -195,8 +195,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition getMatchingExpressions(List acceptedMediaTypes) { + private @Nullable List getMatchingExpressions(List acceptedMediaTypes) { List result = null; for (ProduceMediaTypeExpression expression : this.expressions) { if (expression.match(acceptedMediaTypes)) { 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 e93ab846d0..b53a569e4c 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 @@ -17,8 +17,7 @@ package org.springframework.web.servlet.mvc.condition; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Contract for request mapping conditions. @@ -57,8 +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(HttpServletRequest request); + @Nullable T getMatchingCondition(HttpServletRequest request); /** * Compare this condition to another condition in the context of 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 31de95e336..c2687fbf97 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 @@ -20,8 +20,7 @@ import java.util.Collection; import java.util.Collections; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A holder for a {@link RequestCondition} useful when the type of the request @@ -39,8 +38,7 @@ import org.springframework.lang.Nullable; */ public final class RequestConditionHolder extends AbstractRequestCondition { - @Nullable - private final RequestCondition condition; + private final @Nullable RequestCondition condition; /** @@ -56,8 +54,7 @@ public final class RequestConditionHolder extends AbstractRequestCondition getCondition() { + public @Nullable RequestCondition getCondition() { return this.condition; } @@ -111,8 +108,7 @@ public final class RequestConditionHolder extends AbstractRequestConditionThis is mutually exclusive with {@link #getPathPatternsCondition()} * such that when one returns {@code null} the other one returns an instance. */ - @Nullable - public PatternsRequestCondition getPatternsCondition() { + public @Nullable PatternsRequestCondition getPatternsCondition() { return this.patternsCondition; } @@ -306,8 +300,7 @@ public final class RequestMappingInfo implements RequestCondition getCustomCondition() { + public @Nullable RequestCondition getCustomCondition() { return this.customConditionHolder.getCondition(); } @@ -354,8 +347,7 @@ public final class RequestMappingInfo implements RequestCondition customCondition; + private @Nullable RequestCondition customCondition; private BuilderConfiguration options = new BuilderConfiguration(); @@ -740,14 +729,11 @@ public final class RequestMappingInfo implements RequestCondition infos, String lookupPath, HttpServletRequest request) throws ServletException { if (CollectionUtils.isEmpty(infos)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMappingJacksonResponseBodyAdvice.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMappingJacksonResponseBodyAdvice.java index 56d831cb96..518d9b3f88 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMappingJacksonResponseBodyAdvice.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMappingJacksonResponseBodyAdvice.java @@ -16,6 +16,8 @@ package org.springframework.web.servlet.mvc.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; @@ -23,7 +25,6 @@ import org.springframework.http.converter.json.AbstractJackson2HttpMessageConver import org.springframework.http.converter.json.MappingJacksonValue; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; -import org.springframework.lang.Nullable; /** * A convenient base class for {@code ResponseBodyAdvice} implementations @@ -42,8 +43,7 @@ public abstract class AbstractMappingJacksonResponseBodyAdvice implements Respon } @Override - @Nullable - public final Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, + public final @Nullable Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType contentType, Class> converterType, ServerHttpRequest request, ServerHttpResponse response) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java index b00e71e0b4..4817cb7ece 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodArgumentResolver.java @@ -32,6 +32,7 @@ import java.util.Set; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; @@ -49,7 +50,6 @@ import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.SmartHttpMessageConverter; import org.springframework.http.server.ServletServerHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeTypeUtils; import org.springframework.validation.Errors; @@ -123,8 +123,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements * @throws IOException if the reading from the request fails * @throws HttpMediaTypeNotSupportedException if no suitable message converter is found */ - @Nullable - protected Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, + protected @Nullable Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException { HttpInputMessage inputMessage = createInputMessage(webRequest); @@ -143,9 +142,8 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements * @throws IOException if the reading from the request fails * @throws HttpMediaTypeNotSupportedException if no suitable message converter is found */ - @Nullable @SuppressWarnings({"rawtypes", "unchecked", "NullAway"}) - protected Object readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, + protected @Nullable Object readWithMessageConverters(HttpInputMessage inputMessage, MethodParameter parameter, Type targetType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException { Class contextClass = parameter.getContainingClass(); @@ -330,8 +328,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements * @return the adapted argument, or the original resolved argument as-is * @since 4.3.5 */ - @Nullable - protected Object adaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter) { + protected @Nullable Object adaptArgumentIfNecessary(@Nullable Object arg, MethodParameter parameter) { if (parameter.getParameterType() == Optional.class) { if (arg == null || (arg instanceof Collection collection && collection.isEmpty()) || (arg instanceof Object[] array && array.length == 0)) { @@ -358,8 +355,7 @@ public abstract class AbstractMessageConverterMethodArgumentResolver implements private final HttpHeaders headers; - @Nullable - private final InputStream body; + private final @Nullable InputStream body; public EmptyBodyCheckingHttpInputMessage(HttpInputMessage inputMessage) throws IOException { this.headers = inputMessage.getHeaders(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java index 798b1167d0..5fcf91ddb1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AbstractMessageConverterMethodProcessor.java @@ -30,6 +30,7 @@ import java.util.Set; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.GenericTypeResolver; import org.springframework.core.MethodParameter; @@ -53,7 +54,6 @@ import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.http.converter.SmartHttpMessageConverter; 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.MimeTypeUtils; @@ -551,8 +551,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe return (mediaType != null && (safeMediaType(mediaType))); } - @Nullable - private MediaType resolveMediaType(ServletRequest request, String extension) { + private @Nullable MediaType resolveMediaType(ServletRequest request, String extension) { MediaType result = null; String rawMimeType = request.getServletContext().getMimeType("file." + extension); if (StringUtils.hasText(rawMimeType)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java index e9aa6a196b..12e69e6559 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/AsyncTaskMethodReturnValueHandler.java @@ -16,9 +16,10 @@ package org.springframework.web.servlet.mvc.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.BeanFactory; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.async.WebAsyncTask; import org.springframework.web.context.request.async.WebAsyncUtils; @@ -33,8 +34,7 @@ import org.springframework.web.method.support.ModelAndViewContainer; */ public class AsyncTaskMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - @Nullable - private final BeanFactory beanFactory; + private final @Nullable BeanFactory beanFactory; public AsyncTaskMethodReturnValueHandler(@Nullable BeanFactory beanFactory) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java index d29a45289e..e9cb1f21e9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/CallableMethodReturnValueHandler.java @@ -18,8 +18,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.concurrent.Callable; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.async.WebAsyncUtils; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ContinuationHandlerMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ContinuationHandlerMethodArgumentResolver.java index cc1536040e..0fe6adbdcc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ContinuationHandlerMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ContinuationHandlerMethodArgumentResolver.java @@ -16,8 +16,9 @@ package org.springframework.web.servlet.mvc.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; @@ -37,8 +38,7 @@ public class ContinuationHandlerMethodArgumentResolver implements HandlerMethodA } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java index d871368aac..d0ada8bfe9 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/DeferredResultMethodReturnValueHandler.java @@ -19,8 +19,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.concurrent.CompletionException; import java.util.concurrent.CompletionStage; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.async.DeferredResult; import org.springframework.web.context.request.async.WebAsyncUtils; 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 64d79f7009..2cd1c5b725 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 @@ -26,6 +26,7 @@ import java.util.concurrent.ConcurrentHashMap; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.InitializingBean; @@ -38,7 +39,6 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.web.ErrorResponse; import org.springframework.web.HttpMediaTypeNotAcceptableException; @@ -96,17 +96,13 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce new DisconnectedClientHelper(DISCONNECTED_CLIENT_LOG_CATEGORY); - @Nullable - private List customArgumentResolvers; + private @Nullable List customArgumentResolvers; - @Nullable - private HandlerMethodArgumentResolverComposite argumentResolvers; + private @Nullable HandlerMethodArgumentResolverComposite argumentResolvers; - @Nullable - private List customReturnValueHandlers; + private @Nullable List customReturnValueHandlers; - @Nullable - private HandlerMethodReturnValueHandlerComposite returnValueHandlers; + private @Nullable HandlerMethodReturnValueHandlerComposite returnValueHandlers; private final List> messageConverters = new ArrayList<>(); @@ -116,8 +112,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce private final List errorResponseInterceptors = new ArrayList<>(); - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; private final Map, ExceptionHandlerMethodResolver> exceptionHandlerCache = new ConcurrentHashMap<>(64); @@ -138,8 +133,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce /** * Return the custom argument resolvers, or {@code null}. */ - @Nullable - public List getCustomArgumentResolvers() { + public @Nullable List getCustomArgumentResolvers() { return this.customArgumentResolvers; } @@ -161,8 +155,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() { + public @Nullable HandlerMethodArgumentResolverComposite getArgumentResolvers() { return this.argumentResolvers; } @@ -178,8 +171,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce /** * Return the custom return value handlers, or {@code null}. */ - @Nullable - public List getCustomReturnValueHandlers() { + public @Nullable List getCustomReturnValueHandlers() { return this.customReturnValueHandlers; } @@ -201,8 +193,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() { + public @Nullable HandlerMethodReturnValueHandlerComposite getReturnValueHandlers() { return this.returnValueHandlers; } @@ -275,8 +266,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -433,8 +423,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce * Find an {@code @ExceptionHandler} method and invoke it to handle the raised exception. */ @Override - @Nullable - protected ModelAndView doResolveHandlerMethodException(HttpServletRequest request, + protected @Nullable ModelAndView doResolveHandlerMethodException(HttpServletRequest request, HttpServletResponse response, @Nullable HandlerMethod handlerMethod, Exception exception) { ServletWebRequest webRequest = new ServletWebRequest(request, response); @@ -513,8 +502,7 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce * @param webRequest the original web request that resulted in a handler error * @return a method to handle the exception, or {@code null} if none */ - @Nullable - protected ServletInvocableHandlerMethod getExceptionHandlerMethod( + protected @Nullable ServletInvocableHandlerMethod getExceptionHandlerMethod( @Nullable HandlerMethod handlerMethod, Exception exception, ServletWebRequest webRequest) { List acceptedMediaTypes = List.of(MediaType.ALL); 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 019bf9a75b..352862fb0e 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 @@ -25,9 +25,9 @@ import java.util.function.Predicate; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.beans.MutablePropertyValues; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.WebDataBinder; @@ -132,8 +132,7 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { } @SuppressWarnings("unchecked") - @Nullable - private static Map getUriVars(ServletRequest request) { + private static @Nullable Map getUriVars(ServletRequest request) { return (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); } @@ -148,8 +147,7 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { } } - @Nullable - private Object getHeaderValue(HttpServletRequest request, String name) { + private @Nullable Object getHeaderValue(HttpServletRequest request, String name) { if (!this.headerPredicate.test(name)) { return null; } @@ -183,8 +181,7 @@ public class ExtendedServletRequestDataBinder extends ServletRequestDataBinder { } @Override - @Nullable - protected Object getRequestParameter(String name, Class type) { + protected @Nullable Object getRequestParameter(String name, Class type) { Object value = super.getRequestParameter(name, type); if (value == null) { Map uriVars = getUriVars(getRequest()); 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 fda6f3adbb..97a97e1a31 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 @@ -27,6 +27,7 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; @@ -39,7 +40,6 @@ 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; @@ -141,8 +141,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws IOException, HttpMediaTypeNotSupportedException { @@ -163,8 +162,7 @@ public class HttpEntityMethodProcessor extends AbstractMessageConverterMethodPro } } - @Nullable - private Type getHttpEntityType(MethodParameter parameter) { + private @Nullable Type getHttpEntityType(MethodParameter parameter) { Assert.isAssignable(HttpEntity.class, parameter.getParameterType()); Type parameterType = parameter.getGenericParameterType(); if (parameterType instanceof ParameterizedType type) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java index 224d3a17a0..34a4ce6f60 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/HttpHeadersReturnValueHandler.java @@ -17,11 +17,11 @@ package org.springframework.web.servlet.mvc.method.annotation; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.http.HttpHeaders; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java index c60de4a425..193b584f33 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMapMethodArgumentResolver.java @@ -19,9 +19,10 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -58,8 +59,7 @@ public class MatrixVariableMapMethodArgumentResolver implements HandlerMethodArg } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception { @SuppressWarnings("unchecked") diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java index 37fae80c47..8f33d96487 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/MatrixVariableMethodArgumentResolver.java @@ -20,8 +20,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -75,8 +76,7 @@ public class MatrixVariableMethodArgumentResolver extends AbstractNamedValueMeth @Override @SuppressWarnings("unchecked") - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { Map> pathParameters = (Map>) request.getAttribute(HandlerMapping.MATRIX_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (CollectionUtils.isEmpty(pathParameters)) { 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 9d2b199040..854a255049 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 @@ -18,8 +18,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.Collection; +import org.jspecify.annotations.Nullable; + 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; @@ -47,8 +48,7 @@ import org.springframework.web.servlet.view.FragmentsRendering; */ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - @Nullable - private String[] redirectPatterns; + private String @Nullable [] redirectPatterns; /** @@ -58,7 +58,7 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn * There must be a custom {@link View} that recognizes the prefix as well. * @since 4.1 */ - public void setRedirectPatterns(@Nullable String... redirectPatterns) { + public void setRedirectPatterns(String @Nullable ... redirectPatterns) { this.redirectPatterns = redirectPatterns; } @@ -66,8 +66,7 @@ public class ModelAndViewMethodReturnValueHandler implements HandlerMethodReturn * Return the configured redirect patterns, if any. * @since 4.1 */ - @Nullable - public String[] getRedirectPatterns() { + public String @Nullable [] getRedirectPatterns() { return this.redirectPatterns; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java index 423a4b1513..0386f1e988 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ModelAndViewResolverMethodReturnValueHandler.java @@ -19,8 +19,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.lang.reflect.Method; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.ui.ExtendedModelMap; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -55,8 +56,7 @@ import org.springframework.web.servlet.mvc.annotation.ModelAndViewResolver; */ public class ModelAndViewResolverMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - @Nullable - private final List mavResolvers; + private final @Nullable List mavResolvers; private final ModelAttributeMethodProcessor modelAttributeProcessor = new ServletModelAttributeMethodProcessor(true); 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 c66bb0652e..88cca2755a 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 @@ -28,6 +28,7 @@ import java.util.Set; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.config.ConfigurableBeanFactory; @@ -43,7 +44,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ParameterNameDiscoverer; import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotatedMethod; -import org.springframework.lang.Nullable; import org.springframework.objenesis.ObjenesisException; import org.springframework.objenesis.SpringObjenesis; import org.springframework.util.AntPathMatcher; @@ -678,8 +678,7 @@ public class MvcUriComponentsBuilder { return value; } - @Nullable - private static WebApplicationContext getWebApplicationContext() { + private static @Nullable WebApplicationContext getWebApplicationContext() { RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes(); if (requestAttributes == null) { return null; @@ -722,19 +721,16 @@ public class MvcUriComponentsBuilder { private final Class controllerType; - @Nullable - private Method controllerMethod; + private @Nullable Method controllerMethod; - @Nullable - private Object[] argumentValues; + private Object @Nullable [] argumentValues; ControllerMethodInvocationInterceptor(Class controllerType) { this.controllerType = controllerType; } @Override - @Nullable - public Object intercept(@Nullable Object obj, Method method, Object[] args, @Nullable MethodProxy proxy) { + public @Nullable Object intercept(@Nullable Object obj, Method method, Object[] args, @Nullable MethodProxy proxy) { switch (method.getName()) { case "getControllerType" -> { return this.controllerType; @@ -766,8 +762,7 @@ public class MvcUriComponentsBuilder { } @Override - @Nullable - public Object invoke(Object proxy, Method method, @Nullable Object[] args) { + public @Nullable Object invoke(Object proxy, Method method, Object @Nullable [] args) { return intercept(proxy, method, (args != null ? args : new Object[0]), null); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java index 57486ff311..04fad545be 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMapMethodArgumentResolver.java @@ -19,8 +19,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.Collections; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.PathVariable; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java index e35b49acb7..876dead8b2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PathVariableMethodArgumentResolver.java @@ -20,11 +20,12 @@ import java.beans.PropertyEditor; import java.util.HashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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.Assert; import org.springframework.util.StringUtils; import org.springframework.web.bind.MissingPathVariableException; @@ -89,8 +90,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod @Override @SuppressWarnings("unchecked") - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) throws Exception { Map uriTemplateVars = (Map) request.getAttribute( HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); return (uriTemplateVars != null ? uriTemplateVars.get(name) : null); @@ -137,8 +137,7 @@ public class PathVariableMethodArgumentResolver extends AbstractNamedValueMethod uriVariables.put(name, formatted); } - @Nullable - protected String formatUriValue(@Nullable ConversionService cs, @Nullable TypeDescriptor sourceType, Object value) { + protected @Nullable String formatUriValue(@Nullable ConversionService cs, @Nullable TypeDescriptor sourceType, Object value) { if (value instanceof String string) { return string; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java index 23ebbd3f0d..014f661891 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/PrincipalMethodArgumentResolver.java @@ -19,9 +19,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.security.Principal; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; 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 59b6db526e..ebeb5d0998 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 @@ -29,6 +29,7 @@ import io.micrometer.context.ContextSnapshot; import io.micrometer.context.ContextSnapshotFactory; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -46,7 +47,6 @@ import org.springframework.core.task.support.ContextPropagatingTaskDecorator; 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.ClassUtils; import org.springframework.util.CollectionUtils; @@ -93,8 +93,7 @@ class ReactiveTypeHandler { private final ContentNegotiationManager contentNegotiationManager; - @Nullable - private final Object contextSnapshotHelper; + private final @Nullable Object contextSnapshotHelper; public ReactiveTypeHandler() { @@ -114,8 +113,7 @@ class ReactiveTypeHandler { this.contextSnapshotHelper = initContextSnapshotHelper(contextSnapshotFactory); } - @Nullable - private static Object initContextSnapshotHelper(@Nullable Object snapshotFactory) { + private static @Nullable Object initContextSnapshotHelper(@Nullable Object snapshotFactory) { if (isContextPropagationPresent) { return new ContextSnapshotHelper((ContextSnapshotFactory) snapshotFactory); } @@ -137,8 +135,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, + public @Nullable ResponseBodyEmitter handleValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mav, NativeWebRequest request) throws Exception { Assert.notNull(returnValue, "Expected return value"); @@ -201,8 +198,7 @@ class ReactiveTypeHandler { * @return the concrete streaming {@code MediaType} if one could be found or {@code null} * if none could be found */ - @Nullable - static MediaType findConcreteJsonStreamMediaType(Collection acceptedMediaTypes) { + static @Nullable MediaType findConcreteJsonStreamMediaType(Collection acceptedMediaTypes) { for (MediaType acceptedType : acceptedMediaTypes) { if (WILDCARD_SUBTYPE_SUFFIXED_BY_NDJSON.includes(acceptedType)) { if (acceptedType.isConcrete()) { @@ -250,13 +246,11 @@ class ReactiveTypeHandler { private final TaskExecutor taskExecutor; - @Nullable - private Subscription subscription; + private @Nullable Subscription subscription; private final AtomicReference elementRef = new AtomicReference<>(); - @Nullable - private Throwable error; + private @Nullable Throwable error; private volatile boolean terminated; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java index 9de99cc4c1..ee7a8da726 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RedirectAttributesMethodArgumentResolver.java @@ -18,8 +18,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.ui.Model; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolver.java index 27a1973020..05be76d25a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestAttributeMethodArgumentResolver.java @@ -17,9 +17,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.annotation.RequestAttribute; @@ -49,8 +49,7 @@ public class RequestAttributeMethodArgumentResolver extends AbstractNamedValueMe } @Override - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request){ + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request){ return request.getAttribute(name, RequestAttributes.SCOPE_REQUEST); } 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 4b10e1e385..0d5f204c09 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 @@ -19,10 +19,11 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.io.IOException; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + 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 @@ -86,8 +87,7 @@ public interface RequestBodyAdvice { * @return the value to use, or {@code null} which may then raise an * {@code HttpMessageNotReadableException} if the argument is required */ - @Nullable - Object handleEmptyBody(@Nullable 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/RequestBodyAdviceAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdviceAdapter.java index cdb68a7975..a4560931f2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdviceAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestBodyAdviceAdapter.java @@ -19,10 +19,11 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.io.IOException; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; /** * A convenient starting point for implementing @@ -61,8 +62,7 @@ public abstract class RequestBodyAdviceAdapter implements RequestBodyAdvice { * The default implementation returns the body that was passed in. */ @Override - @Nullable - public Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, + public @Nullable Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class> converterType) { return body; 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 34b38dc2f0..50134833d0 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 @@ -30,6 +30,7 @@ import java.util.function.Predicate; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -53,7 +54,6 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.ui.ModelMap; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -148,23 +148,17 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter ClassUtils.isPresent("jakarta.validation.Validator", HandlerMethod.class.getClassLoader()); - @Nullable - private List customArgumentResolvers; + private @Nullable List customArgumentResolvers; - @Nullable - private HandlerMethodArgumentResolverComposite argumentResolvers; + private @Nullable HandlerMethodArgumentResolverComposite argumentResolvers; - @Nullable - private HandlerMethodArgumentResolverComposite initBinderArgumentResolvers; + private @Nullable HandlerMethodArgumentResolverComposite initBinderArgumentResolvers; - @Nullable - private List customReturnValueHandlers; + private @Nullable List customReturnValueHandlers; - @Nullable - private HandlerMethodReturnValueHandlerComposite returnValueHandlers; + private @Nullable HandlerMethodReturnValueHandlerComposite returnValueHandlers; - @Nullable - private List modelAndViewResolvers; + private @Nullable List modelAndViewResolvers; private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager(); @@ -172,18 +166,15 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter private final List requestResponseBodyAdvice = new ArrayList<>(); - @Nullable - private WebBindingInitializer webBindingInitializer; + private @Nullable WebBindingInitializer webBindingInitializer; private final List errorResponseInterceptors = new ArrayList<>(); - @Nullable - private MethodValidator methodValidator; + private @Nullable MethodValidator methodValidator; private AsyncTaskExecutor taskExecutor = new MvcSimpleAsyncTaskExecutor(); - @Nullable - private Long asyncRequestTimeout; + private @Nullable Long asyncRequestTimeout; private CallableProcessingInterceptor[] callableInterceptors = new CallableProcessingInterceptor[0]; @@ -201,8 +192,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter private ParameterNameDiscoverer parameterNameDiscoverer = new DefaultParameterNameDiscoverer(); - @Nullable - private ConfigurableBeanFactory beanFactory; + private @Nullable ConfigurableBeanFactory beanFactory; private final Map, SessionAttributesHandler> sessionAttributesHandlerCache = new ConcurrentHashMap<>(64); @@ -227,8 +217,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the custom argument resolvers, or {@code null}. */ - @Nullable - public List getCustomArgumentResolvers() { + public @Nullable List getCustomArgumentResolvers() { return this.customArgumentResolvers; } @@ -250,8 +239,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() { + public @Nullable List getArgumentResolvers() { return (this.argumentResolvers != null ? this.argumentResolvers.getResolvers() : null); } @@ -272,8 +260,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() { + public @Nullable List getInitBinderArgumentResolvers() { return (this.initBinderArgumentResolvers != null ? this.initBinderArgumentResolvers.getResolvers() : null); } @@ -289,8 +276,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the custom return value handlers, or {@code null}. */ - @Nullable - public List getCustomReturnValueHandlers() { + public @Nullable List getCustomReturnValueHandlers() { return this.customReturnValueHandlers; } @@ -312,8 +298,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() { + public @Nullable List getReturnValueHandlers() { return (this.returnValueHandlers != null ? this.returnValueHandlers.getHandlers() : null); } @@ -338,8 +323,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the configured {@link ModelAndViewResolver ModelAndViewResolvers}, or {@code null}. */ - @Nullable - public List getModelAndViewResolvers() { + public @Nullable List getModelAndViewResolvers() { return this.modelAndViewResolvers; } @@ -401,8 +385,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the configured WebBindingInitializer, or {@code null} if none. */ - @Nullable - public WebBindingInitializer getWebBindingInitializer() { + public @Nullable WebBindingInitializer getWebBindingInitializer() { return this.webBindingInitializer; } @@ -580,8 +563,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter /** * Return the owning factory of this bean instance, or {@code null} if none. */ - @Nullable - protected ConfigurableBeanFactory getBeanFactory() { + protected @Nullable ConfigurableBeanFactory getBeanFactory() { return this.beanFactory; } @@ -823,8 +805,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter return Collections.emptyList(); } - @Nullable - private LocaleResolver initLocaleResolver() { + private @Nullable LocaleResolver initLocaleResolver() { if (getBeanFactory() != null) { try { return getBeanFactory().getBean( @@ -865,8 +846,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter } @Override - @Nullable - protected ModelAndView handleInternal(HttpServletRequest request, + protected @Nullable ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { ModelAndView mav; @@ -932,8 +912,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter * @see #createInvocableHandlerMethod(HandlerMethod) */ @SuppressWarnings("deprecation") - @Nullable - protected ModelAndView invokeHandlerMethod(HttpServletRequest request, + protected @Nullable ModelAndView invokeHandlerMethod(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception { WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request); @@ -1086,8 +1065,7 @@ public class RequestMappingHandlerAdapter extends AbstractHandlerMethodAdapter return new ServletRequestDataBinderFactory(binderMethods, getWebBindingInitializer()); } - @Nullable - private ModelAndView getModelAndView(ModelAndViewContainer mavContainer, + private @Nullable ModelAndView getModelAndView(ModelAndViewContainer mavContainer, ModelFactory modelFactory, NativeWebRequest webRequest) throws Exception { modelFactory.updateModel(webRequest, mavContainer); 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 f2575527f5..b30058bbe3 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 @@ -28,6 +28,7 @@ import java.util.function.Predicate; import java.util.stream.Stream; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.context.EmbeddedValueResolverAware; import org.springframework.core.annotation.AnnotatedElementUtils; @@ -36,7 +37,6 @@ import org.springframework.core.annotation.MergedAnnotationPredicates; import org.springframework.core.annotation.MergedAnnotations; import org.springframework.core.annotation.MergedAnnotations.SearchStrategy; import org.springframework.core.annotation.RepeatableContainers; -import org.springframework.lang.Nullable; import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; @@ -83,8 +83,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi private ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager(); - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; private RequestMappingInfo.BuilderConfiguration config = new RequestMappingInfo.BuilderConfiguration(); @@ -185,8 +184,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi * @see #getCustomTypeCondition(Class) */ @Override - @Nullable - protected RequestMappingInfo getMappingForMethod(Method method, Class handlerType) { + protected @Nullable RequestMappingInfo getMappingForMethod(Method method, Class handlerType) { RequestMappingInfo info = createRequestMappingInfo(method); if (info != null) { RequestMappingInfo typeInfo = createRequestMappingInfo(handlerType); @@ -204,8 +202,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi return info; } - @Nullable - String getPathPrefix(Class handlerType) { + @Nullable String getPathPrefix(Class handlerType) { for (Map.Entry>> entry : this.pathPrefixes.entrySet()) { if (entry.getValue().test(handlerType)) { String prefix = entry.getKey(); @@ -218,8 +215,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi return null; } - @Nullable - private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { + private @Nullable RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { RequestMappingInfo requestMappingInfo = null; RequestCondition customCondition = (element instanceof Class clazz ? getCustomTypeCondition(clazz) : getCustomMethodCondition((Method) element)); @@ -262,8 +258,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) { + protected @Nullable RequestCondition getCustomTypeCondition(Class handlerType) { return null; } @@ -278,8 +273,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) { + protected @Nullable RequestCondition getCustomMethodCondition(Method method) { return null; } @@ -397,8 +391,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi } @Override - @Nullable - public RequestMatchResult match(HttpServletRequest request, String pattern) { + public @Nullable RequestMatchResult match(HttpServletRequest request, String pattern) { Assert.state(getPatternParser() == null, "This HandlerMapping uses PathPatterns."); RequestMappingInfo info = RequestMappingInfo.paths(pattern).options(this.config).build(); RequestMappingInfo match = info.getMatchingCondition(request); @@ -410,8 +403,7 @@ public class RequestMappingHandlerMapping extends RequestMappingInfoHandlerMappi } @Override - @Nullable - protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { + protected @Nullable CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) { HandlerMethod handlerMethod = createHandlerMethod(handler, method); Class beanType = handlerMethod.getBeanType(); CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java index 47e21fcab2..c3bf08e6b6 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestPartMethodArgumentResolver.java @@ -21,12 +21,12 @@ import java.io.InputStream; import java.util.List; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.http.HttpInputMessage; import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.validation.BindingResult; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -117,8 +117,7 @@ public class RequestPartMethodArgumentResolver extends AbstractMessageConverterM } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest request, @Nullable WebDataBinderFactory binderFactory) throws Exception { HttpServletRequest servletRequest = request.getNativeRequest(HttpServletRequest.class); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java index f5e4834907..5d7fa5ecd5 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyAdviceChain.java @@ -22,13 +22,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.http.HttpInputMessage; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.web.method.ControllerAdviceBean; @@ -108,8 +109,7 @@ class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyA } @Override - @Nullable - public Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType contentType, + public @Nullable Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, MediaType contentType, Class> converterType, ServerHttpRequest request, ServerHttpResponse response) { @@ -117,8 +117,7 @@ class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyA } @Override - @Nullable - public Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, + public @Nullable Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessage, MethodParameter parameter, Type targetType, Class> converterType) { for (RequestBodyAdvice advice : getMatchingAdvice(parameter, RequestBodyAdvice.class)) { @@ -131,8 +130,7 @@ class RequestResponseBodyAdviceChain implements RequestBodyAdvice, ResponseBodyA @SuppressWarnings("unchecked") - @Nullable - private Object processBody(@Nullable Object body, MethodParameter returnType, MediaType contentType, + private @Nullable Object processBody(@Nullable Object body, MethodParameter returnType, MediaType contentType, Class> converterType, ServerHttpRequest request, ServerHttpResponse response) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java index 2e9b6b6572..3436f66878 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestResponseBodyMethodProcessor.java @@ -21,6 +21,8 @@ import java.lang.reflect.Type; import java.net.URI; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.core.Conventions; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; @@ -32,7 +34,6 @@ import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; import org.springframework.http.server.ServletServerHttpRequest; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.validation.BindingResult; import org.springframework.web.ErrorResponse; import org.springframework.web.HttpMediaTypeNotAcceptableException; @@ -142,8 +143,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter * converter to read the content with. */ @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { parameter = parameter.nestedIfOptional(); @@ -168,8 +168,7 @@ public class RequestResponseBodyMethodProcessor extends AbstractMessageConverter } @Override - @Nullable - protected Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, + protected @Nullable Object readWithMessageConverters(NativeWebRequest webRequest, MethodParameter parameter, Type paramType) throws IOException, HttpMediaTypeNotSupportedException, HttpMessageNotReadableException { ServletServerHttpRequest inputMessage = createInputMessage(webRequest); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdvice.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdvice.java index b2b6d48b28..d8f582fadb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdvice.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyAdvice.java @@ -16,12 +16,13 @@ package org.springframework.web.servlet.mvc.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; -import org.springframework.lang.Nullable; /** * Allows customizing the response after the execution of an {@code @ResponseBody} @@ -60,8 +61,7 @@ public interface ResponseBodyAdvice { * @param response the current response * @return the body that was passed in or a modified (possibly new) instance */ - @Nullable - T beforeBodyWrite(@Nullable T body, MethodParameter returnType, MediaType selectedContentType, + @Nullable T beforeBodyWrite(@Nullable T body, MethodParameter returnType, MediaType selectedContentType, Class> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response); 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 e4e5d0e6b7..845194e0b2 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 @@ -24,9 +24,10 @@ import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + 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; @@ -67,11 +68,9 @@ import org.springframework.util.ObjectUtils; */ public class ResponseBodyEmitter { - @Nullable - private final Long timeout; + private final @Nullable Long timeout; - @Nullable - private Handler handler; + private @Nullable Handler handler; /** Store send data before handler is initialized. */ private final Set earlySendAttempts = new LinkedHashSet<>(8); @@ -80,8 +79,7 @@ public class ResponseBodyEmitter { private final AtomicBoolean complete = new AtomicBoolean(); /** Store an error before the handler is initialized. */ - @Nullable - private Throwable failure; + private @Nullable Throwable failure; private final DefaultCallback timeoutCallback = new DefaultCallback(); @@ -112,8 +110,7 @@ public class ResponseBodyEmitter { /** * Return the configured timeout value, if any. */ - @Nullable - public Long getTimeout() { + public @Nullable Long getTimeout() { return this.timeout; } @@ -350,8 +347,7 @@ public class ResponseBodyEmitter { private final Object data; - @Nullable - private final MediaType mediaType; + private final @Nullable MediaType mediaType; public DataWithMediaType(Object data, @Nullable MediaType mediaType) { this.data = data; @@ -362,8 +358,7 @@ public class ResponseBodyEmitter { return this.data; } - @Nullable - public MediaType getMediaType() { + public @Nullable MediaType getMediaType() { return this.mediaType; } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java index 92a571ac44..58caff7281 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java @@ -33,6 +33,7 @@ import jakarta.servlet.WriteListener; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ReactiveAdapterRegistry; @@ -47,7 +48,6 @@ import org.springframework.http.converter.StringHttpMessageConverter; import org.springframework.http.server.DelegatingServerHttpResponse; import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.accept.ContentNegotiationManager; @@ -411,8 +411,7 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur } } - @Nullable - public View resolveViewName(String viewName, Locale locale) throws Exception { + public @Nullable View resolveViewName(String viewName, Locale locale) throws Exception { for (ViewResolver resolver : this.viewResolvers) { View view = resolver.resolveViewName(viewName, locale); if (view != null) { 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 f1a457ad5b..13edb114da 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 @@ -19,6 +19,7 @@ package org.springframework.web.servlet.mvc.method.annotation; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.ConversionNotSupportedException; import org.springframework.beans.TypeMismatchException; @@ -32,7 +33,6 @@ import org.springframework.http.ProblemDetail; import org.springframework.http.ResponseEntity; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.lang.Nullable; import org.springframework.validation.BindException; import org.springframework.validation.method.MethodValidationException; import org.springframework.web.ErrorResponse; @@ -92,8 +92,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private MessageSource messageSource; + private @Nullable MessageSource messageSource; @Override @@ -105,8 +104,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * Get the {@link MessageSource} that this exception handler uses. * @since 6.0.3 */ - @Nullable - protected MessageSource getMessageSource() { + protected @Nullable MessageSource getMessageSource() { return this.messageSource; } @@ -139,8 +137,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa BindException.class, AsyncRequestNotUsableException.class }) - @Nullable - public final ResponseEntity handleException(Exception ex, WebRequest request) throws Exception { + public final @Nullable ResponseEntity handleException(Exception ex, WebRequest request) throws Exception { if (ex instanceof HttpRequestMethodNotSupportedException subEx) { return handleHttpRequestMethodNotSupported(subEx, subEx.getHeaders(), subEx.getStatusCode(), request); } @@ -224,8 +221,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleHttpRequestMethodNotSupported( + protected @Nullable ResponseEntity handleHttpRequestMethodNotSupported( HttpRequestMethodNotSupportedException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { pageNotFoundLogger.warn(ex.getMessage()); @@ -242,8 +238,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleHttpMediaTypeNotSupported( + protected @Nullable ResponseEntity handleHttpMediaTypeNotSupported( HttpMediaTypeNotSupportedException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -259,8 +254,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleHttpMediaTypeNotAcceptable( + protected @Nullable ResponseEntity handleHttpMediaTypeNotAcceptable( HttpMediaTypeNotAcceptableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -277,8 +271,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 4.2 */ - @Nullable - protected ResponseEntity handleMissingPathVariable( + protected @Nullable ResponseEntity handleMissingPathVariable( MissingPathVariableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -294,8 +287,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleMissingServletRequestParameter( + protected @Nullable ResponseEntity handleMissingServletRequestParameter( MissingServletRequestParameterException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -311,8 +303,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleMissingServletRequestPart( + protected @Nullable ResponseEntity handleMissingServletRequestPart( MissingServletRequestPartException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -328,8 +319,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleServletRequestBindingException( + protected @Nullable ResponseEntity handleServletRequestBindingException( ServletRequestBindingException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -345,8 +335,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleMethodArgumentNotValid( + protected @Nullable ResponseEntity handleMethodArgumentNotValid( MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -363,8 +352,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 6.1 */ - @Nullable - protected ResponseEntity handleHandlerMethodValidationException( + protected @Nullable ResponseEntity handleHandlerMethodValidationException( HandlerMethodValidationException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -381,8 +369,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 4.0 */ - @Nullable - protected ResponseEntity handleNoHandlerFoundException( + protected @Nullable ResponseEntity handleNoHandlerFoundException( NoHandlerFoundException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -399,8 +386,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 6.1 */ - @Nullable - protected ResponseEntity handleNoResourceFoundException( + protected @Nullable ResponseEntity handleNoResourceFoundException( NoResourceFoundException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -417,8 +403,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 4.2.8 */ - @Nullable - protected ResponseEntity handleAsyncRequestTimeoutException( + protected @Nullable ResponseEntity handleAsyncRequestTimeoutException( AsyncRequestTimeoutException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -435,8 +420,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 6.0 */ - @Nullable - protected ResponseEntity handleErrorResponseException( + protected @Nullable ResponseEntity handleErrorResponseException( ErrorResponseException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -453,8 +437,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 6.1 */ - @Nullable - protected ResponseEntity handleMaxUploadSizeExceededException( + protected @Nullable ResponseEntity handleMaxUploadSizeExceededException( MaxUploadSizeExceededException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { return handleExceptionInternal(ex, null, headers, status, request); @@ -473,8 +456,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleConversionNotSupported( + protected @Nullable ResponseEntity handleConversionNotSupported( ConversionNotSupportedException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { Object[] args = {ex.getPropertyName(), ex.getValue()}; @@ -497,8 +479,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleTypeMismatch( + protected @Nullable ResponseEntity handleTypeMismatch( TypeMismatchException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { Object[] args = {ex.getPropertyName(), ex.getValue()}; @@ -522,8 +503,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleHttpMessageNotReadable( + protected @Nullable ResponseEntity handleHttpMessageNotReadable( HttpMessageNotReadableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { ProblemDetail body = createProblemDetail(ex, status, "Failed to read request", null, null, request); @@ -543,8 +523,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleHttpMessageNotWritable( + protected @Nullable ResponseEntity handleHttpMessageNotWritable( HttpMessageNotWritableException ex, HttpHeaders headers, HttpStatusCode status, WebRequest request) { ProblemDetail body = createProblemDetail(ex, status, "Failed to write request", null, null, request); @@ -565,8 +544,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 6.1 */ - @Nullable - protected ResponseEntity handleMethodValidationException( + protected @Nullable ResponseEntity handleMethodValidationException( MethodValidationException ex, HttpHeaders headers, HttpStatus status, WebRequest request) { ProblemDetail body = createProblemDetail(ex, status, "Validation failed", null, null, request); @@ -582,8 +560,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * {@code null} when the response is already committed * @since 6.2 */ - @Nullable - protected ResponseEntity handleAsyncRequestNotUsableException( + protected @Nullable ResponseEntity handleAsyncRequestNotUsableException( AsyncRequestNotUsableException ex, WebRequest request) { return null; @@ -607,7 +584,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa */ protected ProblemDetail createProblemDetail( Exception ex, HttpStatusCode status, String defaultDetail, @Nullable String detailMessageCode, - @Nullable Object[] detailMessageArguments, WebRequest request) { + Object @Nullable [] detailMessageArguments, WebRequest request) { ErrorResponse.Builder builder = ErrorResponse.builder(ex, status, defaultDetail); if (detailMessageCode != null) { @@ -638,8 +615,7 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa * @return a {@code ResponseEntity} for the response to use, possibly * {@code null} when the response is already committed */ - @Nullable - protected ResponseEntity handleExceptionInternal( + protected @Nullable ResponseEntity handleExceptionInternal( Exception ex, @Nullable Object body, HttpHeaders headers, HttpStatusCode statusCode, WebRequest request) { if (request instanceof ServletWebRequest servletWebRequest) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java index 160cd0cf3a..f1226fc170 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletCookieValueMethodArgumentResolver.java @@ -18,10 +18,10 @@ package org.springframework.web.servlet.mvc.method.annotation; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.annotation.AbstractCookieValueMethodArgumentResolver; @@ -68,8 +68,7 @@ public class ServletCookieValueMethodArgumentResolver extends AbstractCookieValu @Override - @Nullable - protected Object resolveName(String cookieName, MethodParameter parameter, + protected @Nullable Object resolveName(String cookieName, MethodParameter parameter, NativeWebRequest webRequest) throws Exception { HttpServletRequest servletRequest = webRequest.getNativeRequest(HttpServletRequest.class); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java index 45146aa6d1..413a7adfc7 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletInvocableHandlerMethod.java @@ -25,6 +25,7 @@ import java.util.concurrent.Callable; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.context.MessageSource; import org.springframework.core.KotlinDetector; @@ -32,7 +33,6 @@ import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatusCode; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -67,8 +67,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { private static final Method CALLABLE_METHOD = ClassUtils.getMethod(Callable.class, "call"); - @Nullable - private HandlerMethodReturnValueHandlerComposite returnValueHandlers; + private @Nullable HandlerMethodReturnValueHandlerComposite returnValueHandlers; /** @@ -253,8 +252,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { * Bridge to controller method-level annotations. */ @Override - @Nullable - public A getMethodAnnotation(Class annotationType) { + public @Nullable A getMethodAnnotation(Class annotationType) { return ServletInvocableHandlerMethod.this.getMethodAnnotation(annotationType); } @@ -275,8 +273,7 @@ public class ServletInvocableHandlerMethod extends InvocableHandlerMethod { */ private class ConcurrentResultMethodParameter extends AnnotatedMethodParameter { - @Nullable - private final Object returnValue; + private final @Nullable Object returnValue; private final ResolvableType returnType; 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 de59e9ee27..a1bccaa5e3 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 @@ -20,12 +20,12 @@ import java.util.Collections; import java.util.Map; import jakarta.servlet.ServletRequest; +import org.jspecify.annotations.Nullable; 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.Assert; import org.springframework.util.StringUtils; import org.springframework.validation.DataBinder; @@ -70,8 +70,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * @see #createAttributeFromRequestValue */ @Override - @Nullable - protected final Object createAttribute(String attributeName, MethodParameter parameter, + protected final @Nullable Object createAttribute(String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { String value = getRequestValueForAttribute(attributeName, request); @@ -95,8 +94,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) { + protected @Nullable String getRequestValueForAttribute(String attributeName, NativeWebRequest request) { Map variables = getUriTemplateVariables(request); String variableValue = variables.get(attributeName); if (StringUtils.hasText(variableValue)) { @@ -129,8 +127,7 @@ public class ServletModelAttributeMethodProcessor extends ModelAttributeMethodPr * @return the created model attribute, or {@code null} if no suitable * conversion found */ - @Nullable - protected Object createAttributeFromRequestValue(String sourceValue, String attributeName, + protected @Nullable Object createAttributeFromRequestValue(String sourceValue, String attributeName, MethodParameter parameter, WebDataBinderFactory binderFactory, NativeWebRequest request) throws Exception { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactory.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactory.java index 117b9e08fd..c67e42330f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactory.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestDataBinderFactory.java @@ -18,7 +18,8 @@ package org.springframework.web.servlet.mvc.method.annotation; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.bind.ServletRequestDataBinder; import org.springframework.web.bind.support.WebBindingInitializer; import org.springframework.web.context.request.NativeWebRequest; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java index 319891fc19..bbd9dc6362 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java @@ -28,10 +28,10 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.PushBuilder; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.WebRequest; @@ -88,8 +88,7 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, + public @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, NativeWebRequest webRequest, @Nullable WebDataBinderFactory binderFactory) throws Exception { Class paramType = parameter.getParameterType(); @@ -121,9 +120,8 @@ public class ServletRequestMethodArgumentResolver implements HandlerMethodArgume return nativeRequest; } - @Nullable @SuppressWarnings("deprecation") - private Object resolveArgument(Class paramType, HttpServletRequest request) throws IOException { + private @Nullable Object resolveArgument(Class paramType, HttpServletRequest request) throws IOException { if (HttpSession.class.isAssignableFrom(paramType)) { HttpSession session = request.getSession(); if (session != null && !paramType.isInstance(session)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java index 45e71a9081..176e2ed59a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletResponseMethodArgumentResolver.java @@ -21,9 +21,9 @@ import java.io.OutputStream; import java.io.Writer; import jakarta.servlet.ServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolver.java index c5cce648c0..96aebd371b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SessionAttributeMethodArgumentResolver.java @@ -17,9 +17,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import jakarta.servlet.ServletException; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.ServletRequestBindingException; import org.springframework.web.bind.annotation.SessionAttribute; @@ -49,8 +49,7 @@ public class SessionAttributeMethodArgumentResolver extends AbstractNamedValueMe } @Override - @Nullable - protected Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) { + protected @Nullable Object resolveName(String name, MethodParameter parameter, NativeWebRequest request) { return request.getAttribute(name, RequestAttributes.SCOPE_SESSION); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java index 56ce94231a..29ae344e57 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/SseEmitter.java @@ -24,10 +24,11 @@ import java.util.Set; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.http.server.ServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.web.servlet.ModelAndView; @@ -201,8 +202,7 @@ public class SseEmitter extends ResponseBodyEmitter { private final Set dataToSend = new LinkedHashSet<>(4); - @Nullable - private StringBuilder sb; + private @Nullable StringBuilder sb; private boolean hasName; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandler.java index 230aa99d10..026bf1e809 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/StreamingResponseBodyReturnValueHandler.java @@ -21,13 +21,13 @@ import java.util.concurrent.Callable; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; import org.springframework.core.ResolvableType; import org.springframework.http.ResponseEntity; import org.springframework.http.server.ServerHttpResponse; import org.springframework.http.server.ServletServerHttpResponse; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.context.request.async.WebAsyncUtils; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java index 34fdfce657..eb63fd5c91 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/UriComponentsBuilderMethodArgumentResolver.java @@ -17,9 +17,9 @@ package org.springframework.web.servlet.mvc.method.annotation; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java index dbdb4364ae..48f36d76b0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ViewMethodReturnValueHandler.java @@ -16,8 +16,9 @@ package org.springframework.web.servlet.mvc.method.annotation; +import org.jspecify.annotations.Nullable; + import org.springframework.core.MethodParameter; -import org.springframework.lang.Nullable; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodReturnValueHandler; import org.springframework.web.method.support.ModelAndViewContainer; 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 9808d90bdb..2c1478f67d 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 @@ -16,8 +16,9 @@ package org.springframework.web.servlet.mvc.method.annotation; +import org.jspecify.annotations.Nullable; + 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; @@ -44,8 +45,7 @@ import org.springframework.web.servlet.RequestToViewNameTranslator; */ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValueHandler { - @Nullable - private String[] redirectPatterns; + private String @Nullable [] redirectPatterns; /** @@ -55,15 +55,14 @@ public class ViewNameMethodReturnValueHandler implements HandlerMethodReturnValu * There must be a custom View that recognizes the prefix as well. * @since 4.1 */ - public void setRedirectPatterns(@Nullable String... redirectPatterns) { + public void setRedirectPatterns(String @Nullable ... redirectPatterns) { this.redirectPatterns = redirectPatterns; } /** * The configured redirect patterns, if any. */ - @Nullable - public String[] getRedirectPatterns() { + public String @Nullable [] 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 90c9c46fb5..4c3bd6530e 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,9 +4,7 @@ * {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping} * and {@link org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.mvc.method.annotation; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 372a55d33f..a3cd4888b9 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,9 +2,7 @@ * Servlet-based infrastructure for handler method processing, * building on the {@code org.springframework.web.method} package. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.mvc.method; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 b6ceb39463..1509160cfb 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,9 +2,7 @@ * Standard controller implementations for the Servlet MVC framework that comes with * Spring. Provides various controller styles, including an annotation-based model. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.mvc; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 7de262138c..f44a3eb4a2 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 @@ -22,6 +22,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.ConversionNotSupportedException; import org.springframework.beans.TypeMismatchException; @@ -30,7 +31,6 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ProblemDetail; import org.springframework.http.converter.HttpMessageNotReadableException; import org.springframework.http.converter.HttpMessageNotWritableException; -import org.springframework.lang.Nullable; import org.springframework.validation.method.MethodValidationException; import org.springframework.web.ErrorResponse; import org.springframework.web.HttpMediaTypeNotAcceptableException; @@ -177,8 +177,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes @Override - @Nullable - protected ModelAndView doResolveException( + protected @Nullable ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { try { @@ -273,8 +272,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, + protected @Nullable ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -294,8 +292,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, + protected @Nullable ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupportedException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -315,8 +312,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, + protected @Nullable ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptableException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -335,8 +331,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2 */ - @Nullable - protected ModelAndView handleMissingPathVariable(MissingPathVariableException ex, + protected @Nullable ModelAndView handleMissingPathVariable(MissingPathVariableException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -354,8 +349,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, + protected @Nullable ModelAndView handleMissingServletRequestParameter(MissingServletRequestParameterException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -372,8 +366,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleMissingServletRequestPartException(MissingServletRequestPartException ex, + protected @Nullable ModelAndView handleMissingServletRequestPartException(MissingServletRequestPartException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -392,8 +385,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleServletRequestBindingException(ServletRequestBindingException ex, + protected @Nullable ModelAndView handleServletRequestBindingException(ServletRequestBindingException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -411,8 +403,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * {@code null} indicating the exception should be handled in {@link #handleErrorResponse} * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} */ - @Nullable - protected ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, + protected @Nullable ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotValidException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -431,8 +422,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 6.1 */ - @Nullable - protected ModelAndView handleHandlerMethodValidationException(HandlerMethodValidationException ex, + protected @Nullable ModelAndView handleHandlerMethodValidationException(HandlerMethodValidationException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -452,8 +442,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.0 */ - @Nullable - protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, + protected @Nullable ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { pageNotFoundLogger.warn(ex.getMessage()); @@ -473,8 +462,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 6.1 */ - @Nullable - protected ModelAndView handleNoResourceFoundException(NoResourceFoundException ex, + protected @Nullable ModelAndView handleNoResourceFoundException(NoResourceFoundException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; @@ -494,8 +482,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes * @throws IOException potentially thrown from {@link HttpServletResponse#sendError} * @since 4.2.8 */ - @Nullable - protected ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, + protected @Nullable ModelAndView handleAsyncRequestTimeoutException(AsyncRequestTimeoutException ex, HttpServletRequest request, HttpServletResponse response, @Nullable Object handler) throws IOException { return null; 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 a47f582e6c..85db63ecc0 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,7 +19,8 @@ package org.springframework.web.servlet.mvc.support; import java.util.Collection; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.Model; import org.springframework.web.servlet.FlashMap; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java index de09f4be4a..45333a62d2 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/support/RedirectAttributesModelMap.java @@ -19,7 +19,8 @@ package org.springframework.web.servlet.mvc.support; import java.util.Collection; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.ui.ModelMap; import org.springframework.validation.DataBinder; @@ -35,8 +36,7 @@ import org.springframework.validation.DataBinder; @SuppressWarnings("serial") public class RedirectAttributesModelMap extends ModelMap implements RedirectAttributes { - @Nullable - private final DataBinder dataBinder; + private final @Nullable DataBinder dataBinder; private final ModelMap flashAttributes = new ModelMap(); @@ -76,8 +76,7 @@ public class RedirectAttributesModelMap extends ModelMap implements RedirectAttr return this; } - @Nullable - private String formatValue(@Nullable Object value) { + private @Nullable String formatValue(@Nullable Object value) { if (value == null) { return null; } 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 e9c3ee71b8..2d091ef995 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,9 +2,7 @@ * Support package for MVC controllers. * Contains a special HandlerMapping for controller conventions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.mvc.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 d2d213bb3c..c54c449100 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,9 +7,7 @@ * Expert One-On-One J2EE Design and Development * by Rod Johnson (Wrox, 2002). */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 c4228ce0ed..95f0e5b0c1 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 @@ -21,9 +21,9 @@ import java.util.List; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * Base class for {@link org.springframework.web.servlet.resource.ResourceResolver} @@ -38,28 +38,24 @@ public abstract class AbstractResourceResolver implements ResourceResolver { @Override - @Nullable - public Resource resolveResource(@Nullable HttpServletRequest request, String requestPath, + public @Nullable Resource resolveResource(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain) { return resolveResourceInternal(request, requestPath, locations, chain); } @Override - @Nullable - public String resolveUrlPath(String resourceUrlPath, List locations, + public @Nullable String resolveUrlPath(String resourceUrlPath, List locations, ResourceResolverChain chain) { return resolveUrlPathInternal(resourceUrlPath, locations, chain); } - @Nullable - protected abstract Resource resolveResourceInternal(@Nullable HttpServletRequest request, + protected abstract @Nullable Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain); - @Nullable - protected abstract String resolveUrlPathInternal(String resourceUrlPath, + protected abstract @Nullable String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java index 19e14d7fc8..f8f67bc33b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/AbstractVersionStrategy.java @@ -21,8 +21,8 @@ import java.util.regex.Pattern; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -61,8 +61,7 @@ public abstract class AbstractVersionStrategy implements VersionStrategy { @Override - @Nullable - public String extractVersion(String requestPath) { + public @Nullable String extractVersion(String requestPath) { return this.pathStrategy.extractVersion(requestPath); } @@ -91,8 +90,7 @@ public abstract class AbstractVersionStrategy implements VersionStrategy { } @Override - @Nullable - public String extractVersion(String requestPath) { + public @Nullable String extractVersion(String requestPath) { return (requestPath.startsWith(this.prefix) ? this.prefix : null); } @@ -123,8 +121,7 @@ public abstract class AbstractVersionStrategy implements VersionStrategy { private static final Pattern pattern = Pattern.compile("-(\\S*)\\."); @Override - @Nullable - public String extractVersion(String requestPath) { + public @Nullable String extractVersion(String requestPath) { Matcher matcher = pattern.matcher(requestPath); if (matcher.find()) { String match = matcher.group(1); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java index 2bb0178699..57e8dd7091 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java @@ -24,12 +24,12 @@ import java.util.Locale; import java.util.stream.Collectors; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.core.io.Resource; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -107,8 +107,7 @@ public class CachingResourceResolver extends AbstractResourceResolver { @Override - @Nullable - protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, + protected @Nullable Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain) { String key = computeKey(request, requestPath); @@ -139,8 +138,7 @@ public class CachingResourceResolver extends AbstractResourceResolver { return RESOLVED_RESOURCE_CACHE_KEY_PREFIX + requestPath; } - @Nullable - private String getContentCodingKey(HttpServletRequest request) { + private @Nullable String getContentCodingKey(HttpServletRequest request) { String header = request.getHeader(HttpHeaders.ACCEPT_ENCODING); if (!StringUtils.hasText(header)) { return null; @@ -156,8 +154,7 @@ public class CachingResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - protected String resolveUrlPathInternal(String resourceUrlPath, + protected @Nullable String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { String key = RESOLVED_URL_PATH_CACHE_KEY_PREFIX + resourceUrlPath; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java index 96d8673d45..708e25c4dc 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CssLinkResourceTransformer.java @@ -28,9 +28,9 @@ import java.util.TreeSet; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java index d01e9c3344..daecc8a520 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultResourceResolverChain.java @@ -22,9 +22,9 @@ import java.util.List; import java.util.ListIterator; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -35,11 +35,9 @@ import org.springframework.util.Assert; */ class DefaultResourceResolverChain implements ResourceResolverChain { - @Nullable - private final ResourceResolver resolver; + private final @Nullable ResourceResolver resolver; - @Nullable - private final ResourceResolverChain nextChain; + private final @Nullable ResourceResolverChain nextChain; public DefaultResourceResolverChain(@Nullable List resolvers) { @@ -67,8 +65,7 @@ class DefaultResourceResolverChain implements ResourceResolverChain { @Override - @Nullable - public Resource resolveResource( + public @Nullable Resource resolveResource( @Nullable HttpServletRequest request, String requestPath, List locations) { return (this.resolver != null && this.nextChain != null ? @@ -76,8 +73,7 @@ class DefaultResourceResolverChain implements ResourceResolverChain { } @Override - @Nullable - public String resolveUrlPath(String resourcePath, List locations) { + public @Nullable String resolveUrlPath(String resourcePath, List locations) { return (this.resolver != null && this.nextChain != null ? this.resolver.resolveUrlPath(resourcePath, locations, this.nextChain) : null); } 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 340fbc550e..23476e9f05 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 @@ -23,9 +23,9 @@ import java.util.List; import java.util.ListIterator; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -38,11 +38,9 @@ class DefaultResourceTransformerChain implements ResourceTransformerChain { private final ResourceResolverChain resolverChain; - @Nullable - private final ResourceTransformer transformer; + private final @Nullable ResourceTransformer transformer; - @Nullable - private final ResourceTransformerChain nextChain; + private final @Nullable ResourceTransformerChain nextChain; public DefaultResourceTransformerChain( diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultServletHttpRequestHandler.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultServletHttpRequestHandler.java index 2147c185e9..72846f0022 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultServletHttpRequestHandler.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/DefaultServletHttpRequestHandler.java @@ -24,8 +24,8 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.HttpRequestHandler; @@ -67,11 +67,9 @@ public class DefaultServletHttpRequestHandler implements HttpRequestHandler, Ser private static final String WEBSPHERE_DEFAULT_SERVLET_NAME = "SimpleFileServlet"; - @Nullable - private String defaultServletName; + private @Nullable String defaultServletName; - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java index c3c2c452b7..1c12a73c6d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/EncodedResourceResolver.java @@ -32,11 +32,11 @@ import java.util.Locale; import java.util.Map; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; 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.Assert; /** @@ -130,8 +130,7 @@ public class EncodedResourceResolver extends AbstractResourceResolver { @Override - @Nullable - protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, + protected @Nullable Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain) { Resource resource = chain.resolveResource(request, requestPath, locations); @@ -164,8 +163,7 @@ public class EncodedResourceResolver extends AbstractResourceResolver { return resource; } - @Nullable - private String getAcceptEncoding(HttpServletRequest request) { + private @Nullable String getAcceptEncoding(HttpServletRequest request) { String header = request.getHeader(HttpHeaders.ACCEPT_ENCODING); return (header != null ? header.toLowerCase(Locale.ROOT) : null); } @@ -179,8 +177,7 @@ public class EncodedResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - protected String resolveUrlPathInternal(String resourceUrlPath, + protected @Nullable String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { return chain.resolveUrlPath(resourceUrlPath, locations); @@ -275,8 +272,7 @@ public class EncodedResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.original.getFilename(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java index dc132502f1..a83af81321 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java @@ -19,10 +19,10 @@ package org.springframework.web.servlet.resource; import java.util.List; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.webjars.WebJarVersionLocator; 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 @@ -67,8 +67,7 @@ public class LiteWebJarsResourceResolver extends AbstractResourceResolver { @Override - @Nullable - protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, + protected @Nullable Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain) { Resource resolved = chain.resolveResource(request, requestPath, locations); @@ -82,8 +81,7 @@ public class LiteWebJarsResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - protected String resolveUrlPathInternal(String resourceUrlPath, + protected @Nullable String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { String path = chain.resolveUrlPath(resourceUrlPath, locations); @@ -96,8 +94,7 @@ public class LiteWebJarsResourceResolver extends AbstractResourceResolver { return path; } - @Nullable - protected String findWebJarResourcePath(String path) { + protected @Nullable String findWebJarResourcePath(String path) { int endOffset = path.indexOf('/', 1); if (endOffset != -1) { int startOffset = (path.startsWith("/") ? 1 : 0); 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 2b20a100e2..4663426418 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 @@ -27,12 +27,12 @@ import java.util.Map; import java.util.StringTokenizer; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.core.log.LogFormatUtils; import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.util.ServletRequestPathUtils; import org.springframework.web.util.UriUtils; @@ -52,13 +52,11 @@ import org.springframework.web.util.UrlPathHelper; */ public class PathResourceResolver extends AbstractResourceResolver { - @Nullable - private Resource[] allowedLocations; + private Resource @Nullable [] allowedLocations; private final Map locationCharsets = new HashMap<>(4); - @Nullable - private UrlPathHelper urlPathHelper; + private @Nullable UrlPathHelper urlPathHelper; /** @@ -78,12 +76,11 @@ public class PathResourceResolver extends AbstractResourceResolver { * @since 4.1.2 * @see ResourceHttpRequestHandler#initAllowedLocations() */ - public void setAllowedLocations(@Nullable Resource... locations) { + public void setAllowedLocations(Resource @Nullable ... locations) { this.allowedLocations = locations; } - @Nullable - public Resource[] getAllowedLocations() { + public Resource @Nullable [] getAllowedLocations() { return this.allowedLocations; } @@ -123,31 +120,27 @@ public class PathResourceResolver extends AbstractResourceResolver { * The configured {@link UrlPathHelper}. * @since 4.3.13 */ - @Nullable - public UrlPathHelper getUrlPathHelper() { + public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @Override - @Nullable - protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, + protected @Nullable Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain) { return getResource(requestPath, request, locations); } @Override - @Nullable - protected String resolveUrlPathInternal(String resourcePath, List locations, + protected @Nullable String resolveUrlPathInternal(String resourcePath, List locations, ResourceResolverChain chain) { return (StringUtils.hasText(resourcePath) && getResource(resourcePath, null, locations) != null ? resourcePath : null); } - @Nullable - private Resource getResource(String resourcePath, @Nullable HttpServletRequest request, + private @Nullable Resource getResource(String resourcePath, @Nullable HttpServletRequest request, List locations) { for (Resource location : locations) { @@ -181,8 +174,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 { + protected @Nullable Resource getResource(String resourcePath, Resource location) throws IOException { Resource resource = location.createRelative(resourcePath); if (resource.isReadable()) { if (checkResource(resource, location)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java index 928b040d3b..f4d80c2b0e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHandlerUtils.java @@ -22,12 +22,12 @@ import java.nio.charset.StandardCharsets; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; import org.springframework.core.io.UrlResource; import org.springframework.core.log.LogFormatUtils; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; 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 aa38801ed9..f9ffc15eb7 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 @@ -30,6 +30,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.InitializingBean; import org.springframework.context.ApplicationContext; @@ -45,7 +46,6 @@ 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; @@ -113,38 +113,29 @@ public class ResourceHttpRequestHandler extends WebContentGenerator private final List resourceTransformers = new ArrayList<>(4); - @Nullable - private ResourceResolverChain resolverChain; + private @Nullable ResourceResolverChain resolverChain; - @Nullable - private ResourceTransformerChain transformerChain; + private @Nullable ResourceTransformerChain transformerChain; - @Nullable - private ResourceHttpMessageConverter resourceHttpMessageConverter; + private @Nullable ResourceHttpMessageConverter resourceHttpMessageConverter; - @Nullable - private ResourceRegionHttpMessageConverter resourceRegionHttpMessageConverter; + private @Nullable ResourceRegionHttpMessageConverter resourceRegionHttpMessageConverter; - @Nullable - private ContentNegotiationManager contentNegotiationManager; + private @Nullable ContentNegotiationManager contentNegotiationManager; private final Map mediaTypes = new HashMap<>(4); - @Nullable - private CorsConfiguration corsConfiguration; + private @Nullable CorsConfiguration corsConfiguration; - @Nullable - private UrlPathHelper urlPathHelper; + private @Nullable UrlPathHelper urlPathHelper; private boolean useLastModified = true; - @Nullable - private Function etagGenerator; + private @Nullable Function etagGenerator; private boolean optimizeLocations = false; - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; public ResourceHttpRequestHandler() { @@ -257,8 +248,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * Return the configured resource converter. * @since 4.3 */ - @Nullable - public ResourceHttpMessageConverter getResourceHttpMessageConverter() { + public @Nullable ResourceHttpMessageConverter getResourceHttpMessageConverter() { return this.resourceHttpMessageConverter; } @@ -275,8 +265,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * Return the configured resource region converter. * @since 4.3 */ - @Nullable - public ResourceRegionHttpMessageConverter getResourceRegionHttpMessageConverter() { + public @Nullable ResourceRegionHttpMessageConverter getResourceRegionHttpMessageConverter() { return this.resourceRegionHttpMessageConverter; } @@ -316,8 +305,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * Return the specified CORS configuration. */ @Override - @Nullable - public CorsConfiguration getCorsConfiguration(HttpServletRequest request) { + public @Nullable CorsConfiguration getCorsConfiguration(HttpServletRequest request) { return this.corsConfiguration; } @@ -335,8 +323,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * The configured {@link UrlPathHelper}. * @since 4.3.13 */ - @Nullable - public UrlPathHelper getUrlPathHelper() { + public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @@ -379,8 +366,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator * @return the HTTP ETag generator function * @since 6.1 */ - @Nullable - public Function getEtagGenerator() { + public @Nullable Function getEtagGenerator() { return this.etagGenerator; } @@ -585,8 +571,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator } } - @Nullable - protected Resource getResource(HttpServletRequest request) throws IOException { + protected @Nullable Resource getResource(HttpServletRequest request) throws IOException { String path = getPath(request); path = processPath(path); if (ResourceHandlerUtils.shouldIgnoreInputPath(path) || isInvalidPath(path)) { @@ -644,8 +629,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) { + protected @Nullable MediaType getMediaType(HttpServletRequest request, Resource resource) { MediaType result = null; String mimeType = request.getServletContext().getMimeType(resource.getFilename()); if (StringUtils.hasText(mimeType)) { 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 f4417b9287..c315c38f26 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 @@ -19,9 +19,9 @@ package org.springframework.web.servlet.resource; import java.util.List; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * A strategy for resolving a request to a server-side resource. @@ -47,8 +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(@Nullable HttpServletRequest request, String requestPath, + @Nullable Resource resolveResource(@Nullable HttpServletRequest request, String requestPath, List locations, ResourceResolverChain chain); /** @@ -61,7 +60,6 @@ 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); + @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 678164977e..dba86069f7 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 @@ -19,9 +19,9 @@ package org.springframework.web.servlet.resource; import java.util.List; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; /** * A contract for invoking a chain of {@link ResourceResolver ResourceResolvers} where each resolver @@ -42,8 +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( + @Nullable Resource resolveResource( @Nullable HttpServletRequest request, String requestPath, List locations); /** @@ -55,7 +54,6 @@ 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); + @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 4ebe289956..e4b948a8cb 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 @@ -19,9 +19,9 @@ package org.springframework.web.servlet.resource; import java.util.Collections; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -36,8 +36,7 @@ import org.springframework.util.StringUtils; */ public abstract class ResourceTransformerSupport implements ResourceTransformer { - @Nullable - private ResourceUrlProvider resourceUrlProvider; + private @Nullable ResourceUrlProvider resourceUrlProvider; /** @@ -53,8 +52,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer /** * Return the configured {@code ResourceUrlProvider}. */ - @Nullable - public ResourceUrlProvider getResourceUrlProvider() { + public @Nullable ResourceUrlProvider getResourceUrlProvider() { return this.resourceUrlProvider; } @@ -70,8 +68,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer * @param transformerChain the transformer chain * @return the resolved URL, or {@code} if not resolvable */ - @Nullable - protected String resolveUrlPath(String resourcePath, HttpServletRequest request, + protected @Nullable String resolveUrlPath(String resourcePath, HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) { if (resourcePath.startsWith("/")) { @@ -105,8 +102,7 @@ public abstract class ResourceTransformerSupport implements ResourceTransformer return StringUtils.cleanPath(absolutePath); } - @Nullable - private ResourceUrlProvider findResourceUrlProvider(HttpServletRequest request) { + private @Nullable ResourceUrlProvider findResourceUrlProvider(HttpServletRequest request) { if (this.resourceUrlProvider != null) { return this.resourceUrlProvider; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index 5bd3de0c6d..ea5eac1ef4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -28,8 +28,8 @@ import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponseWrapper; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; import org.springframework.web.filter.GenericFilterBean; import org.springframework.web.util.UrlPathHelper; @@ -69,11 +69,9 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { private static class ResourceUrlEncodingRequestWrapper extends HttpServletRequestWrapper { - @Nullable - private ResourceUrlProvider resourceUrlProvider; + private @Nullable ResourceUrlProvider resourceUrlProvider; - @Nullable - private Integer indexLookupPath; + private @Nullable Integer indexLookupPath; private String prefixLookupPath = ""; @@ -112,8 +110,7 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { } } - @Nullable - public String resolveUrlPath(String url) { + public @Nullable String resolveUrlPath(String url) { if (this.resourceUrlProvider == null) { logger.trace("ResourceUrlProvider not available via request attribute " + ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR); 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 688bd03244..19896a4d06 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 @@ -25,13 +25,13 @@ import java.util.Map; import jakarta.servlet.http.HttpServletRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; -import org.springframework.lang.Nullable; import org.springframework.util.AntPathMatcher; import org.springframework.util.PathMatcher; import org.springframework.util.StringUtils; @@ -55,8 +55,7 @@ public class ResourceUrlProvider implements ApplicationListener= suffixIndex) { @@ -218,9 +216,8 @@ public class ResourceUrlProvider implements ApplicationListener locations, ResourceResolverChain chain) { Resource resolved = chain.resolveResource(request, requestPath, locations); @@ -196,8 +195,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - protected String resolveUrlPathInternal(String resourceUrlPath, + protected @Nullable String resolveUrlPathInternal(String resourceUrlPath, List locations, ResourceResolverChain chain) { String baseUrl = chain.resolveUrlPath(resourceUrlPath, locations); @@ -218,8 +216,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) { + protected @Nullable VersionStrategy getStrategyForPath(String requestPath) { String path = "/".concat(requestPath); List matchingPatterns = new ArrayList<>(); for (String pattern : this.versionStrategyMap.keySet()) { @@ -318,8 +315,7 @@ public class VersionResourceResolver extends AbstractResourceResolver { } @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.original.getFilename(); } 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 720ebf1338..af4537d055 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,9 +1,7 @@ /** * Support classes for serving static resources. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.resource; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; 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 6d72dfb2cc..e02c8c7641 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,7 +16,8 @@ package org.springframework.web.servlet.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; @@ -51,8 +52,7 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * Returns {@code null} if {@link #getRootConfigClasses()} returns {@code null}. */ @Override - @Nullable - protected WebApplicationContext createRootApplicationContext() { + protected @Nullable WebApplicationContext createRootApplicationContext() { Class[] configClasses = getRootConfigClasses(); if (!ObjectUtils.isEmpty(configClasses)) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); @@ -85,8 +85,7 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * @return the configuration for the root application context, or {@code null} * if creation and registration of a root context is not desired */ - @Nullable - protected abstract Class[] getRootConfigClasses(); + protected abstract Class @Nullable [] getRootConfigClasses(); /** * Specify {@code @Configuration} and/or {@code @Component} classes for the @@ -94,7 +93,6 @@ public abstract class AbstractAnnotationConfigDispatcherServletInitializer * @return the configuration for the Servlet application context, or * {@code null} if all configuration is specified through root config classes. */ - @Nullable - protected abstract Class[] getServletConfigClasses(); + protected abstract Class @Nullable [] 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 44559ce60b..00335f0f09 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 @@ -25,10 +25,10 @@ import jakarta.servlet.FilterRegistration.Dynamic; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletRegistration; +import org.jspecify.annotations.Nullable; 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.util.StringUtils; @@ -144,8 +144,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte * @see DispatcherServlet#setContextInitializers * @see #getRootApplicationContextInitializers() */ - @Nullable - protected ApplicationContextInitializer[] getServletApplicationContextInitializers() { + protected ApplicationContextInitializer @Nullable [] getServletApplicationContextInitializers() { return null; } @@ -161,8 +160,7 @@ public abstract class AbstractDispatcherServletInitializer extends AbstractConte * @return an array of filters or {@code null} * @see #registerServletFilter(ServletContext, Filter) */ - @Nullable - protected Filter[] getServletFilters() { + protected Filter @Nullable [] 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 38ee6c19df..788e251c4e 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 @@ -26,8 +26,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -89,8 +89,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { @Override - @Nullable - public final FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response) { + public final @Nullable FlashMap retrieveAndUpdate(HttpServletRequest request, HttpServletResponse response) { List allFlashMaps = retrieveFlashMaps(request); if (CollectionUtils.isEmpty(allFlashMaps)) { return null; @@ -139,8 +138,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) { + private @Nullable FlashMap getMatchingFlashMap(List allMaps, HttpServletRequest request) { List result = new ArrayList<>(); for (FlashMap flashMap : allMaps) { if (isFlashMapForRequest(flashMap, request)) { @@ -218,8 +216,7 @@ public abstract class AbstractFlashMapManager implements FlashMapManager { } } - @Nullable - private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) { + private @Nullable String decodeAndNormalizePath(@Nullable String path, HttpServletRequest request) { if (StringUtils.hasLength(path)) { path = getUrlPathHelper().decodeRequestString(request, path); if (path.charAt(0) != '/') { @@ -236,8 +233,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); + protected abstract @Nullable List retrieveFlashMaps(HttpServletRequest request); /** * Update the FlashMap instances in the underlying storage. @@ -258,8 +254,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) { + protected @Nullable 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 aea93c608a..77c793d1a3 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 @@ -20,10 +20,11 @@ import java.beans.PropertyEditor; import java.util.Arrays; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; import org.springframework.context.NoSuchMessageException; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; import org.springframework.validation.BindingResult; @@ -55,34 +56,25 @@ public class BindStatus { private final boolean htmlEscape; - @Nullable - private final String expression; + private final @Nullable String expression; - @Nullable - private final Errors errors; + private final @Nullable Errors errors; private final String[] errorCodes; - @Nullable - private String[] errorMessages; + private String @Nullable [] errorMessages; - @Nullable - private List objectErrors; + private @Nullable List objectErrors; - @Nullable - private Object value; + private @Nullable Object value; - @Nullable - private Class valueType; + private @Nullable Class valueType; - @Nullable - private Object actualValue; + private @Nullable Object actualValue; - @Nullable - private PropertyEditor editor; + private @Nullable PropertyEditor editor; - @Nullable - private BindingResult bindingResult; + private @Nullable BindingResult bindingResult; /** @@ -196,8 +188,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() { + public @Nullable String getExpression() { return this.expression; } @@ -207,8 +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() { + public @Nullable Object getValue() { return this.value; } @@ -217,8 +207,7 @@ public class BindStatus { * '{@code getValue().getClass()}' since '{@code getValue()}' may * return '{@code null}'. */ - @Nullable - public Class getValueType() { + public @Nullable Class getValueType() { return this.valueType; } @@ -226,8 +215,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() { + public @Nullable Object getActualValue() { return this.actualValue; } @@ -321,8 +309,7 @@ public class BindStatus { * @return the current Errors instance, or {@code null} if none * @see org.springframework.validation.BindingResult */ - @Nullable - public Errors getErrors() { + public @Nullable Errors getErrors() { return this.errors; } @@ -331,8 +318,7 @@ public class BindStatus { * is currently bound to. * @return the current PropertyEditor, or {@code null} if none */ - @Nullable - public PropertyEditor getEditor() { + public @Nullable PropertyEditor getEditor() { return this.editor; } @@ -342,8 +328,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) { + public @Nullable 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 7287685a30..f650221368 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 @@ -24,8 +24,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.PageContext; import jakarta.servlet.jsp.jstl.core.Config; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * JSP-aware (and JSTL-aware) subclass of RequestContext, allowing for @@ -95,8 +94,7 @@ public class JspAwareRequestContext extends RequestContext { * request, session or application scope; if not found, returns {@code null}. */ @Override - @Nullable - protected TimeZone getFallbackTimeZone() { + protected @Nullable TimeZone getFallbackTimeZone() { if (jstlPresent) { TimeZone timeZone = JstlPageLocaleResolver.getJstlTimeZone(getPageContext()); if (timeZone != null) { @@ -113,14 +111,12 @@ public class JspAwareRequestContext extends RequestContext { */ private static class JstlPageLocaleResolver { - @Nullable - public static Locale getJstlLocale(PageContext pageContext) { + public static @Nullable Locale getJstlLocale(PageContext pageContext) { Object localeObject = Config.find(pageContext, Config.FMT_LOCALE); return (localeObject instanceof Locale locale ? locale : null); } - @Nullable - public static TimeZone getJstlTimeZone(PageContext pageContext) { + public static @Nullable TimeZone getJstlTimeZone(PageContext pageContext) { Object timeZoneObject = Config.find(pageContext, Config.FMT_TIME_ZONE); return (timeZoneObject instanceof TimeZone timeZone ? timeZone : null); } 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 25cb945b6a..aecd51efe0 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 @@ -25,11 +25,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpSession; import jakarta.servlet.jsp.jstl.core.Config; import jakarta.servlet.jsp.jstl.fmt.LocalizationContext; +import org.jspecify.annotations.Nullable; 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, 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 f1869b4330..b91631fd77 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 @@ -27,6 +27,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.jsp.jstl.core.Config; +import org.jspecify.annotations.Nullable; import org.springframework.context.MessageSource; import org.springframework.context.MessageSourceResolvable; @@ -34,7 +35,6 @@ 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.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.StringUtils; @@ -95,37 +95,28 @@ public class RequestContext { private final HttpServletRequest request; - @Nullable - private final HttpServletResponse response; + private final @Nullable HttpServletResponse response; - @Nullable - private final Map model; + private final @Nullable Map model; private final WebApplicationContext webApplicationContext; - @Nullable - private Locale locale; + private @Nullable Locale locale; - @Nullable - private TimeZone timeZone; + private @Nullable TimeZone timeZone; @Deprecated - @Nullable - private org.springframework.ui.context.Theme theme; + private org.springframework.ui.context.@Nullable Theme theme; - @Nullable - private Boolean defaultHtmlEscape; + private @Nullable Boolean defaultHtmlEscape; - @Nullable - private final Boolean responseEncodedHtmlEscape; + private final @Nullable Boolean responseEncodedHtmlEscape; private UrlPathHelper urlPathHelper; - @Nullable - private RequestDataValueProcessor requestDataValueProcessor; + private @Nullable RequestDataValueProcessor requestDataValueProcessor; - @Nullable - private Map errorsMap; + private @Nullable Map errorsMap; /** @@ -269,8 +260,7 @@ public class RequestContext { /** * Return the underlying ServletContext. Only intended for cooperating classes in this package. */ - @Nullable - protected final ServletContext getServletContext() { + protected final @Nullable ServletContext getServletContext() { return this.webApplicationContext.getServletContext(); } @@ -285,8 +275,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() { + public final @Nullable Map getModel() { return this.model; } @@ -315,8 +304,7 @@ public class RequestContext { * Also includes a fallback check for JSTL's TimeZone attribute. * @see RequestContextUtils#getTimeZone */ - @Nullable - public TimeZone getTimeZone() { + public @Nullable TimeZone getTimeZone() { return (this.timeZone != null ? this.timeZone : getFallbackTimeZone()); } @@ -343,8 +331,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() { + protected @Nullable TimeZone getFallbackTimeZone() { if (jstlPresent) { TimeZone timeZone = JstlLocaleResolver.getJstlTimeZone(getRequest(), getServletContext()); if (timeZone != null) { @@ -435,7 +422,7 @@ public class RequestContext { * @deprecated as of 6.0, with no direct replacement */ @Deprecated(since = "6.0") - public void changeTheme(@Nullable org.springframework.ui.context.Theme theme) { + public void changeTheme(org.springframework.ui.context.@Nullable Theme theme) { org.springframework.web.servlet.ThemeResolver themeResolver = RequestContextUtils.getThemeResolver(this.request); if (themeResolver == null) { throw new IllegalStateException("Cannot change theme if no ThemeResolver configured"); @@ -483,8 +470,7 @@ public class RequestContext { * Return the default HTML escape setting, differentiating between no default specified and an explicit value. * @return whether default HTML escaping is enabled (null = no explicit default) */ - @Nullable - public Boolean getDefaultHtmlEscape() { + public @Nullable Boolean getDefaultHtmlEscape() { return this.defaultHtmlEscape; } @@ -504,8 +490,7 @@ public class RequestContext { * @return whether default use of response encoding HTML escaping is enabled (null = no explicit default) * @since 4.1.2 */ - @Nullable - public Boolean getResponseEncodedHtmlEscape() { + public @Nullable Boolean getResponseEncodedHtmlEscape() { return this.responseEncodedHtmlEscape; } @@ -534,8 +519,7 @@ public class RequestContext { * WebApplicationContext under the name {@code "requestDataValueProcessor"}. * Or {@code null} if no matching bean was found. */ - @Nullable - public RequestDataValueProcessor getRequestDataValueProcessor() { + public @Nullable RequestDataValueProcessor getRequestDataValueProcessor() { return this.requestDataValueProcessor; } @@ -639,7 +623,7 @@ public class RequestContext { * @param defaultMessage the String to return if the lookup fails * @return the message */ - public String getMessage(String code, @Nullable Object[] args, String defaultMessage) { + public String getMessage(String code, Object @Nullable [] args, String defaultMessage) { return getMessage(code, args, defaultMessage, isDefaultHtmlEscape()); } @@ -662,7 +646,7 @@ public class RequestContext { * @param htmlEscape if the message should be HTML-escaped * @return the message */ - public String getMessage(String code, @Nullable Object[] args, String defaultMessage, boolean htmlEscape) { + public String getMessage(String code, Object @Nullable [] args, String defaultMessage, boolean htmlEscape) { String msg = getMessageSource().getMessage(code, args, defaultMessage, getLocale()); if (msg == null) { return ""; @@ -687,7 +671,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args) throws NoSuchMessageException { return getMessage(code, args, isDefaultHtmlEscape()); } @@ -710,7 +694,7 @@ public class RequestContext { * @return the message * @throws org.springframework.context.NoSuchMessageException if not found */ - public String getMessage(String code, @Nullable Object[] args, boolean htmlEscape) throws NoSuchMessageException { + public String getMessage(String code, Object @Nullable [] args, boolean htmlEscape) throws NoSuchMessageException { String msg = getMessageSource().getMessage(code, args, getLocale()); return (htmlEscape ? HtmlUtils.htmlEscape(msg) : msg); } @@ -763,7 +747,7 @@ public class RequestContext { * @deprecated as of 6.0, with no direct replacement */ @Deprecated - public String getThemeMessage(String code, @Nullable Object[] args, String defaultMessage) { + public String getThemeMessage(String code, Object @Nullable [] args, String defaultMessage) { String msg = getTheme().getMessageSource().getMessage(code, args, defaultMessage, getLocale()); return (msg != null ? msg : ""); } @@ -810,7 +794,7 @@ public class RequestContext { * @deprecated as of 6.0, with no direct replacement */ @Deprecated - public String getThemeMessage(String code, @Nullable Object[] args) throws NoSuchMessageException { + public String getThemeMessage(String code, Object @Nullable [] args) throws NoSuchMessageException { return getTheme().getMessageSource().getMessage(code, args, getLocale()); } @@ -848,8 +832,7 @@ public class RequestContext { * @param name the name of the bind object * @return the Errors instance, or {@code null} if not found */ - @Nullable - public Errors getErrors(String name) { + public @Nullable Errors getErrors(String name) { return getErrors(name, isDefaultHtmlEscape()); } @@ -859,8 +842,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) { + public @Nullable Errors getErrors(String name, boolean htmlEscape) { if (this.errorsMap == null) { this.errorsMap = new HashMap<>(); } @@ -897,8 +879,7 @@ public class RequestContext { * @param modelName the name of the model object * @return the model object */ - @Nullable - protected Object getModelObject(String modelName) { + protected @Nullable Object getModelObject(String modelName) { if (this.model != null) { return this.model.get(modelName); } @@ -935,8 +916,7 @@ public class RequestContext { */ private static class JstlLocaleResolver { - @Nullable - public static Locale getJstlLocale(HttpServletRequest request, @Nullable ServletContext servletContext) { + public static @Nullable Locale getJstlLocale(HttpServletRequest request, @Nullable ServletContext servletContext) { Object localeObject = Config.get(request, Config.FMT_LOCALE); if (localeObject == null) { HttpSession session = request.getSession(false); @@ -950,8 +930,7 @@ public class RequestContext { return (localeObject instanceof Locale locale ? locale : null); } - @Nullable - public static TimeZone getJstlTimeZone(HttpServletRequest request, @Nullable ServletContext servletContext) { + public static @Nullable TimeZone getJstlTimeZone(HttpServletRequest request, @Nullable ServletContext servletContext) { Object timeZoneObject = Config.get(request, Config.FMT_TIME_ZONE); if (timeZoneObject == null) { HttpSession session = request.getSession(false); 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 7f438a03b0..c1c7aa87a6 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 @@ -24,10 +24,10 @@ import jakarta.servlet.ServletContext; import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.context.i18n.LocaleContext; import org.springframework.context.i18n.TimeZoneAwareLocaleContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.web.context.ContextLoader; @@ -80,8 +80,7 @@ public abstract class RequestContextUtils { * @see WebApplicationContextUtils#getWebApplicationContext(ServletContext) * @see ContextLoader#getCurrentWebApplicationContext() */ - @Nullable - public static WebApplicationContext findWebApplicationContext( + public static @Nullable WebApplicationContext findWebApplicationContext( HttpServletRequest request, @Nullable ServletContext servletContext) { WebApplicationContext webApplicationContext = (WebApplicationContext) request.getAttribute( @@ -110,8 +109,7 @@ public abstract class RequestContextUtils { * @see ServletRequest#getServletContext() * @see ContextLoader#getCurrentWebApplicationContext() */ - @Nullable - public static WebApplicationContext findWebApplicationContext(HttpServletRequest request) { + public static @Nullable WebApplicationContext findWebApplicationContext(HttpServletRequest request) { return findWebApplicationContext(request, request.getServletContext()); } @@ -121,8 +119,7 @@ public abstract class RequestContextUtils { * @param request current HTTP request * @return the current {@code LocaleResolver}, or {@code null} if not found */ - @Nullable - public static LocaleResolver getLocaleResolver(HttpServletRequest request) { + public static @Nullable LocaleResolver getLocaleResolver(HttpServletRequest request) { return (LocaleResolver) request.getAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE); } @@ -165,8 +162,7 @@ public abstract class RequestContextUtils { * @see #getLocaleResolver * @see org.springframework.context.i18n.LocaleContextHolder#getTimeZone() */ - @Nullable - public static TimeZone getTimeZone(HttpServletRequest request) { + public static @Nullable TimeZone getTimeZone(HttpServletRequest request) { LocaleResolver localeResolver = getLocaleResolver(request); if (localeResolver instanceof LocaleContextResolver localeContextResolver) { LocaleContext localeContext = localeContextResolver.resolveLocaleContext(request); @@ -184,9 +180,8 @@ public abstract class RequestContextUtils { * @return the current ThemeResolver, or {@code null} if not found * @deprecated as of 6.0, with no direct replacement */ - @Nullable @Deprecated(since = "6.0") - public static org.springframework.web.servlet.ThemeResolver getThemeResolver(HttpServletRequest request) { + public static org.springframework.web.servlet.@Nullable ThemeResolver getThemeResolver(HttpServletRequest request) { return (org.springframework.web.servlet.ThemeResolver) request.getAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE); } @@ -197,9 +192,8 @@ public abstract class RequestContextUtils { * @return the current ThemeSource * @deprecated as of 6.0, with no direct replacement */ - @Nullable @Deprecated(since = "6.0") - public static org.springframework.ui.context.ThemeSource getThemeSource(HttpServletRequest request) { + public static org.springframework.ui.context.@Nullable ThemeSource getThemeSource(HttpServletRequest request) { return (org.springframework.ui.context.ThemeSource) request.getAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE); } @@ -211,9 +205,8 @@ public abstract class RequestContextUtils { * @see #getThemeResolver * @deprecated as of 6.0, with no direct replacement */ - @Nullable @Deprecated(since = "6.0") - public static org.springframework.ui.context.Theme getTheme(HttpServletRequest request) { + public static org.springframework.ui.context.@Nullable Theme getTheme(HttpServletRequest request) { org.springframework.web.servlet.ThemeResolver themeResolver = getThemeResolver(request); org.springframework.ui.context.ThemeSource themeSource = getThemeSource(request); if (themeResolver != null && themeSource != null) { @@ -232,8 +225,7 @@ public abstract class RequestContextUtils { * @see FlashMap */ @SuppressWarnings("unchecked") - @Nullable - public static Map getInputFlashMap(HttpServletRequest request) { + public static @Nullable Map getInputFlashMap(HttpServletRequest request) { return (Map) request.getAttribute(DispatcherServlet.INPUT_FLASH_MAP_ATTRIBUTE); } @@ -255,8 +247,7 @@ public abstract class RequestContextUtils { * @return a {@link FlashMapManager} instance, never {@code null} within a * {@code DispatcherServlet}-handled request */ - @Nullable - public static FlashMapManager getFlashMapManager(HttpServletRequest request) { + public static @Nullable FlashMapManager getFlashMapManager(HttpServletRequest request) { return (FlashMapManager) request.getAttribute(DispatcherServlet.FLASH_MAP_MANAGER_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 dba3274455..d92e7dee84 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 @@ -19,8 +19,7 @@ package org.springframework.web.servlet.support; import java.util.Map; import jakarta.servlet.http.HttpServletRequest; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A contract for inspecting and potentially modifying request data values such @@ -64,8 +63,7 @@ public interface RequestDataValueProcessor { * @param request the current request * @return additional hidden form fields to be added, or {@code null} if none */ - @Nullable - Map getExtraHiddenFields(HttpServletRequest request); + @Nullable Map getExtraHiddenFields(HttpServletRequest request); /** * Invoked when a URL is about to be rendered or redirected to. 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 55041f924e..6098a428e1 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,8 +17,8 @@ package org.springframework.web.servlet.support; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.context.request.RequestAttributes; @@ -44,8 +44,7 @@ import org.springframework.web.util.UrlPathHelper; */ public class ServletUriComponentsBuilder extends UriComponentsBuilder { - @Nullable - private String originalPath; + private @Nullable String originalPath; /** @@ -201,8 +200,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() { + public @Nullable String removePathExtension() { String extension = null; if (this.originalPath != null) { extension = UriUtils.extractFileExtension(this.originalPath); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/SessionFlashMapManager.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/SessionFlashMapManager.java index faf981da87..2880d324d3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/SessionFlashMapManager.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/SessionFlashMapManager.java @@ -21,8 +21,8 @@ import java.util.List; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.servlet.FlashMap; import org.springframework.web.util.WebUtils; @@ -43,8 +43,7 @@ public class SessionFlashMapManager extends AbstractFlashMapManager { */ @Override @SuppressWarnings("unchecked") - @Nullable - protected List retrieveFlashMaps(HttpServletRequest request) { + protected @Nullable List retrieveFlashMaps(HttpServletRequest request) { HttpSession session = request.getSession(false); return (session != null ? (List) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java index cd63dd63fb..4f5a3f7907 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/support/WebContentGenerator.java @@ -27,11 +27,11 @@ import java.util.concurrent.TimeUnit; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import org.jspecify.annotations.Nullable; import org.springframework.http.CacheControl; import org.springframework.http.HttpHeaders; 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; @@ -73,21 +73,17 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { /** Set of supported HTTP methods. */ - @Nullable - private Set supportedMethods; + private @Nullable Set supportedMethods; - @Nullable - private String allowHeader; + private @Nullable String allowHeader; private boolean requireSession = false; - @Nullable - private CacheControl cacheControl; + private @Nullable CacheControl cacheControl; private int cacheSeconds = -1; - @Nullable - private String[] varyByRequestHeaders; + private String @Nullable [] varyByRequestHeaders; /** @@ -128,7 +124,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { *

    Default is GET, HEAD and POST for simple form controller types; * unrestricted for general controllers and interceptors. */ - public final void setSupportedMethods(@Nullable String... methods) { + public final void setSupportedMethods(String @Nullable ... methods) { if (!ObjectUtils.isEmpty(methods)) { this.supportedMethods = new LinkedHashSet<>(Arrays.asList(methods)); } @@ -141,8 +137,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { /** * Return the HTTP methods that this content generator supports. */ - @Nullable - public final String[] getSupportedMethods() { + public final String @Nullable [] getSupportedMethods() { return (this.supportedMethods != null ? StringUtils.toStringArray(this.supportedMethods) : null); } @@ -176,8 +171,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { * call to {@link #checkRequest(HttpServletRequest)}. * @since 4.3 */ - @Nullable - protected String getAllowHeader() { + protected @Nullable String getAllowHeader() { return this.allowHeader; } @@ -209,8 +203,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { * that builds the Cache-Control HTTP response header. * @since 4.2 */ - @Nullable - public final CacheControl getCacheControl() { + public final @Nullable CacheControl getCacheControl() { return this.cacheControl; } @@ -246,7 +239,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { * @param varyByRequestHeaders one or more request header names * @since 4.3 */ - public final void setVaryByRequestHeaders(@Nullable String... varyByRequestHeaders) { + public final void setVaryByRequestHeaders(String @Nullable ... varyByRequestHeaders) { this.varyByRequestHeaders = varyByRequestHeaders; } @@ -254,8 +247,7 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport { * Return the configured request header names for the "Vary" response header. * @since 4.3 */ - @Nullable - public final String[] getVaryByRequestHeaders() { + public final String @Nullable [] getVaryByRequestHeaders() { return this.varyByRequestHeaders; } 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 39d4c2153f..300ebe5b93 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,9 +3,7 @@ * Provides easy evaluation of the request context in views, * and miscellaneous HandlerInterceptor implementations. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.support; -import org.springframework.lang.NonNullApi; -import org.springframework.lang.NonNullFields; +import org.jspecify.annotations.NullMarked; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentAware.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentAware.java index 6e00296c1b..7239e2ca8f 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentAware.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentAware.java @@ -17,8 +17,7 @@ package org.springframework.web.servlet.tags; import jakarta.servlet.jsp.JspTagException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Allows implementing tag to utilize nested {@code spring:argument} tags. diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentTag.java index 84ba71c1f7..56e27d157d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ArgumentTag.java @@ -18,8 +18,7 @@ package org.springframework.web.servlet.tags; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.tagext.BodyTagSupport; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * The {@code } tag is based on the JSTL {@code fmt:param} tag. @@ -55,8 +54,7 @@ import org.springframework.lang.Nullable; @SuppressWarnings("serial") public class ArgumentTag extends BodyTagSupport { - @Nullable - private Object value; + private @Nullable Object value; private boolean valueSet; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java index 75042ea510..4c6c128921 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/BindErrorsTag.java @@ -19,8 +19,8 @@ package org.springframework.web.servlet.tags; import jakarta.servlet.ServletException; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.validation.Errors; /** @@ -74,8 +74,7 @@ public class BindErrorsTag extends HtmlEscapingAwareTag { private String name = ""; - @Nullable - private Errors errors; + private @Nullable Errors errors; /** @@ -115,8 +114,7 @@ public class BindErrorsTag extends HtmlEscapingAwareTag { * Retrieve the Errors instance that this tag is currently bound to. *

    Intended for cooperating nesting tags. */ - @Nullable - public final Errors getErrors() { + public final @Nullable Errors getErrors() { return this.errors; } 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 3ed8806ff9..1e6ffaff68 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 @@ -20,8 +20,8 @@ import java.beans.PropertyEditor; import jakarta.servlet.jsp.JspTagException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.validation.Errors; import org.springframework.web.servlet.support.BindStatus; @@ -97,14 +97,11 @@ public class BindTag extends HtmlEscapingAwareTag implements EditorAwareTag { private boolean ignoreNestedPath = false; - @Nullable - private BindStatus status; + private @Nullable BindStatus status; - @Nullable - private Object previousPageStatus; + private @Nullable Object previousPageStatus; - @Nullable - private Object previousRequestStatus; + private @Nullable Object previousRequestStatus; /** @@ -206,8 +203,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() { + public final @Nullable String getProperty() { return getStatus().getExpression(); } @@ -216,14 +212,12 @@ 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() { + public final @Nullable Errors getErrors() { return getStatus().getErrors(); } @Override - @Nullable - public final PropertyEditor getEditor() { + public final @Nullable PropertyEditor getEditor() { return getStatus().getEditor(); } 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 d6c9e2e773..447a712dd1 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 @@ -19,8 +19,7 @@ package org.springframework.web.servlet.tags; import java.beans.PropertyEditor; import jakarta.servlet.jsp.JspException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Interface to be implemented by JSP tags that expose a @@ -39,7 +38,6 @@ public interface EditorAwareTag { * @return the current PropertyEditor, or {@code null} if none * @throws JspException if resolving the editor failed */ - @Nullable - PropertyEditor getEditor() throws JspException; + @Nullable PropertyEditor getEditor() throws JspException; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java index a0d864b278..c54f9e0853 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EscapeBodyTag.java @@ -21,8 +21,8 @@ import java.io.IOException; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.tagext.BodyContent; import jakarta.servlet.jsp.tagext.BodyTag; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.util.JavaScriptUtils; @@ -76,8 +76,7 @@ public class EscapeBodyTag extends HtmlEscapingAwareTag implements BodyTag { private boolean javaScriptEscape = false; - @Nullable - private BodyContent bodyContent; + private @Nullable BodyContent bodyContent; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java index a956ff8620..477a8555ba 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/EvalTag.java @@ -21,6 +21,7 @@ import java.io.IOException; import jakarta.el.ELContext; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; import org.springframework.context.expression.BeanFactoryResolver; import org.springframework.context.expression.EnvironmentAccessor; @@ -35,7 +36,6 @@ import org.springframework.expression.TypedValue; import org.springframework.expression.spel.standard.SpelExpressionParser; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.expression.spel.support.StandardTypeConverter; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.util.JavaScriptUtils; import org.springframework.web.util.TagUtils; @@ -113,11 +113,9 @@ public class EvalTag extends HtmlEscapingAwareTag { private final ExpressionParser expressionParser = new SpelExpressionParser(); - @Nullable - private Expression expression; + private @Nullable Expression expression; - @Nullable - private String var; + private @Nullable String var; private int scope = PageContext.PAGE_SCOPE; @@ -202,8 +200,7 @@ public class EvalTag extends HtmlEscapingAwareTag { return context; } - @Nullable - private ConversionService getConversionService(PageContext pageContext) { + private @Nullable ConversionService getConversionService(PageContext pageContext) { return (ConversionService) pageContext.getRequest().getAttribute(ConversionService.class.getName()); } @@ -213,8 +210,7 @@ public class EvalTag extends HtmlEscapingAwareTag { private final PageContext pageContext; - @Nullable - private final ELContext elContext; + private final @Nullable ELContext elContext; public JspPropertyAccessor(PageContext pageContext) { @@ -223,8 +219,7 @@ public class EvalTag extends HtmlEscapingAwareTag { } @Override - @Nullable - public Class[] getSpecificTargetClasses() { + public Class @Nullable [] getSpecificTargetClasses() { return null; } @@ -253,8 +248,7 @@ public class EvalTag extends HtmlEscapingAwareTag { throw new UnsupportedOperationException(); } - @Nullable - private Object resolveImplicitVariable(String name) throws AccessException { + private @Nullable Object resolveImplicitVariable(String name) throws AccessException { if (this.elContext == null) { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java index 11327e233f..e4e220ec34 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/HtmlEscapingAwareTag.java @@ -17,8 +17,8 @@ package org.springframework.web.servlet.tags; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.util.HtmlUtils; /** @@ -41,8 +41,7 @@ import org.springframework.web.util.HtmlUtils; @SuppressWarnings("serial") public abstract class HtmlEscapingAwareTag extends RequestContextAwareTag { - @Nullable - private Boolean htmlEscape; + private @Nullable Boolean htmlEscape; /** 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 1c9fec18b6..6751d95e56 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 @@ -24,11 +24,11 @@ import java.util.List; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.JspTagException; +import org.jspecify.annotations.Nullable; 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; @@ -153,24 +153,19 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware { public static final String DEFAULT_ARGUMENT_SEPARATOR = ","; - @Nullable - private MessageSourceResolvable message; + private @Nullable MessageSourceResolvable message; - @Nullable - private String code; + private @Nullable String code; - @Nullable - private Object arguments; + private @Nullable Object arguments; private String argumentSeparator = DEFAULT_ARGUMENT_SEPARATOR; private List nestedArguments = Collections.emptyList(); - @Nullable - private String text; + private @Nullable String text; - @Nullable - private String var; + private @Nullable String var; private String scope = TagUtils.SCOPE_PAGE; @@ -339,7 +334,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware { throw new JspTagException("No resolvable message"); } - private Object[] appendArguments(@Nullable Object[] sourceArguments, Object[] additionalArguments) { + private Object[] appendArguments(Object @Nullable [] sourceArguments, Object[] additionalArguments) { if (ObjectUtils.isEmpty(sourceArguments)) { return additionalArguments; } @@ -356,8 +351,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware { * @throws JspException if argument conversion failed * @see #setArguments */ - @Nullable - protected Object[] resolveArguments(@Nullable Object arguments) throws JspException { + protected Object @Nullable [] resolveArguments(@Nullable Object arguments) throws JspException { if (arguments instanceof String string) { return StringUtils.delimitedListToStringArray(string, this.argumentSeparator); } @@ -396,8 +390,7 @@ public class MessageTag extends HtmlEscapingAwareTag implements ArgumentAware { /** * Return default exception message. */ - @Nullable - protected String getNoSuchMessageExceptionDescription(NoSuchMessageException ex) { + protected @Nullable String getNoSuchMessageExceptionDescription(NoSuchMessageException ex) { return ex.getMessage(); } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java index 23bc3fbcb8..e20b1658bd 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/NestedPathTag.java @@ -20,9 +20,9 @@ import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; import jakarta.servlet.jsp.tagext.TagSupport; import jakarta.servlet.jsp.tagext.TryCatchFinally; +import org.jspecify.annotations.Nullable; import org.springframework.beans.PropertyAccessor; -import org.springframework.lang.Nullable; /** *

    The {@code } tag supports and assists with nested beans or @@ -68,12 +68,10 @@ public class NestedPathTag extends TagSupport implements TryCatchFinally { public static final String NESTED_PATH_VARIABLE_NAME = "nestedPath"; - @Nullable - private String path; + private @Nullable String path; /** Caching a previous nested path, so that it may be reset. */ - @Nullable - private String previousNestedPath; + private @Nullable String previousNestedPath; /** @@ -95,8 +93,7 @@ public class NestedPathTag extends TagSupport implements TryCatchFinally { /** * Return the path that this tag applies to. */ - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.path; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java index 6482a254f6..311999e6bf 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/Param.java @@ -16,7 +16,7 @@ package org.springframework.web.servlet.tags; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Bean used to pass name-value pair parameters from a {@link ParamTag} to a @@ -31,11 +31,9 @@ import org.springframework.lang.Nullable; */ public class Param { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String value; + private @Nullable String value; /** @@ -48,8 +46,7 @@ public class Param { /** * Return the raw parameter name. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -63,8 +60,7 @@ public class Param { /** * Return the raw parameter value. */ - @Nullable - public String getValue() { + public @Nullable String getValue() { return this.value; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java index 513ea6bae2..982b403103 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ParamTag.java @@ -18,8 +18,7 @@ package org.springframework.web.servlet.tags; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.tagext.BodyTagSupport; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * The {@code } tag collects name-value parameters and passes them to a @@ -64,8 +63,7 @@ public class ParamTag extends BodyTagSupport { private String name = ""; - @Nullable - private String value; + private @Nullable String value; private boolean valueSet; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/RequestContextAwareTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/RequestContextAwareTag.java index af503346e0..d80038fc00 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/RequestContextAwareTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/RequestContextAwareTag.java @@ -22,8 +22,8 @@ import jakarta.servlet.jsp.tagext.TagSupport; import jakarta.servlet.jsp.tagext.TryCatchFinally; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.support.JspAwareRequestContext; import org.springframework.web.servlet.support.RequestContext; @@ -61,8 +61,7 @@ public abstract class RequestContextAwareTag extends TagSupport implements TryCa protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private RequestContext requestContext; + private @Nullable RequestContext requestContext; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java index bc026381c7..cbf1d1e520 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/TransformTag.java @@ -21,8 +21,8 @@ import java.io.IOException; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.tagext.TagSupport; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.web.util.TagUtils; /** @@ -88,12 +88,10 @@ import org.springframework.web.util.TagUtils; public class TransformTag extends HtmlEscapingAwareTag { /** the value to transform using the appropriate property editor. */ - @Nullable - private Object value; + private @Nullable Object value; /** the variable to put the result in. */ - @Nullable - private String var; + private @Nullable String var; /** the scope of the variable the result will be put in. */ private String scope = TagUtils.SCOPE_PAGE; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java index 49c9258dbb..3862f91a1a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/UrlTag.java @@ -29,8 +29,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.servlet.support.RequestDataValueProcessor; @@ -149,17 +149,13 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware { private Set templateParams = Collections.emptySet(); - @Nullable - private UrlType type; + private @Nullable UrlType type; - @Nullable - private String value; + private @Nullable String value; - @Nullable - private String context; + private @Nullable String context; - @Nullable - private String var; + private @Nullable String var; private int scope = PageContext.PAGE_SCOPE; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractCheckedElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractCheckedElementTag.java index 0c83f0d662..d3cd4a5513 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractCheckedElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractCheckedElementTag.java @@ -17,8 +17,7 @@ package org.springframework.web.servlet.tags.form; import jakarta.servlet.jsp.JspException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract base class to provide common methods for @@ -81,8 +80,7 @@ public abstract class AbstractCheckedElementTag extends AbstractHtmlInputElement * Return a unique ID for the bound name within the current PageContext. */ @Override - @Nullable - protected String autogenerateId() throws JspException { + protected @Nullable String autogenerateId() throws JspException { String id = super.autogenerateId(); return (id != null ? TagIdGenerator.nextId(id, this.pageContext) : null); } 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 fb017d822c..e82683391b 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 @@ -22,9 +22,9 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; 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; @@ -56,20 +56,17 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im /** * The property path from the {@link FormTag#setModelAttribute form object}. */ - @Nullable - private String path; + private @Nullable String path; /** * The value of the '{@code id}' attribute. */ - @Nullable - private String id; + private @Nullable String id; /** * The {@link BindStatus} of this tag. */ - @Nullable - private BindStatus bindStatus; + private @Nullable BindStatus bindStatus; /** @@ -103,8 +100,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im * Get the value of the '{@code id}' attribute. */ @Override - @Nullable - public String getId() { + public @Nullable String getId() { return this.id; } @@ -129,8 +125,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im * @see #getId() * @see #autogenerateId() */ - @Nullable - protected String resolveId() throws JspException { + protected @Nullable String resolveId() throws JspException { Object id = evaluate("id", getId()); if (id != null) { String idString = id.toString(); @@ -144,8 +139,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 { + protected @Nullable String autogenerateId() throws JspException { String name = getName(); return (name != null ? StringUtils.deleteAny(name, "[]") : null); } @@ -159,8 +153,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 { + protected @Nullable String getName() throws JspException { return getPropertyPath(); } @@ -184,8 +177,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im * Get the value of the nested path that may have been exposed by the * {@link NestedPathTag}. */ - @Nullable - protected String getNestedPath() { + protected @Nullable String getNestedPath() { return (String) this.pageContext.getAttribute(NESTED_PATH_VARIABLE_NAME, PageContext.REQUEST_SCOPE); } @@ -204,16 +196,14 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im * Get the bound value. * @see #getBindStatus() */ - @Nullable - protected final Object getBoundValue() throws JspException { + protected final @Nullable Object getBoundValue() throws JspException { return getBindStatus().getValue(); } /** * Get the {@link PropertyEditor}, if any, in use for value bound to this tag. */ - @Nullable - protected PropertyEditor getPropertyEditor() throws JspException { + protected @Nullable PropertyEditor getPropertyEditor() throws JspException { return getBindStatus().getEditor(); } @@ -222,8 +212,7 @@ public abstract class AbstractDataBoundFormElementTag extends AbstractFormTag im *

    Use {@link #getPropertyEditor()} for internal rendering purposes. */ @Override - @Nullable - public final PropertyEditor getEditor() throws JspException { + public final @Nullable PropertyEditor getEditor() throws JspException { return getPropertyEditor(); } 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 c9dc294c05..469a07374f 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 @@ -19,8 +19,8 @@ package org.springframework.web.servlet.tags.form; import java.beans.PropertyEditor; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.servlet.tags.HtmlEscapingAwareTag; @@ -46,8 +46,7 @@ public abstract class AbstractFormTag extends HtmlEscapingAwareTag { * Evaluate the supplied value for the supplied attribute name. *

    The default implementation simply returns the given value as-is. */ - @Nullable - protected Object evaluate(String attributeName, @Nullable Object value) throws JspException { + protected @Nullable Object evaluate(String attributeName, @Nullable Object value) throws JspException { return value; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementBodyTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementBodyTag.java index a35a6286d1..7362044cd0 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementBodyTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementBodyTag.java @@ -21,8 +21,8 @@ import java.io.IOException; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.tagext.BodyContent; import jakarta.servlet.jsp.tagext.BodyTag; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -38,11 +38,9 @@ import org.springframework.util.StringUtils; @SuppressWarnings("serial") public abstract class AbstractHtmlElementBodyTag extends AbstractHtmlElementTag implements BodyTag { - @Nullable - private BodyContent bodyContent; + private @Nullable BodyContent bodyContent; - @Nullable - private TagWriter tagWriter; + private @Nullable TagWriter tagWriter; @Override diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java index cbb779337a..56c62530d4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlElementTag.java @@ -21,8 +21,8 @@ import java.util.Map; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.tagext.DynamicAttributes; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -78,59 +78,41 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen public static final String ONKEYDOWN_ATTRIBUTE = "onkeydown"; - @Nullable - private String cssClass; + private @Nullable String cssClass; - @Nullable - private String cssErrorClass; + private @Nullable String cssErrorClass; - @Nullable - private String cssStyle; + private @Nullable String cssStyle; - @Nullable - private String lang; + private @Nullable String lang; - @Nullable - private String title; + private @Nullable String title; - @Nullable - private String dir; + private @Nullable String dir; - @Nullable - private String tabindex; + private @Nullable String tabindex; - @Nullable - private String onclick; + private @Nullable String onclick; - @Nullable - private String ondblclick; + private @Nullable String ondblclick; - @Nullable - private String onmousedown; + private @Nullable String onmousedown; - @Nullable - private String onmouseup; + private @Nullable String onmouseup; - @Nullable - private String onmouseover; + private @Nullable String onmouseover; - @Nullable - private String onmousemove; + private @Nullable String onmousemove; - @Nullable - private String onmouseout; + private @Nullable String onmouseout; - @Nullable - private String onkeypress; + private @Nullable String onkeypress; - @Nullable - private String onkeyup; + private @Nullable String onkeyup; - @Nullable - private String onkeydown; + private @Nullable String onkeydown; - @Nullable - private Map dynamicAttributes; + private @Nullable Map dynamicAttributes; /** @@ -145,8 +127,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code class}' attribute. * May be a runtime expression. */ - @Nullable - protected String getCssClass() { + protected @Nullable String getCssClass() { return this.cssClass; } @@ -162,8 +143,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * The CSS class to use when the field bound to a particular tag has errors. * May be a runtime expression. */ - @Nullable - protected String getCssErrorClass() { + protected @Nullable String getCssErrorClass() { return this.cssErrorClass; } @@ -179,8 +159,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code style}' attribute. * May be a runtime expression. */ - @Nullable - protected String getCssStyle() { + protected @Nullable String getCssStyle() { return this.cssStyle; } @@ -196,8 +175,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code lang}' attribute. * May be a runtime expression. */ - @Nullable - protected String getLang() { + protected @Nullable String getLang() { return this.lang; } @@ -213,8 +191,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code title}' attribute. * May be a runtime expression. */ - @Nullable - protected String getTitle() { + protected @Nullable String getTitle() { return this.title; } @@ -230,8 +207,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code dir}' attribute. * May be a runtime expression. */ - @Nullable - protected String getDir() { + protected @Nullable String getDir() { return this.dir; } @@ -247,8 +223,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code tabindex}' attribute. * May be a runtime expression. */ - @Nullable - protected String getTabindex() { + protected @Nullable String getTabindex() { return this.tabindex; } @@ -264,8 +239,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onclick}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnclick() { + protected @Nullable String getOnclick() { return this.onclick; } @@ -281,8 +255,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code ondblclick}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOndblclick() { + protected @Nullable String getOndblclick() { return this.ondblclick; } @@ -298,8 +271,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onmousedown}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnmousedown() { + protected @Nullable String getOnmousedown() { return this.onmousedown; } @@ -315,8 +287,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onmouseup}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnmouseup() { + protected @Nullable String getOnmouseup() { return this.onmouseup; } @@ -332,8 +303,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onmouseover}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnmouseover() { + protected @Nullable String getOnmouseover() { return this.onmouseover; } @@ -349,8 +319,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onmousemove}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnmousemove() { + protected @Nullable String getOnmousemove() { return this.onmousemove; } @@ -365,8 +334,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onmouseout}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnmouseout() { + protected @Nullable String getOnmouseout() { return this.onmouseout; } @@ -382,8 +350,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onkeypress}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnkeypress() { + protected @Nullable String getOnkeypress() { return this.onkeypress; } @@ -399,8 +366,7 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onkeyup}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnkeyup() { + protected @Nullable String getOnkeyup() { return this.onkeyup; } @@ -416,16 +382,14 @@ public abstract class AbstractHtmlElementTag extends AbstractDataBoundFormElemen * Get the value of the '{@code onkeydown}' attribute. * May be a runtime expression. */ - @Nullable - protected String getOnkeydown() { + protected @Nullable String getOnkeydown() { return this.onkeydown; } /** * Get the map of dynamic attributes. */ - @Nullable - protected Map getDynamicAttributes() { + protected @Nullable Map getDynamicAttributes() { return this.dynamicAttributes; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java index ce6a786bab..6c1fab686c 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractHtmlInputElementTag.java @@ -17,8 +17,7 @@ package org.springframework.web.servlet.tags.form; import jakarta.servlet.jsp.JspException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Base class for databinding-aware JSP tags that render HTML form input element. @@ -65,17 +64,13 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag public static final String READONLY_ATTRIBUTE = "readonly"; - @Nullable - private String onfocus; + private @Nullable String onfocus; - @Nullable - private String onblur; + private @Nullable String onblur; - @Nullable - private String onchange; + private @Nullable String onchange; - @Nullable - private String accesskey; + private @Nullable String accesskey; private boolean disabled; @@ -93,8 +88,7 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag /** * Get the value of the '{@code onfocus}' attribute. */ - @Nullable - protected String getOnfocus() { + protected @Nullable String getOnfocus() { return this.onfocus; } @@ -109,8 +103,7 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag /** * Get the value of the '{@code onblur}' attribute. */ - @Nullable - protected String getOnblur() { + protected @Nullable String getOnblur() { return this.onblur; } @@ -125,8 +118,7 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag /** * Get the value of the '{@code onchange}' attribute. */ - @Nullable - protected String getOnchange() { + protected @Nullable String getOnchange() { return this.onchange; } @@ -141,8 +133,7 @@ public abstract class AbstractHtmlInputElementTag extends AbstractHtmlElementTag /** * Get the value of the '{@code accesskey}' attribute. */ - @Nullable - protected String getAccesskey() { + protected @Nullable String getAccesskey() { return this.accesskey; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java index 3547f810cf..bb6616327b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractMultiCheckedElementTag.java @@ -21,10 +21,10 @@ import java.util.Iterator; import java.util.Map; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanWrapper; import org.springframework.beans.PropertyAccessorFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -52,21 +52,18 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem * The {@link java.util.Collection}, {@link java.util.Map} or array of objects * used to generate the '{@code input type="checkbox/radio"}' tags. */ - @Nullable - private Object items; + private @Nullable Object items; /** * The name of the property mapped to the '{@code value}' attribute * of the '{@code input type="checkbox/radio"}' tag. */ - @Nullable - private String itemValue; + private @Nullable String itemValue; /** * The value to be displayed as part of the '{@code input type="checkbox/radio"}' tag. */ - @Nullable - private String itemLabel; + private @Nullable String itemLabel; /** * The HTML element used to enclose the '{@code input type="checkbox/radio"}' tag. @@ -76,8 +73,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem /** * Delimiter to use between each '{@code input type="checkbox/radio"}' tags. */ - @Nullable - private String delimiter; + private @Nullable String delimiter; /** @@ -95,8 +91,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem * Get the {@link java.util.Collection}, {@link java.util.Map} or array of objects * used to generate the '{@code input type="checkbox/radio"}' tags. */ - @Nullable - protected Object getItems() { + protected @Nullable Object getItems() { return this.items; } @@ -114,8 +109,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem * Get the name of the property mapped to the '{@code value}' attribute * of the '{@code input type="checkbox/radio"}' tag. */ - @Nullable - protected String getItemValue() { + protected @Nullable String getItemValue() { return this.itemValue; } @@ -133,8 +127,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem * Get the value to be displayed as part of the * '{@code input type="checkbox/radio"}' tag. */ - @Nullable - protected String getItemLabel() { + protected @Nullable String getItemLabel() { return this.itemLabel; } @@ -151,8 +144,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem * Return the delimiter to be used between each * '{@code input type="radio"}' tag. */ - @Nullable - public String getDelimiter() { + public @Nullable String getDelimiter() { return this.delimiter; } @@ -180,8 +172,7 @@ public abstract class AbstractMultiCheckedElementTag extends AbstractCheckedElem * since we're dealing with multiple HTML elements. */ @Override - @Nullable - protected String resolveId() throws JspException { + protected @Nullable String resolveId() throws JspException { Object id = evaluate("id", getId()); if (id != null) { String idString = id.toString(); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractSingleCheckedElementTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractSingleCheckedElementTag.java index e0683cc64e..336cb9ec50 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractSingleCheckedElementTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/AbstractSingleCheckedElementTag.java @@ -17,8 +17,8 @@ package org.springframework.web.servlet.tags.form; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -35,14 +35,12 @@ public abstract class AbstractSingleCheckedElementTag extends AbstractCheckedEle /** * The value of the '{@code value}' attribute. */ - @Nullable - private Object value; + private @Nullable Object value; /** * The value of the '{@code label}' attribute. */ - @Nullable - private Object label; + private @Nullable Object label; /** @@ -56,8 +54,7 @@ public abstract class AbstractSingleCheckedElementTag extends AbstractCheckedEle /** * Get the value of the '{@code value}' attribute. */ - @Nullable - protected Object getValue() { + protected @Nullable Object getValue() { return this.value; } @@ -72,8 +69,7 @@ public abstract class AbstractSingleCheckedElementTag extends AbstractCheckedEle /** * Get the value of the '{@code label}' attribute. */ - @Nullable - protected Object getLabel() { + protected @Nullable Object getLabel() { return this.label; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java index ff59f33d98..73cd155197 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/ButtonTag.java @@ -17,8 +17,8 @@ package org.springframework.web.servlet.tags.form; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.servlet.support.RequestDataValueProcessor; @@ -78,14 +78,11 @@ public class ButtonTag extends AbstractHtmlElementTag { public static final String DISABLED_ATTRIBUTE = "disabled"; - @Nullable - private TagWriter tagWriter; + private @Nullable TagWriter tagWriter; - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String value; + private @Nullable String value; private boolean disabled; @@ -101,8 +98,7 @@ public class ButtonTag extends AbstractHtmlElementTag { * Set the value of the '{@code name}' attribute. */ @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -116,8 +112,7 @@ public class ButtonTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code value}' attribute. */ - @Nullable - public String getValue() { + public @Nullable String getValue() { return this.value; } 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 f2e9ec6865..f4221c6064 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 @@ -23,8 +23,8 @@ import java.util.List; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; import jakarta.servlet.jsp.tagext.BodyTag; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -210,8 +210,7 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag { /** * Stores any value that existed in the 'errors messages' before the tag was started. */ - @Nullable - private Object oldMessages; + private @Nullable Object oldMessages; private boolean errorMessagesWereExposed; @@ -272,8 +271,7 @@ public class ErrorsTag extends AbstractHtmlElementBodyTag implements BodyTag { * is not a validate attribute for the '{@code span}' element. */ @Override - @Nullable - protected String getName() throws JspException { + protected @Nullable String getName() throws JspException { return null; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java index 834da17878..bd871b922b 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java @@ -25,11 +25,11 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.PropertyAccessor; import org.springframework.core.Conventions; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -290,45 +290,34 @@ public class FormTag extends AbstractHtmlElementTag { private static final String TYPE_ATTRIBUTE = "type"; - @Nullable - private TagWriter tagWriter; + private @Nullable TagWriter tagWriter; private String modelAttribute = DEFAULT_COMMAND_NAME; - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String action; + private @Nullable String action; - @Nullable - private String servletRelativeAction; + private @Nullable String servletRelativeAction; private String method = DEFAULT_METHOD; - @Nullable - private String target; + private @Nullable String target; - @Nullable - private String enctype; + private @Nullable String enctype; - @Nullable - private String acceptCharset; + private @Nullable String acceptCharset; - @Nullable - private String onsubmit; + private @Nullable String onsubmit; - @Nullable - private String onreset; + private @Nullable String onreset; - @Nullable - private String autocomplete; + private @Nullable String autocomplete; private String methodParam = DEFAULT_METHOD_PARAM; /** Caching a previous nested path, so that it may be reset. */ - @Nullable - private String previousNestedPath; + private @Nullable String previousNestedPath; /** @@ -360,8 +349,7 @@ public class FormTag extends AbstractHtmlElementTag { * Get the value of the '{@code name}' attribute. */ @Override - @Nullable - protected String getName() throws JspException { + protected @Nullable String getName() throws JspException { return this.name; } @@ -376,8 +364,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code action}' attribute. */ - @Nullable - protected String getAction() { + protected @Nullable String getAction() { return this.action; } @@ -395,8 +382,7 @@ public class FormTag extends AbstractHtmlElementTag { * Get the servlet-relative value of the '{@code action}' attribute. * @since 3.2.3 */ - @Nullable - protected String getServletRelativeAction() { + protected @Nullable String getServletRelativeAction() { return this.servletRelativeAction; } @@ -426,8 +412,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code target}' attribute. */ - @Nullable - public String getTarget() { + public @Nullable String getTarget() { return this.target; } @@ -442,8 +427,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code enctype}' attribute. */ - @Nullable - protected String getEnctype() { + protected @Nullable String getEnctype() { return this.enctype; } @@ -458,8 +442,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code acceptCharset}' attribute. */ - @Nullable - protected String getAcceptCharset() { + protected @Nullable String getAcceptCharset() { return this.acceptCharset; } @@ -474,8 +457,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code onsubmit}' attribute. */ - @Nullable - protected String getOnsubmit() { + protected @Nullable String getOnsubmit() { return this.onsubmit; } @@ -490,8 +472,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code onreset}' attribute. */ - @Nullable - protected String getOnreset() { + protected @Nullable String getOnreset() { return this.onreset; } @@ -506,8 +487,7 @@ public class FormTag extends AbstractHtmlElementTag { /** * Get the value of the '{@code autocomplete}' attribute. */ - @Nullable - protected String getAutocomplete() { + protected @Nullable String getAutocomplete() { return this.autocomplete; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/InputTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/InputTag.java index c682c11f24..6fa0d362eb 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/InputTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/InputTag.java @@ -19,8 +19,7 @@ package org.springframework.web.servlet.tags.form; import java.util.Map; import jakarta.servlet.jsp.JspException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * The {@code } tag renders an HTML 'input' tag with type 'text' using @@ -247,20 +246,15 @@ public class InputTag extends AbstractHtmlInputElementTag { public static final String AUTOCOMPLETE_ATTRIBUTE = "autocomplete"; - @Nullable - private String size; + private @Nullable String size; - @Nullable - private String maxlength; + private @Nullable String maxlength; - @Nullable - private String alt; + private @Nullable String alt; - @Nullable - private String onselect; + private @Nullable String onselect; - @Nullable - private String autocomplete; + private @Nullable String autocomplete; /** @@ -274,8 +268,7 @@ public class InputTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code size}' attribute. */ - @Nullable - protected String getSize() { + protected @Nullable String getSize() { return this.size; } @@ -290,8 +283,7 @@ public class InputTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code maxlength}' attribute. */ - @Nullable - protected String getMaxlength() { + protected @Nullable String getMaxlength() { return this.maxlength; } @@ -306,8 +298,7 @@ public class InputTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code alt}' attribute. */ - @Nullable - protected String getAlt() { + protected @Nullable String getAlt() { return this.alt; } @@ -322,8 +313,7 @@ public class InputTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code onselect}' attribute. */ - @Nullable - protected String getOnselect() { + protected @Nullable String getOnselect() { return this.onselect; } @@ -338,8 +328,7 @@ public class InputTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code autocomplete}' attribute. */ - @Nullable - protected String getAutocomplete() { + protected @Nullable String getAutocomplete() { return this.autocomplete; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/LabelTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/LabelTag.java index 2ae52eb351..8f866d5e50 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/LabelTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/LabelTag.java @@ -17,8 +17,8 @@ package org.springframework.web.servlet.tags.form; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -190,14 +190,12 @@ public class LabelTag extends AbstractHtmlElementTag { * The {@link TagWriter} instance being used. *

    Stored so we can close the tag on {@link #doEndTag()}. */ - @Nullable - private TagWriter tagWriter; + private @Nullable TagWriter tagWriter; /** * The value of the '{@code for}' attribute. */ - @Nullable - private String forId; + private @Nullable String forId; /** @@ -212,8 +210,7 @@ public class LabelTag extends AbstractHtmlElementTag { * Get the value of the '{@code id}' attribute. *

    May be a runtime expression. */ - @Nullable - protected String getFor() { + protected @Nullable String getFor() { return this.forId; } @@ -240,8 +237,7 @@ public class LabelTag extends AbstractHtmlElementTag { * @return the value for the HTML '{@code name}' attribute */ @Override - @Nullable - protected String getName() throws JspException { + protected @Nullable String getName() throws JspException { // This also suppresses the 'id' attribute (which is okay for a

    Typically a runtime expression. */ - @Nullable - protected Object getItems() { + protected @Nullable Object getItems() { return this.items; } @@ -252,8 +248,7 @@ public class OptionsTag extends AbstractHtmlElementTag { * Return the name of the property mapped to the '{@code value}' * attribute of the '{@code option}' tag. */ - @Nullable - protected String getItemValue() { + protected @Nullable String getItemValue() { return this.itemValue; } @@ -270,8 +265,7 @@ public class OptionsTag extends AbstractHtmlElementTag { * Get the name of the property mapped to the label (inner text) of the * '{@code option}' tag. */ - @Nullable - protected String getItemLabel() { + protected @Nullable String getItemLabel() { return this.itemLabel; } @@ -323,8 +317,7 @@ public class OptionsTag extends AbstractHtmlElementTag { * since we're dealing with multiple HTML elements. */ @Override - @Nullable - protected String resolveId() throws JspException { + protected @Nullable String resolveId() throws JspException { Object id = evaluate("id", getId()); if (id != null) { String idString = id.toString(); @@ -349,8 +342,7 @@ public class OptionsTag extends AbstractHtmlElementTag { */ private class OptionsWriter extends OptionWriter { - @Nullable - private final String selectName; + private final @Nullable String selectName; public OptionsWriter(@Nullable String selectName, Object optionSource, @Nullable String valueProperty, @Nullable String labelProperty) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java index 1aaafeaeec..1271211f67 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectTag.java @@ -20,8 +20,8 @@ import java.util.Collection; import java.util.Map; import jakarta.servlet.jsp.JspException; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.WebDataBinder; import org.springframework.web.servlet.support.BindStatus; @@ -259,43 +259,37 @@ public class SelectTag extends AbstractHtmlInputElementTag { * The {@link Collection}, {@link Map} or array of objects used to generate * the inner '{@code option}' tags. */ - @Nullable - private Object items; + private @Nullable Object items; /** * The name of the property mapped to the '{@code value}' attribute * of the '{@code option}' tag. */ - @Nullable - private String itemValue; + private @Nullable String itemValue; /** * The name of the property mapped to the inner text of the * '{@code option}' tag. */ - @Nullable - private String itemLabel; + private @Nullable String itemLabel; /** * The value of the HTML '{@code size}' attribute rendered * on the final '{@code select}' element. */ - @Nullable - private String size; + private @Nullable String size; /** * Indicates whether the '{@code select}' tag allows * multiple-selections. */ - @Nullable - private Object multiple; + private @Nullable Object multiple; /** * The {@link TagWriter} instance that the output is being written. *

    Only used in conjunction with nested {@link OptionTag OptionTags}. */ - @Nullable - private TagWriter tagWriter; + private @Nullable TagWriter tagWriter; /** @@ -314,8 +308,7 @@ public class SelectTag extends AbstractHtmlInputElementTag { * Get the value of the '{@code items}' attribute. *

    May be a runtime expression. */ - @Nullable - protected Object getItems() { + protected @Nullable Object getItems() { return this.items; } @@ -334,8 +327,7 @@ public class SelectTag extends AbstractHtmlInputElementTag { * Get the value of the '{@code itemValue}' attribute. *

    May be a runtime expression. */ - @Nullable - protected String getItemValue() { + protected @Nullable String getItemValue() { return this.itemValue; } @@ -352,8 +344,7 @@ public class SelectTag extends AbstractHtmlInputElementTag { * Get the value of the '{@code itemLabel}' attribute. *

    May be a runtime expression. */ - @Nullable - protected String getItemLabel() { + protected @Nullable String getItemLabel() { return this.itemLabel; } @@ -368,8 +359,7 @@ public class SelectTag extends AbstractHtmlInputElementTag { /** * Get the value of the '{@code size}' attribute. */ - @Nullable - protected String getSize() { + protected @Nullable String getSize() { return this.size; } @@ -385,8 +375,7 @@ public class SelectTag extends AbstractHtmlInputElementTag { * Get the value of the HTML '{@code multiple}' attribute rendered * on the final '{@code select}' element. */ - @Nullable - protected Object getMultiple() { + protected @Nullable Object getMultiple() { return this.multiple; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java index f8b41e0295..8ef17458a4 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/SelectedValueComparator.java @@ -21,7 +21,8 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.servlet.support.BindStatus; 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 ff4175ab91..46e7b5aa1e 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 @@ -23,8 +23,8 @@ import java.util.Deque; import jakarta.servlet.jsp.JspException; import jakarta.servlet.jsp.PageContext; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -245,11 +245,9 @@ public class TagWriter { */ private static final class SafeWriter { - @Nullable - private PageContext pageContext; + private @Nullable PageContext pageContext; - @Nullable - private Writer writer; + private @Nullable Writer writer; public SafeWriter(PageContext pageContext) { this.pageContext = pageContext; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java index 3842b83504..dd5d8c1e42 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TextareaTag.java @@ -17,8 +17,7 @@ package org.springframework.web.servlet.tags.form; import jakarta.servlet.jsp.JspException; - -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * The {@code