diff --git a/build.gradle b/build.gradle index 2e130944038c..d0347e6f0835 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 f91e78a54875..0db14f210f45 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 5ae3e67b6228..73717dd4e13c 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 ff48a66e39e0..c0c9eea1551b 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 15fbd10d787a..b416fc3edf70 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.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.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 8c2c5d6ef8f0..e7d89ca7bd61 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 @@ 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 806744d09c31..1103590a57ac 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 @@ 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 2cc637621c90..d6f929f8a663 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 d518ddb444a0..df550f771160 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 c19982f31916..9429d43bb7bc 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 @@ default boolean isStatic() { * 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 2e2ee857f3d4..7ffffab8bc4b 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.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.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 static JoinPoint currentJoinPoint() { * 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 static JoinPoint currentJoinPoint() { */ 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 final AspectInstanceFactory getAspectInstanceFactory() { /** * Return the ClassLoader for aspect instances. */ - @Nullable - public final ClassLoader getAspectClassLoader() { + public final @Nullable ClassLoader getAspectClassLoader() { return this.aspectInstanceFactory.getAspectClassLoader(); } @@ -318,8 +312,7 @@ protected Class getDiscoveredReturningType() { return this.discoveredReturningType; } - @Nullable - protected Type getDiscoveredReturningGenericType() { + protected @Nullable Type getDiscoveredReturningGenericType() { return this.discoveredReturningGenericType; } @@ -657,8 +650,7 @@ protected JoinPoint getJoinPoint() { /** * 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 @@ protected JoinPointMatch getJoinPointMatch() { // '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 4ddf6303edd5..b4367ad04aac 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 ec9b634ff89f..b783c37e5710 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.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 void setThrowingName(@Nullable String throwingName) { * @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 String[] getParameterNames(Method method) { * {@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 @@ else if (numAnnotationSlots == 1) { /** * 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 a8081b461aa1..d0ed4f9f241d 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 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 AspectJAfterAdvice( @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 48cedab1be7c..b0a8a99a54b3 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.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 953658d66e50..4444f2175e3d 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 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 void setThrowingName(String name) { } @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 4ea59280d1b1..b97ef421a554 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 static boolean isAfterAdvice(Advisor anAdvisor) { * 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 d1584c54af8a..bc3ca787da32 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.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 @@ protected boolean supportsProceedingJoinPoint() { } @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 aeb258e0a3b5..99b4f1ea4889 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.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.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 @@ private PointcutExpression obtainPointcutExpression() { /** * 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 boolean matches(Method method, Class targetClass, Object... args) { } } - @Nullable - protected String getCurrentProxiedBeanName() { + protected @Nullable String getCurrentProxiedBeanName() { return ProxyCreationContext.getCurrentProxiedBeanName(); } @@ -412,8 +406,7 @@ protected String getCurrentProxiedBeanName() { /** * 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 9f4b1e990d8e..918a61ee5599 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 void setExpression(@Nullable String expression) { this.pointcut.setExpression(expression); } - @Nullable - public String getExpression() { + public @Nullable String getExpression() { return this.pointcut.getExpression(); } @@ -47,8 +47,7 @@ public void setLocation(@Nullable String location) { 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 207291c51d5a..561714af5751 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 @@ 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 543146243ab0..94487cae882b 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 be7c8569404b..9d2875311472 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 @@ 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 68eb55c9c4a6..a53d71c84b39 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.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 MethodInvocationProceedingJoinPoint(ProxyMethodInvocation methodInvocatio } @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 Object getThis() { * 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 String toString() { */ 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[] getParameterTypes() { } @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 bf37296a6e8a..3c34ea0e997b 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.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 beb3ac63bb96..3c26b4abc52c 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.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 static void clearCache() { * @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 f8a674ab13e6..1e2d45f4bf6a 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 @@ 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 final Object getAspectInstance() { } @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 04edaa807663..a285945bc5d7 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 @@ 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 final Object getAspectInstance() { } @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 d6ddae267195..b3cff467db5e 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 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 8400c54360a9..03a36ba11a5b 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.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 void validate(Class aspectClass) throws AopConfigException { * (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 @@ protected static AspectJAnnotation findAspectJAnnotationOnMethod(Method method) 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 @@ private static class AspectJAnnotationParameterNameDiscoverer implements Paramet 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 String[] getParameterNames(Method method) { } @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 926392693e31..f53b1cdba5ee 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.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 @@ @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 cfc88564776a..1c237ed55fd3 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 @@ 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 c3bf1685297e..31dcf53d68ce 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.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 @@ Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInstanceFact * @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 71e7bea2b4ac..f859dc3f822b 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 @@ 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.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 @@ public BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableL */ 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 28d5aa13e50f..d0425b6e0e55 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 @@ 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 Object getAspectInstance() { } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { return (this.beanFactory instanceof ConfigurableBeanFactory cbf ? cbf.getBeanClassLoader() : ClassUtils.getDefaultClassLoader()); } @@ -103,8 +103,7 @@ public AspectMetadata getAspectMetadata() { } @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 21bc248e508a..4cb6dd3cb9dd 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 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 db20f7608131..12a6a47813b6 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 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.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 @@ private static final class PerTargetInstantiationModelPointcut extends DynamicMe 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 73ba36c79dc3..a20fc06df8df 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 @@ 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 boolean isMaterialized() { } @Override - @Nullable - public ClassLoader getAspectClassLoader() { + public @Nullable ClassLoader getAspectClassLoader() { return this.maaif.getAspectClassLoader(); } @@ -85,8 +84,7 @@ public AspectMetadata getAspectMetadata() { } @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 cb3e29baf49a..08c629108100 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 e4eec7a919d9..1f33f9c8c07b 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.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.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 @@ private List getAdvisorMethods(Class aspectClass) { * @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 @@ private Advisor getDeclareParentsAdvisor(Field introductionField) { @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 Advisor getAdvisor(Method candidateAdviceMethod, MetadataAwareAspectInsta } } - @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 @@ private AspectJExpressionPointcut getPointcut(Method candidateAdviceMethod, Clas @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 b5cf52470045..4f9573c2f779 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 d83cd88d541f..65e6bf298d4b 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 2ffe8b16438b..45dce8a86a3d 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 25c8fa2c4d3c..6c53d9df0dda 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 BeanReference[] getBeanReferences() { } @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 1bba8f1c2048..6ec5ea346061 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 @@ 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.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 static void forceAutoProxyCreatorToExposeProxy(BeanDefinitionRegistry reg } } - @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 5acb1cc5acd9..fca1bef8dd98 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 53d0d789a48d..7b283baad8a2 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 70b9762006b0..27090155eb84 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.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 @@ 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 c13c6446a383..bcf4fc006e06 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 @@ 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.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 @@ private AbstractBeanDefinition parsePointcut(Element pointcutElement, ParserCont * {@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 ebff6ee73e28..e48e5feb42a3 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 @@ 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 @@ */ 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 void setBeanFactory(BeanFactory beanFactory) { @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 389a5b4216b8..f089a80d1918 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 BeanDefinition[] getBeanDefinitions() { } @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 446d5f93e0a8..4ad0100ceffc 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 @@ */ 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 Object getAspectInstance() { } @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 f3adcd6a6718..c119ad2771ad 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.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 b0d1010cb327..5fb98e99ed8e 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 95eeda4a7a83..0eb8764cc2fa 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 @@ 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 @@ 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 fa1642835c0e..6e6f7aad5690 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.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 @@ 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 Object getObject() { } @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 707c98f26760..72a9d07d41ea 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.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.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 void setTargetClass(@Nullable Class targetClass) { } @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { return this.targetSource.getTargetClass(); } @@ -705,11 +701,9 @@ private static final class AdvisorKeyEntry implements Advisor { 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 3d31b8c7d481..947b059054e7 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 @@ 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 9653ced6bc8b..cac3ea7785e0 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 static Object currentProxy() throws IllegalStateException { * @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 f103477504a1..b278e64f53cc 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 26651f6200b8..7967fef25eb7 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.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 static boolean equalsAdvisors(AdvisedSupport a, AdvisedSupport b) { * @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 aad0b4e9e0db..bf03bc79b2a9 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 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.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 @@ public CglibAopProxy(AdvisedSupport config) throws AopConfigException { * @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 @@ private static boolean implementsInterface(Method method, Set> ifcs) { * {@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 @@ public static class SerializableNoOp implements NoOp, 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 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy */ 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 @@ public DynamicUnadvisedInterceptor(TargetSource targetSource) { } @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 @@ public DynamicUnadvisedExposedInterceptor(TargetSource targetSource) { } @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 @@ public Object intercept(Object proxy, Method method, Object[] args, MethodProxy */ 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 @@ private static class FixedChainStaticTargetInterceptor implements MethodIntercep 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 @@ public FixedChainStaticTargetInterceptor( } @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 @@ public DynamicAdvisedInterceptor(AdvisedSupport advised) { } @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 f1e06096161a..80c2fe245dc5 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 @@ 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 @@ static Object asFlow(@Nullable Object publisher) { } } - @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 73c2fb430896..686a8df5513f 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 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.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 3ab70ee9e877..ac4c8c0270fa 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 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.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 @@ private ClassLoader determineClassLoader(@Nullable ClassLoader classLoader) { * 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 56330a6395a3..da05db588d86 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 f40ff95ca514..fdec5887de87 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.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.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 void setBeanFactory(BeanFactory beanFactory) { * @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 Object getObject() throws BeansException { * @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 f58e0be379f3..96f224c2c817 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 @@ 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 void setProxyClassLoader(@Nullable ClassLoader classLoader) { /** * 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 b5ad8c36f1e0..e4158ee852f4 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 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 final Object getProxy() { } @Override - @Nullable - public final Object getThis() { + public final @Nullable Object getThis() { return this.target; } @@ -156,8 +152,7 @@ public void setArguments(Object... arguments) { @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 Object proceed() throws Throwable { * @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 void setUserAttribute(String key, @Nullable Object value) { } @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 4ce1c45c87b2..108023045196 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 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 AfterReturningAdviceInterceptor(AfterReturningAdvice advice) { @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 09683e02576e..a7a26a4288ef 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 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 MethodBeforeAdviceInterceptor(MethodBeforeAdvice advice) { @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 2baf3e93b140..b9d03e7b23bd 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.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 int getHandlerMethodCount() { @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 Object invoke(MethodInvocation mi) throws Throwable { * @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 1925e47bfbc6..331af93b4ec6 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 7a71cb57569f..91364f18568b 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 @@ 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.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 @@ @SuppressWarnings("serial") public abstract class AbstractAdvisorAutoProxyCreator extends AbstractAutoProxyCreator { - @Nullable - private BeanFactoryAdvisorRetrievalHelper advisorRetrievalHelper; + private @Nullable BeanFactoryAdvisorRetrievalHelper advisorRetrievalHelper; @Override @@ -73,8 +73,7 @@ protected void initBeanFactory(ConfigurableListableBeanFactory beanFactory) { @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 ffdf6173f126..cb60fccd7261 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 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.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 void setBeanFactory(BeanFactory beanFactory) { * 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 Class determineBeanType(Class beanClass, String beanName) { } @Override - @Nullable - public Constructor[] determineCandidateConstructors(Class beanClass, String beanName) { + public Constructor @Nullable [] determineCandidateConstructors(Class beanClass, String beanName) { return null; } @@ -269,8 +263,7 @@ public Object getEarlyBeanReference(Object bean, String beanName) { } @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 PropertyValues postProcessProperties(PropertyValues pvs, Object bean, Str * @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 @@ protected boolean shouldSkip(Class beanClass, String beanName) { * @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 @@ protected TargetSource getCustomTargetSource(Class beanClass, String beanName * @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 @@ protected boolean advisorsPreFiltered() { * 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 @@ protected void customizeProxyFactory(ProxyFactory proxyFactory) { * @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 0dbea8a467f5..3cba6a7fd5e4 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 @@ 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 92c25b432d5d..0208b14e5184 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 static boolean shouldProxyTargetClass( * @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 a82a8bce56d5..4ff290ec3484 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 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 27aa0547363c..8ab713d01e2f 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 @@ 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 void setBeanNames(String... beanNames) { * @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 @@ protected TargetSource getCustomTargetSource(Class beanClass, String beanName * @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 07aff4a3f91d..98122847d27c 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 void setAdvisorBeanNamePrefix(@Nullable String advisorBeanNamePrefix) { * 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 f283920fca76..0c11bc8c228e 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 @@ @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 314fcc98f236..19a30ad6c7cf 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 @@ private 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 012c060e98d5..e8a88d2d5b79 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 328312146ade..15acaaff35b9 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 b9a5e4e4c422..4fd9054084ea 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 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.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 final void setBeanFactory(BeanFactory beanFactory) { /** * 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 @@ private ConfigurableBeanFactory getConfigurableBeanFactory() { //--------------------------------------------------------------------- @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 @@ protected boolean isPrototypeBased() { * @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 68ca0524471a..bca5d66424d6 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 @@ protected boolean isPrototypeBased() { } @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 f7df6c30249b..18836564c6e6 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 2e0608db9d2c..928aa745b36b 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 c05af5dea98a..db79833a4750 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 536e6e3ade39..a9e7d6ca11e6 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 @@ 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 2d67708c351a..8ff8cbd6197e 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.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 void setLogExceptionStackTrace(boolean logExceptionStackTrace) { * @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 @@ protected void writeToLog(Log logger, String message, @Nullable Throwable ex) { * @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 d9276cef9766..d5588f88675c 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 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.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 void setBeanFactory(BeanFactory beanFactory) { * 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 @@ protected AsyncTaskExecutor determineAsyncExecutor(Method method) { * @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 @@ protected AsyncTaskExecutor determineAsyncExecutor(Method method) { * @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 @@ protected Executor findQualifiedExecutor(@Nullable BeanFactory beanFactory, Stri * @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 @@ protected Executor getDefaultExecutor(@Nullable BeanFactory beanFactory) { * @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 933375922447..edc54e3d2694 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 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.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 AsyncExecutionInterceptor(@Nullable Executor defaultExecutor, AsyncUncaug * 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 Object invoke(final MethodInvocation invocation) throws Throwable { * @see #determineAsyncExecutor(Method) */ @Override - @Nullable - protected String getExecutorQualifier(Method method) { + protected @Nullable String getExecutorQualifier(Method method) { return null; } @@ -154,8 +152,7 @@ protected String getExecutorQualifier(Method method) { * @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 3e6e6e9b7c5b..65d540f939cd 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 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 ConcurrencyThrottleInterceptor() { } @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 46c879ff1d5c..157b5ef1a12b 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 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 06ea6102909e..288771bb9a8a 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 DebugInterceptor(boolean useDynamicLogger) { @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 1f095ed89e9e..f43a9ee8d20b 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 @@ 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.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 ExposeBeanNameInterceptor(String beanName) { } @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 ExposeBeanNameIntroduction(String beanName) { } @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 18c9caf1ea87..a3a7bca9acde 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 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 @@ private ExposeInvocationInterceptor() { } @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 eb2a05f4be05..186d58aa073d 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 2b87bce534c7..f2d5c60508fd 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 af2c7af67aff..d2081dfc6183 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 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.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 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe 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 a787a1ee809c..8beeff41ff26 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 @@ 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.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 void setBeanFactory(BeanFactory beanFactory) { @Override - @Nullable - public Object getObject() { + public @Nullable Object getObject() { if (this.proxy == null) { throw new FactoryBeanNotInitializedException(); } @@ -126,8 +124,7 @@ public Object getObject() { } @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 2eee3a42581e..f2f073613b86 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.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 443f903968fb..2736df6ebf72 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 e6a10c621bf1..6afa797771c9 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.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 @@ @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 void setAdviceBeanName(@Nullable String adviceBeanName) { /** * 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 5330f2c00d64..080751196ae9 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 @@ import java.io.Serializable; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Abstract superclass for expression pointcuts, @@ -33,11 +33,9 @@ @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 void setLocation(@Nullable String location) { * @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 @@ protected void onSetExpression(@Nullable String expression) throws IllegalArgume * 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 fc5527270ed8..72cd6011d1c1 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 @@ 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 @@ @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 acb56fd468d2..885f70a79cee 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.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 38eba72e6d7a..f6fa34241563 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 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.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 static List findAdvisorsThatCanApply(List candidateAdvi * @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 929196e66b74..be84eeb584d0 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.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 432635510c4a..40ba09555dc9 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 @@ 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 43707df5c200..fc7e7af34aab 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.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 ce68704856c6..80ac2ea2612f 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 930255c62cd6..f95cf95a0b2d 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.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 45c2e17254b9..b6e5a5dd80ce 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 @@ 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 0f3d511c0dea..6a4ebc23ccdd 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.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 DelegatePerTargetObjectIntroductionInterceptor(Class defaultImplType, * 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 Object invoke(MethodInvocation mi) throws Throwable { * 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 bd9647a0f462..1948ef564702 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 @@ private void init(Object delegate) { * 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 Object invoke(MethodInvocation mi) throws Throwable { * 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 99b76e135d32..a4ba549c6b2d 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 f2d226adfb28..53c558a498eb 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.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 9a11e60b8733..b3967854d321 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.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 bc41a9fbdd8d..79dca1470735 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 @@ 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 @@ @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 c4bf82a18608..d0cf1eb21a6e 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 @@ 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 9b234633add6..6385d108f7b7 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 @@ 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 c6e11ecf77ae..864ecd9fdc5b 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 @@ 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 520519ff7243..3e637663f0b5 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.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 a5ec1d421ab5..367eb885438d 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 a39f2d4c302c..af967794b426 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 6ab195c0a7bd..55930b639f0b 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 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 BeanFactory getBeanFactory() { @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 57838757015d..7c8af147ad8d 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 @@ 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 synchronized boolean isInitialized() { * @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 30e9c1e2ef23..e6cf192e8fa9 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 final void setBeanFactory(BeanFactory beanFactory) throws BeansException * 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 4c0e5b48da6d..8160f62a4879 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.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 cfcb3b119fdf..75575446f3cd 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 @@ 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 static EmptyTargetSource forClass(@Nullable Class targetClass, boolean // Instance implementation //--------------------------------------------------------------------- - @Nullable - private final Class targetClass; + private final @Nullable Class targetClass; private final boolean isStatic; @@ -94,8 +94,7 @@ private EmptyTargetSource(@Nullable Class targetClass, boolean isStatic) { * 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 boolean isStatic() { * 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 fb5aceefcadf..dd4babd56c2f 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 @@ 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 e69a01842e00..3b766190a773 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 @@ @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 11e3a9e8fead..f947f2980462 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 @@ 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 5871ac8b95d1..645a5602d6c4 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 @@ 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 synchronized Class getTargetClass() { } @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 5ac4c66c1820..27d8af4ff16f 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 292cdcce5d1e..88fb11976c00 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 d7dec7bf33d1..74484dcf7006 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.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.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 e6b8fe34cccb..c84bfd4dd798 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.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 @@ void process(Class beanClass) { } } - @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 810409ee0fda..a9bc36d97d52 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.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.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 @@ private void process(Class beanClass) { } } - @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 6b3e34cba863..d187204d9d75 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.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 @@ private static Answer sneakyThrow(Throwable throwable) { @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 fb4d1ed6f717..5da2f556be4e 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 @@ 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.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 54b3657703f1..0e59d7530caf 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 @@ 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.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 6fae987c9ea7..e1bae0239bfe 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 @@ 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.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 6f50a9aecc17..cec4198aee10 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 @@ 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 ed5ba5ffc9b2..4551a8f3f13d 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.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 df7bb2bd98a1..4eaef005af84 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 @@ 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 675ca10d6886..0497dbf9dbff 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 36080e068da9..b70a6b334672 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 4554b676e4bf..aebcc1a57bd8 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 5543ab52fa10..2b1d21941dcb 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 8b4c08397d73..3b9f9f2da0fe 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 0219086ed48d..c069cf4a36fe 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 @@ 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 6f2e5eff3384..17bcbf39b223 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 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 @@ private void processLocalProperty(PropertyTokenHolder tokens, PropertyValue pv) } @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 Class getPropertyType(String propertyName) throws BeansException { } @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 boolean isWritableProperty(String propertyName) { 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 @@ private Object convertIfNecessary(@Nullable String propertyName, @Nullable Objec } } - @Nullable - protected Object convertForProperty( + protected @Nullable Object convertForProperty( String propertyName, @Nullable Object oldValue, @Nullable Object newValue, TypeDescriptor td) throws TypeMismatchException { @@ -610,16 +603,14 @@ protected Object convertForProperty( } @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 @@ else if (value instanceof Map map) { * 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 @@ protected PropertyHandler getPropertyHandler(String propertyName) throws BeansEx * @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 String toString() { */ protected abstract static class PropertyHandler { - @Nullable - private final Class propertyType; + private final @Nullable Class propertyType; private final boolean readable; @@ -1029,8 +1017,7 @@ public PropertyHandler(@Nullable Class propertyType, boolean readable, boolea this.writable = writable; } - @Nullable - public Class getPropertyType() { + public @Nullable Class getPropertyType() { return this.propertyType; } @@ -1058,11 +1045,9 @@ public TypeDescriptor getCollectionType(int nestingLevel) { 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 PropertyTokenHolder(String name) { 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 01e67dbdf14d..e25bd96e0b23 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.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 void setPropertyValues(PropertyValues pvs, boolean ignoreUnknown, boolean // Redefined with public visibility. @Override - @Nullable - public Class getPropertyType(String propertyPath) { + public @Nullable Class getPropertyType(String propertyPath) { return null; } @@ -154,8 +153,7 @@ public Class getPropertyType(String propertyPath) { * 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 395035467132..26958d37eef3 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 @@ 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 a07cae6d3b84..c7bd4d98727f 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 @@ 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 getBeanClass() { * 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 Constructor getConstructor() { * 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 b8d316db91ee..8c4ad37bc680 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 String getName() { /** * Return the value of the attribute. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } @@ -75,8 +73,7 @@ public void setSource(@Nullable Object source) { } @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 58409cb852da..9aacda4501bf 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 @@ @SuppressWarnings("serial") public class BeanMetadataAttributeAccessor extends AttributeAccessorSupport implements BeanMetadataElement { - @Nullable - private Object source; + private @Nullable Object source; /** @@ -43,8 +43,7 @@ public void setSource(@Nullable Object source) { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -63,8 +62,7 @@ public void addMetadataAttribute(BeanMetadataAttribute attribute) { * @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 void setAttribute(String name, @Nullable Object value) { } @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 7126c64ef279..02fe45a4f17f 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 f4ca77b3e1ca..9d7af79ac7f1 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.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 static T instantiateClass(Class clazz, Class assignableTo) thro * @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 @@ else if (ctors.length == 0) { * @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 static Constructor findPrimaryConstructor(Class clazz) { * @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 static Method findMethod(Class clazz, String methodName, Class... p * @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 static Method findDeclaredMethod(Class clazz, String methodName, Class * @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 static Method findMethodWithMinimalParameters(Class clazz, String meth * 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 static Method findDeclaredMethodWithMinimalParameters(Class clazz, Str * @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 @@ else if (!method.isBridge() && targetMethod.getParameterCount() == numParams) { * @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 static PropertyDescriptor[] getPropertyDescriptors(Class clazz) throws * @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 static PropertyDescriptor getPropertyDescriptor(Class clazz, String pr * @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 static PropertyDescriptor findPropertyForMethod(Method method) throws Bea * @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 static PropertyDescriptor findPropertyForMethod(Method method, Class c * @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 static PropertyEditor findEditorByConvention(@Nullable Class targetTyp * @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 static void copyProperties(Object source, Object target, String... ignore * @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 @@ private static class KotlinDelegate { * 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 static Constructor findPrimaryConstructor(Class clazz) { * @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 3fc2e306739a..721d92216d78 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 93a9724d4420..7171d785214d 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.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 @@ private CachedIntrospectionResults getCachedIntrospectionResults() { * @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 Object convertForProperty(@Nullable Object value, String propertyName) th } @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 TypeDescriptor getCollectionType(int nestingLevel) { } @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 f3816a16db50..fcb8ab9a25f8 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 f29a9d30407d..6c9014af84a4 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 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 @@ Class getBeanClass() { 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 38c5d26a4573..9bff02f0d318 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 41c7f95a9626..aeb0b4744c48 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 @@ 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 145a5cff9919..9c26ee15ab31 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.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 @@ protected DirectFieldAccessor(Object object, String nestedPath, DirectFieldAcces @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 TypeDescriptor getCollectionType(int nestingLevel) { } @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 5cd244f80f9c..d8868153520f 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 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 @@ else if (existingPd instanceof IndexedPropertyDescriptor indexedPd) { } } - @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 @@ public MethodDescriptor[] getMethodDescriptors() { */ 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 @@ public SimplePropertyDescriptor(String propertyName, @Nullable Method readMethod } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @@ -303,8 +297,7 @@ public void setReadMethod(@Nullable Method readMethod) { } @Override - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { return this.writeMethod; } @@ -314,8 +307,7 @@ public void setWriteMethod(@Nullable Method writeMethod) { } @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 @@ public Class getPropertyType() { } @Override - @Nullable - public Class getPropertyEditorClass() { + public @Nullable Class getPropertyEditorClass() { return this.propertyEditorClass; } @@ -362,26 +353,19 @@ public String toString() { */ 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 @@ public SimpleIndexedPropertyDescriptor(String propertyName, @Nullable Method rea } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @@ -415,8 +398,7 @@ public void setReadMethod(@Nullable Method readMethod) { } @Override - @Nullable - public Method getWriteMethod() { + public @Nullable Method getWriteMethod() { return this.writeMethod; } @@ -426,8 +408,7 @@ public void setWriteMethod(@Nullable Method writeMethod) { } @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 @@ public Class getPropertyType() { } @Override - @Nullable - public Method getIndexedReadMethod() { + public @Nullable Method getIndexedReadMethod() { return this.indexedReadMethod; } @@ -451,8 +431,7 @@ public void setIndexedReadMethod(@Nullable Method indexedReadMethod) throws Intr } @Override - @Nullable - public Method getIndexedWriteMethod() { + public @Nullable Method getIndexedWriteMethod() { return this.indexedWriteMethod; } @@ -462,8 +441,7 @@ public void setIndexedWriteMethod(@Nullable Method indexedWriteMethod) throws In } @Override - @Nullable - public Class getIndexedPropertyType() { + public @Nullable Class getIndexedPropertyType() { if (this.indexedPropertyType == null) { try { this.indexedPropertyType = PropertyDescriptorUtils.findIndexedPropertyType( @@ -477,8 +455,7 @@ public Class getIndexedPropertyType() { } @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 5f41742632d9..49b22dcbd907 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.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 @@ 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 78d9e5c62f39..f5ffb2447606 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 a8247f6e421c..b1f4d72c7b06 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.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 @@ public Class getBeanClass() { } @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 @@ public Method getWriteMethodForActualAccess() { 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 @@ public Method getWriteMethodFallback(@Nullable Class valueType) { 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 @@ public TypeDescriptor getTypeDescriptor() { } @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 c0d0f50adbbb..8484bdb613ae 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 41d50521f443..e55ba9c598b4 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 327643cbbf3f..c7b0cdc7cc7b 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 @@ 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 f52780e0ec9d..b2fe8dfb9bdf 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.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 PropertyValue[] getPropertyValues() { } @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 PropertyValue getPropertyValue(String propertyName) { * @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 79e017e89ac7..8f7c63c95019 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 @@ @SuppressWarnings("serial") public class NotWritablePropertyException extends InvalidPropertyException { - @Nullable - private final String[] possibleMatches; + private final String @Nullable [] possibleMatches; /** @@ -86,8 +85,7 @@ public NotWritablePropertyException(Class beanClass, String propertyName, Str * 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 7789437b551a..8e148adc4041 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 @@ 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 @@ @SuppressWarnings("serial") public abstract class PropertyAccessException extends BeansException { - @Nullable - private final PropertyChangeEvent propertyChangeEvent; + private final @Nullable PropertyChangeEvent propertyChangeEvent; /** @@ -61,24 +60,21 @@ public PropertyAccessException(String msg, @Nullable Throwable cause) { *

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 03201a89d0d7..885dee2ffa2c 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 @@ 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 465b3ff8b1d8..73b39e1ca8d1 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 static String canonicalPropertyName(@Nullable String propertyName) { * (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 46491e0d2b88..f4cb0db73d2b 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.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 final PropertyAccessException[] getPropertyAccessExceptions() { /** * 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 90c2aef90275..0feea7208617 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.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 @@ public static void copyNonMethodProperties(PropertyDescriptor source, PropertyDe /** * 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 @@ else if (params[0].isAssignableFrom(propertyType)) { /** * 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 @@ public static boolean equals(PropertyDescriptor pd, PropertyDescriptor otherPd) */ 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 @@ public void setReadMethod(@Nullable Method readMethod) { } @Override - @Nullable - public Method getReadMethod() { + public @Nullable Method getReadMethod() { return this.readMethod; } @@ -303,8 +299,7 @@ public void addWriteMethod(Method writeMethod) { } @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 9cbbc55ca575..8d66df82cc96 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 @@ 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 af3e0cc00c5c..23cb769cc3cf 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.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.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 @@ */ 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 void setConversionService(@Nullable ConversionService conversionService) /** * Return the associated ConversionService, if any. */ - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -178,9 +171,8 @@ public void overrideDefaultEditor(Class requiredType, PropertyEditor property * @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 void registerCustomEditor(@Nullable Class requiredType, @Nullable Stri } @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 boolean hasCustomEditorForElement(@Nullable Class elementType, @Nullab * @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 @@ protected Class getPropertyType(String propertyPath) { * @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 @@ private PropertyEditor getCustomEditor(String propertyName, @Nullable Class r * @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 @@ private PropertyEditor getCustomEditor(@Nullable Class requiredType) { * @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 @@ private static final class CustomEditorHolder { 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 @@ private PropertyEditor getPropertyEditor() { 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 00f567b0f67b..1a867fc5b513 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 @@ 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 String getName() { * 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 synchronized void setConvertedValue(@Nullable Object value) { * 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 b754a32a0f60..4134bc707281 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.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 @@ default Stream stream() { * @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 75c9a699bb69..554298e03af4 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.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 @@ 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 d93d8d6a6905..86905474290c 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.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 200a350727aa..a4ac581a2daa 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 @@ 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 @@ T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType * @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 @@ T convertIfNecessary(@Nullable Object value, @Nullable Class requiredType * @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 f41724275445..54aaa607f075 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 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 @@ public TypeConverterDelegate(PropertyEditorRegistrySupport propertyEditorRegistr * @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 @@ public T convertIfNecessary(@Nullable String propertyName, @Nullable Object * @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 @@ private Object attemptToConvertStringToEnum(Class requiredType, String trimme * @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 @@ private PropertyEditor findDefaultEditor(@Nullable Class requiredType) { * @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 @@ private Collection convertToTypedCollection(Collection original, @Nullable 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 2351382512c9..5bbe75ac3500 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 @@ 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 @@ */ 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 T convertIfNecessary(@Nullable Object value, @Nullable Class requi } @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 T convertIfNecessary(@Nullable Object value, @Nullable Class requi } @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 ccfa6a003050..88e31532bb23 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 @@ 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 void initPropertyName(String propertyName) { * 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 String getPropertyName() { * 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 9290a7153722..ba00f28020b3 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.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 @@ @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 BeanCreationException(@Nullable String resourceDescription, String beanNa * 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 void addRelatedCause(Throwable ex) { * 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 f97c34b086e2..780f10bbb12a 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 @@ @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 BeanDefinitionStoreException( /** * 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 fb1f3ffd9df2..8e113a729f78 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 079760177033..81b083cadf54 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.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 fc26cc0ad55e..5cc7f2420ee0 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 @@ @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 CannotLoadBeanClassException(@Nullable String resourceDescription, String * 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 String getBeanName() { /** * 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 c8d06fe3b01c..17138b0d706b 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 d7504438bed8..3ed796bd1af3 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 f83a5da492f7..981a7109114a 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.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 @@ */ 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 @@ protected 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 MethodParameter getMethodParameter() { *

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 Annotation[] getAnnotations() { * @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 4ce86eceef84..5015197a8928 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.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 @@ Map getBeansOfType(@Nullable Class type, boolean includeNonSin * @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 @@ A findAnnotationOnBean(String beanName, Class annotati * @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 595b40ae982a..99f8a287e620 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 @@ @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 NoSuchBeanDefinitionException(ResolvableType type, String message) { /** * 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 String getBeanName() { * 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 getBeanType() { * 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 c2a6070c9d3f..88e62c0ffcb1 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.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 int getNumberOfBeansFound() { * @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 c008e6537c6d..ffbffc9154c0 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.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 @@ default T getObject(Object... args) throws BeansException { * @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 @@ default void ifAvailable(Consumer dependencyConsumer) throws BeansException { * @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 d11a5a16f823..c59a48ce0fdb 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 @@ @SuppressWarnings("serial") public class UnsatisfiedDependencyException extends BeanCreationException { - @Nullable - private final InjectionPoint injectionPoint; + private final @Nullable InjectionPoint injectionPoint; /** @@ -103,8 +103,7 @@ public UnsatisfiedDependencyException( * 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 7d3fc7628a5b..b788b638eb46 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 b8cb9070636c..4975b70612ea 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 final AnnotationMetadata getMetadata() { } @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 b3550404c5c5..d344ca565f46 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 @@ 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 c187dccf97e1..db86247f36e4 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 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.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 void resetBeanDefinition(String beanName) { } @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 @@ private Collection getAutowiredElements(InjectionMetadata meta 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 determineBeanType(Class beanClass, String beanName) throws Be } @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 @@ private InjectionMetadata buildAutowiringMetadata(Class clazz) { 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 @@ private void registerDependentBeans(@Nullable String beanName, Set autow /** * 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 @@ private class AutowiredFieldElement extends AutowiredElement { 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 @@ protected void inject(Object bean, @Nullable String beanName, @Nullable Property } } - @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 @@ private class AutowiredMethodElement extends AutowiredElement { 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 @@ protected void inject(Object bean, @Nullable String beanName, @Nullable Property } } - @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 @@ private Object[] resolveCachedArguments(@Nullable String beanName, @Nullable Obj 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 @@ private static class AotContribution implements BeanRegistrationAotContribution 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 7df476fe5404..042df2951b07 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.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.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 @@ else if (bf.containsBean(qualifier)) { * @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 86fe4482b2ee..32a7b997b1d4 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 @@ 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 085fe95b0185..79a5b13fcd7b 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 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.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 boolean hasDestroyMethods() { 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 void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, C } @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 @@ private LifecycleMetadata findLifecycleMetadata(RootBeanDefinition beanDefinitio 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 @@ private class LifecycleMetadata { 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 bdd4e4d6a962..1abb51365349 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.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 void clear(@Nullable PropertyValues pvs) { private final Collection injectedElements; - @Nullable - private volatile Set checkedElements; + private volatile @Nullable Set checkedElements; /** @@ -198,11 +198,9 @@ public abstract static class InjectedElement { 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 @@ protected void clearPropertySkipping(@Nullable PropertyValues pvs) { /** * 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 c4ad0a257daa..d11c0eab2817 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 @@ 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 a9dee0daa727..03e253cbd8b1 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.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 static boolean isAutowirable(Parameter parameter, int parameterIndex) { * @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 1e086230061d..fd29c8e102a0 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.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.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 boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDesc * {@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 @@ protected boolean checkQualifier( 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 boolean hasQualifier(DependencyDescriptor descriptor) { } @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 String getSuggestedName(DependencyDescriptor descriptor) { * @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 Object getSuggestedValue(DependencyDescriptor descriptor) { /** * 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 5a277e0126d9..5c96e85a6abc 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 03173bf9a9f7..69d4f79325d4 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 0b1f810726e5..2bbf63c60b3c 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 87613d63dafb..63762b02682b 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 c26a9c1ac845..8b7ba09a5204 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.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 List asList() { * @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 static class Loader { 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 f4c090647919..0f32a8a2acf9 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 @@ default T get(int index, Class requiredType) { * @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 @@ default T get(int index) { * @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 ca3a30e071ba..80ac8fb6dfc9 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.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.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 void resolve(RegisteredBean registeredBean, ThrowingConsumer actio * @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 T resolve(RegisteredBean registeredBean, Class requiredType) { * @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 T resolve(RegisteredBean registeredBean) { * @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 void resolveAndSet(RegisteredBean registeredBean, Object instance) { } } - @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 e52930dc3de7..8775f4466fd1 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.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.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 void resolve(RegisteredBean registeredBean, ThrowingConsumer 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 6938f0c9ef2b..3baa91561928 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 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 @@ BeanDefinitionMethodGenerator getBeanDefinitionMethodGenerator( * @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 29240a2c576d..e412331454b4 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.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.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 @@ CodeBlock generateCode(RootBeanDefinition beanDefinition) { } 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 @@ static void pop() { 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 1b9f1fcc8ad5..e07558a8103f 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.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.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 @@ private static class ManagedMapDelegate implements Delegate { 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 @@ private CodeBlock generateManagedMapCode(ValueCodeGenerator valueCodeGene 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 @@ private CodeBlock generateLinkedHashMapCode(ValueCodeGenerator valueCodeGenerato 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 @@ else if (value instanceof BeanReference beanReference) { 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 cfa48d8fc5ae..efb7e4cf5177 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 89cbce160267..733a76c91207 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.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.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 @@ else if (this.generatorWithArguments != null) { } @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 Method getFactoryMethod() { 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 @@ private ValueHolder resolveArgumentValue(BeanDefinitionValueResolver resolver, V 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 @@ private static class FactoryMethodLookup extends ExecutableLookup { 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 42a16c15238a..da4c5b7a6aae 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 @@ 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 void applyTo(GenerationContext generationContext, * 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 30a57779a2c8..b1e65c238d75 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 183ad41af15c..9f4491c25d5b 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 @@ 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 @@ 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 06e5eb0d33a0..db504c6b8b8e 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.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.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 498b04633b41..48ec28face44 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.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.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 @@ public CodeBlock generateSetBeanDefinitionPropertiesCode( .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 @@ protected CodeBlock generateValueCode(GenerationContext generationContext, Strin 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 c4a8d46f61a6..c331ce404938 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.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.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 bf7c97a915d0..41631ad6a3b6 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 ea7958d4d53f..d3b6364e2d26 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 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.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 void setBeanFactory(@Nullable BeanFactory beanFactory) { /** * Return the BeanFactory that this bean runs in. */ - @Nullable - protected BeanFactory getBeanFactory() { + protected @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @@ -184,8 +179,7 @@ private T getEarlySingletonInstance() throws Exception { * @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 void destroy() throws Exception { * @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 void destroy() throws Exception { * 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 cd7044c89f46..46dff4eab47c 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 @@ 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 @@ Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String be * @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 @@ Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String be * @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 7457494436df..27771db8ebbd 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 @@ 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 0f6f6ab5cb66..f581179a8cfb 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 @@ default boolean hasPropertyValues() { * 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 @@ default boolean hasPropertyValues() { * 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 @@ default boolean hasPropertyValues() { /** * Return a human-readable description of this bean definition. */ - @Nullable - String getDescription(); + @Nullable String getDescription(); // Read-only attributes @@ -373,8 +365,7 @@ default boolean hasPropertyValues() { * 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 @@ default boolean hasPropertyValues() { *

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 9b76f819fce2..eded121a8c2d 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 BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName) { * @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 String getBeanName() { * 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 String[] getAliases() { * @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 878735ec1a2a..f91bf12c3bc6 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.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 @@ */ public class BeanDefinitionVisitor { - @Nullable - private StringValueResolver valueResolver; + private @Nullable StringValueResolver valueResolver; /** @@ -170,8 +170,7 @@ protected void visitGenericArgumentValues(List mapVal) { * @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 7fa5b36b07d8..0b5eb79a6462 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 final ConfigurableBeanFactory getBeanFactory() { return this.beanFactory; } - @Nullable - public final Scope getScope() { + public final @Nullable Scope getScope() { return this.scope; } @@ -54,8 +53,7 @@ public boolean containsObject(String key) { (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 2975de790c4c..30159c400a44 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 7288aa476cf4..5aa701f19331 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 @@ default Object postProcessBeforeInitialization(Object bean, String beanName) thr * @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 af9616b44a17..cfb112815355 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 @@ 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.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 fe451841ab42..c17bb52e999e 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 @@ 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 175f5a4c0ba6..09579f00fb8a 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.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 boolean hasIndexedArgumentValue(int index) { * 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 ValueHolder getIndexedArgumentValue(int index, @Nullable Class require * 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 @@ private void addOrMergeGenericArgumentValue(ValueHolder newValue) { * @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 ValueHolder getGenericArgumentValue(Class requiredType) { * @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 ValueHolder getGenericArgumentValue(Class requiredType, String require * 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 List getGenericArgumentValues() { * @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 ValueHolder getArgumentValue(int index, Class requiredType) { * @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 ValueHolder getArgumentValue(int index, Class requiredType, String req * 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 int hashCode() { */ 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 void setValue(@Nullable Object value) { /** * Return the value for the constructor argument. */ - @Nullable - public Object getValue() { + public @Nullable Object getValue() { return this.value; } @@ -527,8 +514,7 @@ public void setType(@Nullable String type) { /** * Return the type of the constructor argument. */ - @Nullable - public String getType() { + public @Nullable String getType() { return this.type; } @@ -542,8 +528,7 @@ public void setName(@Nullable String name) { /** * Return the name of the constructor argument. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -556,8 +541,7 @@ public void setSource(@Nullable Object source) { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -582,8 +566,7 @@ public synchronized void setConvertedValue(@Nullable Object value) { * 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 64963ead5435..2d3dd8a5bb71 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 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 8bf43ae269a7..901ad062c283 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 @@ 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 @@ */ 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 e7dc1a602a5e..5084f049e890 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 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.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 boolean isEager() { * @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 Object resolveNotUnique(ResolvableType type, Map matching * @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 void initParameterNameDiscovery(@Nullable ParameterNameDiscoverer paramet * 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 f38156bcb950..ea2bf5b8abaa 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 EmbeddedValueResolver(ConfigurableBeanFactory beanFactory) { @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 6c132145b3bd..37f21f36c7f7 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 @@ 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 @@ 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 void setTargetClass(@Nullable Class targetClass) { /** * 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 void setTargetObject(@Nullable Object targetObject) { /** * 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 void setTargetField(@Nullable String targetField) { /** * Return the name of the field to be retrieved. */ - @Nullable - public String getTargetField() { + public @Nullable String getTargetField() { return this.targetField; } @@ -210,8 +201,7 @@ else if (this.targetField == null) { @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 Object getObject() throws IllegalAccessException { } @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 e842353cb55d..c00cb529b21d 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 @@ default boolean postProcessAfterInstantiation(Object bean, String beanName) thro * @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 d9b89210f08d..b73a9f9a8eb5 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 @@ 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 @@ */ 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 b02673c8b789..307fe53ba082 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 @@ 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 @@ */ 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 eb5ae4c0b7af..be10715dd2a2 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 @@ 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 @@ 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 void afterPropertiesSet() throws Exception { * 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 ec89f904e4f4..6e6a4a8a6297 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 void afterPropertiesSet() throws Exception { * 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 Object getObject() throws Exception { * 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 e1f9208ad8c2..1474a3879ec1 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 @@ 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 @@ */ 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 6e37fc17fb46..4c6035d3c92a 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 fc616b895ef9..e100e9e31410 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.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 @@ @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 @@ protected String resolvePlaceholder(String placeholder, Properties props) { * @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 47a857eb1f24..803d59324117 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 @@ 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 final void afterPropertiesSet() throws IOException { } @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 b22e52be3d26..6ef0b5f81cb3 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 @@ 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.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 @@ else if (this.propertyPath == null) { @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 Object getObject() throws BeansException { } @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 51d9124850ca..77d430073e67 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 @@ 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 void setSearchSystemEnvironment(boolean searchSystemEnvironment) { * @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 @@ protected String resolvePlaceholder(String placeholder, Properties props, int sy * @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 @@ protected String resolvePlaceholder(String placeholder, Properties props) { * @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 PlaceholderResolvingStringValueResolver(Properties props) { } @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 @@ private PropertyPlaceholderConfigurerResolver(Properties props) { } @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 96d7bf3a6035..9fcb489660b8 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 @@ 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 @@ */ 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 f04a8d103efd..ad8be03a389b 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 void setSource(@Nullable Object source) { } @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 361b786dd39a..f96518c7c332 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 String getBeanName() { * 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 void setSource(@Nullable Object source) { } @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 8073dda0d912..cb4cb0de1d7b 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 590280998d59..78b5b78160b6 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.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.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 @@ */ 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 @@ else if (paramTypes[i].isInstance(cause)) { @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 @@ private Object invokeServiceLocatorMethod(Method method, Object[] args) throws E /** * 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 8b30f8eb8f48..6b579da35327 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 @@ 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 @@ */ 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 b1f9f876b425..0da3086b9ee4 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 @@ 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 86455b173c11..79aae284a20f 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 @@ 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 @@ default Class determineBeanType(Class beanClass, String beanName) throws B * @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 c4d9c5c8e540..b807dd4cb0a6 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 @@ 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 @@ */ 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 void setValue(@Nullable String value) { /** * Return the String value. */ - @Nullable - public String getValue() { + public @Nullable String getValue() { return this.value; } @@ -133,8 +129,7 @@ public void setTargetTypeName(@Nullable String targetTypeName) { /** * Return the type to convert to. */ - @Nullable - public String getTargetTypeName() { + public @Nullable String getTargetTypeName() { Object targetTypeValue = this.targetType; if (targetTypeValue instanceof Class clazz) { return clazz.getName(); @@ -159,8 +154,7 @@ public boolean hasTargetType() { * @return the resolved type to convert to * @throws ClassNotFoundException if the type cannot be resolved */ - @Nullable - public Class 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 void setSource(@Nullable Object source) { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -195,8 +188,7 @@ public void setSpecifiedTypeName(@Nullable String specifiedTypeName) { /** * Return the type name as actually specified for this particular value, if any. */ - @Nullable - public String getSpecifiedTypeName() { + public @Nullable String getSpecifiedTypeName() { return this.specifiedTypeName; } diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java index ea482766d782..ac3f26e43320 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/config/YamlMapFactoryBean.java @@ -19,9 +19,10 @@ import java.util.LinkedHashMap; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.InitializingBean; -import org.springframework.lang.Nullable; /** * Factory for a {@code Map} that reads from a YAML source, preserving the @@ -74,8 +75,7 @@ public class YamlMapFactoryBean extends YamlProcessor implements FactoryBean map; + private @Nullable Map map; /** @@ -99,8 +99,7 @@ public void afterPropertiesSet() { } @Override - @Nullable - public Map 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 472188fd389f..e0d332027f0f 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 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.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 5c09abda686f..670294147aab 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 @@ 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 void afterPropertiesSet() { } @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 280e916ab186..5ba69e387644 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 0d9a67cd04b6..cbc2ed07e3cb 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.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.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 void setBinding(Binding binding) { /** * 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 int loadBeanDefinitions(EncodedResource encodedResource) throws BeanDefin @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 @@ else if (value instanceof Closure callable) { * */ @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 @@ private static class DeferredProperty { 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 MetaClass getMetaClass() { } @Override - @Nullable - public Object getProperty(String property) { + public @Nullable Object getProperty(String property) { if (property.equals("beanName")) { return getBeanName(); } @@ -809,8 +802,7 @@ private class GroovyPropertyValue extends GroovyObjectSupport { 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 895646d9da0b..b0f71df9bbac 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.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.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 @@ GroovyBeanDefinitionWrapper addProperty(String propertyName, @Nullable Object pr @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 b8b9efd52031..31e9d9de5edf 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.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 @@ public GroovyDynamicElementReader(String namespace, Map namespac @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 9201a5278280..a48700cf4625 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 a29b453f3ee4..48c6b5c60b04 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 27bed9e3c90c..875b6a81d8ad 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 final String getAlias() { } @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 ad8e72ed48f3..4dd2c97ba41f 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 @@ 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 BeanComponentDefinition(BeanDefinition beanDefinition, String beanName) { * @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 efd846cedae7..e7658cd8199a 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 @@ 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 String getName() { } @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 3dc71bb4b35d..1de71d5c927f 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 @@ 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 374025022155..861fc64379d2 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 ImportDefinition(String importedResource, @Nullable Object source) { * @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 final String getImportedResource() { 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 b06c524ce041..50b77dc5345f 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 Resource getResource() { *

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 1205b3fa8e6a..165667d9e941 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 afbb13957125..c1b1afb0fefe 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 @@ 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 void pop() { * 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 1365c9932b6c..1d4525459250 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 86d58000d117..e724c5e85e2e 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 String getResourceDescription() { /** * 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 2b95aa8f6c3b..7879ba648ec4 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 SourceExtractor getSourceExtractor() { * @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 8809cd2473f3..960b0b3ae744 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 0f57ef135159..dcb31b3e7359 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 3ee514663c68..27f3342d7ebd 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 @@ 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 @@ 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 void setServiceType(@Nullable Class serviceType) { /** * 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 535a53716e06..1698abcdc210 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 @@ 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 @@ protected Object getObjectToExpose(ServiceLoader serviceLoader) { } @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 b6a97c2c7ef6..5c6a93356398 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 1ddddbe82db0..dd35a4f867e2 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.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.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 void setParameterNameDiscoverer(@Nullable ParameterNameDiscoverer paramet * 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 Object resolveBeanByName(String name, DependencyDescriptor descriptor) { } @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 Object resolveDependency(DependencyDescriptor descriptor, @Nullable Strin * @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 @@ protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable O * @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 @@ else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) { } @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 @@ protected Class predictBeanType(String beanName, RootBeanDefinition mbd, Clas * (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 @@ protected Class determineTargetType(String beanName, RootBeanDefinition mbd, * @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 @@ protected Object getEarlyBeanReference(String beanName, RootBeanDefinition mbd, * @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 @@ private FactoryBean getSingletonFactoryBeanForTypeCheck(String beanName, Root * @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 @@ protected void applyMergedBeanDefinitionPostProcessors(RootBeanDefinition mbd, C * @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 @@ protected Object resolveBeforeInstantiation(String beanName, RootBeanDefinition * @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 @@ protected Object applyBeanPostProcessorsBeforeInstantiation(Class beanClass, * @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 @@ private BeanWrapper obtainFromSupplier(Supplier supplier, String beanName, Ro * @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 @@ protected Object getObjectForBeanInstance( * @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 @@ protected BeanWrapper instantiateBean(String beanName, RootBeanDefinition mbd) { * @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 @@ protected BeanWrapper instantiateUsingFactoryMethod( * @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 @@ private boolean isConvertibleProperty(String propertyName, BeanWrapper bw) { /** * 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 CreateFromClassBeanDefinition(CreateFromClassBeanDefinition original) { } @Override - @Nullable - public Constructor[] getPreferredConstructors() { + public Constructor @Nullable [] getPreferredConstructors() { Constructor[] fromAttribute = super.getPreferredConstructors(); if (fromAttribute != null) { return fromAttribute; @@ -2002,8 +1988,7 @@ public AutowireByTypeDependencyDescriptor(MethodParameter methodParameter, boole } @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 ab66ca7c8f39..2a8a44e3268f 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.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.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 void setBeanClassName(@Nullable String beanClassName) { * @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 boolean hasBeanClass() { * @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 void setScope(@Nullable String scope) { *

The default is {@link #SCOPE_DEFAULT}. */ @Override - @Nullable - public String getScope() { + public @Nullable String getScope() { return this.scope; } @@ -631,8 +616,7 @@ public boolean isLazyInit() { * @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 int getDependencyCheck() { *

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 void setDependsOn(@Nullable String... dependsOn) { *

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 boolean hasQualifier(String typeName) { /** * 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 void setInstanceSupplier(@Nullable Supplier instanceSupplier) { * 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 void setFactoryBeanName(@Nullable String factoryBeanName) { * @see #getBeanClass() */ @Override - @Nullable - public String getFactoryBeanName() { + public @Nullable String getFactoryBeanName() { return this.factoryBeanName; } @@ -943,8 +923,7 @@ public void setFactoryMethodName(@Nullable String factoryMethodName) { * @see RootBeanDefinition#getResolvedFactoryMethod() */ @Override - @Nullable - public String getFactoryMethodName() { + public @Nullable String getFactoryMethodName() { return this.factoryMethodName; } @@ -1038,7 +1017,7 @@ public boolean hasMethodOverrides() { * @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 void setInitMethodNames(@Nullable String... initMethodNames) { * 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 void setInitMethodName(@Nullable String initMethodName) { *

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 boolean isEnforceInitMethod() { * @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 void setDestroyMethodNames(@Nullable String... destroyMethodNames) { * 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 void setDestroyMethodName(@Nullable String destroyMethodName) { *

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 void setDescription(@Nullable String description) { *

The default is no description. */ @Override - @Nullable - public String getDescription() { + public @Nullable String getDescription() { return this.description; } @@ -1217,8 +1191,7 @@ public void setResource(@Nullable Resource resource) { /** * 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 void setResourceDescription(@Nullable String resourceDescription) { * @see #setResourceDescription */ @Override - @Nullable - public String getResourceDescription() { + public @Nullable String getResourceDescription() { return (this.resource != null ? this.resource.getDescription() : null); } @@ -1252,8 +1224,7 @@ public void setOriginatingBeanDefinition(BeanDefinition originatingBd) { * @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 40a4503551ef..97635a095802 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 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.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 void setResourceLoader(@Nullable ResourceLoader resourceLoader) { } @Override - @Nullable - public ResourceLoader getResourceLoader() { + public @Nullable ResourceLoader getResourceLoader() { return this.resourceLoader; } @@ -141,8 +138,7 @@ public void setBeanClassLoader(@Nullable ClassLoader beanClassLoader) { } @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 60029e60a954..64d89ab6f739 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.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.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 @@ 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 T getBean(String name, Class requiredType) throws BeansException { } @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 Object getBean(String name, Object... args) throws BeansException { * @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 T getBean(String name, @Nullable Class requiredType, @Nullable Obj */ @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 boolean isTypeMatch(String name, Class typeToMatch) throws NoSuchBeanD } @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 String[] getAliases(String name) { //--------------------------------------------------------------------- @Override - @Nullable - public BeanFactory getParentBeanFactory() { + public @Nullable BeanFactory getParentBeanFactory() { return this.parentBeanFactory; } @@ -832,8 +823,7 @@ public void setBeanClassLoader(@Nullable ClassLoader beanClassLoader) { } @Override - @Nullable - public ClassLoader getBeanClassLoader() { + public @Nullable ClassLoader getBeanClassLoader() { return this.beanClassLoader; } @@ -843,8 +833,7 @@ public void setTempClassLoader(@Nullable ClassLoader tempClassLoader) { } @Override - @Nullable - public ClassLoader getTempClassLoader() { + public @Nullable ClassLoader getTempClassLoader() { return this.tempClassLoader; } @@ -864,8 +853,7 @@ public void setBeanExpressionResolver(@Nullable BeanExpressionResolver resolver) } @Override - @Nullable - public BeanExpressionResolver getBeanExpressionResolver() { + public @Nullable BeanExpressionResolver getBeanExpressionResolver() { return this.beanExpressionResolver; } @@ -875,8 +863,7 @@ public void setConversionService(@Nullable ConversionService conversionService) } @Override - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -921,8 +908,7 @@ public void setTypeConverter(TypeConverter typeConverter) { * 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 boolean hasEmbeddedValueResolver() { } @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 String[] getRegisteredScopeNames() { } @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 @@ private void copyRelevantMergedBeanDefinitionCaches(RootBeanDefinition previous, * @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 void clearMetadataCache() { * @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 @@ protected Class resolveBeanClass(RootBeanDefinition mbd, String beanName, Cla } } - @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 @@ else if (evaluated instanceof String name) { * @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 @@ protected Object evaluateBeanDefinitionString(@Nullable String value, @Nullable * (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 @@ protected void registerDisposableBeanIfNecessary(String beanName, Object bean, R * @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 c078572af5ab..a33573cb3645 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 @@ default boolean hasQualifier(DependencyDescriptor descriptor) { * @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 @@ default String getSuggestedName(DependencyDescriptor descriptor) { * 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 @@ default Object getSuggestedValue(DependencyDescriptor descriptor) { * 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 @@ default Object getLazyResolutionProxyIfNecessary(DependencyDescriptor descriptor * @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 1a6f0c87533c..9e79e6e224b4 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.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 d82d66bd75c0..627059921c26 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 @@ 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 eb76dd9d13d8..ef70bb65fa23 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 @@ */ 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 boolean isLazyInit() { * @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 void setInitMethodName(@Nullable String initMethodName) { /** * Return the name of the default initializer method. */ - @Nullable - public String getInitMethodName() { + public @Nullable String getInitMethodName() { return this.initMethodName; } @@ -143,8 +139,7 @@ public void setDestroyMethodName(@Nullable String destroyMethodName) { /** * 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 a815db479f92..0a5ac2cec49d 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 BeanDefinitionOverrideException( * 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 String getResourceDescription() { * 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 8441abbc7664..b6eeb3ae2323 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 b02687792e15..678e37d948b5 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 f59222a96211..54f61ada5fff 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.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 c3efcdcc0b2d..08af87df259a 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.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.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 BeanDefinitionValueResolver(AbstractAutowireCapableBeanFactory beanFactor * @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 T resolveInnerBean(@Nullable String innerBeanName, BeanDefinition inn * @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 @@ protected Object evaluate(TypedStringValue value) { * @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 @@ else if (value instanceof String[] values) { * @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 @@ private Object doEvaluate(@Nullable String value) { * @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 @@ protected Class resolveTargetType(TypedStringValue value) throws ClassNotFoun /** * 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 @@ private Object resolveReference(Object argName, RuntimeBeanReference ref) { * @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 4c1f826f56a0..416e7b29f97c 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 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.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 LookupOverrideMethodInterceptor(RootBeanDefinition beanDefinition, BeanFa } @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 ReplaceOverrideMethodInterceptor(RootBeanDefinition beanDefinition, BeanF 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 Object intercept(Object obj, Method method, Object[] args, MethodProxy mp 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 5f15616d95a1..6cb7c13f0d72 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 @@ @SuppressWarnings("serial") public class ChildBeanDefinition extends AbstractBeanDefinition { - @Nullable - private String parentName; + private @Nullable String parentName; /** @@ -136,8 +136,7 @@ public void setParentName(@Nullable String parentName) { } @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 39d0323db4a1..d3c2bee08bbc 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.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.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 @@ public ConstructorResolver(AbstractAutowireCapableBeanFactory beanFactory) { */ @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 @@ private boolean isStaticCandidate(Method method, Class factoryClass) { */ @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 @@ public BeanWrapper instantiateUsingFactoryMethod( Method factoryMethodToUse = null; ArgumentsHolder argsHolderToUse = null; - Object[] argsToUse = null; + @Nullable Object[] argsToUse = null; if (explicitArgs != null) { argsToUse = explicitArgs; @@ -647,7 +647,7 @@ else if (ambiguousFactoryMethods != null) { } 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 @@ private int resolveConstructorArguments(String beanName, RootBeanDefinition mbd, */ 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 @@ private Constructor getUserDeclaredConstructor(Constructor constructor) { /** * 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 @@ private ResolvableType determineParameterValueType(RootBeanDefinition mbd, Value 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 @@ private Constructor resolveConstructor(String beanName, RootBeanDefinition mb 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 @@ else if (candidates.size() > 1) { return null; } - @Nullable - private Method resolveFactoryMethod(List executables, + private @Nullable Method resolveFactoryMethod(List executables, Function> parameterTypesFactory, List valueTypes) { @@ -1257,8 +1253,7 @@ private Predicate isSimpleValueType(ResolvableType valueType) { 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 @@ static InjectionPoint setCurrentInjectionPoint(@Nullable InjectionPoint injectio * 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 @@ else if (ctors.length == 0) { */ 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 @@ public ArgumentsHolder(int size) { 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 @@ public void storeCache(RootBeanDefinition mbd, Executable constructorOrFactoryMe */ 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 @@ public static String[] evaluate(Constructor candidate, int paramCount) { @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 @@ public boolean hasShortcut() { } @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 48bbeec50f07..692ffcb2d5f9 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.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.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 @@ 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 @@ else if (this.serializationId != null) { * 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 void setBootstrapExecutor(@Nullable Executor bootstrapExecutor) { } @Override - @Nullable - public Executor getBootstrapExecutor() { + public @Nullable Executor getBootstrapExecutor() { return this.bootstrapExecutor; } @@ -313,8 +305,7 @@ public void setDependencyComparator(@Nullable Comparator dependencyCompa * 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 T getBean(Class requiredType) throws BeansException { @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 T getObject(Object... args) throws BeansException { 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 void ifAvailable(Consumer dependencyConsumer) throws BeansException { } } @Override - @Nullable - public T getIfUnique() throws BeansException { + public @Nullable T getIfUnique() throws BeansException { try { return resolveBean(requiredType, null, true); } @@ -511,8 +500,7 @@ public Stream orderedStream() { }; } - @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 Map getBeansWithAnnotation(Class an } @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 @@ protected boolean isBeanEligibleForMetadataCaching(String beanName) { } @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 @@ protected Object obtainInstanceFromSupplier(Supplier supplier, String beanNam } @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 @@ protected void checkMergedBeanDefinition(RootBeanDefinition mbd, String beanName } @Override - @Nullable - protected Boolean isCurrentThreadAllowedToHoldSingletonLock() { + protected @Nullable Boolean isCurrentThreadAllowedToHoldSingletonLock() { return (this.preInstantiationPhase ? this.preInstantiationThread.get() != PreInstantiation.BACKGROUND : null); } @@ -1060,8 +1044,7 @@ public void preInstantiateSingletons() throws BeansException { } } - @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 NamedBeanHolder resolveNamedBean(Class requiredType) throws Bea } @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 @@ else if (candidateNames.length > 1) { 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 @@ private NamedBeanHolder resolveNamedBean( } @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 @@ else if (descriptor.supportsLazyResolution()) { 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 Object doResolveDependency(DependencyDescriptor descriptor, @Nullable Str } } - @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 @@ private Object resolveInstance(Object candidate, DependencyDescriptor descriptor } - @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 @@ else if (Map.class == type) { } - @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 @@ else if (Map.class.isAssignableFrom(type) && type.isInterface()) { 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 @@ private Object resolveMultipleBeanCollection(DependencyDescriptor descriptor, @N 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 @@ private boolean isRequired(DependencyDescriptor descriptor) { 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 @@ else if (containsSingleton(candidateName) || (descriptor instanceof StreamDepend * @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 @@ protected String determineAutowireCandidate(Map candidates, Depe * @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 @@ else if (candidateLocal) { * 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 @@ private boolean isFallback(String beanName) { * @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 @@ private class DependencyObjectProvider implements BeanObjectProvider { 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 Object resolveCandidate(String beanName, Class requiredType, BeanFacto } @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 void ifAvailable(Consumer dependencyConsumer) throws BeansExcepti } @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 boolean usesStandardBeanLookup() { 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 void ifUnique(Consumer dependencyConsumer) throws BeansException } } - @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 Jsr330Provider(DependencyDescriptor descriptor, @Nullable String beanName } @Override - @Nullable - public Object get() throws BeansException { + public @Nullable Object get() throws BeansException { return getValue(); } } @@ -2526,8 +2489,7 @@ public FactoryAwareOrderSourceProvider(Map instancesToBeanNames) } @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 bebcc1154009..da7e299ef22b 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.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.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 void addSingletonCallback(String beanName, Consumer singletonCons } @Override - @Nullable - public Object getSingleton(String beanName) { + public @Nullable Object getSingleton(String beanName) { return getSingleton(beanName, true); } @@ -189,8 +188,7 @@ public Object getSingleton(String beanName) { * @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 Object getSingleton(String beanName, ObjectFactory singletonFactory) { * 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 f95fd951e3f2..1b0149e9febf 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 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.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 @@ public DisposableBeanAdapter(Object bean, List postProcessors) { this.bean = bean; @@ -261,8 +258,7 @@ else if (this.destroyMethodNames != null) { } - @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 @@ private Method determineDestroyMethod(String destroyMethodName) { } } - @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 @@ public static boolean hasDestroyMethod(Object bean, RootBeanDefinition beanDefin *

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 @@ public static boolean hasApplicableProcessors(Object bean, 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 ffcd87bbfbc1..da0199f0d1e4 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 @@ 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.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 @@ ResolvableType getFactoryBeanGeneric(@Nullable ResolvableType type) { * @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 570957cf99a5..fdfb87480bad 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 @@ * @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 void setParentName(@Nullable String parentName) { } @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 f422594f701e..81d4b201cb86 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 @@ 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.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 @@ public class GenericTypeAwareAutowireCandidateResolver extends SimpleAutowireCandidateResolver implements BeanFactoryAware, Cloneable { - @Nullable - private BeanFactory beanFactory; + private @Nullable BeanFactory beanFactory; @Override @@ -54,8 +54,7 @@ public void setBeanFactory(BeanFactory beanFactory) { this.beanFactory = beanFactory; } - @Nullable - protected final BeanFactory getBeanFactory() { + protected final @Nullable BeanFactory getBeanFactory() { return this.beanFactory; } @@ -161,8 +160,7 @@ else if (targetType.resolve() == Properties.class) { 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 @@ protected RootBeanDefinition getResolvedDecoratedDefinition(RootBeanDefinition r 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 22e65bc12be5..76c68376fee5 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 @@ 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 @@ default T getWithException() { * 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 V get(RegisteredBean registeredBean) throws Exception { 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 T get(RegisteredBean registeredBean) throws Exception { 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 450d85aa9ec3..0824a2038b06 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 @@ 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 @@ Object instantiate(RootBeanDefinition bd, @Nullable String beanName, BeanFactory * @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 9cbcbebe94e9..f0be69767c84 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 @@ 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 @@ */ 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 LookupOverride(Method method, @Nullable String beanName) { /** * 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 89e346b2d9b5..f0dead875813 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 @@ 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 2b0a25a91396..43ad078b24f8 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.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 @@ @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 void setSource(@Nullable Object source) { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -95,8 +93,7 @@ public void setElementTypeName(String elementTypeName) { /** * 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 b0eef75e3efa..f5af789f8acc 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.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 @@ @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 void setSource(@Nullable Object source) { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -101,8 +98,7 @@ public void setKeyTypeName(@Nullable String keyTypeName) { /** * 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 void setValueTypeName(@Nullable String valueTypeName) { /** * 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 ef00476dadee..951987f446c6 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 @@ 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 @@ @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 void setSource(@Nullable Object source) { } @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 1381dde65152..dc25faf93d99 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.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 @@ @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 void setSource(@Nullable Object source) { } @Override - @Nullable - public Object getSource() { + public @Nullable Object getSource() { return this.source; } @@ -94,8 +92,7 @@ public void setElementTypeName(@Nullable String elementTypeName) { /** * 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 49ca03408e5e..69d983e57021 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 @@ 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 void setSource(@Nullable Object source) { } @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 d9d9e6c12177..5f1efdc2d064 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.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 boolean isEmpty() { * @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 ab847865b5e0..51de5237ffe8 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 37f90946393a..40a65d4e70eb 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.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.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 void setDefaultParentBean(@Nullable String defaultParentBean) { /** * 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 3f3b25cc5ab1..5bddb9b3887e 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.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.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 boolean isInnerBean() { * 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 InstantiationDescriptor resolveInstantiationDescriptor() { * @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 @@ private static class InnerBeanResolver { 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 4fe5ad846236..ffc3de60c00b 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.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 5f91f6bdcee4..f0483f1c8e0f 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.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 @@ @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 RootBeanDefinition(RootBeanDefinition original) { @Override - @Nullable - public String getParentName() { + public @Nullable String getParentName() { return null; } @@ -299,8 +284,7 @@ public void setDecoratedDefinition(@Nullable BeanDefinitionHolder decoratedDefin /** * 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 void setQualifiedElement(@Nullable AnnotatedElement qualifiedElement) { * 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 void setTargetType(@Nullable Class targetType) { * (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 ResolvableType getResolvableType() { * (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 void setResolvedFactoryMethod(@Nullable Method method) { * 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 1c7e3cb808c9..6e2a25d81f8d 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 boolean hasQualifier(DependencyDescriptor descriptor) { } @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 1b54829f9075..a70a17d7192f 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.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 @@ protected Object instantiateWithMethodInjection(RootBeanDefinition bd, @Nullable } @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 c9bfc61de581..1ae2dd225002 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.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.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 T getBean(String name, @Nullable Class requiredType) throws BeansE } @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 @@ else if (beanNames.length > 1) { } @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 boolean isTypeMatch(String name, @Nullable Class typeToMatch) throws N } @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 @@ else if (beanNames.length > 1) { } } @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 @@ else if (beanNames.length > 1) { } } @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 Map getBeansWithAnnotation(Class an } @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 0a5599d3f0eb..f8bfd78b84df 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 6584e16bb951..8d3b0261bc33 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 @@ 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.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 void setBeanFactory(BeanFactory beanFactory) { *

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 ac8e634cedbf..b7844ade0239 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 boolean indicatesAutowiring() { /** * 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 f6dc9bfcef49..74c3791b2707 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 c069d7d1af60..c251111e9236 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 018c85123f9b..8fb760bcd9f9 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.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 @@ protected void registerBeanDefinition(BeanDefinitionHolder definition, BeanDefin * @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 75b70796e1cc..2bcba9af8efe 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 @@ protected final AbstractBeanDefinition parseInternal(Element element, ParserCont * @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 @@ protected String getParentName(Element element) { * 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 @@ protected Class getBeanClass(Element element) { * 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 a92f282667e3..53da31cdc22f 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 84bf8629d5f4..d97c69d7622f 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 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.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 final XmlReaderContext getReaderContext() { * 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 BeanDefinitionDefaults getBeanDefinitionDefaults() { * 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 String[] getAutowireCandidatePatterns() { * 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 BeanDefinitionHolder parseBeanDefinitionElement(Element ele) { * 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 @@ protected void checkNameUniqueness(String beanName, List aliases, Elemen * 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 void parseQualifierElement(Element ele, AbstractBeanDefinition bd) { * 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 @@ else if (subElement != null) { * @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 Object parsePropertySubElement(Element ele, @Nullable BeanDefinition bd) * @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 @@ else if (nodeNameEquals(ele, PROPS_ELEMENT)) { /** * 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 @@ protected final Object buildTypedStringValueForMap(String value, String defaultT /** * 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 boolean parseMergeAttribute(Element collectionElement) { * @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 BeanDefinition parseCustomElement(Element ele) { * @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 @@ else if (namespaceUri.startsWith("http://www.springframework.org/schema/")) { 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 @@ private BeanDefinitionHolder parseNestedCustomElement(Element ele, @Nullable Bea * 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 16496d31b9b4..053b165fed3b 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 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 b75e54893a74..4c2a6e6c2b5b 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 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.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 @@ protected final XmlReaderContext getReaderContext() { * 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 77ec6469f13e..2a359b740176 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 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 68a96ee9d295..cfa04a15e661 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 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 DefaultNamespaceHandlerResolver(@Nullable ClassLoader classLoader, String * @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 fe8f6f61a37f..1edf6ea01804 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 @@ 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 DelegatingEntityResolver(EntityResolver dtdResolver, EntityResolver schem @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 d5a2122a61e9..afb1968e0fad 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 @@ */ 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 void setLazyInit(@Nullable String lazyInit) { /** * 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 void setMerge(@Nullable String merge) { /** * 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 void setAutowire(@Nullable String autowire) { /** * 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 void setAutowireCandidates(@Nullable String autowireCandidates) { * 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 void setInitMethod(@Nullable String initMethod) { /** * 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 void setDestroyMethod(@Nullable String destroyMethod) { /** * 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 void setSource(@Nullable Object source) { } @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 fa061fe0c181..2dee6de1a66a 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 2e92b258cac2..6707478efe4e 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 b1eec9bbc9f9..3715f1181568 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 @@ 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 BeanDefinition parse(Element element, ParserContext parserContext) { * 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 @@ private BeanDefinitionParser findParserForElement(Element element, ParserContext * 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 BeanDefinitionHolder decorate( * 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 4bd6ef58e966..db4bad7251fd 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 @@ 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 BeanDefinitionParserDelegate getDelegate() { return this.delegate; } - @Nullable - public BeanDefinition getContainingBeanDefinition() { + public @Nullable BeanDefinition getContainingBeanDefinition() { return this.containingBeanDefinition; } @@ -89,13 +88,11 @@ public boolean isDefaultLazyInit() { 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 659b21b40b97..bbf56e67b1a0 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 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 PluggableSchemaResolver(@Nullable ClassLoader classLoader, String schemaM @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 1b348693c9b7..512f09af5e39 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 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 ResourceEntityResolver(ResourceLoader resourceLoader) { @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 @@ else if (systemId.endsWith(DTD_SUFFIX) || systemId.endsWith(XSD_SUFFIX)) { * 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 7cf160d848f0..ab956dd83f6e 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 @@ 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.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 void init() { } @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 ec3c1512d8a8..9ea98fb50045 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.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 void init() { } @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 12232bddf71c..e231df3479fa 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 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.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 a0ca6d0c2045..772a96c6e566 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 @@ 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.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 final BeanDefinitionRegistry getRegistry() { * @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 final ResourceLoader getResourceLoader() { * 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 3dcc0d43ad0b..8c4648abb0ac 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 1bea8aea4582..2cd047cb6588 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 14e4c4b80966..d2da2bd97227 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 @@ 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 705d58fadfab..15de6ae48908 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 @@ 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 727be75c8694..14583451913f 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 @@ 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 0a2882a988c0..c8da0425ac30 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 @@ 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 @@ */ 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 a68d4988e49d..5176ea58e031 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 @@ 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 @@ */ 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 5d71fca9daee..ddc9703cfcc2 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 @@ 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 898adb52ecca..ce97ddd02197 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.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 @@ protected Object convertElement(Object element) { * 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 fcc3f8290a2b..34d9d475fcc5 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.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 d421a8e25c00..b8dddef9a3bf 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.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 @@ protected Object convertValue(Object value) { * 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 e1c8ba38376f..fb36494eedc6 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 @@ 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 303067c5e253..bdf47645ffd1 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 @@ 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 void setAsText(String text) throws IllegalArgumentException { * 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 03f14d117ede..da64aa724af2 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 @@ 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 cccb6c6bfa4d..128b91c73948 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.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 46171fb4b774..676b129ce61b 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 @@ 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 void setAsText(String text) throws IllegalArgumentException { * 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 7149e931df03..742d6e48e3fe 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 @@ 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 d97037c56364..a87b898d34d0 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 @@ import java.beans.PropertyEditorSupport; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -32,8 +33,7 @@ */ 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 e94e65f5a94f..7a7afd224637 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.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 @@ */ 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 ddb64ffdc167..e1dfba14bc7f 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 20dec0c3559b..bea627e669cb 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 @@ 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 @@ */ public class ArgumentConvertingMethodInvoker extends MethodInvoker { - @Nullable - private TypeConverter typeConverter; + private @Nullable TypeConverter typeConverter; private boolean useDefaultConverter = true; @@ -67,8 +67,7 @@ public void setTypeConverter(@Nullable TypeConverter typeConverter) { * (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 void registerCustomEditor(Class requiredType, PropertyEditor propertyE * @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 @@ protected Method findMatchingMethod() { * @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 495072fa36e5..e6f2835613ea 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 @@ 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 063834e1a8d6..161620a403b7 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.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 List getSource() { /** * 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 void setSort(@Nullable SortDefinition sort) { /** * 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 9a9a7d8f30d1..ad0c58bbcdbe 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 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 int compare(T o1, T o2) { * @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 326ce25e1448..73ea6d22c9ac 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 81c4fab0401d..f12fd01e9970 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.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.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 b700314ba1cf..cd4bcf9e8ea5 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.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.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 @@ public BeanWithNullableTypes(@Nullable Integer counter, @Nullable Boolean flag, 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 0621279dc81b..6ec9c4d488c6 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.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.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 916428419991..9d5b31c8c60f 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.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.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 @@ public static TestBean newTestBean2() { static class MixedNullableInjectionBean { - @Nullable - public Integer nullableBean; + public @Nullable Integer nullableBean; public String nonNullBean; @@ -4309,8 +4308,7 @@ public void nullabilityInjection(@Nullable Integer nullableBean, String nonNullB 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 7f38730c03f3..154b417078b9 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.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 @@ static class MockBeanRegistrationExcludeFilter implements 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 0613281ed822..0a2f316b5a50 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 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.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 @@ public void setName(String name) { 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 7379fc22262e..85ef58b32596 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.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.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 4c709272428b..d5b6ad2dffa5 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.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 @@ float getFloat() { 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 144bc37564fd..6c8b10ca7ca6 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.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.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 5229dc46f434..3ca9366496f0 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 @@ private static class ConfigurableFallbackEntityResolver extends ResourceEntityRe private final boolean shouldThrow; - @Nullable - private final InputSource returnValue; + private final @Nullable InputSource returnValue; boolean fallbackInvoked = false; @@ -112,8 +111,7 @@ private ConfigurableFallbackEntityResolver(@Nullable InputSource returnValue) { } @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 110ea9979746..538bc6db4707 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 @@ 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 971ac2bdb31f..eced628a4567 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 343c5db3fdc9..4168a6751cef 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 @@ 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 3ff88b183654..e27ed937ae64 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 @@ 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 580e117c3126..e50b9246aac0 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.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 3d4288278c8b..e94ceaeaea22 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 @@ 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 @@ */ 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 571b2d1509bc..693c9173b0d3 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 GenericFactoryBean(Class beanType) { 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 dc39666d1a57..ee25b9bb9b5f 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 da4b62e471c6..f5ffec852a59 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 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 final AsyncCache getAsyncCache() { @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 CompletableFuture retrieve(Object key, Supplier loadingCache) { return loadingCache.get(key); } @@ -173,8 +169,7 @@ public void put(Object key, @Nullable Object value) { } @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 boolean invalidate() { 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 2ad316114bdc..b08f9d376ee4 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.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 Collection getCacheNames() { } @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 864fb2e3997d..5606a4fdffec 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 c870d843d736..724a66d19ada 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.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 final Cache getNativeCache() { } @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 void put(Object key, @Nullable Object value) { } @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 @@ private static class PutIfAbsentEntryProcessor implements EntryProcessor 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 @@ private ValueLoaderEntryProcessor(Function fromStoreValue, } @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 0e87c8af53ad..c2e90d6e9715 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 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 @@ */ public class JCacheCacheManager extends AbstractTransactionSupportingCacheManager { - @Nullable - private CacheManager cacheManager; + private @Nullable CacheManager cacheManager; private boolean allowNullValues = true; @@ -75,8 +75,7 @@ public void setCacheManager(@Nullable CacheManager cacheManager) { /** * Return the backing JCache {@link CacheManager javax.cache.CacheManager}. */ - @Nullable - public CacheManager getCacheManager() { + public @Nullable CacheManager getCacheManager() { return this.cacheManager; } @@ -121,8 +120,7 @@ protected Collection loadCaches() { } @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 da3a2e15669d..29d246a09f42 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 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 @@ 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 void afterPropertiesSet() { @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 793435d03f46..4bcc7ab2440f 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 @@ 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.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 @@ @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 2690c1ac37bd..d834cd7c35a6 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 76f4b4570266..6f991f5f7316 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 @@ 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 c5adcac5ac60..46899ffad14c 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 06025fc26a13..e128f2f3662e 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 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 @@ protected AbstractCacheInterceptor(CacheErrorHandler errorHandler) { } - @Nullable - protected abstract Object invoke(CacheOperationInvocationContext context, CacheOperationInvoker invoker) + protected abstract @Nullable Object invoke(CacheOperationInvocationContext context, CacheOperationInvoker invoker) throws Throwable; @@ -75,8 +74,7 @@ protected Cache resolveCache(CacheOperationInvocationContext context) { *

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 0ff896eb5e36..a96640275822 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 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 boolean hasCacheOperation(Method method, @Nullable Class targetClass) } @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 @@ else if (cacheNull) { } } - @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 @@ private JCacheOperation computeCacheOperation(Method method, @Nullable Class< * @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 e3ecd6fa3b25..00ad1cb5b7a3 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 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 @@ public KeyGenerator getKeyGenerator() { * @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 036a4f6cb587..8349d2513b70 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.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 @@ public CacheResolver getCacheResolver() { } @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 @@ protected boolean isValue() { return this.isValue; } - public CacheInvocationParameter toCacheInvocationParameter(Object value) { + public CacheInvocationParameter toCacheInvocationParameter(@Nullable Object value) { return new CacheInvocationParameterImpl(this, value); } } @@ -213,9 +216,9 @@ protected static class CacheInvocationParameterImpl implements CacheInvocationPa 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 @@ public Class getRawType() { } @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 e18941574a11..77a989aa1050 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.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 boolean isCandidateClass(Class targetClass) { } @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 @@ else if (cacheRemove != null) { } } - @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 @@ protected CacheResolver getExceptionCacheResolver( } } - @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 f64c09a336f1..61dcdfc07154 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 @@ 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 @@ public CachePutInterceptor(CacheErrorHandler errorHandler) { @Override - @Nullable - protected Object invoke( + protected @Nullable Object invoke( CacheOperationInvocationContext 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 a406418863f2..d35ddfe71557 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.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 @@ public boolean isEarlyPut() { * @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 @@ public CacheInvocationParameter getValueParameter(Object... values) { } - @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 dfd8f0a4cc0e..557cc3fd6c28 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 @@ 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 @@ protected CacheRemoveAllInterceptor(CacheErrorHandler errorHandler) { @Override - @Nullable - protected Object invoke( + protected @Nullable Object invoke( CacheOperationInvocationContext 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 a1075785bb24..95ac57f666c7 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 @@ 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 @@ protected CacheRemoveEntryInterceptor(CacheErrorHandler errorHandler) { @Override - @Nullable - protected Object invoke( + protected @Nullable Object invoke( CacheOperationInvocationContext 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 dbd71ba26485..f071be030c9e 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 @@ 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 @@ public CacheResultInterceptor(CacheErrorHandler errorHandler) { @Override - @Nullable - protected Object invoke( + protected @Nullable Object invoke( CacheOperationInvocationContext context, CacheOperationInvoker invoker) { CacheResultOperation operation = context.getOperation(); @@ -97,8 +97,7 @@ protected void cacheException(@Nullable Cache exceptionCache, ExceptionTypeFilte } } - @Nullable - private Cache resolveExceptionCache(CacheOperationInvocationContext context) { + private @Nullable Cache resolveExceptionCache(CacheOperationInvocationContext context) { CacheResolver exceptionCacheResolver = context.getOperation().getExceptionCacheResolver(); if (exceptionCacheResolver != null) { return extractFrom(exceptionCacheResolver.resolveCaches(context)); @@ -146,8 +145,7 @@ private static CacheOperationInvoker.ThrowableWrapper rewriteCallStack( return new CacheOperationInvoker.ThrowableWrapper(clone); } - @Nullable - private static 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 3f4eedfe1020..7435599a7cef 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 @@ 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 @@ public boolean isAlwaysInvoked() { * 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 @@ public CacheResolver getExceptionCacheResolver() { * 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 35523c2b46a4..8509635beca2 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 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 @@ public Method getMethod() { } @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 9bd230ab9373..4e6a4a4915b9 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 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 @@ public CacheInvocationParameter[] getKeyParameters() { } @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 1b93b140ba2b..6b684b8e61a3 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 @@ 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.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 @@ 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 void setCacheManager(@Nullable CacheManager cacheManager) { /** * 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 void setCacheResolver(@Nullable CacheResolver cacheResolver) { /** * 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 void setExceptionCacheResolver(@Nullable CacheResolver exceptionCacheReso /** * 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 de1ff1a293af..6517f57bf520 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 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.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 void afterPropertiesSet() { } - @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 @@ private CacheOperationInvocationContext createCacheOperationInvocationContext } @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 @@ else if (operation instanceof CacheRemoveAllOperation) { * @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 CacheOperationInvokerAdapter(CacheOperationInvoker delegate) { } @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 81e65d1a1c1c..79dce59d98ad 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 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 JCacheInterceptor(@Nullable Supplier errorHandler) { @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 00c5ef91e9cf..9781d4016aaa 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 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 686066c6028f..9cdf04c93f16 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 @@ 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 @@ default boolean hasCacheOperation(Method method, @Nullable Class targetClass) * 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 bfd4bda19d9b..7f41c18767e2 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 @@ 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 @@ @SuppressWarnings("serial") final class JCacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { - @Nullable - private JCacheOperationSource cacheOperationSource; + private @Nullable JCacheOperationSource cacheOperationSource; public JCacheOperationSourcePointcut() { @@ -85,8 +85,7 @@ public boolean matches(Class clazz) { 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 3fcfe9fc58d9..756464fcc38f 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.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 @@ public Object getTarget() { } @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 @@ private static Object doGenerate(KeyGenerator keyGenerator, CacheKeyInvocationCo @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 70eca3aad5e3..b35ff8dbd0db 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 @@ 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 SimpleExceptionCacheResolver(CacheManager cacheManager) { } @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 c752c806b9fb..d834a0736552 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 e8b5c89807a2..568feb8512f0 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 45b5870dfecc..107529bf1ade 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.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 Object getNativeCache() { } @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 CompletableFuture retrieve(Object key, Supplier failedMessages; - @Nullable - private final Exception[] messageExceptions; + private final Exception @Nullable [] messageExceptions; /** @@ -124,8 +124,7 @@ public final Exception[] getMessageExceptions() { @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 d86db63adb0a..997b20356d61 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 @@ 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 @@ @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 void setFrom(@Nullable String from) { this.from = from; } - @Nullable - public String getFrom() { + public @Nullable String getFrom() { return this.from; } @@ -107,8 +99,7 @@ public void setReplyTo(@Nullable String replyTo) { this.replyTo = replyTo; } - @Nullable - public String getReplyTo() { + public @Nullable String getReplyTo() { return this.replyTo; } @@ -122,8 +113,7 @@ public void setTo(String... to) { this.to = to; } - @Nullable - public String[] getTo() { + public String @Nullable [] getTo() { return this.to; } @@ -133,12 +123,11 @@ public void setCc(@Nullable String cc) { } @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 void setBcc(@Nullable String bcc) { } @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 void setSentDate(@Nullable Date sentDate) { this.sentDate = sentDate; } - @Nullable - public Date getSentDate() { + public @Nullable Date getSentDate() { return this.sentDate; } @@ -172,8 +159,7 @@ public void setSubject(@Nullable String subject) { this.subject = subject; } - @Nullable - public String getSubject() { + public @Nullable String getSubject() { return this.subject; } @@ -182,8 +168,7 @@ public void setText(@Nullable String text) { this.text = text; } - @Nullable - public String getText() { + public @Nullable String getText() { return this.text; } @@ -255,8 +240,7 @@ public String toString() { } - @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 7fe0a9aca896..97771d852355 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 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 @@ protected final FileTypeMap getFileTypeMap() { * @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 165009856082..a21665ec3d55 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 333da35987bb..e89cd78e0670 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.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 void setProtocol(@Nullable String protocol) { /** * Return the mail protocol. */ - @Nullable - public String getProtocol() { + public @Nullable String getProtocol() { return this.protocol; } @@ -190,8 +182,7 @@ public void setHost(@Nullable String host) { /** * Return the mail server host. */ - @Nullable - public String getHost() { + public @Nullable String getHost() { return this.host; } @@ -229,8 +220,7 @@ public void setUsername(@Nullable String username) { /** * 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 void setPassword(@Nullable String password) { /** * 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 void setDefaultEncoding(@Nullable String defaultEncoding) { * 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 void setDefaultFileTypeMap(@Nullable FileTypeMap defaultFileTypeMap) { * 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 void testConnection() throws MessagingException { * @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 302a401f7310..eea388cc1fb7 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.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 final MimeMultipart getMimeMultipart() throws IllegalStateException { * @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 @@ protected String getDefaultEncoding(MimeMessage mimeMessage) { /** * 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 e41d4a226558..09625057a8a4 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 @@ 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 @@ */ 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 @@ public SmartMimeMessage( /** * 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 e5114480e030..280fd4f1d4db 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 a5d452deb96e..fce30404d900 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 73d12fab6927..fe86676a7ee6 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.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.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 void afterPropertiesSet() throws ParseException { @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 32ee0b90de7b..dc15170e8627 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 @@ 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.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 @@ 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 void afterPropertiesSet() { @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 fc8875b58111..a12b9797814e 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 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.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 6034e47822bf..23476846ae12 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 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 d692c4bf74f8..1185b80508d2 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 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.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 @@ 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 @@ protected void postProcessJobDetail(JobDetail jobDetail) { * 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 getTargetClass() { * 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 Object getTargetObject() { @Override - @Nullable - public JobDetail getObject() { + public @Nullable JobDetail getObject() { return this.jobDetail; } @@ -249,8 +240,7 @@ public static class MethodInvokingJob extends QuartzJobBean { 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 996a598460d2..8be7e10533fe 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 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 loadClass(String name, Class clazz) throws Clas } @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 URL getResource(String name) { } @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 e6b1c7aa5437..5947404b0387 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 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.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 83a8b47112d0..2893a8635d88 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.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 @@ */ 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 ddc740a25b28..30b6bee93bca 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 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.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 static ResourceLoader getConfigTimeResourceLoader() { * @see #setTaskExecutor * @see LocalTaskExecutorThreadPool */ - @Nullable - public static Executor getConfigTimeTaskExecutor() { + public static @Nullable Executor getConfigTimeTaskExecutor() { return configTimeTaskExecutorHolder.get(); } @@ -147,8 +145,7 @@ public static Executor getConfigTimeTaskExecutor() { * @see #setDataSource * @see LocalDataSourceJobStore */ - @Nullable - public static DataSource getConfigTimeDataSource() { + public static @Nullable DataSource getConfigTimeDataSource() { return configTimeDataSourceHolder.get(); } @@ -161,43 +158,32 @@ public static DataSource getConfigTimeDataSource() { * @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 static DataSource getConfigTimeNonTransactionalDataSource() { 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 Scheduler getScheduler() { } @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 ee5e43c05c39..9030a61b0420 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 e16a32f59677..fe230490c461 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 @@ 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.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 void afterPropertiesSet() { @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 2d48a2258ae0..cc20770935a2 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.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 @@ 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 6ca38a31963d..a7bbe32ec8c5 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 5b0405c5f401..be9a8f1db70e 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.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 @@ protected void postProcessTemplateLoaders(List templateLoaders) * @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 6a35e066ec4a..796dc4bc6a4c 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 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 @@ public class FreeMarkerConfigurationFactoryBean extends FreeMarkerConfigurationFactory implements FactoryBean, InitializingBean, ResourceLoaderAware { - @Nullable - private Configuration configuration; + private @Nullable Configuration configuration; @Override @@ -68,8 +67,7 @@ public void afterPropertiesSet() throws IOException, TemplateException { @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 1749b0a37d94..f58470949ac8 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 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 SpringTemplateLoader(ResourceLoader resourceLoader, String 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 492946e8998f..20352c9f84f0 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 171616604d39..03ae0ead6f7f 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.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 @@ default CompletableFuture retrieve(Object key, Supplier 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 833715c63cb6..ca7af761d145 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 @@ 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 37eede6f2a5b..a84df83d3d79 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.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.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 @@ @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 CachingConfigurerSupplier(Supplier supplier) { * @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 8f26e688a673..439721958fb7 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.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 boolean isCandidateClass(Class targetClass) { } @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 @@ protected Collection findCacheOperations(Method method) { * @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 @@ protected interface CacheOperationProvider { * @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 10231a157131..158da40e6d9f 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 @@ 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 @@ default boolean isCandidateClass(Class targetClass) { * @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 @@ default boolean isCandidateClass(Class targetClass) { * @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 26b3afb46a22..1d70fa54a20c 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 @@ default CacheManager cacheManager() { * * See {@link EnableCaching} for more complete examples. */ - @Nullable - default CacheResolver cacheResolver() { + default @Nullable CacheResolver cacheResolver() { return null; } @@ -105,8 +104,7 @@ default CacheResolver cacheResolver() { * is used. * See @{@link EnableCaching} for more complete examples. */ - @Nullable - default KeyGenerator keyGenerator() { + default @Nullable KeyGenerator keyGenerator() { return null; } @@ -116,8 +114,7 @@ default KeyGenerator keyGenerator() { * 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 16886ff13f88..33aadd02c33a 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 @@ 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 49bf01e26d10..5851f46bd0a1 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.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 boolean isCandidateClass(Class targetClass) { } @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 @@ private Collection parseCacheAnnotations(DefaultCacheConfig cach return ops; } - @Nullable - private Collection parseCacheAnnotations( + private @Nullable Collection parseCacheAnnotations( DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) { Collection annotations = (localOnly ? @@ -232,17 +229,13 @@ private static class DefaultCacheConfig { 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 0a53f33ac3b4..3c980e2b019d 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 0facea830e29..d73913e336d4 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.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 final ConcurrentMap getNativeCache() { } @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 T get(Object key, Callable valueLoader) { } @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 void put(Object key, @Nullable Object value) { } @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 @@ protected Object toStoreValue(@Nullable Object userValue) { } @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 b559e10b3d6d..ad8023f802df 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 @@ 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 void afterPropertiesSet() { @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 6dfa5a4eda31..ef4a26936068 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.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 Collection getCacheNames() { } @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 5c5feb58e60e..fd7f64befab9 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 f2768059a0db..c2e12c08eeaa 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.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 c85dcad9065d..23a260609d9a 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.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.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 @@ private static class Props { private final String method; - @Nullable - private String[] caches; + private String @Nullable [] caches; Props(Element root) { String defaultCache = root.getAttribute("cache"); @@ -231,8 +230,7 @@ T merge(Element element, ReaderContext reader 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 b26305693b33..39e10f5ebdba 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 84e36757d61c..d8a3cc567523 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.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 CacheErrorHandler getErrorHandler() { * 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 @@ protected Cache.ValueWrapper doGet(Cache cache, Object key) { * @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 @@ protected T doGet(Cache cache, Object key, Callable valueLoader) { * @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 a54ed05f17a1..4cb9d228a4b5 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.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 @@ */ public abstract class AbstractCacheResolver implements CacheResolver, InitializingBean { - @Nullable - private CacheManager cacheManager; + private @Nullable CacheManager cacheManager; /** @@ -103,7 +103,6 @@ public Collection resolveCaches(CacheOperationInvocationContext * @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 2657232886c5..7928cdfd9c06 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 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 boolean hasCacheOperations(Method method, @Nullable Class targetClass) } @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 Collection getCacheOperations(Method method, @Nullable Cl * @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 @@ protected Object getCacheKey(Method method, @Nullable Class targetClass) { 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 @@ private Collection computeCacheOperations(Method method, @Nullab * @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 @@ private Collection computeCacheOperations(Method method, @Nullab * @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 8f97d45f70dd..8928382553cc 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 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.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 void setCacheOperationSource(@Nullable CacheOperationSource cacheOperatio /** * Return the CacheOperationSource for this cache aspect. */ - @Nullable - public CacheOperationSource getCacheOperationSource() { + public @Nullable CacheOperationSource getCacheOperationSource() { return this.cacheOperationSource; } @@ -228,8 +223,7 @@ public void setCacheResolver(@Nullable CacheResolver cacheResolver) { /** * 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 @@ protected void clearMetadataCache() { 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 @@ protected Object execute(CacheOperationInvoker invoker, Object target, Method me * @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 @@ private Object execute(CacheOperationInvoker invoker, Method method, CacheOperat 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 @@ private Object executeSynchronized(CacheOperationInvoker invoker, Method method, * @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 @@ private Object findCachedValue(CacheOperationInvoker invoker, Method method, Cac 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 @@ private Object findInCaches(CacheOperationContext context, Object key, 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 @@ private Object evaluate(@Nullable Object cacheHit, CacheOperationInvoker invoker 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 @@ private Object wrapCacheValue(Method method, @Nullable Object cacheValue) { return cacheValue; } - @Nullable - private Object unwrapReturnValue(@Nullable Object returnValue) { + private @Nullable Object unwrapReturnValue(@Nullable Object returnValue) { return ObjectUtils.unwrapOptional(returnValue); } @@ -633,8 +617,7 @@ private boolean hasCachePut(CacheOperationContexts contexts) { 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 @@ protected class CacheOperationContext implements CacheOperationInvocationContext private final CacheOperationMetadata metadata; - private final Object[] args; + private final @Nullable Object[] args; private final Object target; @@ -849,13 +832,11 @@ protected class CacheOperationContext implements CacheOperationInvocationContext 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 Method getMethod() { } @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 @@ else if (this.metadata.operation instanceof CachePutOperation cachePutOperation) /** * 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 @@ protected Object generateKey(@Nullable Object result) { * @return generated key * @since 6.1.2 */ - @Nullable - protected Object getGeneratedKey() { + protected @Nullable Object getGeneratedKey() { return this.key; } @@ -1018,8 +997,7 @@ public CachePutRequest(CacheOperationContext context) { 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 @@ private class ReactiveCachingHandler { 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 Object executeSynchronized(CacheOperationInvoker invoker, Method method, 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 Object processCacheEvicts(List contexts, @Nullable } @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 @@ private Flux valueToFlux(Object value, CacheOperationContexts contexts) { (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 a31ad42731e1..20b33f5e0b97 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 29604d91b648..d00f8cf903bf 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.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 @@ public void addUnavailableVariable(String name) { * 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 327cfd4d9768..d417f4b80be6 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 @@ 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 @@ public ParameterNameDiscoverer getParameterNameDiscoverer() { * @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 32f55cf77500..7fc9db8786a5 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 @@ 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 @@ public String getMethodName() { 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 2f1f56f14a7d..cc06a5e275bc 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 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 @@ 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 a906e895b323..52f2a50402f6 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 @@ 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 13a49ea1026b..9a68c438bd98 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.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 @@ public CacheOperationExpressionEvaluator(CacheEvaluationContextFactory evaluatio * @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 @@ else if (result != NO_RESULT) { 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 c459a09aea6d..6db02e3c9791 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 @@ 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 e37736480e51..00144c97b2ef 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 601fd4dbb4c1..6a923fcdeec6 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 @@ 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 @@ default boolean hasCacheOperations(Method method, @Nullable Class targetClass * 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 4b9054b10edb..a90daa661674 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 @@ 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 @@ @SuppressWarnings("serial") final class CacheOperationSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { - @Nullable - private CacheOperationSource cacheOperationSource; + private @Nullable CacheOperationSource cacheOperationSource; public CacheOperationSourcePointcut() { @@ -87,8 +87,7 @@ public boolean matches(Class clazz) { 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 4b94ac5edff5..29e1948acce1 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 @@ */ public class CachePutOperation extends CacheOperation { - @Nullable - private final String unless; + private final @Nullable String unless; /** @@ -42,8 +41,7 @@ public CachePutOperation(CachePutOperation.Builder b) { } - @Nullable - public String getUnless() { + public @Nullable String getUnless() { return this.unless; } @@ -54,8 +52,7 @@ public String getUnless() { */ 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 9f7fcc2e97b0..02a71682c789 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 @@ */ public class CacheableOperation extends CacheOperation { - @Nullable - private final String unless; + private final @Nullable String unless; private final boolean sync; @@ -45,8 +44,7 @@ public CacheableOperation(CacheableOperation.Builder b) { } - @Nullable - public String getUnless() { + public @Nullable String getUnless() { return this.unless; } @@ -61,8 +59,7 @@ public boolean isSync() { */ 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 9e1387a9ca04..b54d75083d74 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.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 boolean hasCacheOperations(Method method, @Nullable Class targetClass) } @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 2d99e4994d99..a767b339f3e8 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 @@ 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 a0d2a4ccd7b3..5f71eb761247 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 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 67644f5e92a2..6798ba797a9f 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 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 void addCacheMethod(String methodName, Collection ops) { } @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 61cfc4b469db..71b681ba278c 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 @@ 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 @@ */ public class NamedCacheResolver extends AbstractCacheResolver { - @Nullable - private Collection cacheNames; + private @Nullable Collection cacheNames; public NamedCacheResolver() { @@ -52,8 +52,7 @@ public void setCacheNames(Collection cacheNames) { } @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 99ba25237102..9c3dc0b6de9b 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 3c22f3e328d9..1edd47cd2a27 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 @@ 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 @@ protected Collection getCacheNames(CacheOperationInvocationContext co * @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 d0f2a64ce82c..760a7f7dbe96 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.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 c2365ad9e651..aa16ae05c236 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 @@ import java.lang.reflect.Method; import java.util.Arrays; +import org.jspecify.annotations.Nullable; + import org.springframework.core.KotlinDetector; /** @@ -41,7 +43,8 @@ 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 Object generate(Object target, Method method, Object... params) { /** * 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 97810d21f6d7..6ec6cba01bfd 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 dbb69eaa2ffc..cd14eb950cd4 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 d1e7decdd933..b0eab7674e1b 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.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 void initializeCaches() { // 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 Collection getCacheNames() { * @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 @@ protected Cache decorateCache(Cache cache) { * @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 e9a5d4f08118..e5012b54226b 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 final boolean isAllowNullValues() { } @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 T get(Object key, @Nullable Class type) { * @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 T get(Object key, @Nullable Class type) { * @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 @@ protected Object toStoreValue(@Nullable Object userValue) { * @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 25f0bf12adaa..f4f051a7f2a8 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.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 void afterPropertiesSet() { @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 b8746e97f91a..115eedb5e8ff 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.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 Object getNativeCache() { } @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 T get(Object key, Callable valueLoader) { } @Override - @Nullable - public CompletableFuture retrieve(Object key) { + public @Nullable CompletableFuture retrieve(Object key) { return null; } @@ -98,8 +95,7 @@ public void put(Object key, @Nullable Object value) { } @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 58d914717dd9..ff2e8bbabdc3 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.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 cc60aa47f8ca..01938a06d374 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 @@ 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 460d27a049c3..0eb7c3c52518 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 @@ 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 @@ */ public class SimpleValueWrapper implements ValueWrapper { - @Nullable - private final Object value; + private final @Nullable Object value; /** @@ -47,8 +47,7 @@ public SimpleValueWrapper(@Nullable Object value) { * 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 8e82da01276e..8b3a4173c75b 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 ed5270db78df..1c22b0d5fc11 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 2861196a5426..d33f146834ab 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 @@ 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.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 2949a99c7924..8e30cae76354 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 fd7ecbe23baf..629ae459f248 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 @@ 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 6908b85eddf7..11486fd6dc2a 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 @@ default Object[] getArguments() { * 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 c737fc876404..dd91d5aff1b2 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 @@ 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 bc2def951f3e..69ccfe579ae3 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 @@ 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 final String[] selectImports(AnnotationMetadata importingClassMetadata) { * @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 6b156b4ebb66..109eec9fd2fa 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 @@ 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.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 void registerBean(Class beanClass, @Nullable String name, @Nullabl * @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 d8bb37df83fd..9c51343bc014 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 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.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 String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry * @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 @@ private Set getMetaAnnotationTypes(MergedAnnotation mergedAn * @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 207722a4c562..814d9d0aeaf7 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 @@ 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 878d545deff2..4296cdecbb02 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 @@ 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.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 @@ 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 540515fdf21d..ba1214b0e6a1 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.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.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 @@ private static BeanDefinitionHolder registerPostProcessor( 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 @@ static BeanDefinitionHolder applyScopedProxyMode( 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 cd4d18724422..71f449ce7a20 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 @@ 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 bee5d806d153..5292105c710b 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 @@ 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.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 BeanDefinitionDefaults getBeanDefinitionDefaults() { * 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 6016fcf6556d..c59c7a943bb5 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 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.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 final Environment getEnvironment() { /** * Return the {@link BeanDefinitionRegistry} used by this scanner, if any. */ - @Nullable - protected BeanDefinitionRegistry getRegistry() { + protected @Nullable BeanDefinitionRegistry getRegistry() { return null; } @@ -368,8 +362,7 @@ private boolean indexSupportsIncludeFilter(TypeFilter filter) { * @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 7e65b98cdbf2..8b30c0431fa4 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.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.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 void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, C } @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 BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe 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 void resetBeanDefinition(String beanName) { } @Override - @Nullable - public Object postProcessBeforeInstantiation(Class beanClass, String beanName) { + public @Nullable Object postProcessBeforeInstantiation(Class beanClass, String beanName) { return null; } @@ -585,8 +577,7 @@ protected Object autowireResource(BeanFactory factory, LookupElement element, @N @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 @@ protected abstract static class LookupElement extends InjectionMetadata.Injected 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 @@ private static class AotContribution implements BeanRegistrationAotContribution 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 d38a670c9582..3a1a9ed2cc00 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.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.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 e28dfda7a309..cdf0cee02eb7 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 bccce9326f68..40b007001ff3 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.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.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 @@ private Condition getCondition(String conditionClassName, @Nullable ClassLoader */ 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 @@ public ConditionContextImpl(@Nullable BeanDefinitionRegistry registry, 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 @@ private static ResourceLoader deduceResourceLoader(@Nullable BeanDefinitionRegis 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 @@ public BeanDefinitionRegistry getRegistry() { } @Override - @Nullable - public ConfigurableListableBeanFactory getBeanFactory() { + public @Nullable ConfigurableListableBeanFactory getBeanFactory() { return this.beanFactory; } @@ -231,8 +226,7 @@ public ResourceLoader getResourceLoader() { } @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 7664cb69813a..d4d5a536c6fb 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.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.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 @@ void setBeanName(@Nullable String beanName) { 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 0634bd6edcaf..1775d7de294c 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 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.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 @@ public AnnotationMetadata getMetadata() { } @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 113e0d3007d2..51a5990a2f77 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 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.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 @@ public void end_class() { 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 @@ private static class BeanMethodInterceptor implements MethodInterceptor, Conditi * 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 @@ public Object intercept(Object enhancedConfigInstance, Method beanMethod, Object 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 7fd102e2a9d5..6d90351956b6 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 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.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 @@ else if (configClass.isScanned()) { * @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 @@ private List collectRegisterBeanConditions(ConfigurationClass configu 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 @@ void registerImport(AnnotationMetadata importingClass, String importedClass) { } @Override - @Nullable - public AnnotationMetadata getImportingClassFor(String importedClass) { + public @Nullable AnnotationMetadata getImportingClassFor(String importedClass) { return CollectionUtils.lastElement(this.imports.get(importedClass)); } @@ -769,8 +765,7 @@ public String toString() { 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 7988295f333d..4787f8321653 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 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.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 void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) 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 BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe } @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 BeanFactoryInitializationAotContribution processAheadOfTime(ConfigurableL 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 ImportAwareBeanPostProcessor(BeanFactory beanFactory) { } @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 4d557ae9ea49..381af86d0b4c 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 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.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 @@ static boolean hasBeanMethods(AnnotationMetadata metadata) { * 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 bc012d05807c..f4d1b8bbb259 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.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.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 @@ 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 @@ private static class LazyDependencyTargetSource implements TargetSource, Seriali 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 dedb068b6497..c55a548ce49b 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 24f422e1e8ce..c026153a9ba4 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 @@ 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 @@ private void setAnnotationMetadata(ImportAware instance) { } } - @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 779bbc3058c8..335f7fe80ae6 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 @@ */ 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 7ae3423ec596..804fb337beae 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 @@ 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 06ab3313eccc..45100980c2f7 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.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 final void registerScope(String annotationType, String scopeName) { * @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 86b1ede8f709..064bd1ac28a0 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.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 @@ @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 25715f82cad7..d680e4729be7 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 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.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 adbfbecb457f..20cdd84bebfc 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 @@ 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.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 @@ private static Object[] resolveArgs(Class[] parameterTypes, 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 d3a78ea91b52..eaf2a86d7508 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.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.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 @@ private static String defaultResourceNameForMethod(String methodName) { * @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 26e603bbf259..b9fbdab9c503 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 final AnnotationMetadata getMetadata() { } @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 d40f541f125a..cc6e50066b6d 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 58c63fc117e5..d7cce932a3f4 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 @@ 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 String getArtifactId() { */ 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 47744cb6f723..8d7f7c6e61ab 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 @@ 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 5305508b9da9..e74a416cf586 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 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.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 @@ public void addInitializer(MethodReference methodReference) { 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 d2d5ec73bef6..f549ae46566e 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.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.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 @@ private List getContributions( 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 e8bcb7696385..9820b07bcd77 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.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 @@ 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 4b6a7b79182a..579e73e93fd9 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.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.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 ReflectiveProcessorAotContributionBuilder scan(@Nullable ClassLoader clas 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 void applyTo(GenerationContext generationContext, BeanFactoryInitializati 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 0ba81ec97138..193a201f5137 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.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.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 @@ 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 75fa1bb2c612..d79a7c8926b6 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 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.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 @@ static class RuntimeHintsRegistrarContribution implements BeanFactoryInitializat 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 abb17630288a..c9da373f170d 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 e21b5fe2fd57..8246b6497de2 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.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 2fd447a835e4..3f797dce89f2 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.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 08b96ec341ea..65c0cc7fff34 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 c552e5791593..b46b19b7fd99 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.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.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 @@ private static final class ListenerCacheKey implements Comparable 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 int compareTo(ListenerCacheKey other) { */ 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 cfbdd769a22d..2052d32b9a12 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 @@ 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 585878490656..97fedefef235 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 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.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 @@ protected boolean isDefaultExecution() { * @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 boolean shouldHandle(ApplicationEvent event) { 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 @@ private boolean shouldHandle(ApplicationEvent event, @Nullable Object[] args) { * 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 @@ protected void handleAsyncError(Throwable t) { /** * 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 @@ protected Method getTargetMethod() { * 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 @@ private void assertTargetBean(Method method, Object targetBean, @Nullable Object } } - @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 @@ private String getInvocationErrorMessage(Object bean, @Nullable String message, 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 acef8846be64..385288989ab8 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.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 @@ public boolean condition(String conditionExpression, ApplicationEvent event, Met } 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 fca84af09e26..c04acd097836 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 @@ * @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 5f330e754526..de3db6c05d5d 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 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.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 ef5c2e6e3627..324c24240b75 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 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 @@ 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 void afterPropertiesSet() throws Exception { @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 a0ac143fa309..ec22230acbb6 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 @@ 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 String getListenerId() { } - @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 @@ private static ResolvableType resolveDeclaredEventType(ApplicationListener 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 d2fe7feb5c05..6b60b7d68bf4 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 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 @@ */ 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 void setTaskExecutor(@Nullable Executor taskExecutor) { * 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 void setErrorHandler(@Nullable ErrorHandler errorHandler) { * 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 c56dd33b336a..24767a5f9149 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 7170931aaa0f..14ce1f25d38d 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 79cccd7a46ca..381af6a5dbaf 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 08673db5e6be..901486b982c8 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 @@ 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 961f79de3fcf..adb4d12682d1 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 2f7f162d1047..ef5a6e0079e1 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 8cdea248a654..ba52e13b956f 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 @@ 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 7b7fda745287..aca1b2085e62 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 e630c8cc270f..38053c25066f 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 @@ 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.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 c98d60fa595e..5daf2fe3eaa4 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 @@ 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 MethodBasedEvaluationContext(Object rootObject, Method method, Object[] a @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 8b03a9f25d65..2851ebc83ea2 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 @@ 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.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 void setExpressionParser(ExpressionParser expressionParser) { @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 f08c49a0e63f..cca8a5d23798 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 f10305c831ac..5d5bb2b87eb5 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 @@ 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 97a2a2f1ec41..e54c5d657264 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 @@ 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 static void setLocaleContext(@Nullable LocaleContext localeContext, boole * 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 5d31165db814..769a14ad4cc0 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 Object key() { } @Override - @Nullable - public LocaleContext getValue() { + public @Nullable LocaleContext getValue() { return LocaleContextHolder.getLocaleContext(); } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/SimpleLocaleContext.java b/spring-context/src/main/java/org/springframework/context/i18n/SimpleLocaleContext.java index 0e678f91c858..7a09831ff345 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/SimpleLocaleContext.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/SimpleLocaleContext.java @@ -18,7 +18,7 @@ import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple implementation of the {@link LocaleContext} interface, @@ -32,8 +32,7 @@ */ public class SimpleLocaleContext implements LocaleContext { - @Nullable - private final Locale locale; + private final @Nullable Locale locale; /** @@ -46,8 +45,7 @@ public SimpleLocaleContext(@Nullable Locale locale) { } @Override - @Nullable - public Locale getLocale() { + public @Nullable Locale getLocale() { return this.locale; } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/SimpleTimeZoneAwareLocaleContext.java b/spring-context/src/main/java/org/springframework/context/i18n/SimpleTimeZoneAwareLocaleContext.java index 404c7cf90d21..fcc5b8e55d5c 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/SimpleTimeZoneAwareLocaleContext.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/SimpleTimeZoneAwareLocaleContext.java @@ -19,7 +19,7 @@ import java.util.Locale; import java.util.TimeZone; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Simple implementation of the {@link TimeZoneAwareLocaleContext} interface, @@ -36,8 +36,7 @@ */ public class SimpleTimeZoneAwareLocaleContext extends SimpleLocaleContext implements TimeZoneAwareLocaleContext { - @Nullable - private final TimeZone timeZone; + private final @Nullable TimeZone timeZone; /** @@ -54,8 +53,7 @@ public SimpleTimeZoneAwareLocaleContext(@Nullable Locale locale, @Nullable TimeZ @Override - @Nullable - public TimeZone getTimeZone() { + public @Nullable TimeZone getTimeZone() { return this.timeZone; } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java b/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java index ab93b39b7f0a..79173f9d8b4a 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/TimeZoneAwareLocaleContext.java @@ -18,7 +18,7 @@ import java.util.TimeZone; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Extension of {@link LocaleContext}, adding awareness of the current time zone. @@ -39,7 +39,6 @@ public interface TimeZoneAwareLocaleContext extends LocaleContext { * depending on the implementation strategy. * @return the current TimeZone, or {@code null} if no specific TimeZone associated */ - @Nullable - TimeZone getTimeZone(); + @Nullable TimeZone getTimeZone(); } diff --git a/spring-context/src/main/java/org/springframework/context/i18n/package-info.java b/spring-context/src/main/java/org/springframework/context/i18n/package-info.java index d7eba0bb7f23..8dfd46a24e5e 100644 --- a/spring-context/src/main/java/org/springframework/context/i18n/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/i18n/package-info.java @@ -2,9 +2,7 @@ * Abstraction for determining the current Locale, * plus global holder that exposes a thread-bound Locale. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.i18n; -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/index/CandidateComponentsIndexLoader.java b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java index 194c96df705b..b83b6fae8d6a 100644 --- a/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java +++ b/spring-context/src/main/java/org/springframework/context/index/CandidateComponentsIndexLoader.java @@ -26,11 +26,11 @@ 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.io.UrlResource; import org.springframework.core.io.support.PropertiesLoaderUtils; -import org.springframework.lang.Nullable; import org.springframework.util.ConcurrentReferenceHashMap; /** @@ -83,8 +83,7 @@ private CandidateComponentsIndexLoader() { * @throws IllegalArgumentException if any module index cannot * be loaded or if an error occurs while creating {@link CandidateComponentsIndex} */ - @Nullable - public static CandidateComponentsIndex loadIndex(@Nullable ClassLoader classLoader) { + public static @Nullable CandidateComponentsIndex loadIndex(@Nullable ClassLoader classLoader) { ClassLoader classLoaderToUse = classLoader; if (classLoaderToUse == null) { classLoaderToUse = CandidateComponentsIndexLoader.class.getClassLoader(); @@ -92,8 +91,7 @@ public static CandidateComponentsIndex loadIndex(@Nullable ClassLoader classLoad return cache.computeIfAbsent(classLoaderToUse, CandidateComponentsIndexLoader::doLoadIndex); } - @Nullable - private static CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) { + private static @Nullable CandidateComponentsIndex doLoadIndex(ClassLoader classLoader) { if (shouldIgnoreIndex) { return null; } diff --git a/spring-context/src/main/java/org/springframework/context/index/package-info.java b/spring-context/src/main/java/org/springframework/context/index/package-info.java index e07328eca199..b036b1d3242f 100644 --- a/spring-context/src/main/java/org/springframework/context/index/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/index/package-info.java @@ -1,9 +1,7 @@ /** * Support package for reading and managing the components index. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.context.index; -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/package-info.java b/spring-context/src/main/java/org/springframework/context/package-info.java index 9aae0c27c845..ca71120d16e9 100644 --- a/spring-context/src/main/java/org/springframework/context/package-info.java +++ b/spring-context/src/main/java/org/springframework/context/package-info.java @@ -10,9 +10,7 @@ * is that application objects can often be configured without * any dependency on Spring-specific APIs. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.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/context/support/AbstractApplicationContext.java b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java index 1ed265a35f8c..c1c8bd322b19 100644 --- a/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java +++ b/spring-context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java @@ -33,6 +33,7 @@ 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.CachedIntrospectionResults; @@ -86,7 +87,6 @@ import org.springframework.core.io.support.ResourcePatternResolver; 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.CollectionUtils; import org.springframework.util.ObjectUtils; @@ -189,12 +189,10 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader private String displayName = ObjectUtils.identityToString(this); /** Parent context. */ - @Nullable - private ApplicationContext parent; + private @Nullable ApplicationContext parent; /** Environment used by this context. */ - @Nullable - private ConfigurableEnvironment environment; + private @Nullable ConfigurableEnvironment environment; /** BeanFactoryPostProcessors to apply on refresh. */ private final List 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 String getDisplayName() { * (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 T getBean(String name, Class requiredType) throws BeansException { } @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 T getBean(Class requiredType) throws BeansException { } @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 boolean isTypeMatch(String name, Class typeToMatch) throws NoSuchBeanD } @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 Map getBeansWithAnnotation(Class an } @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 A findAnnotationOnBean(String beanName, Class a } @Override - @Nullable - public A findAnnotationOnBean( + public @Nullable A findAnnotationOnBean( String beanName, Class annotationType, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException { @@ -1474,8 +1460,7 @@ public Set findAllAnnotationsOnBean( //--------------------------------------------------------------------- @Override - @Nullable - public BeanFactory getParentBeanFactory() { + public @Nullable BeanFactory getParentBeanFactory() { return getParent(); } @@ -1489,8 +1474,7 @@ public boolean containsLocalBean(String name) { * 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 @@ protected BeanFactory getInternalParentBeanFactory() { //--------------------------------------------------------------------- @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 @@ private MessageSource getMessageSource() throws IllegalStateException { * 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 cb51fe9def12..c483820ac195 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.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 @@ */ 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 void setParentMessageSource(@Nullable MessageSource parent) { } @Override - @Nullable - public MessageSource getParentMessageSource() { + public @Nullable MessageSource getParentMessageSource() { return this.parentMessageSource; } @@ -97,8 +95,7 @@ public void setCommonMessages(@Nullable Properties commonMessages) { /** * 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 @@ protected boolean isUseCodeAsDefaultMessage() { @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 final String getMessage(String code, @Nullable Object[] args, @Nullable S } @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 final String getMessage(MessageSourceResolvable resolvable, Locale locale * @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 @@ protected String getMessageInternal(@Nullable String code, @Nullable Object[] ar * @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 @@ protected String getMessageFromParent(String code, @Nullable Object[] args, Loca * @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 @@ protected String getDefaultMessage(MessageSourceResolvable resolvable, Locale lo * @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 @@ protected String getDefaultMessage(String code) { * @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 @@ protected Object[] resolveArguments(@Nullable Object[] args, Locale locale) { * @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 @@ protected String resolveCodeWithoutArguments(String code, Locale locale) { * @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 5acf9148f2f8..30d06cc26b48 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 @@ 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 @@ */ 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 901e7152303a..ac63bcd5c505 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 @@ 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 void setConfigLocation(String location) { * 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 void setConfigLocations(@Nullable String... locations) { * @see #getResources * @see #getResourcePatternResolver */ - @Nullable - protected String[] getConfigLocations() { + protected String @Nullable [] getConfigLocations() { return (this.configLocations != null ? this.configLocations : getDefaultConfigLocations()); } @@ -109,8 +108,7 @@ protected String[] getConfigLocations() { * @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 0a0f8bd0be35..45dafd462d11 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.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 void setDefaultEncoding(@Nullable String defaultEncoding) { * 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 void setDefaultLocale(@Nullable Locale defaultLocale) { * @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 961704adcfa9..372f9bc939f6 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 @@ 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.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 @@ protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansE * @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 1da55ce8fe50..7e1124ead0b1 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.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 @@ public ApplicationContextAwareProcessor(ConfigurableApplicationContext applicati @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 342839892a8f..62a3765f73fa 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 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 73d37a4aa261..44fbdce7b2b1 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 @@ 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 @@ protected void initApplicationContext() throws BeansException { * 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 @@ protected final ApplicationContext obtainApplicationContext() { * 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 57fa66128529..bdb2736f3581 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 @@ */ public class ClassPathXmlApplicationContext extends AbstractXmlApplicationContext { - @Nullable - private Resource[] configResources; + private Resource @Nullable [] configResources; /** @@ -204,8 +204,7 @@ public ClassPathXmlApplicationContext(String[] paths, Class clazz, @Nullable @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 525d916ca0c5..531feb00c9db 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.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 @@ protected boolean isEligibleForOverriding(String className) { } @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 f04f33d2fc44..3ca93ab825c7 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 @@ 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 @@ */ 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 @@ protected GenericConversionService createConversionService() { // implementing FactoryBean @Override - @Nullable - public ConversionService getObject() { + public @Nullable ConversionService getObject() { return this.conversionService; } diff --git a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java index e9a918cfc6d5..73e1b735079e 100644 --- a/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java +++ b/spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java @@ -37,6 +37,7 @@ import org.crac.Core; import org.crac.RestoreException; import org.crac.management.CRaCMXBean; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; @@ -49,7 +50,6 @@ import org.springframework.context.SmartLifecycle; import org.springframework.core.NativeDetector; import org.springframework.core.SpringProperties; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -108,15 +108,12 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor private volatile boolean running; - @Nullable - private volatile ConfigurableListableBeanFactory beanFactory; + private volatile @Nullable ConfigurableListableBeanFactory beanFactory; - @Nullable - private volatile Set 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 void checkpointRestore() { */ 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 df09bc8957f9..1d0bf70ae474 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 @@ 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 @@ @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 DefaultMessageSourceResolvable(String[] codes, Object[] arguments) { * @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 DefaultMessageSourceResolvable(MessageSourceResolvable resolvable) { * 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 afe4db3e89b0..23359724f6fb 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 @@ 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 @@ */ public class DelegatingMessageSource extends MessageSourceSupport implements HierarchicalMessageSource { - @Nullable - private MessageSource parentMessageSource; + private @Nullable MessageSource parentMessageSource; @Override @@ -47,15 +47,13 @@ public void setParentMessageSource(@Nullable MessageSource parent) { } @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 @@ else if (defaultMessage != null) { } @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 dc85006c5d87..6f9948e7dc92 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 @@ */ public class EmbeddedValueResolutionSupport implements EmbeddedValueResolverAware { - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; @Override @@ -44,8 +44,7 @@ public void setEmbeddedValueResolver(StringValueResolver resolver) { * @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 c9166da80182..556d077fee29 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 f76668f4ebac..954877fdf1a1 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.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.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 void setClassLoader(@Nullable ClassLoader classLoader) { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { if (this.resourceLoader != null && !this.customClassLoader) { return this.resourceLoader.getClassLoader(); } @@ -612,8 +611,7 @@ public ClassDerivedBeanDefinition(ClassDerivedBeanDefinition original) { } @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 e164165074d3..355986bbc092 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 @@ 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.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 void setProperty(String property, Object newValue) { } @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 ba3f7b7c9b01..508f468d76b1 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 @@ 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 String getMessage(String code, String defaultMessage, Locale locale) { * @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 String getMessage(String code, @Nullable Object[] args, String defaultMes * @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 String getMessage(String code, Locale locale) throws NoSuchMessageExcepti * @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 String getMessage(String code, @Nullable Object[] args) throws NoSuchMess * @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 b860a38082c7..29fd34b1f344 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.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 MessageSourceResourceBundle(MessageSource source, Locale locale, Resource * 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 9aaaf33bcdfc..96b633b4763d 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 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 @@ protected boolean isAlwaysUseMessageFormat() { * @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 @@ protected String renderDefaultMessage(String defaultMessage, @Nullable Object[] * @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 @@ protected MessageFormat createMessageFormat(String msg, Locale locale) { * @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 5d6784191ab7..00d783a9778c 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 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.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 31d1652542b8..36ee67f3a92b 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 @@ 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.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 void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) 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 3f70d049435e..d79fde8e4050 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.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 void setResourceLoader(@Nullable ResourceLoader resourceLoader) { * 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 @@ protected String resolveCodeWithoutArguments(String code, Locale locale) { * 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 @@ protected PropertiesHolder refreshProperties(String filename, @Nullable Properti * @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 String toString() { */ protected class PropertiesHolder { - @Nullable - private final Properties properties; + private final @Nullable Properties properties; private final long fileTimestamp; @@ -668,8 +664,7 @@ public PropertiesHolder(Properties properties, long fileTimestamp) { this.fileTimestamp = fileTimestamp; } - @Nullable - public Properties getProperties() { + public @Nullable Properties getProperties() { return this.properties; } @@ -685,16 +680,14 @@ public long getRefreshTimestamp() { 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 bc3393ebb698..3b325e831d2a 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.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 @@ */ 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 void setBundleClassLoader(ClassLoader classLoader) { *

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 void setBeanClassLoader(ClassLoader classLoader) { * 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 @@ protected String resolveCodeWithoutArguments(String code, Locale locale) { * 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 @@ protected MessageFormat resolveCode(String code, Locale locale) { * @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 @@ protected ResourceBundle loadBundle(InputStream inputStream) throws IOException * 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 @@ protected MessageFormat getMessageFormat(ResourceBundle bundle, String code, Loc * @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 String toString() { 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 ResourceBundle newBundle(String baseName, Locale locale, String format, C } @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 00af013192ef..67bad8cae59b 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 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 Object get(String name, ObjectFactory objectFactory) { } @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 void registerDestructionCallback(String name, Runnable callback) { } @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 fc58e3f5031c..2ede88fd5600 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 @@ 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 9f8ace3ab2fd..44105778d909 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.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 @@ protected String resolveCodeWithoutArguments(String code, Locale locale) { } @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 @@ private class MessageHolder { 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 2ec0ef515332..fabae8e74770 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 db73317d36c3..47a35f93973c 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.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.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 9a815627fb09..927ce20540fb 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 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.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 @@ else if (InstrumentationLoadTimeWeaver.isInstrumentationAvailable()) { * 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 bb045de9a68b..2b06c262ff57 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 @@ */ 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 889d99ed2c6a..4dccb6742c9a 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 501900852b51..4439dd32500e 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 60813fc909b7..a9fb8adae564 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.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 207316bb12a9..473eac451585 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 ff6a5cce22a2..32ba16381dbb 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.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 2c165c5c0feb..0e0c37cd1c1f 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 @@ 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 @@ */ 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 b6f4686c34c1..a56e0229c418 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 9e2f2668ec95..7ef08ebee3fe 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.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 @@ */ public class DateTimeContext { - @Nullable - private Chronology chronology; + private @Nullable Chronology chronology; - @Nullable - private ZoneId timeZone; + private @Nullable ZoneId timeZone; /** @@ -54,8 +53,7 @@ public void setChronology(@Nullable Chronology chronology) { /** * 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 void setTimeZone(@Nullable ZoneId timeZone) { /** * 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 aa5a5223ef30..6fd18beef0a6 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 @@ 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 static void setDateTimeContext(@Nullable DateTimeContext dateTimeContext) * 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 f58b7d602101..8613ac179028 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.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 @@ */ 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 void setStylePattern(String style) { 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 1a48b8c52ba3..35282f468011 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 @@ 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 @@ public class DateTimeFormatterFactoryBean extends DateTimeFormatterFactory implements FactoryBean, InitializingBean { - @Nullable - private DateTimeFormatter dateTimeFormatter; + private @Nullable DateTimeFormatter dateTimeFormatter; @Override @@ -47,8 +47,7 @@ public void afterPropertiesSet() { } @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 ee9a53a36cb0..cc920c7d7d16 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.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 @@ 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 DurationFormatter(DurationFormat.Style style) { * @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 b1f5f3e58bd4..d9266eb91d1a 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.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 static Duration parse(String value, DurationFormat.Style style) { * 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 static String print(Duration value, DurationFormat.Style style) { * 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 static Duration detectAndParse(String value) { * @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 @@ private static Duration parseIso8601(String value) { } } - 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 @@ private static Duration parseSimple(String text, @Nullable DurationFormat.Unit f } } - 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 eec58f9eac3c..0bac06c9656a 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.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 TemporalAccessorParser(Class temporalAccessor } 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 fd73fe6cb3e7..ddd754486773 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 6c030d07868f..94f37a4458a4 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.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 1597180306a6..8bc858a2d9ce 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.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 @@ */ 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 1127b9299ccf..5e51eaefd3ab 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.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 @@ */ 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 91fbcd0f4cf3..79e044d413cf 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 7fffd8adbb7f..6c3fb15ecbcb 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 727b1ad0a9cf..a8e517b5a388 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 b3bd23631f52..50667bd8c7cb 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.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 54ec2a76e9aa..11de9d064774 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.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.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 @@ 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 Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDe 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 Set getConvertibleTypes() { } @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 boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { @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 boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { @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 c4e0ca1a2787..075250cbf548 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 @@ 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.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 @@ 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 @@ else if (candidate instanceof AnnotationFormatterFactory factory) { @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 d1f41d84fcb3..a0aebe73f34d 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 27db8d50e5f4..0e6e1a4723a3 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 b3b57cab0554..7fda4a4d42d0 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.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 static boolean isInstrumentationAvailable() { * @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 @@ private static class FilteringClassFileTransformer implements ClassFileTransform 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 FilteringClassFileTransformer( } @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 ba6fe6084250..ccbd18233c27 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 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 21b75d9c2f2b..fcd07532e3d6 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.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 URL getResource(String requestedPath) { } @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 0512d51de349..448be7e92bc4 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.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 URL getResource(String name) { } @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 b61cceb02ec2..c4debbcaedf2 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 @@ 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 a4329ae2a2c5..44f4ebeba4fc 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 7f9a06d52d78..8188b5a71eb5 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.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 @@ */ 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 6df3504ca9c3..a1ddc170dc70 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.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 7ab813fa0a9f..9977331aa4cb 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 f6db661d974e..7f98672b3083 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.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 74561954733d..b758412f73ab 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 82ed42c3b699..73711875a1d3 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 a22203404e76..96032cfe54b4 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.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 c1ac847dad67..8f2e06a38dc2 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 a6e8a89c823a..c51a9562684e 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 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 2cd42366d217..55494b1ce5d4 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 @@ 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 063993eb0983..f160509d164e 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.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.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 void setEnvironment(@Nullable Map environment) { * {@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 void setManagementInterface(@Nullable Class managementInterface) { * 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 @@ protected boolean isPrepared() { * @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 Object invoke(MethodInvocation invocation) throws Throwable { * @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 @@ else if (logger.isWarnEnabled()) { * @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 @@ else if (rex instanceof RuntimeErrorException runtimeErrorException) { } } - @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 @@ private Object invokeOperation(Method method, Object[] args) throws JMException, * @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 @@ private static final class MethodCacheKey implements Comparable * @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 b0c62aa13a17..77e671667ee7 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 @@ 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 void afterPropertiesSet() throws MBeanServerNotFoundException, MBeanInfoR @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 159e067e6126..c2f18b3ee8fe 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 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 void setEnvironment(@Nullable Map environment) { * {@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 adac687a46f2..70e314fd6579 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 ec845f54d85c..030f94263c93 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.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.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 @@ protected boolean isMBean(@Nullable Class beanClass) { * @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 @@ private interface AutodetectCallback { @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 3398cc8803cd..b190f2196632 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.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.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 @@ */ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFactoryAware { - @Nullable - private StringValueResolver embeddedValueResolver; + private @Nullable StringValueResolver embeddedValueResolver; @Override @@ -74,8 +74,7 @@ public void setBeanFactory(BeanFactory beanFactory) { @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 org.springframework.jmx.export.metadata.ManagedResource getManagedResourc } @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 org.springframework.jmx.export.metadata.ManagedAttribute getManagedAttrib } @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 org.springframework.jmx.export.metadata.ManagedMetric getManagedMetric(Me } @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 @@ private static T[] copyPropertiesToBeanArray( 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 ee176795f649..19719ff67272 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 dba27a1205f6..663164005e0f 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 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 @@ */ 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 11902dea7329..58b1460de82f 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.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 void setDefaultCurrencyTimeLimit(@Nullable Integer defaultCurrencyTimeLim /** * 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 void setParameterNameDiscoverer(@Nullable ParameterNameDiscoverer paramet * 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 4be4b5e050d5..8a838f4a3f0f 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.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 @@ 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 86d0cca923e2..f12552047ea0 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.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.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 @@ public class MetadataMBeanInfoAssembler extends AbstractReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler, InitializingBean { - @Nullable - private JmxAttributeSource attributeSource; + private @Nullable JmxAttributeSource attributeSource; /** @@ -428,8 +428,7 @@ private int resolveIntDescriptor(int getter, int setter) { * @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 @@ private Object resolveObjectDescriptor(@Nullable Object getter, @Nullable Object * @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 af780d54a86a..3e54718a5626 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.Properties; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -56,11 +57,9 @@ */ 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 f0d1392d5783..503564486792 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.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 cb5997945d62..b144b30663a0 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 3921d122505d..43b557a9dc48 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 @@ 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 d7139b411d17..947aebcb432b 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 void setDefaultValue(@Nullable Object defaultValue) { /** * Return the default value of this attribute. */ - @Nullable - public Object getDefaultValue() { + public @Nullable Object getDefaultValue() { return this.defaultValue; } @@ -63,8 +60,7 @@ public void setPersistPolicy(@Nullable String persistPolicy) { 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 495fb5c24b5b..b3b9fd122198 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 @@ */ 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 void setCategory(@Nullable String category) { /** * 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 void setDisplayName(@Nullable String displayName) { /** * A display name for this metric. */ - @Nullable - public String getDisplayName() { + public @Nullable String getDisplayName() { return this.displayName; } @@ -117,8 +112,7 @@ public void setPersistPolicy(@Nullable String persistPolicy) { /** * The persist policy for this metric. */ - @Nullable - public String getPersistPolicy() { + public @Nullable String getPersistPolicy() { return this.persistPolicy; } @@ -132,8 +126,7 @@ public void setUnit(@Nullable String unit) { /** * 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 3512b26bb2e0..5446d806ffa7 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 @@ */ 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 void setNotificationType(String notificationType) { /** * 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 void setName(@Nullable String name) { /** * Return the name of this notification. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -85,8 +81,7 @@ public void setDescription(@Nullable String description) { /** * 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 e85bda8c7d2f..4d99558fcf8d 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 @@ */ 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 void setObjectName(@Nullable String objectName) { /** * Return the JMX ObjectName of this managed resource. */ - @Nullable - public String getObjectName() { + public @Nullable String getObjectName() { return this.objectName; } @@ -78,8 +72,7 @@ public void setLogFile(@Nullable String logFile) { this.logFile = logFile; } - @Nullable - public String getLogFile() { + public @Nullable String getLogFile() { return this.logFile; } @@ -87,8 +80,7 @@ public void setPersistPolicy(@Nullable String persistPolicy) { this.persistPolicy = persistPolicy; } - @Nullable - public String getPersistPolicy() { + public @Nullable String getPersistPolicy() { return this.persistPolicy; } @@ -104,8 +96,7 @@ public void setPersistName(@Nullable String persistName) { this.persistName = persistName; } - @Nullable - public String getPersistName() { + public @Nullable String getPersistName() { return this.persistName; } @@ -113,8 +104,7 @@ public void setPersistLocation(@Nullable String persistLocation) { 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 1163b2280f26..2edf716cb82d 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 3c8aafe62349..3bc1221a358f 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 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 60edf694fb34..5a145df7e0c5 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 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 ea4792a14b51..4d97025ff211 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 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 8a75e8d702cb..7616732af0c9 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 @@ 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 98056c29034f..a47fbcd74c41 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 10056eb1327e..97aa54e3e5e4 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 5adaaf68c7ee..6aec88a4966c 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 65922f4b756e..4e0d43ecc40b 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 799c5c8cbb3c..475e1ac65de6 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.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 void run() { @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 43cb7e719ace..6b39dd7bdda4 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 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 static MBeanServer locateMBeanServer(@Nullable String agentId) throws MBe * @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 static Class[] parameterInfoToTypes(@Nullable MBeanParameterInfo[] par * @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 static boolean isMBean(@Nullable Class clazz) { * @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 static Class getMBeanInterface(@Nullable Class clazz) { * @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 26c696d1f261..b187eb6bf8f5 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 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 void setServer(@Nullable MBeanServer server) { /** * 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 dfaf6d7afcaa..3759f61f9de1 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.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.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 @@ 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 @@ private void createLazyConnection() { @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 259bc23b5008..930b9a4dbdbd 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 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 @@ protected MBeanServer createMBeanServer(@Nullable String defaultDomain, boolean @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 9244be32ced0..012cd6312c5d 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.NotificationListener; import javax.management.ObjectName; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -42,17 +43,13 @@ */ 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 void setNotificationListener(@Nullable NotificationListener notificationL /** * Get the {@link javax.management.NotificationListener}. */ - @Nullable - public NotificationListener getNotificationListener() { + public @Nullable NotificationListener getNotificationListener() { return this.notificationListener; } @@ -84,8 +80,7 @@ public void setNotificationFilter(@Nullable NotificationFilter notificationFilte * 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 void setHandback(@Nullable Object handback) { * @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 void setMappedObjectNames(Object... mappedObjectNames) { * 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 d648547da279..1e287db019da 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 44ed724aff5f..ae20c8d0ed50 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 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 void setJndiEnvironment(@Nullable Properties jndiEnvironment) { /** * 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 cf53e20a47b1..36948c6b49ec 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 @@ 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 c46b2fa94038..ae34d6dc1158 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 @@ 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 7e255cc688c7..e2b5d5530dfd 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 @@ 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 bba7d9b44a2d..60f36355d857 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 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.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 @@ 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 @@ else if (logger.isDebugEnabled()) { * 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 JndiContextExposingInterceptor(JndiTemplate jndiTemplate) { } @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 1bdecce4b925..fea6a6aab11e 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 @@ 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 @@ */ 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 void setJndiName(@Nullable String jndiName) { /** * Return the JNDI name to look up. */ - @Nullable - public String getJndiName() { + public @Nullable String getJndiName() { return this.jndiName; } @@ -86,8 +84,7 @@ public void setExpectedType(@Nullable Class expectedType) { * 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 cc8e392a7778..6afc62f3fd85 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 @@ 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 void afterPropertiesSet() throws NamingException { @Override - @Nullable - public Class getTargetClass() { + public @Nullable Class getTargetClass() { if (this.cachedObject != null) { return this.cachedObject.getClass(); } @@ -128,8 +126,7 @@ public boolean isStatic() { } @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 88a4aa4c06f0..31efaff38613 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 @@ 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 JndiPropertySource(String name, JndiLocatorDelegate jndiLocator) { * {@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 e08829e70c73..5936b42158e7 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 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 void setEnvironment(@Nullable Properties environment) { /** * 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 Properties getEnvironment() { * @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 a5931d894f9f..b64874545ed5 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 @@ 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 1ef8b64ac15a..1c833c48687f 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 beb548986386..5d3ff1e14045 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 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.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 T getBean(String name, Class requiredType) throws BeansException { } @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 T getBean(Class requiredType) throws BeansException { } @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 T getObject(Object... args) throws BeansException { 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 T getIfAvailable() throws BeansException { } } @Override - @Nullable - public T getIfUnique() throws BeansException { + public @Nullable T getIfUnique() throws BeansException { try { return getBean(requiredType); } @@ -233,14 +232,12 @@ public boolean isTypeMatch(String name, @Nullable Class typeToMatch) throws N } @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 3669b23b625f..ba21e4d4576b 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 e1b2349ea84b..bee6db255972 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 @@ default boolean isLongLived() { * @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 a25739772fea..07b77bd64c7c 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.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 @@ default Clock getClock() { * 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 4739ecf2b43e..5de2fca11835 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 @@ 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 @@ default Date nextExecutionTime(TriggerContext triggerContext) { * 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 d2fc96d677d0..5db303df142d 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.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 @@ default Clock getClock() { *

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 @@ default Date lastScheduledExecutionTime() { * 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 @@ default Date lastScheduledExecutionTime() { *

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 @@ default Date lastActualExecutionTime() { * 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 @@ default Date lastActualExecutionTime() { * @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 @@ default Date lastCompletionTime() { * 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 35e08bec19e7..f851696c4305 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.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.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 @@ @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 ae9a987b5282..8b3f44c35a88 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 @@ 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 AnnotationAsyncExecutionInterceptor(@Nullable Executor defaultExecutor, A * @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 f88cd4acf281..818043f28ad2 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.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.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 9d8f801590eb..9d7c85971528 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 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 c7f50aed70a8..a69a43b561b4 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 488297171ba6..a840df3fe3db 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 @@ 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 @@ default Executor getAsyncExecutor() { * 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 4c1e83146873..4c2a0a95218d 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 @@ 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 @@ 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 85ba965e07cb..7f9f39139906 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.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 @@ @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 boolean isDone() { } @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 V get() throws ExecutionException { } @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 17178ba0f32e..060e4191e590 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 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.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 @@ protected Runnable createRunnable(Object target, Method method, @Nullable String * @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 a51af6a215ea..6f2d2705da87 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.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.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 @@ static final class SubscribingRunnable implements SchedulingAwareRunnable { final String displayName; - @Nullable - private final String qualifier; + private final @Nullable String qualifier; private final List subscriptionTrackerRegistry; @@ -219,8 +218,7 @@ static final class SubscribingRunnable implements SchedulingAwareRunnable { } @Override - @Nullable - public String getQualifier() { + public @Nullable String getQualifier() { return this.qualifier; } @@ -276,15 +274,13 @@ private static final class TrackingSubscriber implements Subscriber, Run 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 e876e68edf2e..8247daf25a05 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 7bda93c2e959..322ced233ae9 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 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 b004b0d5c3e1..2d2322b0b5af 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 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 Future submit(Callable task) { } @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 TriggerAdapter(Trigger adaptee) { } @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 boolean skipRun(LastExecution lastExecutionInfo, Date scheduledRunTime) { 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 417a542c6862..04e4dfd2adca 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 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 c30f209c53f0..fd2c3ac3f8aa 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 @@ 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 @@ public DelegatingErrorHandlingCallable(Callable delegate, @Nullable ErrorHand @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 99f22d71a09c..9a0b820e6182 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 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.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 e8e705fc2179..3a49ca6ef288 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.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 26b1165201fb..2de78626fdb8 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 @@ 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 void afterPropertiesSet() { @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 c14be23fd5cc..d5aab59378a0 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.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 @@ public ReschedulingRunnable(Runnable delegate, Trigger trigger, Clock clock, } - @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 c41101b49953..dfdf377df77b 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.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 @@ protected Runnable getRunnableToSchedule(ScheduledExecutorTask task) { @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 7e55e5eecfc3..dc2b55d4217f 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 @@ import java.util.concurrent.TimeUnit; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -41,8 +42,7 @@ */ 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 ebba61059942..21cb4cc68675 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.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.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 Future submit(Callable task) { } @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 7680a2634f71..d57c979ecca3 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.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 @@ protected void initiateEarlyShutdown() { @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 9451b64839b9..f4999fb4314f 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.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 581e1d485205..b0d754cc670c 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.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 Future submit(Callable task) { // 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 7caa0796d908..435f8199d228 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 8f09ae665a44..c10e3d64ed50 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.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 4f0265237e31..14062c14b5a6 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.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 void cancel(boolean mayInterruptIfRunning) { * 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 700c0e9e27e2..49f5d455d1db 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.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 @@ else if (scheduler instanceof ScheduledExecutorService ses) { /** * 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 void setObservationRegistry(@Nullable ObservationRegistry observationRegi * 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 @@ private void addScheduledTask(@Nullable ScheduledTask task) { * @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 ScheduledTask scheduleTriggerTask(TriggerTask task) { * (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 ScheduledTask scheduleCronTask(CronTask task) { * (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 ScheduledTask scheduleFixedRateTask(FixedRateTask task) { * (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 ScheduledTask scheduleFixedDelayTask(FixedDelayTask task) { * (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 ae14768a7d85..ef9c9042d5dd 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 @@ 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 boolean isLongLived() { 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 cbb6e1ec4cb8..b049296dc08f 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 @@ 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 b065156dd0ee..6566263f6200 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 @@ 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 @@ 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 @@ private void determinePoolSizeRange(ThreadPoolTaskExecutor executor) { @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 21898b50efa2..0a4080d2d03b 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 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.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 void setBeanFactory(@Nullable BeanFactory beanFactory) { @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 @@ protected TaskScheduler determineTargetScheduler(Runnable task) { } } - @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 3ddfc3ca96ec..962ffb54bfca 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 8880b4ba376f..950be2506968 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 3ef274e63c5c..5b662d3bf94d 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.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 @@ private static ValueRange parseRange(String value, Type type) { } - @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 c69fdb12ff7a..856058189575 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 @@ import java.time.temporal.Temporal; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -56,9 +57,8 @@ public static CronField compose(CronField[] fields, Type type, String value) { } - @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 47b5db1a2c18..bdb5249ea3c5 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.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 @@ private static String resolveMacros(String expression) { * @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 @@ private > T nextOrSame(T temporal) { 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 e1702c9a548b..31161c85b30d 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.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 @@ private static String replaceOrdinals(String value, String[] list) { * @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 dc8c9a4ab527..8aab327bf5fd 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.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 String getExpression() { * 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 8b354ebec3d7..067d29540042 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 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 c2733dd86ea7..cf5680de944c 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.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 @@ 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 71096a893460..fa075a276293 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.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 long getInitialDelay() { * 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 8c0873d15109..19ddf63da088 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.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 @@ private static Temporal rollbackToMidnight(Temporal current, Temporal result) { @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 @@ public > T nextOrSame(T temporal) { 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 87412218f902..57312e3c416d 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 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 Method getMethod() { } @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 52088fb41dde..519a19aa86f7 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.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 SimpleTriggerContext(@Nullable Date lastScheduledExecutionTime, @Nullable 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 Clock getClock() { } @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 7a286639e38d..3d8a068fe68b 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 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 228c69c6a956..485d12506043 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 25e4b0815105..91e8107de23e 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 @@ @SuppressWarnings("serial") public class ScriptCompilationException extends NestedRuntimeException { - @Nullable - private final ScriptSource scriptSource; + private final @Nullable ScriptSource scriptSource; /** @@ -88,8 +88,7 @@ public ScriptCompilationException(ScriptSource scriptSource, String msg, Throwab * 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 762a2282e742..3fa401bcc805 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 @@ 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 5c535c36f04c..fb60a7ce317f 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 @@ 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 @@ Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... actual * @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 87e695470402..75515cc0d1b0 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 @@ 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 07697f0d0890..b6aef2c71f4b 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 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 @@ */ public class BshScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware { - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; /** @@ -64,14 +63,12 @@ public void setBeanClassLoader(ClassLoader classLoader) { @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 235593df9ed8..4d355ffa3094 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 @@ 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 BshScriptFactory(String scriptSourceLocator) { * @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 String getScriptSourceLocator() { } @Override - @Nullable - public Class[] getScriptInterfaces() { + public Class @Nullable [] getScriptInterfaces() { return this.scriptInterfaces; } @@ -122,8 +118,7 @@ public boolean requiresConfigInterface() { * @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 Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... } @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 8469e4884cac..308ea1950fb5 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.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 static Object createBshObject(String scriptSource) throws EvalError { * @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 static Object createBshObject(String scriptSource, @Nullable Class... * @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 static Object createBshObject(String scriptSource, @Nullable Class[] s * @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 @@ else if (result != null) { * @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 BshObjectInvocationHandler(XThis xt) { } @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 eb70e4afb8d1..d5e2fb0d2776 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 06d6cd7727fb..47c0a447f930 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 @@ 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.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 @@ public ScriptBeanDefinitionParser(String scriptFactoryClassName) { */ @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 @@ else if (beanDefinitionDefaults.getDestroyMethodName() != null) { * 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 f4068e09cbb0..60b3ec1b993a 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 0d2c295d5b93..e10b2dde004f 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 21a34f10a35f..e63945ee87bf 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.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 @@ */ public class GroovyScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAware { - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; private CompilerConfiguration compilerConfiguration = new CompilerConfiguration(); @@ -98,14 +97,12 @@ public void setBeanClassLoader(ClassLoader classLoader) { @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 216518606829..d3faceca8982 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 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 String getScriptSourceLocator() { * @return {@code null} always */ @Override - @Nullable - public Class[] getScriptInterfaces() { + public Class @Nullable [] getScriptInterfaces() { return null; } @@ -221,8 +214,7 @@ public boolean requiresConfigInterface() { * @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 Object getScriptedObject(ScriptSource scriptSource, @Nullable Class... } @Override - @Nullable - public Class getScriptedObjectType(ScriptSource scriptSource) + public @Nullable Class getScriptedObjectType(ScriptSource scriptSource) throws IOException, ScriptCompilationException { synchronized (this.scriptClassMonitor) { @@ -314,8 +305,7 @@ public boolean requiresScriptedObjectRefresh(ScriptSource scriptSource) { * 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 String toString() { */ 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 336139003789..fa250edaa085 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 53a043f760d0..29d2f16d78c9 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 0cdceadfe7f2..94860e0aa283 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 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 @@ protected long retrieveLastModifiedTime() { } @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 ac1b678dfbf2..5d71cb0ebad6 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 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.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 int getOrder() { @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 PropertyValues postProcessProperties(PropertyValues pvs, Object bean, Str } @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 @@ protected ScriptSource convertToScriptSource(String beanName, String scriptSourc * @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 @@ protected Class createCompositeInterface(Class[] interfaces) { * @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 @@ protected BeanDefinition createScriptedObjectBeanDefinition(BeanDefinition bd, S * @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 d907574ef2c7..4103d54695b3 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.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 @@ */ 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 void setBeanClassLoader(ClassLoader classLoader) { @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 a2e4c4f32f18..3373f26d4316 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.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 @@ */ 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 StandardScriptFactory(String scriptEngineName, String scriptSourceLocator * 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 String getScriptSourceLocator() { } @Override - @Nullable - public Class[] getScriptInterfaces() { + public Class @Nullable [] getScriptInterfaces() { return this.scriptInterfaces; } @@ -140,8 +136,7 @@ public boolean requiresConfigInterface() { * 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 @@ protected Object evaluateScript(ScriptSource scriptSource) { } } - @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 @@ protected ScriptEngine retrieveScriptEngine(ScriptSource scriptSource) { return null; } - @Nullable - protected Object adaptToInterfaces( + protected @Nullable Object adaptToInterfaces( @Nullable Object script, ScriptSource scriptSource, Class... actualInterfaces) { Class adaptedIfc; @@ -260,8 +253,7 @@ protected Object adaptToInterfaces( } @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 c1163e9ece40..9b2fd1dc9e21 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 synchronized boolean isModified() { } @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 dc8b765754bb..c006546a2f2f 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 829c45e73e2c..9cb0299d7d32 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 25e3d4d7b052..4247bed6291e 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.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 ConcurrentModel(Object attributeValue) { @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 boolean containsAttribute(String attributeName) { } @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 5ec0a109e487..356e95964abd 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 @@ 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 83cd2ee8baee..e6ba37e63fb8 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 @@ 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 48c887666fb2..dac97a4ccd3a 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.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 boolean containsAttribute(String attributeName) { * @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 ab52272b0df6..0fefadc27e71 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 15bf064d4687..e5c9485fbedb 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 cedb3f0bba43..d8cc933f1cad 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 9e79100a5310..73bac948adad 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 @@ @Deprecated(since = "6.0") public class DelegatingThemeSource implements HierarchicalThemeSource { - @Nullable - private ThemeSource parentThemeSource; + private @Nullable ThemeSource parentThemeSource; @Override @@ -46,15 +46,13 @@ public void setParentThemeSource(@Nullable ThemeSource parentThemeSource) { } @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 f93bdf7e4da8..338ac0b9a924 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 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 void setParentThemeSource(@Nullable ThemeSource parent) { } @Override - @Nullable - public ThemeSource getParentThemeSource() { + public @Nullable ThemeSource getParentThemeSource() { return this.parentThemeSource; } @@ -138,8 +133,7 @@ public void setBeanClassLoader(@Nullable ClassLoader beanClassLoader) { * @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 9a6e0876238f..e854b4e06844 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 96269d532a03..18e621b220f1 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 64b9c9b5fb1c..fc2d2b8fcea0 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.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 String getObjectName() { } @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 List getGlobalErrors() { } @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 List getFieldErrors() { } @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 List getFieldErrors(String field) { } @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 FieldError getFieldError(String field) { } @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 @@ else if (getTarget() != null) { * @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 Map getModel() { } @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 Object getRawFieldValue(String field) { * 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 PropertyEditor findEditor(@Nullable String field, @Nullable Class valu * This implementation returns {@code null}. */ @Override - @Nullable - public PropertyEditorRegistry getPropertyEditorRegistry() { + public @Nullable PropertyEditorRegistry getPropertyEditorRegistry() { return null; } @@ -378,16 +371,14 @@ public int hashCode() { * 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 int hashCode() { * 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 460d860f85a5..584d9f5162e9 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.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 61675d953e17..d2dc5d84171f 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 @@ 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.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 @@ @SuppressWarnings("serial") public abstract class AbstractPropertyBindingResult extends AbstractBindingResult { - @Nullable - private transient ConversionService conversionService; + private transient @Nullable ConversionService conversionService; /** @@ -70,8 +70,7 @@ public void initConversion(ConversionService conversionService) { * @see #getPropertyAccessor() */ @Override - @Nullable - public PropertyEditorRegistry getPropertyEditorRegistry() { + public @Nullable PropertyEditorRegistry getPropertyEditorRegistry() { return (getTarget() != null ? getPropertyAccessor() : null); } @@ -89,8 +88,7 @@ protected String canonicalFieldName(String field) { * @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 Class getFieldType(@Nullable String field) { * @see #getPropertyAccessor() */ @Override - @Nullable - protected Object getActualFieldValue(String field) { + protected @Nullable Object getActualFieldValue(String field) { return getPropertyAccessor().getPropertyValue(field); } @@ -110,8 +107,7 @@ protected Object getActualFieldValue(String field) { * @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 @@ protected Object formatFieldValue(String field, @Nullable Object value) { * @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 @@ protected PropertyEditor getCustomEditor(String fixedField) { * 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 1cc6bb8e3654..54b6143b6ca0 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 @@ 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 @@ @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 BeanPropertyBindingResult(@Nullable Object target, String objectName, @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 b84c81081a87..0e2ea2630cc1 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.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 void reject(String errorCode, String defaultMessage) { } @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 void rejectValue(@Nullable String field, String errorCode, String default @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 List getGlobalErrors() { } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return this.bindingResult.getGlobalError(); } @@ -192,8 +192,7 @@ public List getFieldErrors() { } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.bindingResult.getFieldError(); } @@ -213,26 +212,22 @@ public List getFieldErrors(String field) { } @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 Map getModel() { } @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 ed3e3a1d70ff..e0625d631667 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 @@ 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 04694d823f83..b1d3c12be4fd 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 @@ 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 41b8ec3a58f8..7991072db02b 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 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.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 DataBinder(@Nullable Object target, String objectName) { *

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 void setTargetType(ResolvableType targetType) { * 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 boolean isIgnoreInvalidFields() { * @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 void setAllowedFields(@Nullable String... allowedFields) { * @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 String[] getAllowedFields() { * @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 void setDisallowedFields(@Nullable String... disallowedFields) { * @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 String[] getDisallowedFields() { * @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 void setRequiredFields(@Nullable String... requiredFields) { * 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 void setNameResolver(NameResolver nameResolver) { * constructor parameters. * @since 6.1 */ - @Nullable - public NameResolver getNameResolver() { + public @Nullable NameResolver getNameResolver() { return this.nameResolver; } @@ -728,8 +711,7 @@ public void replaceValidators(Validator... validators) { /** * 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 void setConversionService(@Nullable ConversionService conversionService) /** * Return the associated ConversionService, if any. */ - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -847,36 +828,31 @@ public void registerCustomEditor(@Nullable Class requiredType, @Nullable Stri } @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 void construct(ValueResolver valueResolver) { } } - @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 @@ private boolean hasValuesFor(String paramPath, ValueResolver resolver) { } @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 @@ private List createList( } @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 @@ private Map createMap( } @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 @@ private V[] createArray(String paramPath, ResolvableType type, ValueResolver 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 interface NameResolver { * 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 interface ValueResolver { * @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 a18554a5543f..63421ec83c06 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.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 f01232ca1f6f..00c6c0c1ed5d 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 @@ @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 DirectFieldBindingResult(@Nullable Object target, String objectName, bool @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 a7292a5af9dc..cb8ff224cf4b 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.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 @@ default void reject(String errorCode, String defaultMessage) { * @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 @@ default void rejectValue(@Nullable String field, String errorCode, String defaul * @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 @@ default int getGlobalErrorCount() { * @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 @@ default int getFieldErrorCount() { * @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 @@ default List getFieldErrors(String field) { * @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 @@ default FieldError getFieldError(String field) { * @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 @@ default FieldError getFieldError(String field) { * @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 bb57d556ff39..cc21efb743e1 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 FieldError(String objectName, String field, String defaultMessage) { * @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 String getField() { /** * 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 41860a4c1d42..f15a1ae7b5a1 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 @@ 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 MapBindingResult(Map target, String objectName) { } @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 48d918e9da15..ca45259d46ca 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 2a985e6439d2..8518a20b5f24 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 b8187d34739e..05eca672ebbd 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 ObjectError(String objectName, @Nullable String defaultMessage) { * @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 6854f26235ea..edb2c3d860c9 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.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 String getObjectName() { } @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 List getFieldErrors() { } @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 Object getFieldValue(String field) { } @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 c033a9266dac..c64a62ad3853 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 @@ default void validateValue( * 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 042668317d93..263558009cd1 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 @@ 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 static void invokeValidator(Validator validator, Object target, Errors er * {@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 static void rejectIfEmpty(Errors errors, String field, String errorCode, * @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 static void rejectIfEmptyOrWhitespace( * (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 static void rejectIfEmptyOrWhitespace( * @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 9a612eeda4a9..e29718758757 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 @@ 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 177ad9c8d98b..afce17fc8ad2 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 50d66dcf4981..c81ec72182c8 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.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.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 @@ public BeanRegistrationAotContribution processAheadOfTime(RegisteredBean registe */ 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 @@ private static Validator getValidatorIfAvailable() { } } - @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 77c7966a0ed1..d912eef2b5fe 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.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 @@ */ 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 37800c7df5f4..50f14273cd5d 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.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 @@ */ 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 6a0f939c4f9c..00e7af3ee290 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.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.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 void setApplicationContext(ApplicationContext applicationContext) { @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 f65fb56b7f40..d9829014ebeb 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.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.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[] determineValidationGroups(Object target, Method method) { @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 @@ private final class ParamValidationResultBuilder { 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 @@ private final class ParamErrorsBuilder { 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 ce39c9aa08c5..3d1f6aa11042 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.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.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 @@ private MethodValidationInterceptor(MethodValidationAdapter validationAdapter, b @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 @@ static Object[] insertAsyncValidation( 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 8e518bbc14fe..6b97534466c4 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.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 @@ protected MessageSourceResolvable getResolvableField(String objectName, String f * @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 String[] getCodes() { } @Override - @Nullable - public Object[] getArguments() { + public Object @Nullable [] getArguments() { return null; } @@ -446,11 +443,9 @@ public String toString() { @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 boolean shouldRenderDefaultMessage() { @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 c367d4b45534..9f6498812eae 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 3a937edd4b8a..2b97be8e4297 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 @@ 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 @@ MethodValidationResult validateArguments( * @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 ad3bba6b747c..81ee1235923f 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 @@ 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 void reject(String errorCode, String defaultMessage) { } @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 void rejectValue(@Nullable String field, String errorCode, String default @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 List getGlobalErrors() { } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return this.errors.getGlobalError(); } @@ -170,8 +170,7 @@ public List getFieldErrors() { } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.errors.getFieldError(); } @@ -191,20 +190,17 @@ public List getFieldErrors(String field) { } @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 740796976d07..e3a753c9b4cd 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.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 MethodParameter getMethodParameter() { /** * The method argument value that was validated. */ - @Nullable - public Object getArgument() { + public @Nullable Object getArgument() { return this.argument; } @@ -132,8 +128,7 @@ public List getResolvableErrors() { * {@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 Object getContainer() { * {@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 Integer getContainerIndex() { * 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 001ea1b69c45..04f41ca92a6d 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 cc26d2bb6776..2af4394c823a 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 3411f9a909fa..bca828e8dd85 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 @@ 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 @@ 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 c37eca8a7a0e..573c3826270b 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 @@ 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 355c476679f1..e7197c303bb5 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 c7f56212bc4d..98ac18bee378 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 @@ 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.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 ed740ab88ce9..1c7b6740469c 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 @@ 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.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 bc6f45bfc44c..34e6bc313b3d 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.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.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 49e142044fbf..b99c0c13ccc1 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 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.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 343633881fa6..245bc5ed4829 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 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.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 f2fb4eea74a1..811a5550d571 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 @@ 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.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 481fe6e591ec..273ff8978bec 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 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.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 90731091f331..3b1615338f32 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 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.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 @@ public void setProxyObject(boolean proxyObject) { } @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 799cbf11e05a..350e7e4138bb 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 @@ 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 9d358b81cdc2..3d524830c9bf 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.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.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 @@ public MyCacheResolver() { } @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 c43df31de414..e065cde9d10e 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.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.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 3b826775a545..75ff994160ed 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.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.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 4e5cafd54b9d..39fad9892b8a 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.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.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 @@ private RuntimeCacheResolver(CacheManager cacheManager) { } @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 @@ private NullCacheResolver(CacheManager cacheManager) { } @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 c7ccf72758f2..2d96f0d34320 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.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.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 9b7777cbf9f9..7d238cb6a26b 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 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.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 @@ public void setImportMetadata(AnnotationMetadata importMetadata) { 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 @@ private RegisteredBean getRegisteredBean(Class bean) { } - @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 5f2fb5f9dcf4..2014c12000b2 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.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.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 String[] selectImports(AnnotationMetadata importingClassMetadata) { } @Override - @Nullable - public Predicate getExclusionFilter() { + public @Nullable Predicate getExclusionFilter() { return className -> className.endsWith("ImportedSelector1"); } } @@ -440,18 +439,16 @@ static class GroupedConfig2 { 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 String[] selectImports(AnnotationMetadata importingClassMetadata) { 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 String[] selectImports(AnnotationMetadata importingClassMetadata) { 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 String[] selectImports(AnnotationMetadata importingClassMetadata) { return new String[] { DeferredImportedSelector3.class.getName() }; } - @Nullable @Override - public Class getImportGroup() { + public @Nullable Class getImportGroup() { return TestImportGroup.class; } @@ -537,9 +531,8 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) { 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 5e08fafbf6ba..2e2dc67b2b4d 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 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.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 bb4aa59ff8b1..ecf4d6f22a02 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.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.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 80add57c4d2d..4b3773c7ca79 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 @@ 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 51f06ee24fd3..bbff12e68667 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 b4e5d98ffbe6..7df44c59232a 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 @@ 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 90e3ccba6040..c42422d2a702 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.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.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 @@ public Set getConvertibleTypes() { 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 62535c0d2724..2f1d47fc2c1c 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.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.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 819dc5af86e6..1878c0aee731 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.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 17c3f20883ec..ebe8931ae01e 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.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.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 @@ public AsyncUncaughtExceptionHandler exceptionHandler() { 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 4e7fc7c470b1..e1d24884835b 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.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.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 ad1f6222d367..c51cf92192b1 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.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 @@ private static TriggerContext context(@Nullable Object scheduled, @Nullable Obje 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 @@ private static Instant toInstant(@Nullable Object o) { 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 8bcc9ffde890..4f219bb84f69 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 @@ 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 5c36f02ce4f2..4b2f9ceb48f1 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.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 819c72227ab0..e375b2832a70 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.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 @@ static class NestedDataClass { 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 @@ public String param1() { 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 81ee18a8a438..77549a817716 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.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.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 3147fd8555b6..9197c706b18f 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.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.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 @@ private void process(Class beanClass) { } } - @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 76a3caae13ca..b5437b7e9c40 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 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 8326a5c23874..6eac0de1ac01 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.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 a058f2c24112..cc16e59096d8 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.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.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 @@ static class MyValidClientInterfaceMethodInterceptor implements MethodIntercepto 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 4fd7e9c0456d..899662bdc6d7 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 @@ 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 d86dafb55329..36d7f40a4758 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.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 static ClassLoader index(ClassLoader classLoader, Resource... resources) } - @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 92b0e3fc4b24..cd1d0dee9e23 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 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 Hashtable getEnvironment() { } @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 fa253ada9863..19ca64a6672a 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 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 @@ 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 35610a92220f..22ec0e45a320 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.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 static Field classgetField(Class clazz, String name) throws NoSuchFiel 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 static URL classgetResource(Class clazz, String name) { 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 static Class classloaderloadClass(ClassLoader classLoader, String name 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 static URL classloadergetResource(ClassLoader classLoader, String name) { 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 f9cc6abd17f3..f3babf532ad6 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.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 4a2f119445ec..0ab3fa387e02 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 @@ 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 7572fcebdde4..20e411e7eeeb 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.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 @@ */ 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 List getArgumentTypes(int index) { * @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 String toString() { */ 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 Builder withArgument(@Nullable Object argument) { * @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 e03f71de77f1..1d1cf826a1b6 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.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 1ea09811ae19..e19fa356b961 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 dc7ecdddfd68..ff84188ae02c 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 9235cf21d597..7f00527d6136 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 70a6067a6a0d..135ffbf98699 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.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 @@ protected MockSpringFactoriesLoader(@Nullable ClassLoader classLoader, @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 99ef46417165..d87f5a2b56fd 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 595c920a3acc..711ed5d2e403 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.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 boolean isEmpty() { * @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 fe728b22acfa..8d626d6823bf 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.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 @@ protected Class findClass(String name) throws ClassNotFoundException { 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 @@ protected Enumeration findResources(String name) throws IOException { } @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 1ef3175e4507..4125df1c4139 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.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 cd395d4a46b2..de8ee3360f1e 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 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 @@ String getClassName() { 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 c55d66401192..3a95b7e53f0f 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.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 @@ protected Class findClass(String name) throws ClassNotFoundException { 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 @@ protected Enumeration findResources(String name) throws IOException { } @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 @@ protected URL findResource(String name) { 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 @@ private static Method lookupMethod(Class target, String name, Class... par private static class SingletonEnumeration implements Enumeration { - @Nullable - private E element; + private @Nullable E element; SingletonEnumeration(@Nullable E element) { @@ -177,8 +173,7 @@ public boolean hasMoreElements() { } @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 bbc81923a7cf..f17d7b048f7f 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 @@ 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 f59f33fb738b..dbbf3f79a1b0 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 23b2d47ccd30..29c0f2e9710f 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.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 @@ boolean isEmpty() { 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 5e09f46e5430..43a4bae34214 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 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 @@ */ class DynamicResourceFileObject extends SimpleJavaFileObject { - @Nullable - private volatile byte[] bytes; + private volatile byte @Nullable [] bytes; DynamicResourceFileObject(String fileName) { @@ -73,8 +72,7 @@ private void closeOutputStream(byte[] bytes) { 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 1a53e922774b..870713cf5b66 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 @@ 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 boolean isEmpty() { * @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 8db946050b88..02918a4bc698 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.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 ad8bab385af9..1505a5412d6c 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.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 boolean isEmpty() { * @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 bb77051b9e7f..14027e6a5c37 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.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 @@ */ 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 a541c066c4cb..750eb47a7152 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 71a30eba42e2..76d7e4016cb0 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 48c88041e484..dc617405ec4d 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.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 3018c6407cfc..77c860ffe2a6 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 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 2b1caa6d1365..23c7a81920c4 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.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 @@ */ public final class GeneratedClass { - @Nullable - private final GeneratedClass enclosingClass; + private final @Nullable GeneratedClass enclosingClass; private final ClassName name; @@ -98,8 +98,7 @@ private String generateSequencedMethodName(MethodName name) { * 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 5e057001bb2d..e6aad3d286c5 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.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 98979191a81a..2b98963b14ac 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 @@ 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 boolean exists() { * 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 9e2ec90886b3..54bb19bcbb41 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 @@ private GeneratedTypeReference(ClassName className) { 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 b79a0b3318bc..7e82efa15c6a 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.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 Map getGeneratedFiles(Kind kind) { * @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 String getGeneratedFileContent(Kind kind, String path) throws IOException * @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 6a4ff72f6f97..7630055f176d 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 @@ 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 a33573d74fd3..42ff4169aa8d 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 @@ 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 @@ interface ArgumentCodeGenerator { * @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 dead0694e49d..2faba073c194 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 @@ @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 @@ private static String buildErrorMessage(@Nullable Object value) { /** * 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 b30b1acff152..4699261f1668 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.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 CodeBlock generateCode(@Nullable Object value) { * {@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 interface Delegate { * @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 86904a0c30d3..bccc9986f5bf 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.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 @@ protected CollectionDelegate(Class collectionType, CodeBlock emptyResult) { @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 static class MapDelegate implements Delegate { 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 CodeBlock generateCode(ValueCodeGenerator valueCodeGenerator, Object valu * @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 @@ private static class PrimitiveDelegate implements Delegate { @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 @@ private String escape(char ch) { 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 CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { 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 CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { 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 CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { 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 CodeBlock generateCode(ValueCodeGenerator codeGenerator, Object value) { 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 @@ private static CodeBlock generateCodeWithGenerics(ResolvableType target, Class 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 c6c380a8e2c4..b85a083bf375 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 77c78341674f..a70ecfcd6c68 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 @@ 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 String getSimpleName() { 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 00d258cc2314..3f60d79bc5c7 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 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 c9784ef592c2..a19bc26bf6da 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 5d0c3a4d26dc..265377497690 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.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 static class Builder { private final List 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 2de9e84c4423..c4e0a03de017 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 @@ 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 8f41d18f51bc..46bdf6c091f1 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 @@ 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 TypeReference getType() { } @Override - @Nullable - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -75,8 +73,7 @@ public static class Builder { 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 4310ab5a4f0b..b9ddfec42582 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.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 List getProxiedInterfaces() { return this.proxiedInterfaces; } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -97,8 +95,7 @@ public static class Builder { 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 d16778dac9e8..e66aaec41111 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.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 Stream typeHints() { * @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 TypeHint getTypeHint(TypeReference type) { * @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 3e4a26557a9e..1e55f338b8a3 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 @@ private ReflectionTypeReference(Class type) { 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 c6a652260d21..e14c9f3cc9ef 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 @@ 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 String getBaseName() { return this.baseName; } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -74,8 +72,7 @@ public static class Builder { 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 490dd257f497..021bf7fe2020 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.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 b403e7d4df40..5dda53db96ae 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 @@ 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 boolean matches(String path) { 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 952c441392c2..d9b2c8bcd330 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.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 742be48a4111..c84f6410cb19 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 70b9df428427..bca351b44918 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.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 62a3ff9978cf..98d7d03e3437 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 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 70b7b7ea0eee..4502e502f5e7 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.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 TypeReference getType() { return this.type; } - @Nullable @Override - public TypeReference getReachableType() { + public @Nullable TypeReference getReachableType() { return this.reachableType; } @@ -144,8 +143,7 @@ public static class Builder { 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 6bc2c8cf2886..809b2970dde2 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 @@ 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 129744a1c592..e3983f511213 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 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 @@ protected void registerReflectionHints(ReflectionHints hints, Class target, M 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 fac70357524e..263ff633eb7e 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 19bccf9a7fe3..d8448d481a6d 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 69ba572e3503..47dc61429f8d 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.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.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 static class TypeHintPredicate implements Predicate { 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 static class FieldHintPredicate implements Predicate { 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 8d6d410e07a2..5bb1f8bf6cb0 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 22119ee762e8..a7f9bfc99d6d 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.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 ed820c4a1532..2f3137155a83 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 c086c2c7ec76..b477cbce80fc 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.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 371812e06c5b..60f1203c7caf 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 8081223c5215..d43cff56ae53 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 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 @@ private void registerHints(RuntimeHints hints, ClassLoader classLoader, } } - @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 50e61caa4dae..e6cd63d4767d 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 87ce610cfe09..02331601b1ee 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 22a0cd5c9d1f..2ddc0dc7a373 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.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 468a9d51fbb7..db246f0a2d31 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.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.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 db71c8c1a6f7..87aa20315f18 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 4cbc5065727e..056c804af7a8 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 dca0e7c5600d..d11c6ea3bf24 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 36bce0751c66..4ca9a01ba13b 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 3347e4a4e399..721ce6d6108b 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 @@ 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 @@ default T computeAttribute(String name, Function computeFunction) * @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 87e1975a82b6..c1645140b760 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.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 void setAttribute(String name, @Nullable Object value) { } @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 T computeAttribute(String name, Function computeFunction) } @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 a5c666202515..934f040e19d0 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.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 @@ private static boolean isBridgedCandidateFor(Method candidateMethod, Method brid * @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 @@ private static boolean isResolvedTypeMatch(Method genericMethod, Method candidat * 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 @@ private static Method findGenericDeclaration(Method bridgeMethod) { 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 @@ private static Method searchInterfaces(Class[] interfaces, Method bridgeMetho * 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 83af2d54dd4e..ebdc5b7cd2b4 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.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 @@ else if (HashMap.class == mapType) { 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 eb845e47977d..60425774d592 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.ObjectInputStream; import java.io.ObjectStreamClass; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -35,8 +36,7 @@ */ public class ConfigurableObjectInputStream extends ObjectInputStream { - @Nullable - private final ClassLoader classLoader; + private final @Nullable ClassLoader classLoader; private final boolean acceptProxyClasses; @@ -144,8 +144,7 @@ protected Class resolveFallbackIfPossible(String className, ClassNotFoundExce *

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 7e794fe4d288..e7456bef7950 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.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 eae2f796fb29..88aeba5f0295 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.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 48efd73d748e..c336fe30edc0 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.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 787c1e14e390..24a1f60034e6 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 @@ 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 a5e0d74c65bd..e849a594ea97 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.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 static Class resolveReturnType(Method method, Class clazz) { * @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 static Class resolveReturnTypeArgument(Method method, Class generic * @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 static Class resolveTypeArgument(Class clazz, Class genericType) 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 @@ private static Class getSingleGeneric(ResolvableType resolvableType) { * @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 TypeVariableMapVariableResolver(Map typeVariableMap) } @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 696ee372b00e..ad9976ce931c 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 @@ 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 @@ @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 485e289444df..fe7faca79770 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 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 @@ 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 String[] getParameterNames(Method method) { } @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 String[] getParameterNames(Constructor ctor) { } } - @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 b7a450e49e38..b7efe2ab2dea 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 @@ 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 f1ceac4a7ccf..91f9e4534768 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.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 interface MetadataLookup { * @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 fd2d666fe1a4..61860d73e809 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.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 MethodParameter(MethodParameter original) { *

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 Method getMethod() { *

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 void setTypeIndexForCurrentLevel(int typeIndex) { * 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 Integer getTypeIndexForCurrentLevel() { * @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 Annotation[] getMethodAnnotations() { * @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 boolean hasParameterAnnotations() { * @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 void initParameterNameDiscovery(@Nullable ParameterNameDiscoverer paramet * {@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 static MethodParameter forFieldAwareConstructor(Constructor ctor, int */ 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 46d72b7bdd7e..87f2f83c0fd0 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 @@ 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 dcf25b5f5c04..1195c04f09ac 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 NestedCheckedException(@Nullable String msg, @Nullable Throwable cause) { * 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 a2a596eacfc2..eba27406021e 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 static String buildMessage(@Nullable String message, @Nullable Throwable * @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 bd6afe4d14cc..0a50f34b2aa9 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 NestedRuntimeException(@Nullable String msg, @Nullable Throwable cause) { * @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 2724a414cf20..43b8409e8e9e 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.Comparator; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ObjectUtils; /** @@ -140,8 +141,7 @@ protected int getOrder(@Nullable Object obj) { * @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 @@ protected Integer findOrder(Object obj) { * @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 interface OrderSourceProvider { * @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 63aeab629aae..15c8c7cca98a 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 @@ 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 @@ protected boolean isEligibleForOverriding(String className) { * @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 @@ protected Class loadClassForOverriding(String name) throws ClassNotFoundExcep * 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 @@ protected byte[] loadBytesForClass(String name) throws ClassNotFoundException { * @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 f60d28b637ee..460327fd1f30 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 @@ 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 d9c1361d482e..5bd2683e36aa 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 @@ 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 bb6932783381..02eea42306a9 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.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 void addDiscoverer(ParameterNameDiscoverer pnd) { @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 String[] getParameterNames(Method method) { } @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 0356f47f59ef..ee06e4e57b5c 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 @@ 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 01ffdb9e209f..9deb8948906a 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.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.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 @@ */ 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 boolean hasAdapters() { * 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 ReactiveAdapter getAdapter(Class reactiveType) { * (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 9d53e023bd30..518ef6425083 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 @@ 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 d8d4ac98e7fc..b6428acab82a 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.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 Type getType() { * 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 ResolvableType getNested(int nestingLevel, @Nullable Map[] resolveGenerics(Class fallback) { * @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 resolveGeneric(int... indexes) { * @see #resolveGeneric(int...) * @see #resolveGenerics() */ - @Nullable - public Class resolve() { + public @Nullable Class resolve() { return this.resolved; } @@ -908,8 +897,7 @@ public Class resolve(Class fallback) { 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 @@ ResolvableType resolveType() { 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 @@ private int calculateHashCode() { /** * Adapts this {@code ResolvableType} to a {@link VariableResolver}. */ - @Nullable - VariableResolver asVariableResolver() { + @Nullable VariableResolver asVariableResolver() { if (this == NONE) { return null; } @@ -1190,7 +1175,7 @@ public static ResolvableType forClassWithGenerics(Class clazz, Class... ge * @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 @@ interface VariableResolver extends 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 @@ private static class DefaultVariableResolver implements VariableResolver { } @Override - @Nullable - public ResolvableType resolveVariable(TypeVariable variable) { + public @Nullable ResolvableType resolveVariable(TypeVariable variable) { return this.source.resolveVariable(variable); } @@ -1610,16 +1593,15 @@ private static class TypeVariablesVariableResolver implements VariableResolver { 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 String getTypeName() { } @Override - @Nullable - public Type getOwnerType() { + public @Nullable Type getOwnerType() { return null; } @@ -1787,8 +1768,7 @@ public ResolvableType[] getBounds() { * @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 0f5b6b585a4b..037bf3d8cca7 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 ba7bc2a60f22..9a568e07a5ac 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.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 @@ private 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 @@ public static Type forField(Field field) { * 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 @@ public static T unwrap(T type) { *

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 @@ interface TypeProvider extends Serializable { /** * 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 @@ public TypeProxyInvocationHandler(TypeProvider provider) { } @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 @@ private void readObject(ObjectInputStream inputStream) throws IOException, Class @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 @@ static class MethodInvokeTypeProvider implements TypeProvider { 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 @@ public MethodInvokeTypeProvider(TypeProvider provider, Method method, int index) } @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 @@ public Type getType() { } @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 695d09c68e9b..1a8162d277a3 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 @@ 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 cb3e7a93e28b..6ec7dc775ffc 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.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 e82c371a191b..54f0d079f0a3 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.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 static void setProperty(String key, @Nullable String value) { * @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 7d03c2160747..8d6bf5534067 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 @@ private 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 9bce47f435b4..6a8cbdf649be 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.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 @@ 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 978e9684c25a..0c80f267f6c8 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.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 @@ */ abstract class AbstractMergedAnnotation implements MergedAnnotation { - @Nullable - private volatile A synthesizedAnnotation; + private volatile @Nullable A synthesizedAnnotation; @Override @@ -230,8 +230,7 @@ private T getRequiredAttributeValue(String attributeName, Class type) { * @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 1ac4f84a5e80..83d22e58bc9d 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.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 static boolean isAnnotated(AnnotatedElement element, String annotationNam * @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 static AnnotationAttributes getMergedAnnotationAttributes( * @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 static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElemen * @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 static AnnotationAttributes getMergedAnnotationAttributes(AnnotatedElemen * @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 static Set getMergedRepeatableAnnotations( * 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 static MultiValueMap getAllAnnotationAttributes( * @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 static boolean hasAnnotation(AnnotatedElement element, Class annotationType, boolean classValuesAsString, boolean nestedAnnotationsAsMap) { MergedAnnotation mergedAnnotation = findAnnotations(element) @@ -604,8 +598,7 @@ public static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedEleme * @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 static AnnotationAttributes findMergedAnnotationAttributes(AnnotatedEleme * @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 @@ private static MergedAnnotations findRepeatableAnnotations(AnnotatedElement elem 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 @@ private static Comparator> highAggreg 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 @@ private static class AnnotatedElementForAnnotations implements AnnotatedElement @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 e50e79bf9004..a7e24d5c119b 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.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 boolean isVoid() { * @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 String toString() { // 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 @@ protected static String formatArgumentError(MethodParameter param, String messag */ 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 @@ protected AnnotatedMethodParameter(AnnotatedMethodParameter original) { } @Override - @NonNull - public Method getMethod() { + public @NonNull Method getMethod() { return AnnotatedMethod.this.getBridgedMethod(); } @@ -278,8 +274,7 @@ public Class getContainingClass() { } @Override - @Nullable - public T getMethodAnnotation(Class annotationType) { + public @Nullable T getMethodAnnotation(Class annotationType) { return AnnotatedMethod.this.getMethodAnnotation(annotationType); } @@ -335,8 +330,7 @@ public AnnotatedMethodParameter clone() { */ 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 7732e008062e..30f43f90b84a 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.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 AnnotationAttributes(String annotationType, @Nullable ClassLoader classLo } @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 @@ private static Class getAnnotationType(String annotationTy * @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 @@ private String valueToString(Object value) { * 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 3ac17cd27e56..ac1b86f2a46f 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.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 @@ protected Integer findOrder(Object obj) { 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 @@ private Integer findOrderFromAnnotation(Object obj) { * 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 5bda87e8dadd..f5e1a4ceafe8 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 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 @@ AnnotationTypeMapping getRoot() { * 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 @@ List> getMetaTypes() { * 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 @@ int getConventionMapping(int attributeIndex) { * 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 @@ MirrorSet get(int index) { 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 e8e07ec311d0..e26201476d0b 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.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 b46bd281ec61..8a6b393366d8 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.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 static boolean isCandidateClass(Class clazz, String annotationName) { * @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 static A getAnnotation(Annotation annotation, Clas * @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 @@ private static boolean isSingleLevelPresent(MergedAnnotat * @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 static A getAnnotation(Method method, Class ann * @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 static Annotation[] getAnnotations(AnnotatedElement annotatedElement) { * @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 static Set getDeclaredRepeatableAnnotations(Ann * @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 static A findAnnotation( * @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 static A findAnnotation(Method method, @Nullable C * @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 static A findAnnotation(Class clazz, @Nullable * @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 static Class findAnnotationDeclaringClass( * @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 static void postProcessAnnotationAttributes(@Nullable Object annotatedEle } } - @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 @@ private static Object getAttributeValueForMirrorResolution(Method attribute, @Nu 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 @@ private static Object adaptValue( * 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 static Object getValue(Annotation annotation) { * 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 static Object getValue(@Nullable Annotation annotation, @Nullable String * @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 @@ private static void handleValueRetrievalFailure(Annotation annotation, Throwable * @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 static Object getDefaultValue(Annotation annotation) { * @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 static Object getDefaultValue(@Nullable Annotation annotation, @Nullable * @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 static Object getDefaultValue(Class annotationType) * @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 f7a3d16f2df3..8c1c81824eb4 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 @@ 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 @@ default R doWithAggregate(C context, int aggregateIndex) { * {@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 @@ default R doWithAggregate(C context, int aggregateIndex) { * @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 a3d08f369bbe..8b09b1d5ce16 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.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 @@ private 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 @@ private static R process(C context, AnnotatedElement source, 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 @@ private static R processClass(C context, Class source, SearchStrategy }; } - @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 @@ private static R processClassInheritedAnnotations(C context, Class sou 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 @@ private static R processClassHierarchy(C context, Class source, 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 @@ private static R processClassHierarchy(C context, int[] aggregateIndex, C 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 @@ private static R processMethod(C context, Method source, }; } - @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 @@ private static R processMethodInheritedAnnotations(C context, Method sour 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 @@ private static boolean hasSameGenericTypeParameters( 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 @@ private static R processMethodAnnotations(C context, int aggregateIndex, 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 @@ private static R processElement(C context, AnnotatedElement source, } @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 fb8c2bda38c7..c524f355eb9c 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.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 @@ private void assertAnnotation(Annotation annotation) { * @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 23178ce385a7..5bcdfbae37bb 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 @@ 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 @@ public void log(String message) { }; - @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 6d9c1bcf5de3..f67befc9d3c1 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.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 95c2bd6a5209..dc0e1612bd6b 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.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 @@ private static class FirstRunOfPredicate implements Predic 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 7d054454a1c8..8f4733e885aa 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.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 01c0bafd1b21..6908fa19560d 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.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 @@ public MergedAnnotation get(String annotationType, } @SuppressWarnings("unchecked") - @Nullable - private MergedAnnotation find(Object requiredType, + private @Nullable MergedAnnotation find(Object requiredType, @Nullable Predicate> predicate, @Nullable MergedAnnotationSelector selector) { @@ -222,8 +222,7 @@ static MergedAnnotations of(Collection> annotations) { private class AnnotationsSpliterator implements Spliterator> { - @Nullable - private final Object requiredType; + private final @Nullable Object requiredType; private final int[] mappingCursors; @@ -259,8 +258,7 @@ public boolean tryAdvance(Consumer> action) { 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 @@ private AnnotationTypeMapping getNextSuitableMapping(int annotationIndex) { 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 @@ private MergedAnnotation createMergedAnnotationIfPossible(int annotationIndex } @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 0c7c9abad61a..1b8840bf8831 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.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 @@ public boolean isPresent() { } @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 41db68d95cf2..f3f3031f811b 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 @@ 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 static int getOrder(Class type, int defaultOrder) { * @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 static Integer getOrder(Class type, @Nullable Integer defaultOrder) { * @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 static Integer getOrder(Class type) { * @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 static Integer getOrder(AnnotatedElement element) { * @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 @@ static Integer getOrderFromAnnotations(AnnotatedElement element, MergedAnnotatio 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 @@ private static Integer findOrder(MergedAnnotations annotations) { * @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 c050a695f4fc..2e82f189dc13 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 @@ 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 9f7bf61ad2d6..cc53a6ce2271 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.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 RepeatableContainers and(Class container, 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 @@ private static class StandardRepeatableContainers extends 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 @@ Annotation[] findRepeatedAnnotations(Annotation annotation) { 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 @@ private Class deduceContainer(Class } @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 2319be3b6d03..560b74a844c9 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.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 1d0d093aa2c1..c28fa9336dd2 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.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 @@ private TypeMappedAnnotation(AnnotationTypeMapping mapping, @Nullable ClassLoade 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 @@ public int getAggregateIndex() { } @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 @@ private boolean isSynthesizable(Annotation annotation) { } @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 @@ private Object getRequiredValue(int attributeIndex, String attributeName) { 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 @@ private T getValue(int attributeIndex, Class type) { 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 @@ private Object getValue(int attributeIndex, boolean useConventionMapping, boolea 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 @@ private Object getValueFromMetaAnnotation(int attributeIndex, boolean forMirrorR 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 @@ private boolean isFiltered(String attributeName) { return false; } - @Nullable - private ClassLoader getClassLoader() { + private @Nullable ClassLoader getClassLoader() { if (this.classLoader != null) { return this.classLoader; } @@ -619,8 +607,7 @@ static MergedAnnotation of( 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 @@ static TypeMappedAnnotation createIfPossible( 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 @@ static TypeMappedAnnotation createIfPossible( 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 @@ private static TypeMappedAnnotation createIfPossible( } @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 7187cceb42ae..c83b33282357 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.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 @@ private List getAggregates() { 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 @@ private IsPresent(RepeatableContainers repeatableContainers, } @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 @@ private class MergedAnnotationFinder 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 @@ private class MergedAnnotationFinder } @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 @@ public MergedAnnotation doWithAnnotations(Object type, int aggregateIndex, 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 @@ private void updateLastResult(MergedAnnotation candidate) { } @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 @@ private class AggregatesCollector implements AnnotationsProcessor 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 @@ private static class Aggregate { private final int aggregateIndex; - @Nullable - private final Object source; + private final @Nullable Object source; private final List annotations; @@ -527,8 +512,7 @@ int size() { 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 @@ AnnotationTypeMappings getMappings(int annotationIndex) { return this.mappings[annotationIndex]; } - @Nullable - MergedAnnotation createMergedAnnotationIfPossible( + @Nullable MergedAnnotation createMergedAnnotationIfPossible( int annotationIndex, int mappingIndex, IntrospectionFailureLogger logger) { return TypeMappedAnnotation.createIfPossible( @@ -554,15 +537,13 @@ MergedAnnotation createMergedAnnotationIfPossible( */ 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 @@ private boolean tryAdvance(Aggregate aggregate, Consumer> 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 5f1b2146393c..e3cc58c27fef 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.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 af9d8e10ab11..27602936c7c2 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 340792259bbd..7df7afe64a95 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.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.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 655b53e41130..7db7d427eb40 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 @@ 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 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 Mono decodeToMono(Publisher input, ResolvableType elementT * {@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 7810d20681e4..ddf3dbcf9c48 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 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 49915e02a703..160be4b1f28c 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 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 719b6f2773bb..74da39021665 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 @@ 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.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 65f8222d1774..74aa33513471 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 @@ 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 6eef1a1f771f..94329d6eef4c 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 @@ 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 0da03706e5bd..3f2659e46b3a 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 @@ 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 8d600661526b..c86371db6b36 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 @@ 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 6745a2e00c61..0ce75215bb36 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.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 4103a1cec2c3..b7e239cfed07 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.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.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 f621858783a7..a519d9d7233b 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 788eafdb0e69..c03508858f63 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 @@ 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 88e8f1cc2a96..4f7af8db2209 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 @@ 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 f49063f101ae..285b46998b10 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.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 @@ Mono decodeToMono(Publisher inputStream, ResolvableType elementTy * @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 873996dbcb36..d87a0aac10ba 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 8cbcfcfbc93b..551c6dd9d1dc 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.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 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 7d9f7a1a1b12..5c5b83f22962 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 21ad5dd20430..91b44b362558 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.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 150db2b893e6..9b81fa509514 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 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 588367132d96..63a0a5f21a04 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 @@ 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.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 569a5cc83246..7f185e6fc157 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 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 da07d638aa0e..ea177f3863ed 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 @@ 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.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 b62964ef36df..ab0ca020a418 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 @@ 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.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 Resource decode(DataBuffer dataBuffer, ResolvableType elementType, 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 long contentLength() { 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 58b0a094fbea..1c6c29a9f734 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 @@ 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.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 3330ac6e1555..9e1109744176 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.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.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 d68abc2a33e3..2612e5b5988a 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 @@ 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 acf70ed8f96c..4fcd5b047a71 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 9f47c8317578..7fb395086bb2 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 @@ @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 ConversionFailedException(@Nullable TypeDescriptor sourceType, TypeDescri /** * 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 TypeDescriptor getTargetType() { /** * 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 9c02d51cbcf4..3ce51475b11a 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 @@ default Object convert(@Nullable Object source, TypeDescriptor targetType) { * @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 e4dd3c51a04a..3b7f64ebf4b2 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 @@ @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 ConverterNotFoundException(@Nullable TypeDescriptor sourceType, TypeDescr /** * 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 f22251515084..2d1eed925252 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.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 Class getType() { /** * 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 @@ private MethodParameter resolveMethodParameter() { 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 @@ private void addAnnotationsToMap( } } - @Nullable - private Field getField() { + private @Nullable Field getField() { String name = getName(); if (!StringUtils.hasLength(name)) { return null; @@ -245,8 +238,7 @@ private Field getField() { 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 a29ae07516bb..48aefd8daa8f 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.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 TypeDescriptor(Property property) { * @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 Object getSource() { * {@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 TypeDescriptor narrow(@Nullable Object value) { * @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 boolean hasAnnotation(Class annotationType) { * @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 boolean isArray() { * 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 TypeDescriptor getElementTypeDescriptor() { * @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 boolean isMap() { * 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 TypeDescriptor getMapKeyTypeDescriptor() { * @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 TypeDescriptor getMapKeyTypeDescriptor(Object mapKey) { * 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 TypeDescriptor getMapValueTypeDescriptor() { * @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 String toString() { * @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 static TypeDescriptor map(Class mapType, @Nullable TypeDescriptor keyT * @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 static TypeDescriptor array(@Nullable TypeDescriptor elementTypeDescripto * {@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 static TypeDescriptor nested(MethodParameter methodParameter, int nesting * @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 static TypeDescriptor nested(Field field, int nestingLevel) { * @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 @@ private AnnotatedElementAdapter(Annotation[] annotations) { 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 boolean isAnnotationPresent(Class annotationClass) } @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 b603fdc28bbe..5f3b59b37e5a 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 a313a7938a1d..63b122550b03 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 @@ 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 ConversionServiceConverter(ConversionService conversionService, ClassFor {@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 c7a057daabdf..9438b49ce72f 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 7cef7265ea03..2c0dbc6cb3c1 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 10307745227a..0326aaab2f00 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 7a9c76239da9..01f9e0626e4f 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 4547d1873451..40e58ca3ffa1 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 fad85e51337f..5f5e4845643f 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 3023eb6781fa..55c7791f12a0 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 @@ 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 @@ private boolean matchesToByteBuffer(TypeDescriptor sourceType) { } @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 @@ public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDe 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 026587a03d66..83fd24e26046 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 f20c950d61e1..3447c8a728ea 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 81b4a41adcff..23433009be35 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 e007ee279dfa..e1d7313c1bc3 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 7275d3124124..901fb2215f51 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 @@ 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 f2f400da324d..aad0e4d13bc9 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 @@ */ 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 dcf4c8bb8b14..c3787dc281a1 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 @@ 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 void setAsText(@Nullable String text) throws IllegalArgumentException { } @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 7e5acd9d1858..9f486796538e 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.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 @@ */ 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 63313d3ae6a7..7f783a32f761 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 a662918b641c..edff9b016370 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.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.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 boolean canBypassConvert(@Nullable TypeDescriptor sourceType, TypeDescrip @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 String toString() { * @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 @@ protected Object convertNullSource(@Nullable TypeDescriptor sourceType, TypeDesc * 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 @@ protected GenericConverter getConverter(TypeDescriptor sourceType, TypeDescripto * @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 @@ private void invalidateCache() { 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 @@ private Object handleConverterNotFound( 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 boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 void remove(Class sourceType, Class targetType) { * @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 GenericConverter find(TypeDescriptor sourceType, TypeDescriptor targetTyp 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 void add(GenericConverter converter) { 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 NoOpConverter(String name) { } @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 c3984fb039ad..7908ed6e579a 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 @@ public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDe 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 3247e5bf3d0a..7f6fb0351eb4 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 @@ private boolean canConvertValue(TypeDescriptor sourceType, TypeDescriptor target 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 @@ private Object convertValue(Object sourceValue, TypeDescriptor sourceType, @Null 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 e57a7b815329..21041df78470 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 28cf07c2b490..8d0e49f9ea89 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 b65f11f24f0a..6d948c69270c 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 @@ static boolean hasConversionMethodOrConstructor(Class targetClass, Class s 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 @@ else if (executable instanceof Constructor constructor) { } } - @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 @@ private static Method determineToMethod(Class targetClass, Class sourceCla 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 @@ private static boolean areRelatedTypes(Class type1, Class type2) { 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 2993326c4c7e..49b3df34c08f 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.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 438d58c6f538..d1840e357e03 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.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 @@ public boolean matchesToStream(@Nullable TypeDescriptor elementType, TypeDescrip } @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 @@ public Object convert(@Nullable Object source, TypeDescriptor sourceType, TypeDe 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 7cece80cf880..7c6508c39b12 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 694e85b87683..3f265186657d 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 @@ 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 97374fbba74f..92d987d7f758 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 @@ 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 df565b4ed1d3..4a7276e67fff 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.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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 887690be5928..78427e4ca879 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 @@ private static class StringToEnum implements Converter { @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 082d4c972a6d..508741d5e7bd 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 @@ public StringToNumber(Class targetType) { } @Override - @Nullable - public T convert(String source) { + public @Nullable T convert(String source) { if (source.isEmpty()) { return null; } diff --git a/spring-core/src/main/java/org/springframework/core/convert/support/StringToPatternConverter.java b/spring-core/src/main/java/org/springframework/core/convert/support/StringToPatternConverter.java index ca2634b2117b..512401f2436a 100644 --- a/spring-core/src/main/java/org/springframework/core/convert/support/StringToPatternConverter.java +++ b/spring-core/src/main/java/org/springframework/core/convert/support/StringToPatternConverter.java @@ -18,8 +18,9 @@ import java.util.regex.Pattern; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.converter.Converter; -import org.springframework.lang.Nullable; /** * Converts from a String to a {@link java.util.regex.Pattern}. @@ -31,8 +32,7 @@ final class StringToPatternConverter implements Converter { @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 10a1b93d1981..35c75d23ccd3 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 @@ 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 cb63290f4eea..ea189065fb36 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 @@ 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 @@ 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 c516a7e37fd3..6ca951f898bd 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 de1e84c535b3..fa3fa1907bdc 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 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 @@ protected Set doGetActiveProfiles() { * @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 @@ protected Set doGetDefaultProfiles() { * @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 boolean containsProperty(String key) { } @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return this.propertyResolver.getProperty(key); } @@ -563,8 +560,7 @@ public String getProperty(String key, String defaultValue) { } @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 151c482b7ed9..fdea0e0ce2b6 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 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 boolean containsProperty(String key) { } @Override - @Nullable - public String getProperty(String key) { + public @Nullable String getProperty(String key) { return getProperty(key, String.class); } @@ -264,8 +258,7 @@ private String doResolvePlaceholders(String text, PropertyPlaceholderHelper help * @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 @@ protected T convertValueIfNecessary(Object value, @Nullable Class targetT * @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 d221596667e0..aa3a5f15c855 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.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 @@ public boolean containsOption(String optionName) { *

{@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 a49d3e93d897..3e941d53cb9c 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 @@ 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 final boolean containsProperty(String name) { * #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 final String getProperty(String name) { *

  • 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 5fe8115842c1..c3c0ba4aae12 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.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 CompositePropertySource(String name) { @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 01f47dae1f62..f4113d144c62 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 679bca5b1438..6a90eed00907 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 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 String[] getPropertyNames() { } @Override - @Nullable - public List 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 36597a5b24a5..975c086b3de2 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 @@ import java.util.Map; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -45,8 +46,7 @@ public MapPropertySource(String name, Map source) { @Override - @Nullable - public Object getProperty(String name) { + public @Nullable Object getProperty(String name) { return this.source.get(name); } diff --git a/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java b/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java index bedb7918c15f..4a213dec1b56 100644 --- a/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java +++ b/spring-core/src/main/java/org/springframework/core/env/MutablePropertySources.java @@ -22,7 +22,7 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.stream.Stream; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * The default implementation of the {@link PropertySources} interface. @@ -87,8 +87,7 @@ public boolean contains(String name) { } @Override - @Nullable - public PropertySource 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 int precedenceOf(PropertySource propertySource) { * 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 dcc9474e5dd3..b4398dc6c1be 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.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 173a1a33784d..e346e53041fd 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 3135f0722001..98e91745763b 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 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 boolean containsProperty(String name) { * @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 StubPropertySource(String name) { * Always returns {@code null}. */ @Override - @Nullable - public String getProperty(String name) { + public @Nullable String getProperty(String name) { return null; } } @@ -251,8 +249,7 @@ public boolean containsProperty(String name) { } @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 0296ea1a271c..d6e6ab80fac3 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 @@ 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 @@ default Stream> stream() { * 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 3558d0fa7759..9b35cc2d686c 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 @@ */ public class PropertySourcesPropertyResolver extends AbstractPropertyResolver { - @Nullable - private final PropertySources propertySources; + private final @Nullable PropertySources propertySources; /** @@ -57,25 +56,21 @@ public boolean containsProperty(String key) { } @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 767d9b6211f6..64dd05cd4f94 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 @@ import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -126,8 +127,7 @@ protected boolean containsOption(String name) { } @Override - @Nullable - protected List 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 ebea27125309..33e088597d72 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 @@ 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 boolean containsProperty(String name) { * 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 @@ protected final String resolvePropertyName(String name) { 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 a0784c4c8d76..d2253a9b0496 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 4e70092fb793..87b98ed8ce90 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 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 Resource createRelative(String relativePath) throws IOException { * 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 b0f84a946030..03af0cbc92a4 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.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 1454b92f8057..72e8c532ddf0 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.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 final String getPath() { /** * 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 boolean isReadable() { * 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 Resource createRelative(String relativePath) { * @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 c7a7403a748e..eac1fd464690 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.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 @@ */ 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 void setClassLoader(@Nullable ClassLoader classLoader) { * @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 49d9d854a965..1c600f5bb013 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.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 fcae1575c6b9..acd8c98abdb9 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.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 b910bbc9165b..7bb38ad93d68 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.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 @@ */ 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 906eb233a6c6..1666d1e9399a 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 @@ 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 225a6042a397..0413f83667f8 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.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 Resource createRelative(String relativePath) { } @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 729f08023015..fb6ba958a146 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.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 53cc9301eb60..cf0def7ca8c9 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 91458934fed3..44975e1fdccd 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.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 @@ default String getContentAsString(Charset charset) throws IOException { * 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 0eec6fd6a3d8..1cb67aa89880 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 @@ 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 @@ protected String resolvePath(String path) { @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 2c58f931d187..cc44f95cfc8d 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 4c5c3e0226d3..a85ddbf8a595 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.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 @@ protected URL createRelativeURL(String relativePath) throws MalformedURLExceptio * @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 00203ed3b923..16f2a7757ead 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.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 781712a224aa..6ecdbf2c3b97 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.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 @@ protected static Object getRoot(URL url) throws IOException { 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 e8de69083d99..87aef781cce4 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 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.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 d9d43da4eeaf..fa05dd6ae1df 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.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 5d211bfc314a..3ce726369bbe 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.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 70a544cd4f0f..418938eaa582 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 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 @@ private static final class BufferComponentIterator 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 ddcc6c6f9b39..9c7d22e15b7d 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 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 dc6cad91014d..4dadbd61633e 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.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 @@ private static final class OutputStreamSubscription extends OutputStream impl 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 4fc6d0eae76d..505260af86d1 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.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 ResourceLoader getResourceLoader() { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return getResourceLoader().getClassLoader(); } @@ -1075,8 +1072,7 @@ protected Set findAllModulePathResources(String locationPattern) throw 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 PatternVirtualFileVisitor(String rootPath, String subPattern, PathMatcher } @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 void visit(Object vfsResource) { } } - @Nullable - public Object getAttributes() { + public @Nullable Object getAttributes() { return VfsPatternUtils.getVisitorAttributes(); } @@ -1224,8 +1218,7 @@ private static String fixPath(String path) { * @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 85d53d40475a..3a6955bd03da 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 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 af5d58e8ec9e..241f1ee552ad 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.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 6c3059b52787..7b55af24dce8 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 @@ 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 3de69fca7c39..3ee58ad9eee2 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 @@ 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 02f0370b2256..33174276ec3a 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 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.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 0a16606c9cc1..cb30e846c17f 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 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 c6c778430b61..a3e4e3b01366 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 ad9e57aa4b2b..342588ec7b49 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.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 @@ 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 2bfefa1c404c..c2dc31a2c365 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.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 @@ private List loadFactoryNames(Class factoryType) { 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 @@ static FactoryInstantiator forClass(Class factoryImplementationClass) 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 @@ private static Constructor findConstructor(Class factoryImplementationClas 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 @@ private static boolean isKotlinType(Class factoryImplementationClass) { 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 @@ private static Constructor findDeclaredConstructor(Class factoryImplementa */ 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 interface ArgumentResolver { * @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 5fcaf8af34dc..767ed0796716 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.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 @@ */ 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 2b1395fbb2eb..36169e1f5149 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 52cf86663edc..6ddce2c76d92 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.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 e1206d5c3530..12669dc7eff5 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 @@ import java.util.function.Supplier; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -42,8 +43,7 @@ */ public abstract class LogMessage implements CharSequence { - @Nullable - private String result; + private @Nullable String result; @Override @@ -176,8 +176,7 @@ private abstract static class FormatMessage extends LogMessage { 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 @@ protected String buildString() { 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 @@ String buildString() { 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 @@ String buildString() { 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 @@ String buildString() { 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 b14fac177c63..eb628ffa883c 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 9a497d3eb9ee..b32263a01b50 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.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 @@ public long getId() { } @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 e9061cb4235d..2f35beefdc58 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 @@ 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 54b7c8db1137..b005cb230b78 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 8774a4bd1113..c4deb39d6a95 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 703f29b4b238..b347e187ed14 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 3096daf9611f..9a642fe4c82e 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.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 @@ */ 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 88f4d3ba4a36..f3d5b1780242 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 782ddc901bd5..c8accc6e3893 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 @@ 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 4e46ea8a5921..499d6224ab8d 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 9eb0d37205fe..5ad1e93a59e3 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 3dd8891646b8..50548a6d1771 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.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 fbb5cc96bd18..d857f8598279 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 3e20e72d94a1..06d3793e9de0 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 974a72d551dd..a2e21f5a9576 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 c3fe9bfa482d..7bd028d63c91 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 413a80367d1f..1d7e821a702e 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.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 void setThreadFactory(@Nullable ThreadFactory threadFactory) { /** * 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 099867d9c64f..367345a7175a 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 a9878aab2e23..fd9788e35c6a 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.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 e9dfcd9dc443..9eb9c5293770 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 f5608ffc346c..5fab2a3b1957 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.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.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 @@ default boolean isAnnotated(String annotationName) { * 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 @@ default Map getAnnotationAttributes(String annotationName) { * 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 @@ default Map getAnnotationAttributes(String annotationName, * 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 @@ default MultiValueMap getAllAnnotationAttributes(String annotati * 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 cbb5ab4168fe..96ab62f0220d 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 @@ default boolean hasEnclosingClass() { * 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 @@ default boolean hasSuperClass() { * 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 bc34ed937a51..33356252e5bf 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.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 Set getAnnotationTypes() { } @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 Map getAnnotationAttributes(String annotationName, boolea } @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 702b5c1b7744..6e57d49c45ae 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 @@ 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 boolean isIndependent() { } @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 40943a223f31..7d300dd3b76b 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.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 @@ private boolean isPrivate() { } @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 Map getAnnotationAttributes(String annotationName, boolea } @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 9d9956fcf26a..6c8241a5d6d7 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.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 1a2bfe899dfd..e37379a19055 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.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 @@ */ 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 @@ public void visitEnum(String name, String descriptor, String value) { } @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 @@ public > void visitEnum(String descriptor, String value, Consu } @SuppressWarnings("unchecked") - @Nullable - private AnnotationVisitor visitAnnotation( + private @Nullable AnnotationVisitor visitAnnotation( String descriptor, Consumer> consumer) { String className = Type.getType(descriptor).getClassName(); @@ -121,8 +118,7 @@ private AnnotationVisitor visitAnnotation( } @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 @@ public void visitEnum(String name, String descriptor, String value) { } @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 ba4c84f1c27f..ceb3bb698cd8 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.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 @@ public boolean isIndependent() { } @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 a4e1128e6244..d3b72faed06e 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 @@ 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.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 @@ */ 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 @@ else if (this.className.equals(outerClassName)) { } @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 08150a51a476..fece634b13a1 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 @@ 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 46aa8f4771d8..58a834a309bd 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 @@ 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 4b4a0ac5e5fe..c7016ff8540d 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 895887263e53..0e1c686230b4 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.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 @@ */ 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 @@ static final class Source { 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 37a94af610b3..2adda8552098 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 ee7d6d5046e2..119ba4fb015b 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 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 @@ protected boolean matchClassName(String className) { /** * 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 5584edcb688a..114adc96d021 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 @@ 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 @@ protected boolean matchSelf(MetadataReader metadataReader) { } @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 86fbde43636e..c78cb7eb8b15 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.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 53566f60a739..7293eb297396 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 @@ protected boolean matchClassName(String className) { } @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 dacedaf28a13..6589c371cb62 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 f63ddb1be36b..6b0d6a987bbb 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 f06fca0539ba..e159afd4883e 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 9afaf2532381..267e1f9eb1e0 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.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 @@ protected static class AntPathStringMatcher { private final boolean exactMatch; - @Nullable - private final Pattern pattern; + private final @Nullable Pattern pattern; private final List variableNames = new ArrayList<>(); @@ -856,8 +854,8 @@ else if (info2.getUriVars() < info1.getUriVars()) { */ private static class PatternInfo { - @Nullable - private final String pattern; + + private final @Nullable String pattern; private int uriVars; @@ -869,8 +867,7 @@ private static class PatternInfo { 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 71db4555051b..31dea190276f 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.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 static void doesNotContain(@Nullable String textToSearch, String substrin * @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 static void notEmpty(@Nullable Object[] array, String message) { * @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 static void notEmpty(@Nullable Object[] array, Supplier messageSu * @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 static void noNullElements(@Nullable Object[] array, String message) { * @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 @@ private static String messageWithTypeName(String msg, @Nullable Object typeName) 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 4a01bd502128..45dcae322533 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.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 91df05d57387..5a66d209d5f0 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.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 @@ private static void registerCommonClasses(Class... commonClasses) { * @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 static ClassLoader getDefaultClassLoader() { * @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 @@ private static boolean isLoadable(Class clazz, ClassLoader classLoader) { * @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 static Class createCompositeInterface(Class[] interfaces, @Nullable * 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 static Class getUserClass(Class clazz) { * @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 static boolean hasConstructor(Class clazz, Class... paramTypes) { * @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 @@ else if (candidates.isEmpty()) { * @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 @@ private static Method getInterfaceMethodIfPossible(Method method, @Nullable Clas 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 static Method getPubliclyAccessibleMethodIfPossible(Method method, @Nulla 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 @@ private static boolean isOverridable(Method method, @Nullable Class targetCla * @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 static Method getStaticMethod(Class clazz, String methodName, Class } - @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 65ff2debd911..aaa9d7a7886f 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.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 static boolean containsAny(Collection source, Collection candidates * @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 static E findFirstMatch(Collection source, Collection candidate * 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 static T findValueOfType(Collection collection, @Nullable Class * @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 @@ else if (candidate != elem) { * @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 @@ else if (candidate != val.getClass()) { * @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 static T firstElement(@Nullable Set set) { * @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 static T firstElement(@Nullable List list) { * @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 static T lastElement(@Nullable Set set) { * @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 6678806df479..8902a3ea085b 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.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 @@ public boolean containsValue(Object value) { } @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 @@ public V get(Object key) { } @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 @@ public V put(K key, V value) { } @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 4bc86031403a..fb30d3b32ee5 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 @@ 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 926bb671ce89..d783b8b171f3 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.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 boolean contains(K key) { * @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 void drainAll() { 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 void setPrevious(@Nullable Node prev) { this.prev = prev; } - @Nullable - public Node getNext() { + public @Nullable Node getNext() { return this.next; } @@ -523,15 +518,12 @@ V getValue() { 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 090622e01953..9213241de101 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.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 @@ protected int getHash(@Nullable Object o) { } @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 boolean containsKey(@Nullable Object key) { * @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 @@ protected V execute(@Nullable Reference ref, @Nullable Entry entry, } @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 @@ protected V execute(@Nullable Reference ref, @Nullable Entry entry) } @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 @@ protected Boolean execute(@Nullable Reference ref, @Nullable Entry e } @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 @@ protected Boolean execute(@Nullable Reference ref, @Nullable Entry e } @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 Set> entrySet() { 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 Segment(int initialSize, int resizeThreshold) { 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 Reference getReference(@Nullable Object key, int hash, Restructure * @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 @@ private void restructure(boolean allowResize, @Nullable Reference ref) { } } - @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 @@ protected interface Reference { /** * 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 @@ protected interface Reference { /** * 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 @@ protected interface Reference { */ 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 Entry(@Nullable K key, @Nullable V value) { } @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 boolean hasOption(TaskOption option) { * @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 @@ protected T execute(@Nullable Reference ref, @Nullable Entry entry, * @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 @@ private class EntryIterator implements Iterator> { 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 Reference createReference(Entry entry, int hash, @Nullable Re * @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 @@ private static final class SoftEntryReference extends SoftReference nextReference; + private final @Nullable Reference nextReference; public SoftEntryReference(Entry entry, int hash, @Nullable Reference next, ReferenceQueue> queue) { @@ -1051,8 +1020,7 @@ public int getHash() { } @Override - @Nullable - public Reference getNext() { + public @Nullable Reference getNext() { return this.nextReference; } @@ -1070,8 +1038,7 @@ private static final class WeakEntryReference extends WeakReference nextReference; + private final @Nullable Reference nextReference; public WeakEntryReference(Entry entry, int hash, @Nullable Reference next, ReferenceQueue> queue) { @@ -1087,8 +1054,7 @@ public int getHash() { } @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 dd4fc28e7f5d..fbb775c6f6bb 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 @@ 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 void setThreadGroup(@Nullable ThreadGroup threadGroup) { * 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 e91eda569920..02599754ad89 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.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 @@ private static final class FastByteArrayInputStream extends UpdateMessageDigestI 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 f68a89524659..388ab5e34108 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.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 d060c1c1187e..c857588d18f9 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.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 ab2c59a592a6..320572152213 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.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 e4bb17d86225..d577fd4e2148 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.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 @@ public boolean containsKey(Object key) { @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 @@ public V get(Object key) { } @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 @@ public V put(K key, V value) { @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 21d6ac6e17e0..acf03d0c3b89 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 @@ 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 08e2000f1a3d..7e2005a28669 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 @@ 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 3a1f9f102946..6fbc5fa1bebe 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.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 boolean containsValue(Object value) { } @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 V get(Object key) { } @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 V getOrDefault(Object key, V defaultValue) { } @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 void putAll(Map map) { } @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 V putIfAbsent(String key, @Nullable V value) { } @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 V computeIfAbsent(String key, Function mappi } @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 @@ protected boolean removeEldestEntry(Map.Entry eldest) { return false; } - @Nullable - private String removeCaseInsensitiveKey(String key) { + private @Nullable String removeCaseInsensitiveKey(String key) { return this.caseInsensitiveKeys.remove(convertKey(key)); } @@ -494,8 +484,7 @@ private abstract class EntryIterator implements Iterator { 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 73171aec1de7..f17b0aca39ec 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.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 void setTargetClass(@Nullable Class targetClass) { /** * 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 void setTargetObject(@Nullable Object targetObject) { /** * 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 void setTargetMethod(@Nullable String targetMethod) { /** * 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 void setStaticMethod(String staticMethod) { * 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 @@ protected Class resolveClassName(String className) throws ClassNotFoundExcept * @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 boolean isPrepared() { * @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 Object invoke() throws InvocationTargetException, IllegalAccessException * @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 5a328468429b..4ced66b01036 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.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 String getSubtype() { * 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 String getSubtypeSuffix() { * @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 Charset getCharset() { * @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 f3a9f2b688c8..06dbca09b3cb 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.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 959a69b843ed..e7e80a8643d1 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.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 @@ public boolean containsValue(@Nullable Object value) { } @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 @@ public void forEach(BiConsumer action) { 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 @@ private V adaptValue(@Nullable List values) { } } - @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 262601a5a4ae..195db529d055 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 @@ 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 4c7c2f1d133c..97207b8f007b 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.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 MultiValueMapAdapter(Map> targetMap) { // 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 boolean containsValue(Object value) { } @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 27bb5db53b90..8ac49b939675 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.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 07e338a7da4d..ad22311e99c0 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.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 static boolean isCheckedException(Throwable ex) { * @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 static boolean isArray(@Nullable Object obj) { * @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 static boolean isEmpty(@Nullable Object obj) { * 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 static Object unwrapOptional(@Nullable Object obj) { * @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 static > E caseInsensitiveValueOf(E[] enumValues, Strin * @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 static A[] addObjectToArray(@Nullable A[] array, @Nullab * @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 @@ private static boolean arrayEquals(Object o1, Object o2) { * @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 static int nullSafeHashCode(@Nullable Object obj) { * @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 static int nullSafeHashCode(@Nullable Object[] array) { * @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 static int nullSafeHashCode(@Nullable boolean[] array) { * @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 static int nullSafeHashCode(@Nullable byte[] array) { * @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 static int nullSafeHashCode(@Nullable char[] array) { * @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 static int nullSafeHashCode(@Nullable double[] array) { * @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 static int nullSafeHashCode(@Nullable float[] array) { * @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 static int nullSafeHashCode(@Nullable int[] array) { * @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 static int nullSafeHashCode(@Nullable long[] array) { * @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 static String nullSafeToString(@Nullable Object obj) { * @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 static String nullSafeToString(@Nullable Object[] array) { * @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 static String nullSafeToString(@Nullable boolean[] array) { * @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 static String nullSafeToString(@Nullable byte[] array) { * @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 static String nullSafeToString(@Nullable char[] array) { * @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 static String nullSafeToString(@Nullable double[] array) { * @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 static String nullSafeToString(@Nullable float[] array) { * @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 static String nullSafeToString(@Nullable int[] array) { * @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 static String nullSafeToString(@Nullable long[] array) { * @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 9f050351f0b6..dc4afcb6d3f4 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 static boolean simpleMatch(@Nullable String pattern, @Nullable String str * @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 22aa50e602ef..751b29f741e4 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 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 @@ private NestedPlaceholderPart createNestedPlaceholderPart(String text, List visitedPlaceholders; + private @Nullable Set visitedPlaceholders; PartResolutionContext(PlaceholderResolver resolver, String prefix, String suffix, @@ -323,8 +319,7 @@ static class PartResolutionContext implements PlaceholderResolver { } @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 @@ public String text() { * @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 @@ static class SimplePlaceholderPart extends AbstractPart { private final String key; - @Nullable - private final String fallback; + private final @Nullable String fallback; /** * Create a new instance. @@ -539,8 +532,7 @@ static class NestedPlaceholderPart extends AbstractPart { 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 805467730188..1a28a371aec8 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.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 8e1d6094c642..ae73ab29737b 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 @@ 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 interface PlaceholderResolver { * @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 4d1af9d2175d..ec29a41f6bb1 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.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 static void makeAccessible(Constructor ctor) { * @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 static Method findMethod(Class clazz, String name) { * (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 @@ private static boolean hasSameParams(Method method, Class[] paramTypes) { * @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 static Object invokeMethod(Method method, @Nullable Object target) { * @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 @@ private static Method[] getDeclaredMethods(Class clazz, boolean defensive) { 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 static void makeAccessible(Method method) { * @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 static Field findField(Class clazz, String name) { * @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 static Field findField(Class clazz, @Nullable String name, @Nullable C * @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 static void setField(Field field, @Nullable Object target, @Nullable Obje * (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 9a2f12f1cdbf..7cf9c53cc753 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.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 166f9e677d03..3011300cb7a5 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 @@ 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 1eb905a785f0..a8f34a790860 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.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 static byte[] serialize(@Nullable Object object) { * 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 ead414e1f3ef..dbb3710e4913 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 @@ 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 boolean match(String pattern, Route route) { } @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 f02bb4ee9429..013e9d0a0ba9 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.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 @@ public SingleToMultiValueMapAdapter(Map targetMap) { // MultiValueMap implementation @Override - @Nullable - public V getFirst(K key) { + public @Nullable V getFirst(K key) { return this.targetMap.get(key); } @@ -154,15 +151,13 @@ public boolean containsValue(@Nullable Object value) { } @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 @@ else if (values.size() == 1) { } @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 49b888dd938f..1211f0388cdb 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.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 boolean isRunning() { * @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 99b44e03f29e..c169d3cc7759 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.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 86fc164c8cf9..246960e15035 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.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 static String deleteAny(String inString, @Nullable String charsToDelete) * @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 static String quote(@Nullable String str) { * @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 @@ private static String changeFirstCharacterCase(String str, boolean capitalize) { * @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 static String getFilename(@Nullable String path) { * @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 static String uriDecode(String source, Charset charset) { * @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 static Locale parseLocale(String localeValue) { * @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 static String[] toStringArray(@Nullable Enumeration enumeration) * @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 static String[] addStringToArray(@Nullable String[] array, String str) { * @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 static String[] removeDuplicateStrings(String[] array) { * 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 static String[] split(@Nullable String toSplit, @Nullable String delimite * @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 static Properties splitArrayElementsIntoProperties(String[] array, String * @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 static String collectionToCommaDelimitedString(@Nullable Collection co * @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 static String arrayToDelimitedString(@Nullable Object[] arr, String delim * @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 1335de95867f..822840af4669 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 eb962efc5bb3..802a4567642f 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 SystemPropertyPlaceholderResolver(String text) { } @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 b118aa2eeef0..e45d1e011dff 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.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 9a14150156ca..b7b8ff7778ba 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.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 @@ public boolean containsValue(Object value) { } @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 @@ public Collection> values() { // 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 @@ public void forEachRemaining(Consumer>> action) { } @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 @@ public void forEachRemaining(Consumer> action) { } @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 071542a7a1b4..c4e680b5a1e5 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 6f65f92d5b72..f3626f84b282 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 @@ 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 66d4b4f37df7..e56384cedc4f 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 @@ 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 77dce7608270..3c89ec971358 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 @@ 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 3d4ebd53b7f7..7fae7e8e4c23 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 43afe42b3006..8864d4477cf3 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.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 boolean isDone() { } @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 @@ final T adaptInternal(S adapteeResult) throws ExecutionException { * 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 fc4777eff0f0..556f3300be26 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 9cd7f7b33f52..270bc494b46e 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.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 @@ */ 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 @@ private SingletonSupplier(T singletonInstance) { * @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 static SingletonSupplier of(T instance) { * @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 static SingletonSupplier of(Supplier 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 af97e2fd99e0..1513ec2ca353 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 @@ 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 static T resolve(@Nullable Supplier supplier) { * @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 7c16649bd9a5..8ecebcf9a38b 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 1c57d89eed18..55dca7cc132c 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 33f76e9586ee..25c234c5d427 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.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 bad1762bf616..91c7390e4faf 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 4a4c443e2134..e440f5e6a834 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.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 7d3e03b8d586..ef128895e112 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.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.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 3cf3108db6dd..08f597e30621 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.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 @@ */ 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 @@ public void setContentHandler(@Nullable ContentHandler contentHandler) { } @Override - @Nullable - public ContentHandler getContentHandler() { + public @Nullable ContentHandler getContentHandler() { return this.contentHandler; } @@ -74,8 +67,7 @@ public void setDTDHandler(@Nullable DTDHandler dtdHandler) { } @Override - @Nullable - public DTDHandler getDTDHandler() { + public @Nullable DTDHandler getDTDHandler() { return this.dtdHandler; } @@ -85,8 +77,7 @@ public void setEntityResolver(@Nullable EntityResolver entityResolver) { } @Override - @Nullable - public EntityResolver getEntityResolver() { + public @Nullable EntityResolver getEntityResolver() { return this.entityResolver; } @@ -96,13 +87,11 @@ public void setErrorHandler(@Nullable ErrorHandler errorHandler) { } @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 @@ public void setFeature(String name, boolean value) throws SAXNotRecognizedExcept * 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 e50a5dd0dd48..3709dc8b920b 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.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 @@ public void require(int expectedType, String namespaceURI, String localName) thr } @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 6481dbba3091..9dc17011cca9 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.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.NodeList; import org.xml.sax.ContentHandler; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -92,8 +92,7 @@ public static List getChildElementsByTagName(Element ele, String childE * @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 static Element getChildElementByTagName(Element ele, String childEleName) * @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 488b70b47d91..b5708256ab9d 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.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 @@ public XMLEvent nextEvent() { } @Override - @Nullable - public XMLEvent peek() { + public @Nullable XMLEvent peek() { if (hasNext()) { return this.events.get(this.cursor); } @@ -105,8 +104,7 @@ else if (!event.isCharacters()) { } @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 4b8abba3903c..76e09ef3957b 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 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 @@ else if (this.prefixToNamespaceUri.containsKey(prefix)) { } @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 e57141af1e2e..67281a9dc7ef 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.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 f5179707ca16..b40477896c77 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.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 @@ public int getLineNumber() { 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 @@ public String getXMLVersion() { 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 80a86a04a312..767af71cf1a4 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.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 @@ */ class StaxResult extends SAXResult { - @Nullable - private XMLEventWriter eventWriter; + private @Nullable XMLEventWriter eventWriter; - @Nullable - private XMLStreamWriter streamWriter; + private @Nullable XMLStreamWriter streamWriter; /** @@ -85,8 +82,7 @@ public StaxResult(XMLStreamWriter streamWriter) { * @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 @@ public XMLEventWriter getXMLEventWriter() { * @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 392cd123c9fe..dcd0e82422a8 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.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 @@ */ 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 @@ XMLEventReader getXMLEventReader() { * @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 ebc5386ff17b..55889f233021 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.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 @@ public int getLineNumber() { 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 @@ public String getXMLVersion() { 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 3555606de4bc..de4d578c2b30 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.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 static boolean isStaxSource(Source source) { * @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 @@ else if (source instanceof StaxSource staxSource) { * @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 static boolean isStaxResult(Result result) { * @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 @@ else if (result instanceof StaxResult staxResult) { * @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 67d37d5e5f7b..5fec714d6fa9 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.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 @@ public int getEventType() { } @Override - @Nullable - public String getVersion() { + public @Nullable String getVersion() { if (this.event.isStartDocument()) { return ((StartDocument) this.event).getVersion(); } @@ -115,14 +114,12 @@ public boolean standaloneSet() { } @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 1248ab0b3948..06c242062f5d 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.InputStream; import java.io.InputStreamReader; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.StringUtils; /** @@ -170,8 +171,7 @@ private String consumeCommentTokens(String line) { * 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 b077891dd66f..bc39307e9201 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 bc62da2b9ba4..083e0583dd9e 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 @@ 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.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 5c45bca59941..952f5fc7d79d 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 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.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 @@ private GeneratedFileAssert assertThatFileAdded(Kind kind, String path) 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 @@ GeneratedFileAssert assertThatFileAdded(Kind kind, String path) 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 @@ public GeneratedFileAssert hasOverride(boolean expected) { 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 dc755467ec1c..ad0733c6bae3 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 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.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 7756980bdb11..1b7c0ecd1af6 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.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 @@ private Consumer typeWithMemberCategories(Class type, MemberCategor @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 e01f0275cea4..22433969befa 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 @@ void nestedWithTypeIndexReturnsNewInstance() throws Exception { 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 bf6a82bb5751..353ba3d313ef 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.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.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 @@ static class ResourceHolder { 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 de5319b4f942..56695ac3fba3 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 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 @@ void plainWhenJavaLangAnnotationReturnsTrue() { @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 16c5425116ea..1e99bc44f9c3 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 @@ private Method[] resolveMirrorSets(AnnotationTypeMapping mapping, Class eleme 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 4185df3c4a13..b127137cfc93 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.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 @@ void isAnnotationInheritedForAllScenarios() { @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 6400a880c33c..1c5e508eb3e7 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.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 @@ void scanWhenProcessorReturnsFromDoWithAggregateExitsEarly() { 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 @@ void scanWhenProcessorHasFinishMethodUsesFinishResult() { 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 @@ public void method() { 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 093b570a53c4..d0d2477e1fe8 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.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.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 @@ interface AnnotatedInterface { 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 0d325a2eef39..1e45d29949c7 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 @@ 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.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 81d61747949a..f1b35cc7c089 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.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.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 3faacdbfeb7d..c39a5a0d90d8 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.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.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 @@ public Set getConvertibleTypes() { } @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 @@ public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) { } @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 c408bce244a6..cbd026ebbe71 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.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 @@ protected Set getReservedDefaultProfiles() { 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 @@ public CustomPropertySourcesPropertyResolver(PropertySources propertySources) { 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 67647495ccce..00bcae566825 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 @@ 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.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 1a96590db745..bfbdeadaa1e2 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.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 95a148ae9817..f39b95131c0b 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.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 7f51d8af088a..ce00140acbce 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.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.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 961457942908..4e6aec96de56 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.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.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 fdc5c191c7f0..0127e40fd20b 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 @@ 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.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 307cac0b7817..0fc5aef20fbd 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 @@ 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 3c9c232c3ee1..886644f28189 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 @@ 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 0fb89de103e9..64e86bb81c50 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.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 @@ default List getMethodResolvers() { /** * 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 @@ default TypedValue assignVariable(String name, Supplier valueSupplie * @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 ec66a5268294..1ee1d34b00db 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 a34daa068e38..4da51d7cb2ea 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 @@ T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType * @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 @@ T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType * @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 @@ T getValue(@Nullable Object rootObject, @Nullable Class desiredResultType * @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 @@ T getValue(EvaluationContext context, @Nullable Class desiredResultType) * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 @@ T getValue(EvaluationContext context, @Nullable Object rootObject, @Nullable * @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 925a18e05bd4..a79b9fad5614 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 @@ @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 ExpressionException(int position, String message, @Nullable Throwable cau /** * 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 1cb24e5d1672..87000d450abe 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 1471ad48df35..adf4c3db5f7e 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 9fb9137c8e4e..314159311af7 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 @@ 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 8bece1f0fefc..3c6d36d68144 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 3c85016d1657..ed23f06bf815 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 84e4fe5ac1dd..5dd20f33b0f0 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 6403f9ca07ba..556036cf17c9 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 88d07d39fb8e..d940e0f5c8e8 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 6974d6b8747c..7e83e8eff59a 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 b97020a259ec..204c68a34008 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 TypedValue(@Nullable Object value, @Nullable TypeDescriptor typeDescripto } - @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 8bb6dcf195ce..0b1349720aa4 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 String getValue() throws EvaluationException { } @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 String getValue(@Nullable Object rootObject) throws EvaluationException { } @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 String getValue(EvaluationContext context) throws EvaluationException { } @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 String getValue(EvaluationContext context, @Nullable Object rootObject) t } @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 3ea264baf769..9489f9f3bc9a 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 ca9275ad214c..3876b0488bd7 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 String getValue() { } @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 String getValue(@Nullable Object rootObject) { } @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 String getValue(EvaluationContext context) { } @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 String getValue(EvaluationContext context, @Nullable Object rootObject) t } @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 bdf4ad1660d5..967950551bf3 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.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 080af63ff99b..f91c56608f67 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 48a91d155356..bd9caff6139c 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 85e9bb61db11..19ad503887a2 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.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 void exitCompilationScope() { /** * 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 acab38946db5..27eb79d2a3e8 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 eaf5e4d9ecac..b8bde3014988 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.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.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 Object convertValue(Object value, TypeDescriptor targetTypeDescriptor) th 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 d6e173c5f140..434192b36558 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 InternalParseException(@Nullable SpelParseException cause) { } @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 9817ba413490..cc9e53377162 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 SpelMessage getMessageCode() { /** * 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 03c7fd131243..3808a89f9afc 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 @@ 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 3e2036d031ee..bf4bc8c65b1b 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 4b5e4c5010db..7ec863a489a7 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 27b6ccff35fb..701c72cbdd93 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 @@ 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 SpelCompilerMode getCompilerMode() { /** * 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 fcb03ced3b84..78ef30847d54 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.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 e4253f7eee8f..8196a2234bc3 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.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.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 c05cfad67435..a3d5a2dad3c1 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 @@ 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 20ee8e20b597..5734b40fb868 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.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.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 @@ private TypedValue executeFunctionViaMethod(ExpressionState state, Method method * @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 b6b09c1fb764..5134fe8368aa 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.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.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 @@ private AccessMode(boolean supportsReads, boolean supportsWrites) { 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 @@ private class MapIndexingValueRef implements ValueRef { private final Map map; - @Nullable - private final Object key; + private final @Nullable Object key; private final TypeDescriptor mapEntryDescriptor; @@ -905,8 +898,7 @@ public boolean isWritable() { 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 4498d9f6a5de..5a2cc0c6f856 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.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.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 @@ */ 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 InlineList(int startPos, int endPos, SpelNodeImpl... args) { *

    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 boolean isConstant() { } @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 b9450134f24a..abffdd0996ed 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.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 @@ */ 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 InlineMap(int startPos, int endPos, SpelNodeImpl... args) { *

    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 boolean isConstant() { } @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 dbd9e0f2836b..abe35c6cc92c 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 @@ */ 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 Literal(@Nullable String originalValue, int startPos, int endPos) { } - @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 e8d15e5b0532..5f02f790717e 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.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.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 @@ private List getArgumentTypes(Object... arguments) { 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 @@ private class MethodValueRef implements ValueRef { 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 @@ private static class CachedMethodExecutor { 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 99c5694095f1..e91050a3d0a2 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.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 4caf753c85a5..4383b68b49b0 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.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 910031017738..485aacb33aa7 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 @@ 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.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 a425fd4f4f0f..91c23cb595e6 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 @@ 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 36dfc4c4366b..d106ce507ce5 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.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 @@ */ 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 56d0b2f34d2d..aaab0800c861 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.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 c40dc8a61dcf..a49319845674 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.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.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 d66a4c39ce83..1acd99787c78 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 @@ */ 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 b5ed9d0e2cc9..6543cf5527d3 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.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.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 @@ protected boolean nextChildIs(Class... classes) { } @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 int getChildCount() { } @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 boolean isNullSafe() { 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 @@ protected static void generateCodeForArguments( } } - @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 360e7598fa4e..21cd5c469445 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 @@ 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 dd199ccb54e7..c38c0c9b0eac 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 31cf1f699d0d..7bb013b9c855 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 @@ 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.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 d6c0b5ec6d98..cba46a2d7d36 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 81dc5f52c6da..27ee1302254a 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 c6bbfbfc29c3..05111daa74d0 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.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.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 @@ private void checkExpressionLength(String string) { // | (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 @@ private SpelNodeImpl eatExpression() { } //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 @@ private SpelNodeImpl eatLogicalOrExpression() { } // 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 @@ private SpelNodeImpl eatLogicalAndExpression() { } // 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 @@ private SpelNodeImpl eatRelationalExpression() { } //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 @@ else if (t.kind == TokenKind.MINUS) { } // 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 @@ else if (t.kind == TokenKind.MOD) { } // 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 @@ private SpelNodeImpl eatPowerIncDecExpression() { } // 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 @@ private SpelNodeImpl eatUnaryExpression() { } // 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 @@ private SpelNodeImpl eatPrimaryExpression() { } // 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 @@ private boolean maybeEatFunctionOrVar() { } // 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 @@ private int positionOf(@Nullable Token t) { // | lastSelection // | indexer // | constructor - @Nullable - private SpelNodeImpl eatStartNode() { + private @Nullable SpelNodeImpl eatStartNode() { if (maybeEatLiteral()) { return pop(); } @@ -917,8 +905,7 @@ private boolean maybeEatParenExpression() { // 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 @@ private Token takeToken() { 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 e8802052bd81..39e563e0a3d0 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 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.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 @@ private SpelCompiler(@Nullable ClassLoader classloader) { * @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 @@ private String getNextSuffix() { * @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 f4ea32211f17..a101d38453f9 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 @@ 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.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 String getExpressionString() { } @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 Object getValue() throws EvaluationException { @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 T getValue(@Nullable Class expectedResultType) throws EvaluationEx } @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 Object getValue(@Nullable Object rootObject) throws EvaluationException { @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 T getValue(@Nullable Object rootObject, @Nullable Class expectedRe } @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 Object getValue(EvaluationContext context) throws EvaluationException { @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 T getValue(EvaluationContext context, @Nullable Class expectedResu } @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 Object getValue(EvaluationContext context, @Nullable Object rootObject) t @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 T getValue(EvaluationContext context, @Nullable Object rootObject, @N } @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 getValueType(EvaluationContext context) throws EvaluationExcepti } @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 ee64ba4da2e0..e122017ed2e5 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 61ccc8267fc0..f56a57193c3f 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 e26fe15427b9..b9ac97ce14e3 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 120bb0806173..9684ce90850d 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.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 @@ private DataBindingMethodResolver() { } @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 c45464e5451b..d038043d74b0 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.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 @@ else if (ClassUtils.isAssignable(paramTypeClazz, superClass)) { * @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 e77eaa3ac586..b2122be88863 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 @@ 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 ea2c5b054ad9..d5039e6a604c 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.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.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 601f2792c290..011557ae46ff 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 @@ 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.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 b66312328f93..e4addc87622d 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 @@ 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 final Method getMethod() { * @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 5ee90278734b..df3dbd3e85e4 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.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.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 void registerMethodFilter(Class type, @Nullable MethodFilter filter) { * */ @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 9139d08cb4fa..fec2427874d7 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.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.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 ReflectivePropertyAccessor(boolean allowWrite) { * 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 void write(EvaluationContext context, @Nullable Object target, String nam } - @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 @@ private TypeDescriptor getTypeDescriptor(EvaluationContext context, Object targe 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 @@ private Method findGetterForProperty(String propertyName, Class clazz, Object 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 @@ private Method findSetterForProperty(String propertyName, Class clazz, Object /** * 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 @@ protected Method findGetterForProperty(String propertyName, Class clazz, bool /** * 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 @@ protected String getPropertyMethodSuffix(String propertyName) { 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 @@ private Field findField(String name, Class clazz, Object target) { /** * 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 @@ private static class OptimalPropertyAccessor implements CompilablePropertyAccess } @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 3a11e8277e55..ed1f8e076cc6 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.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.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 List getMethodResolvers() { * @return always {@code null} */ @Override - @Nullable - public BeanResolver getBeanResolver() { + public @Nullable BeanResolver getBeanResolver() { return null; } @@ -257,8 +257,7 @@ public void setVariable(String name, @Nullable Object value) { * @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 static final class Builder { 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 5d196b7e930e..7dcca874ce19 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.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.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 void setBeanResolver(BeanResolver beanResolver) { } @Override - @Nullable - public BeanResolver getBeanResolver() { + public @Nullable BeanResolver getBeanResolver() { return this.beanResolver; } @@ -400,8 +392,7 @@ public void registerFunction(String name, MethodHandle methodHandle) { * @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 7b8d892b0d7e..21f7727953e1 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 fc913470dc44..aa6bcb8c513a 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 @@ 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 eeb1c09397db..9d57d9bb4650 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 @@ 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.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 boolean canConvert(@Nullable TypeDescriptor sourceType, TypeDescriptor ta } @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 816b66cb71c5..1ad740b02d2c 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.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 @@ */ 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 findType(String typeName) throws EvaluationException { 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 d77cb741fa54..7c9c08fd9cea 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 6aede670ad58..a909159c06fd 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 @@ 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.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 3bbb9411f80e..f32b3a06325a 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 @@ 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 52b9e4c0203e..6eadff9af744 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.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.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 a05e52ccb281..0bae62c0dc84 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 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.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 5e7d4987da53..3ec7587e0c48 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.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.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 @@ void SPR9994_bridgeMethods() throws Exception { 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 @@ public void setProperty(Integer value) { } @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 659a99a87adf..23e1978e7088 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 @@ 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 @@ private static TargetedAccessor createAccessor(String name, Class type) { 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 945cc4e7c6f3..a99072ac7c18 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 24fc744adf85..a88dde59f667 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 eb0eb0f184e5..6fa6d3ef3fcf 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 @@ 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 BadSqlGrammarException(String task, String sql, SQLException ex) { /** * 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 1439b89db13c..4cf6fd381669 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 @@ 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 d671af15f7a6..9b76ad5a8d8b 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 @@ 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 @@ @SuppressWarnings("serial") public class InvalidResultSetAccessException extends InvalidDataAccessResourceUsageException { - @Nullable - private final String sql; + private final @Nullable String sql; /** @@ -64,8 +64,7 @@ public InvalidResultSetAccessException(SQLException ex) { /** * Return the wrapped SQLException. */ - @Nullable - public SQLException getSQLException() { + public @Nullable SQLException getSQLException() { return (SQLException) getCause(); } @@ -73,8 +72,7 @@ public SQLException getSQLException() { * 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 2019b2ebd2f9..7acc07e8f5f5 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 @@ 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 SQLWarningException(String msg, SQLWarning ex) { * 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 SQLWarning getSQLWarning() { * @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 897acfbdbdb6..e64155f7d834 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 @@ 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 @@ 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 UncategorizedSQLException(String task, @Nullable String sql, SQLException /** * 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 08d07565bc97..cd6e09e94f89 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 @@ 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.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 @@ public static void setDatabasePopulator(Element element, BeanDefinitionBuilder b } } - @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 @@ private static BeanDefinition createDatabasePopulator(Element element, List 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 void setMappedClass(Class mappedClass) { /** * 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 void setConversionService(@Nullable ConversionService conversionService) * or {@code null} if none. * @since 4.3 */ - @Nullable - public ConversionService getConversionService() { + public @Nullable ConversionService getConversionService() { return this.conversionService; } @@ -426,8 +420,7 @@ protected void initBeanWrapper(BeanWrapper bw) { * @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 @@ protected Object getColumnValue(ResultSet rs, int index, PropertyDescriptor pd) * @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 7fb2ad7f0aca..dc929ea87371 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 @@ 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 501938d45e18..03208b18b743 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.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 CallableStatementCreator newCallableStatementCreator(ParameterMapper inPa */ 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 e6ea97a98c41..f310823c7428 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.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 @@ protected String getColumnKey(String columnName) { * @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 25bbfd49499d..19eac368c464 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 @@ 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 a8ba50dae0ab..b14bf961cc41 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.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 @@ */ 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 9824337edcf7..acbdd5b56915 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.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 @@ T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtracto * @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 @@ T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtracto * @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 @@ T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtracto * @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 @@ T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtracto * @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 @@ T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtracto * @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 @@ T query(String sql, @Nullable PreparedStatementSetter pss, ResultSetExtracto * @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 @@ List query(String sql, @Nullable PreparedStatementSetter pss, RowMapper 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 @@ List query(String sql, @Nullable PreparedStatementSetter pss, RowMapper 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 @@ List query(String sql, @Nullable PreparedStatementSetter pss, RowMapper 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 @@ Stream queryForStream(String sql, @Nullable PreparedStatementSetter pss, * @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 @@ Stream queryForStream(String sql, RowMapper rowMapper, @Nullable Objec * 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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper row * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper row * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper row * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, Class require * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, Class require * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, Class require * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, Class require * @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 @@ T queryForObject(String sql, Object[] args, int[] argTypes, Class require * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ List queryForList(String sql, Object[] args, int[] argTypes, Class ele * @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 @@ int[][] batchUpdate(String sql, Collection batchArgs, int batchSize, * @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 @@ int[][] batchUpdate(String sql, Collection batchArgs, int batchSize, * @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 9401a8feba7e..17b67c5a7fc5 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 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.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 boolean isResultsMapCaseInsensitive() { //------------------------------------------------------------------------- @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 @@ protected Connection createConnectionProxy(Connection con) { // 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 @@ private T execute(StatementCallback action, boolean closeResources) throw } @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 void execute(final String sql) throws DataAccessException { // 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 String getSql() { } @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 T query(final String sql, final ResultSetExtractor rse) throws Dat // 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 Map queryForMap(String sql) throws DataAccessException { } @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 int[] batchUpdate(final String... sql) throws DataAccessException { // 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 @@ private String appendSql(@Nullable String sql, String statement) { } @Override - @Nullable - public String getSql() { + public @Nullable String getSql() { return this.currSql; } } @@ -639,8 +630,7 @@ public String getSql() { // 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 @@ private T execute(PreparedStatementCreator psc, PreparedStatementCallback } @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 T execute(String sql, PreparedStatementCallback action) throws Dat * @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 T query( 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 T doInPreparedStatement(PreparedStatement ps) throws SQLException { } @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 void query(String sql, @Nullable PreparedStatementSetter pss, RowCallback } @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 List query(String sql, @Nullable PreparedStatementSetter pss, RowM } @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 Stream queryForStream(String sql, @Nullable PreparedStatementSette } @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 T queryForObject(String sql, Object[] args, int[] argTypes, RowMapper @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 T queryForObject(String sql, Object[] args, int[] argTypes, Class @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 int update(String sql, @Nullable PreparedStatementSetter pss) throws Data } @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 int[][] batchUpdate(String sql, final Collection batchArgs, final //------------------------------------------------------------------------- @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 T execute(CallableStatementCreator csc, CallableStatementCallback } @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 @@ protected void applyStatementSettings(Statement stmt) throws SQLException { * @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 @@ protected PreparedStatementSetter newArgPreparedStatementSetter(@Nullable Object * @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 @@ protected DataAccessException translateException(String task, @Nullable String s * @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 CloseSuppressingInvocationHandler(Connection target) { } @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 RowCallbackHandlerResultSetExtractor(RowCallbackHandler rch) { } @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 boolean tryAdvance(Consumer action) { } @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 97c9f32aa98a..235bf55234db 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 @@ 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 ddc9ac073c63..f98468641d0a 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.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 PreparedStatementSetter newPreparedStatementSetter(@Nullable List para * 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 PreparedStatementCreator newPreparedStatementCreator(@Nullable List pa * 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 PreparedStatementCreator newPreparedStatementCreator(@Nullable Object[] p * 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 0acaf0620df8..33a7ba541df2 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 @@ 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 0c8b9b42b610..3ef1703bf77e 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 @@ 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 @@ */ 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 boolean isResultSetSupported() { /** * 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 2d2b09ac9a98..35161ec92bb9 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.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 @@ protected void processRow(ResultSet rs, int rowNum) throws SQLException { * @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 final int[] getColumnTypes() { * @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 291d3f2ac1a4..92cbb414c8e1 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 @@ 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 43dffc066eba..1b8f3b6af501 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.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 @@ */ 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 void setConversionService(@Nullable ConversionService conversionService) */ @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 T mapRow(ResultSet rs, int rowNum) throws SQLException { * @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 @@ protected Object getColumnValue(ResultSet rs, int index, @Nullable Class requ * @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 @@ protected Object getColumnValue(ResultSet rs, int index) throws SQLException { * @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 a43ec1a0dd86..c7b177a42b92 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 @@ 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 @@ */ public class SqlOutParameter extends ResultSetSupportingSqlParameter { - @Nullable - private SqlReturnType sqlReturnType; + private @Nullable SqlReturnType sqlReturnType; /** @@ -114,8 +113,7 @@ public SqlOutParameter(String name, int sqlType, RowMapper rm) { /** * 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 339611df6849..609ed04b31f2 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 @@ 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 @@ 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 SqlParameter(SqlParameter otherParam) { /** * 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 int getSqlType() { /** * 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 boolean isResultsParameter() { * 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 30159fe4dcee..d693b8bc8bc0 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 @@ */ public class SqlParameterValue extends SqlParameter { - @Nullable - private final Object value; + private final @Nullable Object value; /** @@ -89,8 +88,7 @@ public SqlParameterValue(SqlParameter declaredParam, @Nullable Object value) { /** * 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 e060bc1522a3..01b8c0b2267e 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 f2558c669116..c2d609b7b584 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 @@ 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 2349ac1cb2f6..8c30cda0937c 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 @@ 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 1297b94dea2d..907027d5d3f0 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 @@ 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 3eea1df60613..0f3fb0f2a5a4 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 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 @@ private static boolean isDateValue(Class inValueType) { * @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 fdc66aa1c342..d291aa37df50 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 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.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 void setProcedureName(@Nullable String procedureName) { /** * Get the name of the procedure. */ - @Nullable - public String getProcedureName() { + public @Nullable String getProcedureName() { return this.procedureName; } @@ -166,8 +160,7 @@ public void setCatalogName(@Nullable String catalogName) { /** * Get the name of the catalog. */ - @Nullable - public String getCatalogName() { + public @Nullable String getCatalogName() { return this.catalogName; } @@ -181,8 +174,7 @@ public void setSchemaName(@Nullable String schemaName) { /** * Get the name of the schema. */ - @Nullable - public String getSchemaName() { + public @Nullable String getSchemaName() { return this.schemaName; } @@ -285,8 +277,7 @@ public SqlParameter createReturnResultSetParameter(String parameterName, RowMapp * 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 a13a43161ffc..1d564f16bfc2 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.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 @@ void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @N * 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 @@ void initializeWithProcedureColumnMetaData(DatabaseMetaData databaseMetaData, @N * 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 2b7a61c069d7..5103f034911b 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 @@ 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 boolean isFunction() { /** * Return the parameter name. */ - @Nullable - public String getParameterName() { + public @Nullable String getParameterName() { return this.parameterName; } @@ -129,8 +126,7 @@ public int getSqlType() { /** * 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 66c49564681c..0de476af1f0d 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.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 void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQL } @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 efaa556cf6b3..84767aa76f2d 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.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 DerbyCallMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLEx @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 5eb124b063f6..96de2873a261 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 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 List getCallParameterMetaData() { } @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 String metaDataCatalogNameToUse(@Nullable String catalogName) { } @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 String metaDataSchemaNameToUse(@Nullable String schemaName) { } @Override - @Nullable - public String parameterNameToUse(@Nullable String parameterName) { + public @Nullable String parameterNameToUse(@Nullable String parameterName) { return identifierNameToUse(parameterName); } @@ -279,8 +273,7 @@ protected boolean isStoresLowerCaseIdentifiers() { } - @Nullable - private String identifierNameToUse(@Nullable String identifierName) { + private @Nullable String identifierNameToUse(@Nullable String identifierName) { if (identifierName == null) { return null; } @@ -438,8 +431,7 @@ private ProcedureMetadata getProcedureMetadataAsFunction(DatabaseMetaData databa 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 b5e65f418b9b..defbd02b89ec 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 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 List getTableParameterMetaData() { } @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 @@ else if (isStoresLowerCaseIdentifiers()) { } @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 String metaDataSchemaNameToUse(@Nullable String schemaName) { /** * 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 boolean isGetGeneratedKeysSimulated(){ } @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 f655eb090347..cc64c1a3be22 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.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 int getRefCursorSqlType() { } @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 5374099fee64..b2535c1c519c 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.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 OracleTableMetaDataProvider(DatabaseMetaData databaseMetaData, boolean in /* * 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 @@ private static String lookupDefaultSchema(DatabaseMetaData databaseMetaData) { } @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 31275e90ebbf..93a77e88149e 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.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 int getRefCursorSqlType() { } @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 5e745930812e..794de56f2475 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 @@ 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 SqlServerCallMetaDataProvider(DatabaseMetaData databaseMetaData) throws S @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 566361531209..7e3b454b819c 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 @@ 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 SybaseCallMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLE @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 e7cb34de8fb9..f31e7ef68d74 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 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 void setTableName(@Nullable String tableName) { /** * 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 void setCatalogName(@Nullable String catalogName) { /** * 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 void setSchemaName(@Nullable String schemaName) { /** * 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 boolean isGetGeneratedKeysSimulated() { * 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 boolean isGeneratedKeysColumnNameArraySupported() { 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 1af80eec37f5..299d782ca351 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.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 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla * 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 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla *

    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 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla *

    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 @@ void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData, @Nulla * 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 3627e646b39e..909f18d6f721 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 a68f7899ca9c..4766feea574f 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.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 int getSqlType(String paramName) { * 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 bb2c595b6534..4eb53d854133 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.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 boolean hasValue(String paramName) { } @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 int getSqlType(String paramName) { } @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 f3034c9daa9b..e4a8d09e82e4 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 boolean hasValue(String paramName) { } @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 int getSqlType(String paramName) { } @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 e3502ac63de6..b7bd54ed6984 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.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 boolean hasValue(String paramName) { } @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 Object getValue(String paramName) { } @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 5de5917194fd..ca0503d468d8 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 @@ */ public class NamedParameterJdbcDaoSupport extends JdbcDaoSupport { - @Nullable - private NamedParameterJdbcTemplate namedParameterJdbcTemplate; + private @Nullable NamedParameterJdbcTemplate namedParameterJdbcTemplate; /** @@ -48,8 +48,7 @@ protected void initTemplateConfig() { /** * 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 f594c5e536f7..4edfe6aae5a1 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.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.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 @@ T execute(String sql, SqlParameterSource paramSource, PreparedStatementCallb * @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 @@ T execute(String sql, Map paramMap, PreparedStatementCallback * @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 @@ T execute(String sql, Map paramMap, PreparedStatementCallback * @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 @@ T query(String sql, SqlParameterSource paramSource, ResultSetExtractor rs * @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 @@ T query(String sql, Map paramMap, ResultSetExtractor rse) * @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 @@ Stream queryForStream(String sql, Map paramMap, RowMapper r * 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 @@ T queryForObject(String sql, SqlParameterSource paramSource, RowMapper ro * 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 @@ T queryForObject(String sql, Map paramMap, RowMapper rowMapper * @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 @@ T queryForObject(String sql, SqlParameterSource paramSource, Class requir * @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 cba5c9bda0bd..ec51624fe0d1 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 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.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 int getCacheLimit() { @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 Stream queryForStream(String sql, Map paramMap, RowMapp } @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 T queryForObject(String sql, SqlParameterSource paramSource, RowMappe } @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 int update(String sql, SqlParameterSource paramSource, KeyHolder generate @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 int[] batchUpdate(String sql, SqlParameterSource[] batchArgs, KeyHolder g @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 4d9f1141dfa3..750cf85ad005 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.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 static Object[] buildValueArray( * @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 60583679a725..ca018cfd6d32 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.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 boolean hasValue(String paramName) { } @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 63747b25284e..48340f4abd69 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 @@ default int getSqlType(String paramName) { * @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 @@ default String getTypeName(String paramName) { * @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 9709561eb286..81c303c8ee5e 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.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 static SqlParameterSource[] createBatch(Map[] valueMaps) { * @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 d3fc2928d6d4..1b4a01787c13 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 2d79acddb044..0d0e604d4e08 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 d09c7e9e6c77..ba027c5705c2 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 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.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 void setProcedureName(@Nullable String procedureName) { /** * Get the name of the stored procedure. */ - @Nullable - public String getProcedureName() { + public @Nullable String getProcedureName() { return this.callMetaDataContext.getProcedureName(); } @@ -148,8 +145,7 @@ public void setCatalogName(@Nullable String catalogName) { /** * Get the catalog name used. */ - @Nullable - public String getCatalogName() { + public @Nullable String getCatalogName() { return this.callMetaDataContext.getCatalogName(); } @@ -163,8 +159,7 @@ public void setSchemaName(@Nullable String schemaName) { /** * Get the schema name used. */ - @Nullable - public String getSchemaName() { + public @Nullable String getSchemaName() { return this.callMetaDataContext.getSchemaName(); } @@ -226,8 +221,7 @@ public void setAccessCallParameterMetaData(boolean accessCallParameterMetaData) /** * 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 @@ private Map executeCallInternal(Map args) { * 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 6b86dbb67390..fbda7f1a3217 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 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.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 void setTableName(@Nullable String tableName) { /** * 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 void setSchemaName(@Nullable String schemaName) { /** * 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 void setCatalogName(@Nullable String catalogName) { /** * 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 int getBatchSize() { * @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 7ef7d6ccfc0a..c6f030456dae 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 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.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 @@ private PreparedStatementCreator statementCreatorForIndexedParams() { 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 5f80796b1aa8..92f646fc69d8 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 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.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 6331423200b4..ffcdcfc6f9a1 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 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 SimpleJdbcCall withNamedBinding() { } @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 91db9847925d..ea784a403892 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 @@ 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 d8a3bb7e5311..59c640dc1166 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 c56e4a2811f9..a6d8516df472 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.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 28e10a985255..fb04aeb08316 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.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 9f932a5cfde0..c6db333402d6 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 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 f9a5ceb934a4..5ff1f765f7f7 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 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 @@ */ public abstract class JdbcDaoSupport extends DaoSupport { - @Nullable - private JdbcTemplate jdbcTemplate; + private @Nullable JdbcTemplate jdbcTemplate; /** @@ -77,8 +77,7 @@ protected JdbcTemplate createJdbcTemplate(DataSource dataSource) { /** * 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 final void setJdbcTemplate(@Nullable JdbcTemplate jdbcTemplate) { * 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 08a9f3019c46..7f113eb5f6e4 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.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 aaaf80d79835..6ef5e04fa252 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.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 c208be0e3f40..15bd704aaf4c 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.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 @@ @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 SqlLobValue(@Nullable byte[] bytes) { * @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 7e0621e7740b..b8969eabd1b1 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 df6df3e6278f..075d983f497e 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.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 @@ */ 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 void setUrl(@Nullable String url) { /** * 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 void setUsername(@Nullable String username) { /** * 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 void setPassword(@Nullable String password) { /** * 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 void setCatalog(@Nullable String catalog) { * 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 void setSchema(@Nullable String schema) { * 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 void setConnectionProperties(@Nullable Properties connectionProperties) { /** * 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 c8f01712c825..644036065ed1 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.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 ConnectionHolder(Connection connection, boolean transactionActive) { /** * 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 49d111d3d6bf..6069e2016b2d 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 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 @@ 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 void setDataSource(@Nullable DataSource dataSource) { /** * 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 ad99f2e2d55d..05adc178922d 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 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 @@ private static Connection fetchConnection(DataSource dataSource) throws SQLExcep * @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 fccd2b69b643..d99de4f80275 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 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 @@ */ public class DelegatingDataSource implements DataSource, InitializingBean { - @Nullable - private DataSource targetDataSource; + private @Nullable DataSource targetDataSource; /** @@ -73,8 +73,7 @@ public void setTargetDataSource(@Nullable DataSource targetDataSource) { /** * 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 86a7b91de7ea..6a624e47081d 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.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 void setIsolationLevel(int isolationLevel) { * 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 @@ protected Connection doGetConnection(@Nullable String username, @Nullable String * @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 @@ protected Integer getCurrentIsolationLevel() { * @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 49421e52fcf2..580eba7c3888 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.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 @@ */ 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 void setPreviousIsolationLevel(@Nullable Integer previousIsolationLevel) /** * 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 38cd26a6272f..313bfb944edd 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 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 @@ protected void checkDefaultConnectionProperties(Connection con) throws SQLExcept /** * 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 Connection getConnection(String username, String password) throws SQLExce */ 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 @@ private class LazyConnectionInvocationHandler implements InvocationHandler { private boolean closed = false; - @Nullable - private Connection target; + private @Nullable Connection target; public LazyConnectionInvocationHandler() { this.autoCommit = defaultAutoCommit(); @@ -328,8 +318,7 @@ public LazyConnectionInvocationHandler(String username, String password) { } @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 13194ec754c8..73e97529e055 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 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 @@ */ 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 f9c99b177f7c..3f868dc19fb3 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 @@ 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 99a00687e470..e81365a540e1 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.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 @@ */ public class SimpleDriverDataSource extends AbstractDriverBasedDataSource { - @Nullable - private Driver driver; + private @Nullable Driver driver; /** @@ -127,8 +127,7 @@ public void setDriver(@Nullable Driver driver) { /** * 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 a258aa3a21a0..6fdef5d1ffcf 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.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 void setAutoCommit(boolean autoCommit) { * 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 CloseSuppressingInvocationHandler(Connection target) { } @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 d9cfce3885e8..f3f95f2e3055 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 javax.sql.DataSource; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.transaction.support.TransactionSynchronizationManager; /** @@ -180,8 +181,7 @@ private class TransactionAwareInvocationHandler implements InvocationHandler { private final DataSource targetDataSource; - @Nullable - private Connection target; + private @Nullable Connection target; private boolean closed = false; @@ -190,8 +190,7 @@ public TransactionAwareInvocationHandler(DataSource targetDataSource) { } @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 98203528fc41..b47a3ca3818c 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 @@ 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 @@ */ 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 7375d7044e38..f764a3b08cd9 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 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 0b08b5955ddb..d7205235ca21 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 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 @@ protected void shutdownDatabase() { * 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 a1e050236775..a5659ac56461 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 @@ 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 @@ public class EmbeddedDatabaseFactoryBean extends EmbeddedDatabaseFactory implements FactoryBean, InitializingBean, DisposableBean { - @Nullable - private DatabasePopulator databaseCleaner; + private @Nullable DatabasePopulator databaseCleaner; /** @@ -66,8 +66,7 @@ public void afterPropertiesSet() { @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 9f44861ed8d0..dc4f5e1cf935 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 @@ 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 c3a816e0cf15..14e92dba381c 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 @@ import java.sql.Driver; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -33,8 +34,7 @@ */ 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 8f3c69fe3bb2..e8c04da4c8ed 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 @@ import java.sql.Driver; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.ClassUtils; /** @@ -32,8 +33,7 @@ */ 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 2f9576f22e3f..2c181736a5e4 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 4a57474b5599..5e5cec82fc97 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 @@ 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 @@ */ 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 214a857620ba..45d768bb1ab4 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 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 eb782d1e9835..09cd90d48d13 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 7c9f3f06b17e..d414a82263bc 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 cf1d803b6101..0fbfd7b824a3 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 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 @@ static String readScript(EncodedResource resource, @Nullable String separator, } } - 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 1e1d53e3a6c9..ac625201d2b4 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 b9d203f20234..02065d765d06 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 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 @@ */ 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 Map getResolvedDataSources() { * @since 5.2.9 * @see #setDefaultTargetDataSource */ - @Nullable - public DataSource getResolvedDefaultDataSource() { + public @Nullable DataSource getResolvedDefaultDataSource() { return this.resolvedDefaultDataSource; } @@ -271,7 +267,6 @@ protected DataSource determineTargetDataSource() { * 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 ff7e8825ae0e..a8eb53048b57 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 @@ 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 @@ */ 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 1ee290230ab7..70ca89daabbb 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 @@ 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 @@ else if (lookupKey instanceof String constantName) { } @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 297a8051c17a..19a17d079f0b 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 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 e5dd2ecb8616..901256a8a6ae 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 baa79a5f8656..619f2e139d70 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 c27089201d39..fd9f17ac0694 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 @@ 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 @@ */ 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 void afterPropertiesSet() { @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 86e38b0200e3..b10136dca5b3 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 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 MappingSqlQuery(DataSource ds, String sql) { * @see #mapRow(ResultSet, int) */ @Override - @Nullable - protected final T mapRow(ResultSet rs, int rowNum, @Nullable Object[] parameters, @Nullable Map 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 @@ protected final T mapRow(ResultSet rs, int rowNum, @Nullable Object[] parameters * Subclasses can simply not catch SQLExceptions, relying on the * framework to clean up. */ - @Nullable - protected abstract T mapRow(ResultSet rs, int rowNum) throws SQLException; + protected abstract @Nullable T mapRow(ResultSet rs, int rowNum) throws SQLException; } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java index 5743e3c76363..94727f0ee99d 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/MappingSqlQueryWithParameters.java @@ -22,8 +22,9 @@ 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 @@ -73,7 +74,7 @@ public MappingSqlQueryWithParameters(DataSource ds, String sql) { * 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 @@ protected RowMapper newRowMapper(@Nullable Object[] parameters, @Nullable Map * 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 @@ protected abstract T mapRow(ResultSet rs, int rowNum, @Nullable Object[] paramet */ 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 fe7b05b11131..19acf5eb7076 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 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 boolean isReturnGeneratedKeys() { * 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 void setGeneratedKeysColumnNames(@Nullable String... names) { /** * 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 void setSql(@Nullable String sql) { * 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 @@ protected String resolveSql() { * {@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 @@ protected void checkCompiled() { * @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 0f8600659f0e..5c3c182c5785 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 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 @@ protected void onCompileInternal() { /** * 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 59408ac658a4..c9be8bd09e75 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 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 void setResultType(Class resultType) { * 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 int run(Object... parameters) { * 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 Object runGeneric() { * @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 Object runGeneric(int parameter) { * @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 94c4af9ebab0..de6e81737418 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 @@ protected ParsedSql getParsedSql() { * 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 @@ protected final PreparedStatementSetter newPreparedStatementSetter(@Nullable Obj * 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 @@ protected final PreparedStatementCreator newPreparedStatementCreator(@Nullable O * 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 170771928ec0..ad0d7b03c2e0 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 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 int getRowsExpected() { * @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 List executeByNamedParam(Map paramMap) throws DataAccessExc * 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 T findObject(@Nullable Object[] params, @Nullable Map context) thro /** * 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 T findObject(Object... params) throws DataAccessException { * 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 T findObject(int p1) throws DataAccessException { * 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 T findObject(int p1, int p2) throws DataAccessException { * 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 T findObject(long p1) throws DataAccessException { * 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 T findObject(String p1) throws DataAccessException { * @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 T findObjectByNamedParam(Map paramMap, @Nullable Map con * 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 T findObjectByNamedParam(Map paramMap) throws DataAccessExcept * 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 1c3fa977d2b4..9e4e3ad1a9b3 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 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 UpdatableSqlQuery(DataSource ds, String sql) { * 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 @@ protected RowMapper newRowMapper(@Nullable Object[] parameters, @Nullable Map */ 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 727aa94964f0..12744377641c 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 86f4c59af6af..b2a919f527f6 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 f82e8475ce1d..89ac060fcf93 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 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 void setFallbackTranslator(@Nullable SQLExceptionTranslator fallback) { * 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 void setCustomTranslator(@Nullable SQLExceptionTranslator customTranslato * @since 6.1 * @see #setCustomTranslator */ - @Nullable - public SQLExceptionTranslator getCustomTranslator() { + public @Nullable SQLExceptionTranslator getCustomTranslator() { return this.customTranslator; } @@ -91,8 +87,7 @@ public SQLExceptionTranslator getCustomTranslator() { * {@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 DataAccessException translate(String task, @Nullable String sql, 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 8c84cb34074d..d27d4793102a 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 void setExceptionClass(@Nullable Class exceptionClass) { /** * 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 259353a04f73..ce8e6d2844cd 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 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 void registerTranslator(String dbName, SQLExceptionTranslator translator) * @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 f518103d2e3b..19cde00c58db 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 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 d1c26195edb8..4bca6a858d2e 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.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 GeneratedKeyHolder(List> keyList) { @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 T getKeyAs(Class keyType) throws InvalidDataAccessApiUsageExceptio } @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 5178b4a0f4e6..7b778b73d72d 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 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 void setDataSource(@Nullable DataSource dataSource) { /** * 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 6d630cc5f530..82770bde48a3 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 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 @@ @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 84867940ef6c..84a37f8bcf75 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 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 static void closeResultSet(@Nullable ResultSet rs) { * @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 @@ else if (obj instanceof Number number) { * @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 static boolean supportsBatchUpdates(Connection con) { * @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 static boolean isNumeric(int sqlType) { * (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 e022341d2720..15274ef2112a 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 @@ 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 b7e0af91d57c..f402e9e1b239 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 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.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 void setSqlErrorCodes(@Nullable SQLErrorCodes sec) { * 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 @@ else if (Arrays.binarySearch(sqlErrorCodes.getCannotSerializeTransactionCodes(), * @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 @@ protected DataAccessException customTranslate(String task, @Nullable String sql, * {@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 5d4498c05230..a990e33401b6 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 @@ */ 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 void setDatabaseProductName(@Nullable String databaseProductName) { 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 String getDatabaseProductName() { * 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 void setCustomTranslations(CustomSQLErrorCodesTranslation... customTransl this.customTranslations = customTranslations; } - @Nullable - public CustomSQLErrorCodesTranslation[] getCustomTranslations() { + public CustomSQLErrorCodesTranslation @Nullable [] getCustomTranslations() { return this.customTranslations; } @@ -214,8 +209,7 @@ public void setCustomSqlExceptionTranslator(@Nullable SQLExceptionTranslator cus 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 4b4575cc8e96..65461393da08 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 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 @@ protected 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 SQLErrorCodes getErrorCodes(DataSource dataSource) { * @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 SQLErrorCodes registerDatabase(DataSource dataSource, String databaseName * @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 eb5fdcd25024..214c1d92ce26 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.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.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 SQLExceptionSubclassTranslator() { } @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 349ea1d29c70..4c52546c9c08 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 @@ 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 ad68fcf54d40..2e9e04b1d2d1 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 @@ 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.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 @@ else if (PESSIMISTIC_LOCKING_FAILURE_CODES.contains(classCode)) { * 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 a6834efaed89..4f4fc1139698 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.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 6f761ea9861e..8022eec12c93 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 @@ 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 @@ */ 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 dab17298db3f..4fc7bba19ab2 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 d2ff13ec95ef..30d5490c1506 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.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 @@ 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 01fe9316befd..fc497a4f0ada 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 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 void setCreateTemporaryLob(boolean createTemporaryLob) { @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 byte[] getBlobAsBytes(ResultSet rs, int columnIndex) throws SQLException } @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 InputStream getBlobAsBinaryStream(ResultSet rs, int columnIndex) throws S } @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 LobCreator getLobCreator() { 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 4c59328629aa..1b07cb22260a 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.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 11fea7e50dec..1f852af0c969 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.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 93238ea41ec0..4ca1e69d1ac8 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.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 @@ @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 8dea8a2c842a..5c7ca574cd7c 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.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 @@ @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 7a0e18db9ca3..820ca7b8c284 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 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 a07f8dac5d02..85525271fe83 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 bd868877a9af..44d0b871a4a3 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 04d90e000cba..9f3c0feb9595 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.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 int findColumn(String columnLabel) throws InvalidResultSetAccessException * @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 BigDecimal getBigDecimal(int columnIndex) throws InvalidResultSetAccessEx * @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 byte getByte(String columnLabel) throws InvalidResultSetAccessException { * @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 Date getDate(int columnIndex) throws InvalidResultSetAccessException { * @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 Date getDate(String columnLabel) throws InvalidResultSetAccessException { * @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 Date getDate(int columnIndex, Calendar cal) throws InvalidResultSetAccess * @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 long getLong(String columnLabel) throws InvalidResultSetAccessException { * @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 String getNString(int columnIndex) throws InvalidResultSetAccessException * @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 String getNString(String columnLabel) throws InvalidResultSetAccessExcept * @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 Object getObject(int columnIndex) throws InvalidResultSetAccessException * @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 Object getObject(String columnLabel) throws InvalidResultSetAccessExcepti * @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 Object getObject(int columnIndex, Map> map) throws Inval * @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 Object getObject(String columnLabel, Map> map) throws In * @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 T getObject(int columnIndex, Class type) throws InvalidResultSetAc * @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 short getShort(String columnLabel) throws InvalidResultSetAccessException * @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 String getString(int columnIndex) throws InvalidResultSetAccessException * @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 String getString(String columnLabel) throws InvalidResultSetAccessExcepti * @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 Time getTime(int columnIndex) throws InvalidResultSetAccessException { * @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 Time getTime(String columnLabel) throws InvalidResultSetAccessException { * @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 Time getTime(int columnIndex, Calendar cal) throws InvalidResultSetAccess * @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 Time getTime(String columnLabel, Calendar cal) throws InvalidResultSetAcc * @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 Timestamp getTimestamp(int columnIndex) throws InvalidResultSetAccessExce * @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 Timestamp getTimestamp(String columnLabel) throws InvalidResultSetAccessE * @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 Timestamp getTimestamp(int columnIndex, Calendar cal) throws InvalidResul * @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 88ad0941f593..8e8decbe1f4e 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 @@ 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 a460f8154004..1de3e7d24fe0 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.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 d38a51b1c694..4481066ea3eb 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 9a5775c71206..75c1807cfde8 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.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 Source getXmlAsSource(ResultSet rs, String columnName, @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 @@ protected void provideXml(SQLXML xmlObject) throws SQLException, IOException { */ 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 de37b3b95b39..e9fd4304fafc 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 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 24e863bfd6ae..d0553a560df3 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 1a7b808c23fb..f6480ab7511b 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 e03b2d336152..bc1065d4aaa2 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 @@ 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.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 @@ private void assertCorrectSetupAndCloseContext(String file, int count, String... } } - @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 a6c318ef1a38..db12eeeec8ee 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.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 1872fbe522d8..6b4243dd4782 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.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 1a525815aa54..2af6f993223a 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 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.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 @@ void testQueryWithoutParams() throws SQLException { 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 1a5d833de0b7..750351ea0fff 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 @@ 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 76ec0720b32b..4fc8995646d7 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 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.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 @@ void customTranslateMethodTranslation() { 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 28758b874560..b3156a7073ca 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 @@ 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.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 e3e086b30f6d..6ed59b8a468d 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 f8a74a4216f7..b8dd071e4d6f 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 JmsException(@Nullable Throwable cause) { * @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 String getErrorCode() { * @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 d35c228f226a..319069bd7035 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 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.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 @@ private String getEndpointId(JmsListener jmsListener) { } } - @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 @@ private String resolve(String value) { */ 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 7aca3605b61c..3caf9f55bd77 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 32816c009275..6ba62252e7a9 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.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 0338478a0864..48c16ac13518 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 @@ 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 f11d9ae7d89e..d3290a510499 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 @@ 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 @@ 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 85d075415a9a..7eb7c6e19a58 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 @@ 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.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 faaf91197318..f815d76df04d 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 @@ 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 @@ */ 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 void setEndpointRegistry(@Nullable JmsListenerEndpointRegistry endpointRe * 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 void setMessageHandlerMethodFactory(@Nullable MessageHandlerMethodFactory /** * Return the custom {@link MessageHandlerMethodFactory} to use, if any. */ - @Nullable - public MessageHandlerMethodFactory getMessageHandlerMethodFactory() { + public @Nullable MessageHandlerMethodFactory getMessageHandlerMethodFactory() { return this.messageHandlerMethodFactory; } @@ -197,8 +191,7 @@ private static class JmsListenerEndpointDescriptor { 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 b111fb1165b0..42ee66b1bb65 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 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.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 void onApplicationEvent(ContextRefreshedEvent event) { * @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 3bedccadde5c..f6005558c4af 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 @@ 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.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 @@ */ 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 void setBean(@Nullable Object bean) { this.bean = bean; } - @Nullable - public Object getBean() { + public @Nullable Object getBean() { return this.bean; } @@ -84,8 +79,7 @@ public void setMethod(@Nullable Method method) { this.method = method; } - @Nullable - public Method getMethod() { + public @Nullable Method getMethod() { return this.method; } @@ -99,8 +93,7 @@ public void setMostSpecificMethod(@Nullable Method mostSpecificMethod) { this.mostSpecificMethod = mostSpecificMethod; } - @Nullable - public Method getMostSpecificMethod() { + public @Nullable Method getMostSpecificMethod() { if (this.mostSpecificMethod != null) { return this.mostSpecificMethod; } @@ -188,8 +181,7 @@ protected MessagingMessageListenerAdapter createMessageListenerInstance() { /** * 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 @@ protected String getDefaultResponseDestination() { 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 @@ private SendTo getSendTo(Method specificMethod) { 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 5dfc42ad2883..6978e54659be 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 @@ */ public class SimpleJmsListenerEndpoint extends AbstractJmsListenerEndpoint { - @Nullable - private MessageListener messageListener; + private @Nullable MessageListener messageListener; /** @@ -47,8 +46,7 @@ public void setMessageListener(@Nullable MessageListener messageListener) { * 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 615ba9a71df1..391ad07a1923 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 33c5708c4329..a64186666208 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.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 @@ public String getMessageSelector() throws JMSException { } @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 91f24ccd00a0..20cfc4b5fd72 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.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 6c24dc7828bb..9bca4e364b64 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.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 void resetConnection() { * 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 CachedSessionInvocationHandler(Session target, Deque sessionList } @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 @@ private static class DestinationCacheKey implements Comparable C getConnection(Class connectionType) { + public @Nullable C getConnection(Class connectionType) { return CollectionUtils.findValueOfType(this.connections, connectionType); } @@ -194,8 +191,7 @@ public C getConnection(Class connectionType) { *

    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 @@ Session getOriginalSession() { * 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 Session getSession() { * 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 S getSession(Class sessionType) { * 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 3ffd27e867d7..99a6820e57ae 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.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 @@ 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 void setConnectionFactory(@Nullable ConnectionFactory cf) { /** * 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 LazyJmsResourceHolder(@Nullable ConnectionFactory connectionFactory) { } @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 @@ private void initializeSession() { */ 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 186fcaa3baab..5149d4aa53a5 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.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 void setTargetConnectionFactory(@Nullable ConnectionFactory targetConnect * 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 void setClientId(@Nullable String clientId) { * 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 void setExceptionListener(@Nullable ExceptionListener exceptionListener) * 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 @@ else if (getExceptionListener() != null || isReconnectOnException()) { * 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 @@ protected Connection getSharedConnectionProxy(Connection target) { */ 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 e5ffb4b0673a..dab2aef3ac37 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.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 @@ public class TransactionAwareConnectionFactoryProxy implements ConnectionFactory, QueueConnectionFactory, TopicConnectionFactory { - @Nullable - private ConnectionFactory targetConnectionFactory; + private @Nullable ConnectionFactory targetConnectionFactory; private boolean synchedLocalTransactionAllowed = false; @@ -327,8 +326,7 @@ public CloseSuppressingSessionInvocationHandler(Session target) { } @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 5d5868e8b9cd..ffce4224a175 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.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 @@ 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 f075ee2297cc..3bc4d6ccbc4a 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 1a076bad5012..303267cb3a59 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 @@ 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 ebb821da62cd..921cab42ebff 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 @@ 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 @@ void convertAndSend(String destinationName, Object payload, @Nullable Map 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 @@ void convertAndSend(String destinationName, Object payload, @Nullable Map 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 @@ void convertAndSend(String destinationName, Object payload, @Nullable Map 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 @@ void convertAndSend(String destinationName, Object payload, @Nullable Map 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 @@ void convertAndSend(String destinationName, Object payload, @Nullable Map 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 @@ T convertSendAndReceive(String destinationName, Object request, @Nullable Ma * @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(String destinationName, Object request, Class targetClass, + @Nullable T convertSendAndReceive(String destinationName, Object request, Class targetClass, MessagePostProcessor requestPostProcessor) throws MessagingException; /** @@ -186,8 +180,7 @@ T convertSendAndReceive(String destinationName, Object request, Class tar * @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(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 5c0aeb27b959..4b87ce0fb2b2 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.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.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 @@ 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 void setConnectionFactory(ConnectionFactory connectionFactory) { * 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 void setJmsTemplate(@Nullable JmsTemplate jmsTemplate) { /** * Return the configured {@link JmsTemplate}. */ - @Nullable - public JmsTemplate getJmsTemplate() { + public @Nullable JmsTemplate getJmsTemplate() { return this.jmsTemplate; } @@ -158,8 +154,7 @@ public void setDefaultDestinationName(@Nullable String defaultDestinationName) { /** * Return the configured default destination name. */ - @Nullable - public String getDefaultDestinationName() { + public @Nullable String getDefaultDestinationName() { return this.defaultDestinationName; } @@ -233,8 +228,7 @@ public void convertAndSend(String destinationName, Object payload, @Nullable Map } @Override - @Nullable - public Message receive() { + public @Nullable Message receive() { Destination defaultDestination = getDefaultDestination(); if (defaultDestination != null) { return receive(defaultDestination); @@ -245,8 +239,7 @@ public Message receive() { } @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 T receiveAndConvert(Class targetClass) { } @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 T receiveAndConvert(String destinationName, Class targetClass) thr } @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 Message sendAndReceive(Message requestMessage) { } @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 T convertSendAndReceive(Object request, Class targetClass, @Nullab } @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 T convertSendAndReceive(String destinationName, Object request, Class @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 @@ protected void doSend(String destinationName, Message message) { } @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 @@ protected Message doReceive(Destination destination) { } } - @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 @@ protected Message doReceive(String destinationName) { } @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 @@ protected Message doSendAndReceive(Destination destination, Message reques } } - @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 @@ protected String getRequiredDefaultDestinationName() { 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 0aa7888819a1..2245d596522e 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 @@ 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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 @@ void convertAndSend(String destinationName, Object message, MessagePostProcessor * @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 ecae541c4e31..3fef51127710 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.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.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 void setDefaultDestination(@Nullable Destination destination) { * 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 void setDefaultDestinationName(@Nullable String destinationName) { * 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 void setMessageConverter(@Nullable MessageConverter messageConverter) { /** * Return the message converter for this template. */ - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { return this.messageConverter; } @@ -485,8 +478,7 @@ public void setObservationRegistry(ObservationRegistry observationRegistry) { //--------------------------------------------------------------------------------------- @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 T execute(SessionCallback action) throws JmsException { * @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 T execute(SessionCallback action, boolean startConnection) throws } @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 T execute(ProducerCallback action) throws JmsException { } @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 T execute(final @Nullable Destination destination, final ProducerCall } @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 void convertAndSend( //--------------------------------------------------------------------------------------- @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 Message receive() throws JmsException { } @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 Message receiveSelected(String messageSelector) throws JmsException { } @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 Message receiveSelected(final String destinationName, @Nullable final Str * @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 @@ protected Message doReceive(Session session, Destination destination, @Nullable * @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 @@ else if (isClientAcknowledge(session)) { //--------------------------------------------------------------------------------------- @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 Object receiveSelectedAndConvert(String destinationName, String messageSe * @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 @@ protected Object doConvertFromMessage(@Nullable Message message) { //--------------------------------------------------------------------------------------- @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 Message sendAndReceive(MessageCreator messageCreator) throws JmsException } @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 Message sendAndReceive(final String destinationName, final MessageCreator *

    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 @@ protected Message doSendAndReceive(Session session, Destination destination, Mes * 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 @@ private T executeLocal(SessionCallback action, boolean startConnection) t //--------------------------------------------------------------------------------------- @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 T browse(BrowserCallback action) throws JmsException { } @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 T browseSelected(String messageSelector, BrowserCallback action) t } @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 T browseSelected(final Queue queue, @Nullable final String messageSel } @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 T browseSelected(final String queueName, @Nullable final String messa * @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 @@ protected Connection getConnection(JmsResourceHolder holder) { * @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 @@ protected QueueBrowser createBrowser(Session session, Queue queue, @Nullable Str 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 952d3a6d15a0..e86c19980153 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 @@ 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 99dfe64b0ca8..1357b006e093 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 @@ 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 4beb013c5759..1270b14b6c84 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 627e5fc311b1..99de379a7327 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 @@ 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 @@ protected JmsTemplate createJmsTemplate(ConnectionFactory connectionFactory) { /** * 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 final void setJmsTemplate(@Nullable JmsTemplate jmsTemplate) { /** * 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 55535f37a3b4..dc74a7fea9be 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 8ed0f74fe252..ad4fedb93c74 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 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.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 @@ 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 void setClientId(@Nullable String clientId) { * 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 void setBeanName(@Nullable String beanName) { * 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 f803fc3aa11e..5977d125f945 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.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 void setDestination(@Nullable Destination destination) { * 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 void setDestinationName(@Nullable String destinationName) { * {@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 void setMessageSelector(@Nullable String messageSelector) { /** * 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 void setMessageListener(@Nullable Object messageListener) { /** * Return the message listener object to register. */ - @Nullable - public Object getMessageListener() { + public @Nullable Object getMessageListener() { return this.messageListener; } @@ -428,8 +414,7 @@ public void setSubscriptionName(@Nullable String subscriptionName) { * 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 void setDurableSubscriptionName(@Nullable String durableSubscriptionName) /** * 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 void setReplyQosSettings(@Nullable QosSettings replyQosSettings) { } @Override - @Nullable - public QosSettings getReplyQosSettings() { + public @Nullable QosSettings getReplyQosSettings() { return this.replyQosSettings; } @@ -534,8 +517,7 @@ public void setMessageConverter(@Nullable MessageConverter messageConverter) { } @Override - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { return this.messageConverter; } @@ -551,8 +533,7 @@ public void setExceptionListener(@Nullable ExceptionListener exceptionListener) * 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 void setErrorHandler(@Nullable ErrorHandler errorHandler) { * 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 void setObservationRegistry(@Nullable ObservationRegistry observationRegi * {@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 71c4ad360de3..9de98b612761 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.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 void setTransactionManager(@Nullable PlatformTransactionManager transacti * 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 @@ private void rollbackOnException(PlatformTransactionManager manager, Transaction * @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 @@ protected void noMessageReceived(Object invoker, Session session) { * @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 @@ protected Connection getConnection(JmsResourceHolder holder) { * @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 @@ protected Session getSession(JmsResourceHolder holder) { 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 91975cb88b71..165315f138ee 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.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.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 final boolean isRecovering() { */ 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 @@ private class AsyncMessageListenerInvoker implements SchedulingAwareRunnable { 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 a1fd33b3b1d5..90766c96ccba 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 e445eb34e1c4..5a32cf955009 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.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 8bb8d92c5ca1..fbfebabf9f76 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.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.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 void setMessageConverter(@Nullable MessageConverter messageConverter) { * 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 void setResponseQosSettings(@Nullable QosSettings responseQosSettings) { * 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 @@ protected Destination getResponseDestination(Message request, Message response, * @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 @@ protected class LazyResolutionMessage implements org.springframework.messaging.M 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 0bd717501649..e0ce32085ca3 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 @@ 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 T getResponse() { * @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 f30c2e4b8e43..ca4b1aff0582 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.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 @@ protected Object[] buildListenerArguments(Object extractedMessage) { * @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 6518a5cd51d9..973abcba992d 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 @@ 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 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageListener implements SubscriptionNameProvider { - @Nullable - private InvocableHandlerMethod handlerMethod; + private @Nullable InvocableHandlerMethod handlerMethod; /** @@ -103,8 +102,7 @@ protected Message toMessagingMessage(jakarta.jms.Message jmsMessage) { * 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 57f5b0228924..bb8b651007d8 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 ec1d22184b5f..d6c7f1b54125 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 @@ 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 void setReplyQosSettings(@Nullable QosSettings replyQosSettings) { this.replyQosSettings = replyQosSettings; } - @Nullable - public QosSettings getReplyQosSettings() { + public @Nullable QosSettings getReplyQosSettings() { return this.replyQosSettings; } @@ -154,8 +145,7 @@ public void setSubscriptionName(@Nullable String subscriptionName) { this.subscriptionName = subscriptionName; } - @Nullable - public String getSubscriptionName() { + public @Nullable String getSubscriptionName() { return this.subscriptionName; } @@ -164,8 +154,7 @@ public void setDurableSubscriptionName(@Nullable String durableSubscriptionName) this.subscriptionDurable = (durableSubscriptionName != null); } - @Nullable - public String getDurableSubscriptionName() { + public @Nullable String getDurableSubscriptionName() { return (this.subscriptionDurable ? this.subscriptionName : null); } @@ -173,8 +162,7 @@ public void setClientId(@Nullable String clientId) { this.clientId = clientId; } - @Nullable - public String getClientId() { + public @Nullable String getClientId() { return this.clientId; } @@ -182,8 +170,7 @@ public void setMessageSelector(@Nullable String messageSelector) { this.messageSelector = messageSelector; } - @Nullable - public String getMessageSelector() { + public @Nullable String getMessageSelector() { return this.messageSelector; } @@ -297,8 +284,7 @@ public void setMessageConverter(@Nullable MessageConverter messageConverter) { /** * 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 6a164236d715..7769ec8351d1 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.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 @@ */ 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 64e380f8137b..4dc7290ae4ea 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 @@ 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.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 void setActivationSpecConfig(@Nullable JmsActivationSpecConfig activation * 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 void setupMessageListener(Object messageListener) { } @Override - @Nullable - public MessageConverter getMessageConverter() { + public @Nullable MessageConverter getMessageConverter() { JmsActivationSpecConfig config = getActivationSpecConfig(); if (config != null) { return config.getMessageConverter(); @@ -201,8 +198,7 @@ public MessageConverter getMessageConverter() { } @Override - @Nullable - public DestinationResolver getDestinationResolver() { + public @Nullable DestinationResolver getDestinationResolver() { if (this.activationSpecFactory instanceof StandardJmsActivationSpecFactory standardFactory) { return standardFactory.getDestinationResolver(); } @@ -228,8 +224,7 @@ public boolean isReplyPubSubDomain() { } @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 81232764d511..62d312cc050b 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.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 @@ */ 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 void setDestinationResolver(@Nullable DestinationResolver destinationReso /** * 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 ActivationSpec createActivationSpec(ResourceAdapter adapter, JmsActivatio * 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 23a0e183cd40..98a6278d912c 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 2652ddc6f189..c7b7c404f4d2 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 e114d09c017c..5c68e46f6604 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 5145749e7fb8..f963c9aebf38 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.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 void setConnectionFactory(@Nullable ConnectionFactory connectionFactory) * 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 3523c7808ba6..17534797b58a 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.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 @@ protected JmsMessageHeaderAccessor(Message message) { * 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 String getCorrelationId() { * 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 Destination getDestination() { * 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 Integer getDeliveryMode() { * 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 Long getExpiration() { * 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 String getMessageId() { * 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 Integer getPriority() { * 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 Destination getReplyTo() { * 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 Boolean getRedelivered() { * 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 String getType() { * @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 b4815924fa10..d5a88a35458a 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.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.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 static void rollbackIfNecessary(Session session) throws JMSException { * @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 39ee533489c4..117566562786 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 50e1099a4091..f45a140f1c8f 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.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 @@ protected JavaType getJavaTypeForMessage(Message message) throws JMSException { * 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 afea54c559c2..1bada096ffd4 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.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 @@ */ 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 e6ba699751d0..142a6e4be831 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 188ff2348428..117ca437eca9 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 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 3a6468d78c83..a2cc701b09cc 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 @@ 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 53c46520b704..97a800b9b435 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 291e7a3d0790..0bd70301939d 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 @@ 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 @@ */ 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 ce3e74f1cdab..63faba406595 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 ddc273729ab6..c7a8f178a2d4 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 @@ 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 0a1d885f7ef5..331e6457ceb2 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.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 6711e7030f72..15fdc84e69a7 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.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 @@ protected Destination resolveDestinationName(Session session, String destination * @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 b27d883a0884..ae9b29e4b667 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.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 91b3c3e50211..b7b8c73afc1f 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 34433006917d..e85dac873ecb 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 b158f8c3464a..b592219d2a8e 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 @@ 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.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 7ce757365866..18128bd1df99 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.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.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 82f5f08918ba..bffebc7d6957 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.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 3dee45d9b93e..392060c75522 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.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 f73fafb8960e..9a1ad8dcbeb3 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 5d0f0d2c85fe..c7cdb761e7f2 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 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 @@ protected static IdGenerator getIdGenerator() { 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 Set> entrySet() { } @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 bd2f8d26af1d..05ed6d76e6cd 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 @@ @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 MessagingException(Message message, @Nullable String description, @Nul } - @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 1dc0ba778074..8bedc2814ffe 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 a73dccd77baa..a837d6fc2f0e 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.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 @@ protected boolean supports(Class clazz) { } @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 @@ else if (payload instanceof byte[] bytes) { } @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 60c88c0ea9a8..2c3249b0240e 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 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 void setContentTypeResolver(@Nullable ContentTypeResolver resolver) { * Return the {@link #setContentTypeResolver(ContentTypeResolver) configured} * {@code ContentTypeResolver}. */ - @Nullable - public ContentTypeResolver getContentTypeResolver() { + public @Nullable ContentTypeResolver getContentTypeResolver() { return this.contentTypeResolver; } @@ -169,14 +167,12 @@ public Class getSerializedPayloadClass() { @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 final Object fromMessage(Message message, Class targetClass, @Nulla } @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 @@ protected boolean supportsMimeType(@Nullable MessageHeaders headers) { 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 @@ protected MimeType getMimeType(@Nullable MessageHeaders headers) { * @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 @@ protected MimeType getDefaultContentType(Object payload) { * 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 @@ protected Object convertFromInternal( * 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 0a26c82f0dad..8762b6cab46e 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 @@ protected boolean supports(Class clazz) { } @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 0c46db923453..cc803975dcc0 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.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 CompositeMessageConverter(Collection converters) { @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 Object fromMessage(Message message, Class targetClass) { } @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 Object fromMessage(Message message, Class targetClass, @Nullable Ob } @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 Message toMessage(Object payload, @Nullable MessageHeaders headers) { } @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 b116e8bdb8a4..61440abbe0fb 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 8dca8058c291..77bba894611b 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 @@ */ public class DefaultContentTypeResolver implements ContentTypeResolver { - @Nullable - private MimeType defaultMimeType; + private @Nullable MimeType defaultMimeType; /** @@ -49,15 +49,13 @@ public void setDefaultMimeType(@Nullable MimeType defaultMimeType) { * 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 fbe8165b98db..1b55d55b5368 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 GenericMessageConverter(ConversionService conversionService) { @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 d43e991870fb..56bd08feeaec 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.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 @@ protected boolean supports(Class clazz) { } @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 @@ else if (payload instanceof byte[] bytes) { } @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 @@ protected Object convertToInternal(Object payload, @Nullable MessageHeaders head * @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 0821559db609..92653d96ce82 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.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 @@ */ 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 void setMarshaller(@Nullable Marshaller marshaller) { /** * Return the configured Marshaller. */ - @Nullable - public Marshaller getMarshaller() { + public @Nullable Marshaller getMarshaller() { return this.marshaller; } @@ -117,8 +115,7 @@ public void setUnmarshaller(@Nullable Unmarshaller unmarshaller) { /** * Return the configured unmarshaller. */ - @Nullable - public Unmarshaller getUnmarshaller() { + public @Nullable Unmarshaller getUnmarshaller() { return this.unmarshaller; } @@ -142,8 +139,7 @@ protected boolean supports(Class clazz) { } @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 @@ private Source getSource(Object payload) { } @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 3a6922a2fca6..68ab72732553 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 84d95e6d7d4a..3de08c007ec0 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 62fa2c620651..17f300fd2d5e 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 @@ 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 ProtobufJsonFormatMessageConverter(@Nullable ExtensionRegistry extensionR * 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 ProtobufJsonFormatMessageConverter( * 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 bab066d23b13..e3ae17469707 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 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 @@ static class ProtobufJavaUtilSupport implements ProtobufFormatSupport { 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 9f2407300ce0..ba5fd5040c44 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 @@ 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 cba7ff9c2a6e..5120b1a6a28f 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 9bcfcc93a4ca..85293e9baf61 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 @@ 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 @@ protected Object convertFromInternal(Message message, Class targetClass, @ } @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 c5dcb046af75..3a76fc8b7a77 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 d16dda9f5634..3b29c9843429 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 @@ 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 void setDestinationResolver(@Nullable DestinationResolver destinationR /** * Return the configured destination resolver. */ - @Nullable - public DestinationResolver getDestinationResolver() { + public @Nullable DestinationResolver getDestinationResolver() { return this.destinationResolver; } @@ -102,36 +101,31 @@ public void convertAndSend(String destinationName, T payload, } @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 T convertSendAndReceive(String destinationName, Object request, } @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 T convertSendAndReceive(String destinationName, Object request, Class } @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 ab869001986d..518faee93491 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 Message receive(D destination) { * @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 T receiveAndConvert(D destination, Class targetClass) { * @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 699dabe9e231..9e012166b761 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 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 void setDefaultDestination(@Nullable D defaultDestination) { /** * Return the configured default destination. */ - @Nullable - public D getDefaultDestination() { + public @Nullable D getDefaultDestination() { return this.defaultDestination; } @@ -194,8 +192,7 @@ protected Message doConvert(Object payload, @Nullable Map hea * @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 2814e3512c29..9911e7734e66 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 @@ 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 T convertSendAndReceive(D destination, Object request, Class targe @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 3ff3cd6826ef..3a189a9a49b8 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 @@ 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 bf83792123f8..240cb82a8eef 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 @@ 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 282b4a2de831..17899462d6d2 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 b85f20622cb5..035b97dcbaba 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 16c3e4e4e163..f90dc2235da0 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 @@ 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 @@ T convertSendAndReceive(String destinationName, Object request, Class tar * @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 @@ T convertSendAndReceive(String destinationName, Object request, * @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 @@ T convertSendAndReceive(String destinationName, Object request, Class tar * @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 6abe4dda58be..4a40707d7ed4 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 @@ 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 95952f4b0b9f..a6e82711b630 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 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 @@ else if (message.getHeaders().containsKey(this.sendTimeoutHeader) } @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 @@ protected final Message doReceive(MessageChannel channel, long timeout) { } @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 @@ private long receiveTimeout(Message requestMessage) { 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 @@ private static final class TemporaryReplyChannel implements PollableChannel { private final boolean throwExceptionOnLateReply; - @Nullable - private volatile Message replyMessage; + private volatile @Nullable Message replyMessage; private volatile boolean hasReceived; @@ -302,14 +297,12 @@ public void setSendFailed(boolean hasSendError) { } @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 18a1062f2d59..2079db56fd3a 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 249fa9c66801..83882510dc0a 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 @@ 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 @@ T convertSendAndReceive( * @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 @@ T convertSendAndReceive( * @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 @@ T convertSendAndReceive(D destination, Object request, Class targetClass, * @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 93944974a0ff..f961d0dc7957 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 @@ 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 ed87d0e45aea..41eb9cd090fd 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 1df91f749549..085ce64ac536 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 @@ 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 d9c908fb9284..75f6f482d9e7 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.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 @@ private > T combine(MessageCondition first, Mes } @Override - @Nullable - public CompositeMessageCondition getMatchingCondition(Message 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 bdb6e23dec39..4035666940bc 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.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 @@ else if (!other.patterns.isEmpty()) { * 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 7dfd09c6f4dc..08ad08ea3863 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 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 @@ protected Class getContainingClass() { * resolved via {@link #createWithResolvedBean()}. * @since 4.3 */ - @Nullable - public HandlerMethod getResolvedFromHandlerMethod() { + public @Nullable HandlerMethod getResolvedFromHandlerMethod() { return this.resolvedFromHandlerMethod; } @@ -215,7 +212,7 @@ public int hashCode() { * 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 @@ protected void assertTargetBean(Method method, Object targetBean, Object[] args) } } - 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 e2547f08f778..9fb9b81e88d6 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 21216f1bf6d2..9d5eb345b880 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 94b592f067ba..a5ff0004bab8 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.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 @@ protected void registerReturnValueHints(ReflectionHints hints, Method method) { 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 3259288c04f6..07a9bff88d22 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 1a169e7294d9..22e8cb9d0329 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 @@ 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.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 @@ protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionS @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 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu * 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 @@ private Object resolveEmbeddedValuesAndExpressions(String value) { * @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 @@ private Object resolveEmbeddedValuesAndExpressions(String value) { * 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 @@ protected static class NamedValueInfo { 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 6cd3f07f08cf..367241fbc1ab 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 @@ 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 0c632ee931bf..35f752b11d83 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 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 @@ protected Object resolveArgumentInternal(MethodParameter parameter, Message m 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 @@ private Object getNativeHeaderValue(Message message, String name) { } @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 3912b97ce22e..86cff187003f 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 @@ 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 boolean supportsParameter(MethodParameter parameter) { } @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 850fefbf1759..6a910678fe68 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.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.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 void setValidator(@Nullable Validator validator) { /** * Return the configured Validator instance. */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return this.validator; } @@ -151,8 +147,7 @@ public void setRouteMatcher(@Nullable RouteMatcher routeMatcher) { * Return the {@code RouteMatcher} used to map messages to handlers. * May be {@code null} before the component is initialized. */ - @Nullable - public RouteMatcher getRouteMatcher() { + public @Nullable RouteMatcher getRouteMatcher() { return this.routeMatcher; } @@ -272,8 +267,7 @@ protected List initReturnValueHandler @Override - @Nullable - protected CompositeMessageCondition getMappingForMethod(Method method, Class handlerType) { + protected @Nullable CompositeMessageCondition getMappingForMethod(Method method, Class handlerType) { CompositeMessageCondition methodCondition = getCondition(method); if (methodCondition != null) { CompositeMessageCondition typeCondition = getCondition(handlerType); @@ -289,8 +283,7 @@ protected CompositeMessageCondition getMappingForMethod(Method method, Class * @param element the element to check * @return the condition, or {@code null} */ - @Nullable - protected CompositeMessageCondition getCondition(AnnotatedElement element) { + protected @Nullable CompositeMessageCondition getCondition(AnnotatedElement element) { MessageMapping ann = AnnotatedElementUtils.findMergedAnnotation(element, MessageMapping.class); if (ann == null || ann.value().length == 0) { return null; @@ -326,15 +319,13 @@ protected Set getDirectLookupMappings(CompositeMessageCondition mapping) } @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); } @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 53004446d1cd..dbf352a148c9 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 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.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 List> getDecoders() { /** * Return the configured validator, if any. */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return this.validator; } @@ -196,8 +194,7 @@ private MethodArgumentResolutionException getUnexpectedPayloadError( * {@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 @@ private MethodArgumentResolutionException handleMissingBody(MethodParameter para "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 cd1dcb8aba17..923889f9d850 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 fd17f5e1f7ec..2e8cab2909d8 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 @@ 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.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 @@ protected AbstractNamedValueMethodArgumentResolver(ConversionService conversionS @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 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu * 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 @@ private Object resolveEmbeddedValuesAndExpressions(String value) { * @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 @@ protected abstract Object resolveArgumentInternal(MethodParameter parameter, Mes * 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 @@ protected static class NamedValueInfo { 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 b1022ff357d8..4637549f67a5 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.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 ad80d5922dc1..7caab83952e5 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 @@ 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 e6b50f058631..e5b120ce5572 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 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 @@ protected Object resolveArgumentInternal(MethodParameter parameter, Message m 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 @@ private Object getNativeHeaderValue(Message message, String name) { } @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 1981c1b254d5..b4d3cce6bdfd 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 @@ 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 boolean supportsParameter(MethodParameter parameter) { } @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 46f5c77884f1..4cac2c3a0e04 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 @@ 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 @@ */ 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 9ab9da75ed6f..c581f86a6946 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 @@ @SuppressWarnings("serial") public class MethodArgumentNotValidException extends MethodArgumentResolutionException { - @Nullable - private final BindingResult bindingResult; + private final @Nullable BindingResult bindingResult; /** @@ -60,8 +60,7 @@ public MethodArgumentNotValidException(Message message, MethodParameter param * 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 e38629fbeeae..b6bd7c14c816 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 @@ 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 boolean supportsParameter(MethodParameter parameter) { } @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 494657e5c675..43dd5f21e721 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 38801e420d80..85279806e1f1 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 1c5b1593c847..dfd7ea3342b1 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.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 boolean hasExceptionMappings() { * @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 Method resolveMethod(Throwable exception) { * @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 Method resolveMethodByExceptionType(Class exceptionT * 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 c469fe0db2d5..99279d4827c9 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 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 void setApplicationContext(@Nullable ApplicationContext applicationContex this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -343,8 +340,7 @@ private String formatMappings(Class userType, Map methods) { * @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 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) { * 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 @@ protected Log getReturnValueHandlerLogger() { * 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 void handleMessage(Message message) throws MessagingException { 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 void handleMessage(Message message) throws MessagingException { *

    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 @@ private void addMatchesToCollection(Collection mappingsToCheck, Message me * @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 @@ protected void processHandlerMethodException(HandlerMethod handlerMethod, Except * @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 876329c2e238..cff9ff3fede1 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 @@ 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 4d1c17f95d99..3a49369a181e 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 966fa7083496..5b89bb8cda59 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.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 boolean supportsParameter(MethodParameter parameter) { * @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 Object resolveArgument(MethodParameter parameter, Message message) thr * 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 3dca2443cc4c..ca768b7d7f89 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 5e3ed7e3a8a0..d2b43df03157 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 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 boolean supportsReturnType(MethodParameter returnType) { } @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 boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType } @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 cc74ad6ed900..c3a6ce5609af 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.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 void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc * @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 Object invoke(Message message, @Nullable Object... providedArgs) throw *

    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 @@ protected Object[] getMethodArgumentValues(Message message, @Nullable Object. /** * 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 @@ MethodParameter getAsyncReturnValueType(@Nullable Object returnValue) { 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 21a795a807eb..1e4f6e1e156b 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 18a5948f64d2..73cf3412dbc3 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 @@ 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 boolean isAsyncReturnValue(Object returnValue, MethodParameter returnType } @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 eb05eec33d8e..1fa831548820 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 bfb05d91ed84..5d5d5198aa18 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 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.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 @@ else if (type != ResolvableType.NONE) { } } - @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 c8731bfc49d2..145a1b214a13 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 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.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 void setHandlerPredicate(@Nullable Predicate> handlerPredicate) /** * Return the {@link #setHandlerPredicate configured} handler predicate. */ - @Nullable - public Predicate> getHandlerPredicate() { + public @Nullable Predicate> getHandlerPredicate() { return this.handlerPredicate; } @@ -193,8 +188,7 @@ public void setApplicationContext(@Nullable ApplicationContext applicationContex this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -365,8 +359,7 @@ private String formatMappings(Class userType, Map methods) { * @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 @@ protected Mono handleMatch(T mapping, HandlerMethod handlerMethod, Message 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 @@ private Match getHandlerMethod(Message message) { * 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 @@ private void addMatchesToCollection( * @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 @@ private void addMatchesToCollection( * @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 0edef96cf256..2c77297a77f6 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 @@ 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 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 @@ public ChannelSendOperator(Publisher source, Function, @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 @@ private class WriteBarrier implements CoreSubscriber, Subscription, Publisher 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 @@ private class WriteBarrier implements CoreSubscriber, Subscription, Publisher 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 @@ private class WriteCompletionBarrier implements CoreSubscriber, Subscripti 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 fc73bf63dea7..5ea4d42cde2a 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 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 Mono resolveArgument(MethodParameter parameter, Message messag * 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 4d0efbdeb6b8..7628048e1484 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 724fc8b650d0..ebe91fee7ee9 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 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 Mono handleReturnValue(@Nullable Object returnValue, MethodParamete } @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 ccb9c3c198b3..91a0cd9fe4af 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 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 @@ public InvocableHandlerMethod initMessageMappingMethod(HandlerMethod handlerMeth * @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 e933104d5c40..8a4f05369769 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 @@ default Mono resolveArgument(MethodParameter parameter, Message messa * @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 27a85c242db9..a4d42cb5fe7e 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 d4ae3f87b9d2..9ca6dcb80926 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 875d7b5b727c..2d31f80a4e37 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 9db72199ddb2..d791cc8f5e67 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.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 43ea6d6f64b3..73117463fd38 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 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.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 @@ public RSocketClient rsocketClient() { return this.rsocketClient; } - @Nullable @Override - public RSocket rsocket() { + public @Nullable RSocket rsocket() { return this.rsocket; } @@ -132,11 +130,9 @@ private class DefaultRequestSpec implements RequestSpec { 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 @@ public RequestSpec data(Object producer, Class elementClass) { 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 e3a045d7f20a..fb2a63595c45 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.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.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 ec6ceab06bc0..385d3036c3f9 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.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.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 @@ static class DefaultRSocketStrategiesBuilder implements RSocketStrategies.Builde 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 507745c7e127..5f153b3c39b2 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.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.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 @@ else if (!this.metadataMimeType.equals(mimeType)) { * 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 667e02cd3022..4856cf398ca9 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 @@ 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 2c946d5c3137..baac049c56bf 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.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 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 8e8a43a10f16..914deca8a18e 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.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.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 ed54c26543bb..272bc6591bed 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 b7686c46f5e4..163fc0a65181 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.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 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 e8167a3f1402..111a8f6b8efb 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.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 @@ protected String getToStringInfix() { * @param message the current message * @return the frame type or {@code null} if not found */ - @Nullable - public static FrameType getFrameType(Message message) { + public static @Nullable FrameType getFrameType(Message message) { return (FrameType) message.getHeaders().get(RSocketFrameTypeMessageCondition.FRAME_TYPE_HEADER); } @@ -134,8 +133,7 @@ public RSocketFrameTypeMessageCondition combine(RSocketFrameTypeMessageCondition } @Override - @Nullable - public RSocketFrameTypeMessageCondition getMatchingCondition(Message 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 d83119b1b7ff..a663a8b0d1da 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.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.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 void setDefaultDataMimeType(@Nullable MimeType mimeType) { * Return the configured * {@link #setDefaultDataMimeType defaultDataMimeType}, or {@code null}. */ - @Nullable - public MimeType getDefaultDataMimeType() { + public @Nullable MimeType getDefaultDataMimeType() { return this.defaultDataMimeType; } @@ -311,8 +309,7 @@ protected List initReturnValueHandler @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 @@ else if (parameter.nested().getNestedParameterType().equals(Void.class)) { } @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 78f8ce774b5b..dc86c82d7dfa 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.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.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 @@ protected Mono handleNoContent(MethodParameter returnType, Message mess 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 4c02159a3c0c..ee1caa3abef6 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 9cb5ed03acdf..5d33cca2d618 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 99b00160da2a..a1c822c16af7 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 @@ 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 3e89f95bede2..537fca18953e 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 b80c747bbdc2..bcb140458246 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 d9ed6be31461..f80a6743ad9a 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 @@ 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.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 @@ */ 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 4866b033f421..1666803f0889 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.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 @@ */ 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 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 Map getMetadata() { *

    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 Object getPayloadValue() { *

    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 static Builder builder(@Nullable String route) { */ 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 a15b97e86b70..a26f671f1baf 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 1b6c87f81746..acc60e3cb7d0 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.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.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 @@ private static MethodParameter[] initMethodParameters(Method method) { 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 @@ public Method getMethod() { 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 bfab89ed5789..3d449795c624 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 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 static Builder builder() { */ 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 @@ private ServiceMethodInterceptor(List methods) { } @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 65c6ba8c22df..e9dcd84d49c4 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 8946b6db20c6..7970fb17c48c 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 @@ 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 SimpAttributes(String sessionId, Map attributes) { * @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 6474d56afce7..8acde1194265 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 static void setAttributesFromMessage(Message message) { * 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 015db5c8dc37..dde426e0d504 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.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 void setMessageTypeIfNotSet(SimpMessageType messageType) { } } - @Nullable - public SimpMessageType getMessageType() { + public @Nullable SimpMessageType getMessageType() { return (SimpMessageType) getHeader(MESSAGE_TYPE_HEADER); } @@ -134,8 +133,7 @@ public void setDestination(@Nullable String destination) { setHeader(DESTINATION_HEADER, destination); } - @Nullable - public String getDestination() { + public @Nullable String getDestination() { return (String) getHeader(DESTINATION_HEADER); } @@ -143,8 +141,7 @@ public void setSubscriptionId(@Nullable String subscriptionId) { setHeader(SUBSCRIPTION_ID_HEADER, subscriptionId); } - @Nullable - public String getSubscriptionId() { + public @Nullable String getSubscriptionId() { return (String) getHeader(SUBSCRIPTION_ID_HEADER); } @@ -155,8 +152,7 @@ public void setSessionId(@Nullable String sessionId) { /** * 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 void setSessionAttributes(@Nullable Map attributes) { * 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 void setUser(@Nullable Principal principal) { /** * 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 static SimpMessageHeaderAccessor wrap(Message message) { 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 4523714ecccf..9131c291ada3 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 SimpMessageMappingInfo combine(SimpMessageMappingInfo other) { } @Override - @Nullable - public SimpMessageMappingInfo getMatchingCondition(Message 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 e1cac48b59b8..11583e51390e 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 @@ 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 522cd82fc700..e8bfa3145847 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.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 SimpMessageTypeMessageCondition combine(SimpMessageTypeMessageCondition o } @Override - @Nullable - public SimpMessageTypeMessageCondition getMatchingCondition(Message 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 fdd5f357a771..89c7f64a6b1f 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 @@ 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 objectFactory) { } @Override - @Nullable - public Object remove(String name) { + public @Nullable Object remove(String name) { SimpAttributes simpAttributes = SimpAttributesContextHolder.currentAttributes(); synchronized (simpAttributes.getSessionMutex()) { Object value = simpAttributes.getAttribute(name); @@ -71,8 +71,7 @@ public void registerDestructionCallback(String name, Runnable callback) { } @Override - @Nullable - public Object resolveContextualObject(String key) { + public @Nullable Object resolveContextualObject(String key) { return null; } diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/package-info.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/package-info.java index c121def42dba..baf6f519294e 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/package-info.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/package-info.java @@ -1,9 +1,7 @@ /** * Annotations and for handling messages from Simple Messaging Protocols such as STOMP. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.messaging.simp.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/simp/annotation/support/PrincipalMethodArgumentResolver.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolver.java index 524f4b973d2f..156f6e85193a 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolver.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/annotation/support/PrincipalMethodArgumentResolver.java @@ -19,8 +19,9 @@ import java.security.Principal; 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.handler.invocation.HandlerMethodArgumentResolver; import org.springframework.messaging.simp.SimpMessageHeaderAccessor; @@ -41,8 +42,7 @@ public boolean supportsParameter(MethodParameter parameter) { } @Override - @Nullable - public Object resolveArgument(MethodParameter parameter, Message 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 44bc35404c5f..042265f3a967 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.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 void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -208,8 +207,7 @@ private DestinationHelper getDestinationHelper(MessageHeaders headers, MethodPar 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 @@ private class DestinationHelper { 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 @@ private Map getTemplateVariables(MessageHeaders headers) { 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 caefa70ac49c..fd974e599405 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.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.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 void setDestinationPrefixes(@Nullable Collection prefixes) { 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 PathMatcher getPathMatcher() { /** * Return the configured Validator instance. */ - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return this.validator; } @@ -269,8 +263,7 @@ public void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -396,8 +389,7 @@ protected boolean isHandler(Class beanType) { } @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 @@ protected Set getDirectLookupDestinations(SimpMessageMappingInfo mapping } @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 @@ protected String getLookupDestination(@Nullable String destination) { } @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 8ff4d521a2fe..f6d316ec8145 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 void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia /** * 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 bc4b50f166d1..c5810b2e5507 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 7c17734e0652..7ddf02c8252e 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.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 void setApplicationEventPublisher(@Nullable ApplicationEventPublisher pub 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 078ed325a7ac..76798f769a09 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.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.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 void setSelectorHeaderName(@Nullable String selectorHeaderName) { * @since 4.2 * @see #setSelectorHeaderName(String) */ - @Nullable - public String getSelectorHeaderName() { + public @Nullable String getSelectorHeaderName() { return this.selectorHeaderName; } @@ -165,8 +164,7 @@ protected void addSubscriptionInternal( 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 @@ private static final class SessionRegistry { 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 void addSubscription(String sessionId, Subscription subscription) { 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 Collection getSubscriptions() { 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 void addSubscription(Subscription subscription) { 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 @@ private static final class Subscription { 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 boolean isPattern() { 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 5d26ccbea72f..0d20c2c71c20 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.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 static boolean supportsOrderedMessages(MessageChannel channel) { /** * 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 @@ private final class PostHandleTask implements Runnable { 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 80bcfe99e473..bd1703c89e81 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.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 void setTaskScheduler(@Nullable TaskScheduler taskScheduler) { * Return the configured TaskScheduler. * @since 4.2 */ - @Nullable - public TaskScheduler getTaskScheduler() { + public @Nullable TaskScheduler getTaskScheduler() { return this.taskScheduler; } @@ -226,7 +219,7 @@ public TaskScheduler getTaskScheduler() { * (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 void setHeartbeatValue(@Nullable long[] heartbeat) { * 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 void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia * Return the configured header initializer. * @since 4.1 */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -444,8 +435,7 @@ private static class SessionInfo { private final String sessionId; - @Nullable - private final Principal user; + private final @Nullable Principal user; private final MessageChannel clientOutboundChannel; @@ -459,7 +449,7 @@ private static class SessionInfo { 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 String getSessionId() { 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 afc2f7016ca5..3059a03c42ec 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 37c2d3b40022..194bc027f9e4 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.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 9c505329dc65..b55bda3dc000 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.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 void setApplicationContext(@Nullable ApplicationContext applicationContex this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -324,8 +319,7 @@ protected void configureMessageBroker(MessageBrokerRegistry registry) { * 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 @@ protected void addReturnValueHandlers(List retu } @Bean - @Nullable - public AbstractBrokerMessageHandler simpleBrokerMessageHandler( + public @Nullable AbstractBrokerMessageHandler simpleBrokerMessageHandler( AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, AbstractSubscribableChannel brokerChannel, UserDestinationResolver userDestinationResolver) { @@ -414,8 +407,7 @@ private void updateUserDestinationResolver( } @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 UserDestinationMessageHandler userDestinationMessageHandler( } @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 void validate(@Nullable Object target, Errors errors) { * 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 ad8649587ace..f6d63f0e9e3d 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.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 @@ */ 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 45caca7de75f..a2892b4a56d6 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 @@ 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 @@ protected ChannelRegistration getBrokerChannelRegistration() { 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 MessageBrokerRegistry setApplicationDestinationPrefixes(String... prefixe return this; } - @Nullable - protected Collection getApplicationDestinationPrefixes() { + protected @Nullable Collection getApplicationDestinationPrefixes() { return (this.applicationDestinationPrefixes != null ? Arrays.asList(this.applicationDestinationPrefixes) : null); } @@ -161,8 +152,7 @@ public MessageBrokerRegistry setUserDestinationPrefix(String destinationPrefix) return this; } - @Nullable - protected String getUserDestinationPrefix() { + protected @Nullable String getUserDestinationPrefix() { return this.userDestinationPrefix; } @@ -177,8 +167,7 @@ public void setUserRegistryOrder(int order) { this.userRegistryOrder = order; } - @Nullable - protected Integer getUserRegistryOrder() { + protected @Nullable Integer getUserRegistryOrder() { return this.userRegistryOrder; } @@ -204,8 +193,7 @@ public MessageBrokerRegistry setPathMatcher(PathMatcher pathMatcher) { return this; } - @Nullable - protected PathMatcher getPathMatcher() { + protected @Nullable PathMatcher getPathMatcher() { return this.pathMatcher; } @@ -236,8 +224,7 @@ public MessageBrokerRegistry setPreservePublishOrder(boolean preservePublishOrde 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 @@ protected SimpleBrokerMessageHandler getSimpleBroker(SubscribableChannel brokerC 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 628914a9d78c..99b14b5ad130 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 @@ */ 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 417a4dcab50c..333651492f41 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 StompBrokerRelayRegistration setUserDestinationBroadcast(String destinati return this; } - @Nullable - protected String getUserDestinationBroadcast() { + protected @Nullable String getUserDestinationBroadcast() { return this.userDestinationBroadcast; } @@ -254,8 +247,7 @@ public StompBrokerRelayRegistration setUserRegistryBroadcast(String destination) 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 f9cfdb07ad2a..89141906fe12 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 09947fad0c32..21b960eb753a 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 2907d6c3322b..c6b727907e8f 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 b7c9e1e32238..ad57a7a265d5 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.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 int getBufferSize() { /** * 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 3ecbe0a799e9..84b549aaa407 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.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 void setTaskScheduler(@Nullable TaskScheduler taskScheduler) { /** * 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 Receiptable send(StompHeaders headers, Object payload) { 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 @@ private void resetConnection() { 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 @@ private void initReceiptHandling() { } @Override - @Nullable - public String getReceiptId() { + public @Nullable String getReceiptId() { return this.receiptId; } @@ -671,8 +661,7 @@ public DefaultSubscription(StompHeaders headers, StompFrameHandler handler) { } @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 e321e19f6670..8548c41a276d 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 @@ 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 811157d51a28..f8a1daaed962 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.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 void setVirtualHost(@Nullable String virtualHost) { /** * Return the configured virtual host value. */ - @Nullable - public String getVirtualHost() { + public @Nullable String getVirtualHost() { return this.virtualHost; } @@ -371,8 +367,7 @@ public void setTcpClient(@Nullable TcpOperations tcpClient) { * 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 void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -429,8 +423,7 @@ public void setTaskScheduler(@Nullable TaskScheduler taskScheduler) { this.taskScheduler = taskScheduler; } - @Nullable - public TaskScheduler getTaskScheduler() { + public @Nullable TaskScheduler getTaskScheduler() { return this.taskScheduler; } @@ -644,15 +637,13 @@ private class RelayConnectionHandler implements StompTcpConnectionHandler 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 StompHeaderAccessor getConnectHeaders() { 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 03df60b74675..f699ea41bca5 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 @@ 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 void setTaskScheduler(@Nullable TaskScheduler taskScheduler) { /** * 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 442c4301acc4..f3a2c800576c 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.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 void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia /** * Return the configured {@code MessageHeaderInitializer}, if any. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -129,9 +127,8 @@ public List> decode(ByteBuffer byteBuffer, /** * 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 @@ else if (c == '\\') { 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 8d9da03c4252..29b7e0e2d224 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.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 a0a9448e1080..037e305fbfeb 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 @@ 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 44fec8110a4f..6320d9f3a317 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.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 @@ protected MessageHeaderAccessor createAccessor(Message message) { // Redeclared for visibility within simp.stomp @Override - @Nullable - protected Map> getNativeHeaders() { + protected @Nullable Map> getNativeHeaders() { return super.getNativeHeaders(); } @@ -228,8 +228,7 @@ else if (!StompCommand.MESSAGE.equals(command)) { /** * 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 void setHost(@Nullable String host) { setNativeHeader(STOMP_HOST_HEADER, host); } - @Nullable - public String getHost() { + public @Nullable String getHost() { return getFirstNativeHeader(STOMP_HOST_HEADER); } @@ -300,8 +298,7 @@ private void trySetStompHeaderForSubscriptionId() { } } - @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 void setAck(@Nullable String ack) { setNativeHeader(STOMP_ACK_HEADER, ack); } - @Nullable - public String getAck() { + public @Nullable String getAck() { return getFirstNativeHeader(STOMP_ACK_HEADER); } @@ -327,8 +323,7 @@ public void setNack(@Nullable String nack) { setNativeHeader(STOMP_NACK_HEADER, nack); } - @Nullable - public String getNack() { + public @Nullable String getNack() { return getFirstNativeHeader(STOMP_NACK_HEADER); } @@ -336,8 +331,7 @@ public void setLogin(@Nullable String login) { setNativeHeader(STOMP_LOGIN_HEADER, login); } - @Nullable - public String getLogin() { + public @Nullable String getLogin() { return getFirstNativeHeader(STOMP_LOGIN_HEADER); } @@ -357,8 +351,7 @@ private void protectPasscode() { /** * 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 void setReceiptId(@Nullable String receiptId) { 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 void setReceipt(@Nullable String receiptId) { 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 void setMessage(@Nullable String content) { setNativeHeader(STOMP_MESSAGE_HEADER, content); } - @Nullable - public String getMessageId() { + public @Nullable String getMessageId() { return getFirstNativeHeader(STOMP_MESSAGE_ID_HEADER); } @@ -399,8 +388,7 @@ public void setMessageId(@Nullable String id) { setNativeHeader(STOMP_MESSAGE_ID_HEADER, id); } - @Nullable - public String getVersion() { + public @Nullable String getVersion() { return getFirstNativeHeader(STOMP_VERSION_HEADER); } @@ -526,22 +514,19 @@ public static StompHeaderAccessor wrap(Message message) { /** * 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 ef253caa5745..f023946fb1c1 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.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 void setContentType(@Nullable MimeType mimeType) { /** * 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 void setReceipt(@Nullable String receipt) { /** * Get the receipt header. */ - @Nullable - public String getReceipt() { + public @Nullable String getReceipt() { return getFirst(RECEIPT); } @@ -195,8 +194,7 @@ public void setHost(@Nullable String host) { /** * Get the host header. */ - @Nullable - public String getHost() { + public @Nullable String getHost() { return getFirst(HOST); } @@ -205,7 +203,7 @@ public String getHost() { * 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 void setAcceptVersion(@Nullable String... acceptVersions) { * 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 void setLogin(@Nullable String login) { /** * Get the login header. */ - @Nullable - public String getLogin() { + public @Nullable String getLogin() { return getFirst(LOGIN); } @@ -253,8 +249,7 @@ public void setPasscode(@Nullable String passcode) { /** * Get the passcode header. */ - @Nullable - public String getPasscode() { + public @Nullable String getPasscode() { return getFirst(PASSCODE); } @@ -262,7 +257,7 @@ public String getPasscode() { * 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 void setHeartbeat(@Nullable long[] heartbeat) { /** * 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 void setSession(@Nullable String session) { /** * Get the session header. */ - @Nullable - public String getSession() { + public @Nullable String getSession() { return getFirst(SESSION); } @@ -326,8 +319,7 @@ public void setServer(@Nullable String server) { * 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 void setDestination(@Nullable String destination) { * 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 void setId(@Nullable String id) { /** * Get the id header. */ - @Nullable - public String getId() { + public @Nullable String getId() { return getFirst(ID); } @@ -374,8 +364,7 @@ public void setAck(@Nullable String ack) { /** * Get the ack header. */ - @Nullable - public String getAck() { + public @Nullable String getAck() { return getFirst(ACK); } @@ -390,8 +379,7 @@ public void setSubscription(@Nullable String subscription) { /** * Get the subscription header. */ - @Nullable - public String getSubscription() { + public @Nullable String getSubscription() { return getFirst(SUBSCRIPTION); } @@ -406,8 +394,7 @@ public void setMessageId(@Nullable String messageId) { /** * Get the message-id header. */ - @Nullable - public String getMessageId() { + public @Nullable String getMessageId() { return getFirst(MESSAGE_ID); } @@ -422,8 +409,7 @@ public void setReceiptId(@Nullable String receiptId) { /** * Get the receipt header. */ - @Nullable - public String getReceiptId() { + public @Nullable String getReceiptId() { return getFirst(RECEIPT_ID); } @@ -433,8 +419,7 @@ public String getReceiptId() { * @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 boolean containsValue(Object value) { } @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 94875b6d0a97..1af02d99ede0 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 @@ 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 @@ interface Receiptable { * 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 @@ interface Subscription extends Receiptable { /** * 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 c55b8b26f5d7..aefd083cce5b 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 2d57f14574b0..cc0b13afb99b 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 @@ 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 6b42fa754c88..d4b398bc07a7 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 822864ae09b4..f059866110d5 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.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 boolean isRemoveLeadingSlash() { @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 UserDestinationResult resolveDestination(Message message) { 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 @@ private ParseResult parse(Message message) { 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 @@ protected boolean checkDestination(String destination, String requiredPrefix) { * @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 @@ private static class ParseResult { 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 Set getSessionIds() { /** * 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 14d4c21df46f..f041968b5222 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.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 void onApplicationEvent(ApplicationEvent event) { // 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 @@ private static class TransferSimpUser implements SimpUser { 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 String getName() { return this.name; } - @Nullable @Override - public Principal getPrincipal() { + public @Nullable Principal getPrincipal() { return null; } @@ -327,8 +325,7 @@ public boolean hasSessions() { } @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 bcd0d6739273..677d467d5bfa 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 @@ 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 9847104d31cb..ded0e4d22145 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 @@ 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 9c8d24faaba8..ddd4226a6073 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.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 void setBroadcastDestination(@Nullable String destination) { /** * 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 void setHeaderInitializer(@Nullable MessageHeaderInitializer headerInitia /** * Return the configured header initializer. */ - @Nullable - public MessageHeaderInitializer getHeaderInitializer() { + public @Nullable MessageHeaderInitializer getHeaderInitializer() { return this.headerInitializer; } @@ -262,8 +257,7 @@ private static class SendHelper { 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 String getBroadcastDestination() { 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 95e5e4480874..1efb0315a644 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 aa74978e1f17..c47607bac9ab 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 @@ 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 String getSubscribeDestination() { * 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 eb55f0110e40..4696e3049d9d 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.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 bd59b706f119..95d5b632c1b2 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 c729f871f382..2405bcdf0ea9 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 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 @@ protected String toHeaderName(String propertyName) { * 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 d1d209e8af64..6c097e581429 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 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 @@ protected class ChannelInterceptorChain { 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 boolean applyPreReceive(MessageChannel channel) { 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 4dd9dbd7c2df..b83c54e369cf 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 @@ default boolean preReceive(MessageChannel channel) { * 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 e097701169eb..d0b31f6adcc0 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 @@ 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 ErrorMessage(Throwable payload, MessageHeaders headers, Message origin * 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 ef34ae90ec65..57d92d29be0d 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 1d8b56531d52..8875e6ba9f6c 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.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 @@ */ 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 ExecutorSubscribableChannel(@Nullable Executor executor) { } - @Nullable - public Executor getExecutor() { + public @Nullable Executor getExecutor() { return this.executor; } @@ -168,8 +167,7 @@ public void run() { } } - @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 72b06f560ad4..263f1660229a 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 @@ 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 cbd338cda89b..9c05c25d24c0 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 void setIdGenerator(@Nullable IdGenerator idGenerator) { /** * 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 028bbbc52470..73cd088c7500 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 @@ 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 ab39f57211b8..dff4c9ced00e 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.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 Map toMap() { * @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 @@ protected boolean isReadOnly(String headerName) { // 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 UUID getId() { 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 void setContentType(MimeType contentType) { 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 void setReplyChannel(MessageChannel replyChannel) { setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel); } - @Nullable - public Object getReplyChannel() { + public @Nullable Object getReplyChannel() { return getHeader(MessageHeaders.REPLY_CHANNEL); } @@ -491,8 +486,7 @@ public void setErrorChannel(MessageChannel errorChannel) { setHeader(MessageHeaders.ERROR_CHANNEL, errorChannel); } - @Nullable - public Object getErrorChannel() { + public @Nullable Object getErrorChannel() { return getHeader(MessageHeaders.ERROR_CHANNEL); } @@ -586,8 +580,7 @@ public String toString() { * @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 static MessageHeaderAccessor getAccessor(Message message) { * @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 static T getAccessor(Message message * @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 aafc1dcca400..e8ab4c98883b 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.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 @@ protected NativeMessageHeaderAccessor(@Nullable Message message) { * 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 boolean containsNativeHeader(String headerName) { * @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 List getNativeHeader(String headerName) { * @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 void addNativeHeaders(@Nullable MultiValueMap headers) { * @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 List removeNativeHeader(String headerName) { * @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 b2213f6a1634..cdc809c8792b 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 572866d39941..eebbc41975bb 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 2b940f2170cf..8eb670ba0051 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 624201cdcb2b..f8cace98efb3 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.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.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 35ff79fc7818..106496a3f903 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.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.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 0fbf6c5be757..976a3d45c031 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 320fd1adc121..adce141d90df 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 @@ 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 1c3c826fb0c4..82874614891a 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 @@ 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 static HeaderPredicate headerPlain() { 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 boolean test(MethodParameter parameter) { 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 da36141e3064..b63e3bf9dd50 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.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.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 @@ private DataBuffer toDataBuffer(String value) { @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 cdd1fcb27ad8..06b9fa532225 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 @@ 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 @@ public void invocationErrorMessage() { .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 31df4ee8cc66..47fc6b28a7ea 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 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.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 @@ private List applyFilters() { 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 Object intercept(Object object, Method method, @Nullable Object[] args, @ } @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 fb8e7db1bf26..a2010c444673 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 @@ 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 d07b83aed619..21c0fab5e55c 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 @@ 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 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 67eb668c3be2..1413e76e3d1c 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.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 @@ void voidMonoMethod() { } - @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 f48f5ce592ad..6078e83ff406 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.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 @@ protected List initReturnValueHandler return Collections.singletonList(this.returnValueHandler); } - @Nullable - public Object getLastReturnValue() { + public @Nullable Object getLastReturnValue() { return this.returnValueHandler.getLastReturnValue(); } @@ -238,8 +237,7 @@ protected Set getDirectLookupMappings(String mapping) { } @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 c5b5b9ecf0b5..12fe1000f26b 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 @@ 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 22ea181370fd..ba83bc7f44ee 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 @@ */ 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 9de9f9627aca..baf908d569ca 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 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.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 15580a3026b6..17332a4084e1 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 @@ 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 void setPayloadFluxToReturn(Flux payloadFluxToReturn) { 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 209c2fadfc98..f23fd0ae3526 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 @@ 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 f1f5ac9527d1..037bf9355224 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 @@ 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 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 ef1fe46c77c6..107e16b25138 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.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 @@ void process(Class beanClass) { } } - @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 7b534dcca8a2..6b7b5b5c3e64 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 @@ 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 @@ */ 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 7421a10d3c65..6369215aa854 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.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.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 3445bb0a32c7..e8ad5acb2573 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.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.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 65d54e36164c..36648bea3f20 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.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 a5d264067132..e127c17685c3 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.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 133116e9898b..a0926df29494 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 @@ 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 bad87cf42c44..5dc420936b25 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 @@ 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 548d820646bb..736568ac9d26 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.Map; import java.util.Set; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * @author Rossen Stoyanchev @@ -44,9 +44,8 @@ public String getName() { 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 e1ec61dd8905..0f2548f879e7 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 @@ 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 0799a5033ee1..8fc038ed6bf3 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 @@ @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 ObjectOptimisticLockingFailureException( * 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 getPersistentClass() { * 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 String getPersistentClassName() { /** * 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 54536f5d5705..7a359a7ca61c 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 @@ @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 ObjectRetrievalFailureException( * 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 getPersistentClass() { * 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 String getPersistentClassName() { /** * 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 38265a6f1f9d..084adf9fedcf 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.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 fc247d49f5b7..dcc9978498de 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 @@ 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 @@ */ public class HibernateExceptionTranslator implements PersistenceExceptionTranslator { - @Nullable - private SQLExceptionTranslator jdbcExceptionTranslator; + private @Nullable SQLExceptionTranslator jdbcExceptionTranslator; /** @@ -66,8 +65,7 @@ public void setJdbcExceptionTranslator(SQLExceptionTranslator jdbcExceptionTrans @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 3e3674502cbb..fad5469844bf 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 @@ 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 SQLException getSQLException() { /** * 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 1122c91a2498..68fa2a3e63ad 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 HibernateQueryException(QueryException ex) { /** * 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 5831fa0ba4f0..fba045573dc0 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 13c707d701d4..798ddbbad38d 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.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.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 @@ 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 void setSessionFactory(@Nullable SessionFactory sessionFactory) { /** * 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 void setDataSource(@Nullable DataSource dataSource) { /** * 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 void setEntityInterceptor(@Nullable Interceptor entityInterceptor) { * @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 @@ protected DataAccessException convertHibernateAccessException(HibernateException */ private class HibernateTransactionObject extends JdbcTransactionObjectSupport { - @Nullable - private SessionHolder sessionHolder; + private @Nullable SessionHolder sessionHolder; private boolean newSessionHolder; @@ -808,8 +799,7 @@ private class HibernateTransactionObject extends JdbcTransactionObjectSupport { 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 void setPreviousHoldability(@Nullable Integer previousHoldability) { this.previousHoldability = previousHoldability; } - @Nullable - public Integer getPreviousHoldability() { + public @Nullable Integer getPreviousHoldability() { return this.previousHoldability; } @@ -911,8 +900,7 @@ private static final class SuspendedResourcesHolder { 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 @@ private SessionHolder getSessionHolder() { 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 f0ee7c9f91c0..c810de1a150c 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.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.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 final Configuration getConfiguration() { @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 ad92e4b96084..004466170e48 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.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.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 a52839762836..92f126a54a7c 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.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.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 static void closeSession(@Nullable Session session) { * @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 261035a45da7..90ea49d2a82c 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 @@ 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 @@ */ 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 void setTransaction(@Nullable Transaction transaction) { setTransactionActive(transaction != null); } - @Nullable - public Transaction getTransaction() { + public @Nullable Transaction getTransaction() { return this.transaction; } @@ -68,8 +65,7 @@ public void setPreviousFlushMode(@Nullable FlushMode previousFlushMode) { 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 f4c0b4149f74..727d05d22ca5 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.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 @@ private static final class SpringContainedBean implements ContainedBean { 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 72f93fd7b64e..e444a8326fc6 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 ea814641ca2a..d57ca1942229 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.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 0ee67d0774f4..7b8f451af2ca 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 14edcf28026f..9a5540922560 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 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 dade7e24c863..49a24fcaae37 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.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 void setSessionFactory(@Nullable SessionFactory sessionFactory) { /** * 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 a2016e8314a1..267243c4c8cb 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.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 @@ */ public class OpenSessionInterceptor implements MethodInterceptor, InitializingBean { - @Nullable - private SessionFactory sessionFactory; + private @Nullable SessionFactory sessionFactory; /** @@ -64,8 +63,7 @@ public void setSessionFactory(@Nullable SessionFactory sessionFactory) { /** * 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 void afterPropertiesSet() { @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 8eb94296292a..c6a1cbfd087a 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 94c88ec65fdf..d645fa1e0f0e 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.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.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 void setPersistenceProvider(@Nullable PersistenceProvider persistenceProv } @Override - @Nullable - public PersistenceProvider getPersistenceProvider() { + public @Nullable PersistenceProvider getPersistenceProvider() { return this.persistenceProvider; } @@ -189,8 +175,7 @@ public void setPersistenceUnitName(@Nullable String persistenceUnitName) { } @Override - @Nullable - public String getPersistenceUnitName() { + public @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -255,8 +240,7 @@ public void setEntityManagerInterface(@Nullable Class e } @Override - @Nullable - public Class getEntityManagerInterface() { + public @Nullable Class getEntityManagerInterface() { return this.entityManagerInterface; } @@ -272,8 +256,7 @@ public void setJpaDialect(@Nullable JpaDialect jpaDialect) { } @Override - @Nullable - public JpaDialect getJpaDialect() { + public @Nullable JpaDialect getJpaDialect() { return this.jpaDialect; } @@ -291,8 +274,7 @@ public void setJpaVendorAdapter(@Nullable JpaVendorAdapter jpaVendorAdapter) { * 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 void setBootstrapExecutor(@Nullable AsyncTaskExecutor bootstrapExecutor) * 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 @@ else if (emf != null) { * 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 @@ else if (method.getName().equals("createEntityManager") && args != null && args. * @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 @@ protected void postProcessEntityManager(EntityManager rawEntityManager) { } @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 DataSource getDataSource() { * Return the singleton EntityManagerFactory. */ @Override - @Nullable - public EntityManagerFactory getObject() { + public @Nullable EntityManagerFactory getObject() { return this.entityManagerFactory; } @@ -719,8 +696,7 @@ public ManagedEntityManagerFactoryInvocationHandler(AbstractEntityManagerFactory } @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 f562fa03e249..0aca79d5ca31 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 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 Object beginTransaction(EntityManager entityManager, TransactionDefinitio } @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 void cleanupTransaction(@Nullable Object transactionData) { * 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 void releaseJdbcConnection(ConnectionHandle conHandle, EntityManager em) * @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 32bb7fdd609c..f034fcaf2eb9 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.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 void setEntityManagerFactory(@Nullable EntityManagerFactory emf) { * 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 void setPersistenceUnitName(@Nullable String persistenceUnitName) { /** * 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 @@ protected EntityManager createEntityManager() throws IllegalStateException { * @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 cdb9dda3ce55..8d8d649c0c9d 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.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 b9f38e313b44..9f194f526be5 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.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.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 static EntityManagerFactory findEntityManagerFactory( * @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 static EntityManager getTransactionalEntityManager(EntityManagerFactory e * @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 static EntityManager getTransactionalEntityManager(EntityManagerFactory e * @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 static EntityManager doGetTransactionalEntityManager(EntityManagerFactory * @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 @@ else if (!TransactionSynchronizationManager.isSynchronizationActive()) { * (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 static void applyTransactionTimeout(Query query, EntityManagerFactory emf * @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 @@ private static class TransactionalEntityManagerSynchronization 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 cc72652674dd..1c5c09df6482 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 @@ */ 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 @@ protected void setSavepointManager(@Nullable SavepointManager savepointManager) 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 72891dffdc02..3ed7953dc7f5 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 @@ 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 3d31c1f75540..9e7716a5a13d 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.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 @@ private static final class ExtendedEntityManagerInvocationHandler implements Inv private final EntityManager target; - @Nullable - private final PersistenceExceptionTranslator exceptionTranslator; + private final @Nullable PersistenceExceptionTranslator exceptionTranslator; private final boolean jta; @@ -293,8 +292,7 @@ private boolean isJtaEntityManager() { } @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 @@ private static class ExtendedEntityManagerSynchronization 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 61eaa9bef2d5..cbccef3da2a8 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 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 @@ Object beginTransaction(EntityManager entityManager, TransactionDefinition defin * @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 @@ Object prepareTransaction(EntityManager entityManager, boolean readOnly, @Nullab * @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 168938c70b72..9b8d020f877b 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.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.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 @@ 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 void setEntityManagerFactory(@Nullable EntityManagerFactory emf) { /** * 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 void setPersistenceUnitName(@Nullable String persistenceUnitName) { /** * 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 void setDataSource(@Nullable DataSource dataSource) { /** * 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 @@ protected void doCleanupAfterCompletion(Object transaction) { */ 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 void setTransactionData(@Nullable Object transactionData) { } } - @Nullable - public Object getTransactionData() { + public @Nullable Object getTransactionData() { return this.transactionData; } @@ -808,8 +798,7 @@ private static final class SuspendedResourcesHolder { 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 @@ private EntityManagerHolder getEntityManagerHolder() { 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 d55a6b614b49..1120ad11379f 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.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 @@ default String getPersistenceProviderRootPackage() { * 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 bc66db3acf11..ad9e00a4b31b 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.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.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 @@ 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 @@ protected void postProcessEntityManagerFactory(EntityManagerFactory emf, Persist @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 String getPersistenceUnitName() { } @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 88b3d1128fa3..31e204c21dc5 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.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 void setDataSource(@Nullable DataSource dataSource) { * @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 9dfb8c7d0eb4..d3ae81bc32c2 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.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 @@ private static class SharedEntityManagerInvocationHandler implements InvocationH 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 @@ private void initProxyClassLoader() { } @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 @@ private static class DeferredQueryInvocationHandler implements InvocationHandler 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 ae73e43ba2c9..1bb8358803d2 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 0654e12c3d9e..529504237a00 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 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 @@ public ClassFileTransformerAdapter(ClassTransformer classTransformer) { @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 058f5e9184d3..f1c0b1711061 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.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.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 void setDataSourceLookup(@Nullable DataSourceLookup dataSourceLookup) { * 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 void setDefaultDataSource(@Nullable DataSource defaultDataSource) { * 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 void setDefaultJtaDataSource(@Nullable DataSource defaultJtaDataSource) { * 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 DataSource getDefaultJtaDataSource() { *

    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 void setPersistenceUnitPostProcessors(@Nullable PersistenceUnitPostProces * 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 void setLoadTimeWeaver(@Nullable LoadTimeWeaver loadTimeWeaver) { * 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 @@ private void applyManagedTypes(SpringPersistenceUnitInfo scannedUnit, Persistenc * @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 @@ private URL determineDefaultPersistenceUnitRootUrl() { *

    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 @@ private Resource getOrmXmlForDefaultPersistenceUnit() { * @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 2393c67fae5f..c8691065a19b 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.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 @@ @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 void setPersistenceUnitName(@Nullable String persistenceUnitName) { } @Override - @Nullable - public String getPersistenceUnitName() { + public @Nullable String getPersistenceUnitName() { return this.persistenceUnitName; } @@ -103,8 +95,7 @@ public void setPersistenceProviderClassName(@Nullable String persistenceProvider } @Override - @Nullable - public String getPersistenceProviderClassName() { + public @Nullable String getPersistenceProviderClassName() { return this.persistenceProviderClassName; } @@ -128,8 +119,7 @@ public void setJtaDataSource(@Nullable DataSource jtaDataSource) { } @Override - @Nullable - public DataSource getJtaDataSource() { + public @Nullable DataSource getJtaDataSource() { return this.jtaDataSource; } @@ -138,8 +128,7 @@ public void setNonJtaDataSource(@Nullable DataSource nonJtaDataSource) { } @Override - @Nullable - public DataSource getNonJtaDataSource() { + public @Nullable DataSource getNonJtaDataSource() { return this.nonJtaDataSource; } @@ -166,8 +155,7 @@ public void setPersistenceUnitRootUrl(@Nullable URL persistenceUnitRootUrl) { } @Override - @Nullable - public URL getPersistenceUnitRootUrl() { + public @Nullable URL getPersistenceUnitRootUrl() { return this.persistenceUnitRootUrl; } @@ -258,8 +246,7 @@ public void setPersistenceProviderPackageName(@Nullable String persistenceProvid this.persistenceProviderPackageName = persistenceProviderPackageName; } - @Nullable - public String getPersistenceProviderPackageName() { + public @Nullable String getPersistenceProviderPackageName() { return this.persistenceProviderPackageName; } @@ -269,8 +256,7 @@ public String getPersistenceProviderPackageName() { * @see org.springframework.util.ClassUtils#getDefaultClassLoader() */ @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -291,14 +277,12 @@ public ClassLoader getNewTempClassLoader() { } @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 738b14294fa0..4c953dcef452 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.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 89800bdae4f9..3af979ec7ecb 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.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.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 @@ private void contributeHibernateHints(RuntimeHints hints, @Nullable ClassLoader } } - @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 a76b1a4b588c..fef854dee334 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.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.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 @@ private static class ScanResult { 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 22f6d057a11d..069420cab048 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.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.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 @@ void parseJarFiles(Element persistenceUnit, SpringPersistenceUnitInfo unitInfo) * @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 6a9b54642c00..e56992533362 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 @@ 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 @@ public List getManagedPackages() { } @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 e188d4c4ce99..3dabc9807525 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 @@ 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 @@ */ class SpringPersistenceUnitInfo extends MutablePersistenceUnitInfo { - @Nullable - private LoadTimeWeaver loadTimeWeaver; + private @Nullable LoadTimeWeaver loadTimeWeaver; - @Nullable - private ClassLoader classLoader; + private @Nullable ClassLoader classLoader; /** @@ -70,8 +68,7 @@ public void init(@Nullable ClassLoader classLoader) { * 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 e27e279a1c13..d3f6e6a54318 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 3bee08ed148e..db6be53668cb 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 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 4b1854005440..a3ace5665a21 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.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 void setEntityManagerFactoryBeanName(@Nullable String entityManagerFactor * 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 void setPersistenceUnitName(@Nullable String persistenceUnitName) { /** * 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 e6cc8f14fe55..9d1f4349a441 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 @@ 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 f5e17433c649..e163fdde9c46 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.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.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 void resetBeanDefinition(String beanName) { } @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 @@ private InjectionMetadata buildPersistenceMetadata(Class clazz) { * 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 @@ protected EntityManagerFactory getPersistenceUnit(@Nullable String unitName) { * @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 @@ private class PersistenceElement extends InjectionMetadata.InjectedElement { 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 0b460b000014..61b7a7d0de30 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 @@ 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 @@ 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 final void afterPropertiesSet() { @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 b2b1b32ba47c..f8486431655b 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 f79bb3f5d858..88713bbed664 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 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 void setDatabasePlatform(@Nullable String databasePlatform) { /** * 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 @@ protected boolean isShowSql() { @Override - @Nullable - public String getPersistenceProviderRootPackage() { + public @Nullable String getPersistenceProviderRootPackage() { return null; } @@ -141,8 +138,7 @@ public String getPersistenceProviderRootPackage() { } @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 5b313816d120..b8f2ee89d541 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.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 void setLazyDatabaseTransaction(boolean lazyDatabaseTransaction) { @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 @@ private static class EclipseLinkConnectionHandle implements ConnectionHandle { 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 4cbe6c71d7ea..84cfaac3e570 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 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 Map getJpaPropertyMap() { * @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 12a9d75c97ba..cc62cde226e6 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.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.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 Object prepareTransaction(EntityManager entityManager, boolean readOnly, 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 ConnectionHandle getJdbcConnection(EntityManager entityManager, boolean r } @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 @@ protected SessionImplementor getSession(EntityManager entityManager) { 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 @@ private static class SessionTransactionData { 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 520442894417..b8561cd3450c 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.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 @@ private Map buildJpaPropertyMap(boolean connectionReleaseOnClose * @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 @@ protected Class determineDatabaseDialectClass(Database database) { * @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 b14f429ab986..10fb63e595b9 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 2b6a01a34ffd..33e510e6a7c7 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 cb31b8bf0142..78dc137844a4 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.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.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 @@ private void testCompile(RegisteredBean registeredBean, .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 877863a66ead..36c91e0bc790 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.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 ade307a3b386..327da6edea4c 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.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.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 9907718e49ee..800e594cdefe 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 b989541fd35a..7bf0a5ee23fc 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.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.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 efddba004567..120e9592641f 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.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.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 void setContextPath(@Nullable String contextPath) { /** * Return the JAXB context path. */ - @Nullable - public String getContextPath() { + public @Nullable String getContextPath() { return this.contextPath; } @@ -244,15 +225,14 @@ public String getContextPath() { *

    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[] getClassesToBeBound() { *

    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 8a630106f418..e9d62635a6ed 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 11f24456d0a7..9aa2b230da4d 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 f22ab1632ecf..ad72e5eb1489 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 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 e45a3c35144d..2479d62ec3d4 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 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 b62881733dea..180b9402d022 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 a9774649b72d..09cff99872af 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 a3925acb5039..df150cc5edd8 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 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.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 @@ protected XMLReader createXmlReader() throws SAXException, ParserConfigurationEx * 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 e2b7882485c6..45f65624cb51 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.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.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 @@ private static final class MarshallingXMLReader implements XMLReader { 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 void setContentHandler(@Nullable ContentHandler contentHandler) { } @Override - @Nullable - public ContentHandler getContentHandler() { + public @Nullable ContentHandler getContentHandler() { return this.contentHandler; } @@ -148,8 +142,7 @@ public void setDTDHandler(@Nullable DTDHandler dtdHandler) { } @Override - @Nullable - public DTDHandler getDTDHandler() { + public @Nullable DTDHandler getDTDHandler() { return this.dtdHandler; } @@ -159,8 +152,7 @@ public void setEntityResolver(@Nullable EntityResolver entityResolver) { } @Override - @Nullable - public EntityResolver getEntityResolver() { + public @Nullable EntityResolver getEntityResolver() { return this.entityResolver; } @@ -170,13 +162,11 @@ public void setErrorHandler(@Nullable ErrorHandler errorHandler) { } @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 void setFeature(String name, boolean value) throws SAXNotRecognizedExcept } @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 b2e14d524887..73c63b5372a3 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 @@ 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 static InputSource createInputSource(Resource resource) throws IOExceptio * 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 e421943a51b7..fab4ceb1c0b7 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 a727bf1c2eaf..91a7bd47b8af 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.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.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 c01a9cbd1075..220ef5d73d6f 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 84effd5a8f25..17a38a9e3c34 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 BadSqlGrammarException(String task, String sql, R2dbcException ex) { /** * 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 3c0b6acfa709..43fb1f5c3506 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 @@ 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 UncategorizedR2dbcException(String msg, @Nullable String sql, R2dbcExcept /** * 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 847dd93b725d..81a4819c2edc 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.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.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 dd1b9c36c718..7f5b1a45eea3 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 @@ 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 d7dd814f6e3c..32c9b9299bd9 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.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 @@ @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 void setConnectionFactory(@Nullable ConnectionFactory connectionFactory) /** * 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 @@ protected Mono prepareTransactionalConnection(Connection con, TransactionD * 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 @@ private record ExtendedTransactionDefinition(@Nullable String transactionName, @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 String toString() { */ 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 65e9786f8b1e..c31a9a309df8 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.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 void setAutoCommit(boolean autoCommit) { * 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 @@ private static class CloseSuppressingInvocationHandler implements InvocationHand } @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 c9d47089e877..7ff8ecc15052 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 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 @@ private static class TransactionAwareInvocationHandler implements InvocationHand } @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 bfd89a9596c3..9aabcf8a9d38 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 @@ */ 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 86dc2f4fcf23..3f7d2b188c88 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.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.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 17491c476aff..8e8b0e97a931 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 1b9d6883a9f7..aba165b5ebae 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 8bf20593e2e5..abe44653975f 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.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.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 e28bcfa4428e..9e01277a129b 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 900197f5c0cb..c219d5fdb822 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 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 5359fec11258..96f48d4a09df 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 @@ */ 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 cd99f598865d..499e6c13c96c 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 5da1a594ea92..dbeb5f8bcdac 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 fbae6633ad89..d3b7f004781c 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.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 @@ protected T constructMappedInstance(Readable readable, List 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 5382452bd0a9..0c060e3fe398 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 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 @@ protected String getColumnKey(String columnName) { * @param index is the column index * @return the Object returned */ - @Nullable - protected Object getColumnValue(Row row, int index) { + protected @Nullable Object getColumnValue(Row row, int index) { return row.get(index); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java index d535a3989b6a..35f44b4e2661 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/DefaultDatabaseClient.java @@ -45,13 +45,13 @@ import io.r2dbc.spi.Wrapped; 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; import org.springframework.beans.BeanUtils; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.lang.Nullable; import org.springframework.r2dbc.connection.ConnectionFactoryUtils; import org.springframework.r2dbc.core.binding.BindMarkersFactory; import org.springframework.r2dbc.core.binding.BindTarget; @@ -82,8 +82,7 @@ final class DefaultDatabaseClient implements DatabaseClient { private final ExecuteFunction executeFunction; - @Nullable - private final NamedParameterExpander namedParameterExpander; + private final @Nullable NamedParameterExpander namedParameterExpander; DefaultDatabaseClient(BindMarkersFactory bindMarkersFactory, ConnectionFactory connectionFactory, @@ -208,8 +207,7 @@ private static Mono sumRowsUpdated(Function> resu * @return the SQL string, or {@code null} * @see SqlProvider */ - @Nullable - private static String getSql(Object object) { + private static @Nullable String getSql(Object object) { if (object instanceof SqlProvider sqlProvider) { return sqlProvider.getSql(); } @@ -475,8 +473,7 @@ private MapBindParameterSource retrieveParameters(String sql, List param return new MapBindParameterSource(namedBindings); } - @Nullable - private Parameter getParameter(Map remainderByName, + private @Nullable Parameter getParameter(Map remainderByName, Map remainderByIndex, List parameterNames, String parameterName) { if (this.byName.containsKey(parameterName)) { @@ -530,8 +527,7 @@ private static class CloseSuppressingInvocationHandler implements InvocationHand } @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 c8811043aed3..a93ffb3bc854 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 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 @@ */ 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 a25bddd7f665..1be2d1cf1052 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 @@ 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 @@ public R apply(Connection t) { 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 f6696e8d9cd9..680213cb0909 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.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 @@ NamedParameter getOrCreate(String namedParameter) { return param; } - @Nullable - List getMarker(String name) { + @Nullable List getMarker(String name) { return this.references.get(name); } @@ -566,8 +565,7 @@ public void bindNull(BindTarget target, String identifier, Parameter parameter) } } - @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 7d0d482fac13..b5b892d1de00 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 @@ @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 static Parameter empty(Class type) { * 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 1204eac5df01..1dbdb45b880a 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 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 @@ public Flux apply(Connection connection) { .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 a46c98af84ca..3b8c84d2707a 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 c658352846d7..8a4ff087c8bc 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 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 interface BindMarkerFactoryProvider { * @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 @@ static class BuiltInBindMarkersFactoryProvider implements BindMarkerFactoryProvi @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 a0a6eacc737b..445a46df2208 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.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 boolean isNull() { * @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 boolean hasValue() { } @Override - @NonNull - public Object getValue() { + public @NonNull Object getValue() { return this.value; } @@ -237,8 +235,7 @@ public boolean hasValue() { } @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 e95acdc21d77..36ea3a687597 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 a85478547b10..78aa55e025f0 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 c892eec7f380..dc32fb63973c 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 93f9a65d97fb..fd2a22c52d32 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.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.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 @@ private MockResult mockSingleColumnEmptyResult() { * 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 964c7688bc10..0fa7e3a27a97 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 10736fe4f024..42222f449375 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.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 3feddab58699..8809f4d60825 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 36f5a5bb3950..1bba82406207 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 18bda66888a6..df2c8eaefec8 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 1b9d39b50b60..e9ca3ee6d171 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.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.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 @@ private MockServerHttpRequest(HttpMethod httpMethod, @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 @@ private static class DefaultBodyBuilder implements BodyBuilder { private final URI url; - @Nullable - private String contextPath; + private @Nullable String contextPath; private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance(); @@ -424,14 +417,11 @@ private static class DefaultBodyBuilder implements BodyBuilder { 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 b989b2d96b71..599c9d115fbf 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 a0a739765e36..25249a7d93cb 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.LinkedList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; /** @@ -63,13 +64,11 @@ List getStringValues() { 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 982d4e3b261e..20761a496e81 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.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 ServletRequest getRequest() { } @Override - @Nullable - public ServletResponse getResponse() { + public @Nullable ServletResponse getResponse() { return this.response; } @@ -110,8 +107,7 @@ public void dispatch(@Nullable ServletContext context, String path) { } } - @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 81a905150eca..6bc5923cd85e 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 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 c7ec34d0882a..4e08336dd68b 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.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 void setExpires(@Nullable ZonedDateTime expires) { * @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 void setSameSite(@Nullable String sameSite) { * 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 2a48a42e5edf..3d666d56d0bd 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.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 @@ */ 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 @@ private static List initFilterList(Servlet servlet, Filter... filters) { /** * 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 5557276184f0..c6904bce4df2 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 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 void addInitParameter(String name, String value) { } @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 b73c4bfb4dc3..3edbe35746ec 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 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 String getName() { return this.name; } - @Nullable @Override - public String getClassName() { + public @Nullable String getClassName() { return this.className; } @@ -79,9 +77,8 @@ public boolean setInitParameter(String name, String value) { 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 17615a3bdcf9..50d854c52031 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 @@ 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 String getServletName() { } @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 bb1b861fdd64..8f2500c89e7b 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.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 @@ protected void checkActive() throws IllegalStateException { // --------------------------------------------------------------------- @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { checkActive(); return this.attributes.get(name); } @@ -398,8 +379,7 @@ public Enumeration getAttributeNames() { } @Override - @Nullable - public String getCharacterEncoding() { + public @Nullable String getCharacterEncoding() { return this.characterEncoding; } @@ -429,7 +409,7 @@ private void updateContentTypeHeader() { * @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 void setContent(@Nullable byte[] content) { * @see #setContent(byte[]) * @see #getContentAsString() */ - @Nullable - public byte[] getContentAsByteArray() { + public byte @Nullable [] getContentAsByteArray() { return this.content; } @@ -458,8 +437,7 @@ public byte[] getContentAsByteArray() { * @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 void setContentType(@Nullable String contentType) { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -628,8 +605,7 @@ public void removeAllParameters() { } @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 Enumeration getParameterNames() { } @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 void setAsyncContext(@Nullable MockAsyncContext asyncContext) { } @Override - @Nullable - public AsyncContext getAsyncContext() { + public @Nullable AsyncContext getAsyncContext() { return this.asyncContext; } @@ -1021,12 +995,11 @@ public void setAuthType(@Nullable String authType) { } @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 @@ private static String encodeCookies(Cookie... cookies) { } @Override - @Nullable - public Cookie[] getCookies() { + public Cookie @Nullable [] getCookies() { return this.cookies; } @@ -1166,8 +1138,7 @@ private long parseDateHeader(String name, String value) { } @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 void setMethod(@Nullable String method) { } @Override - @Nullable - public String getMethod() { + public @Nullable String getMethod() { return this.method; } @@ -1217,14 +1187,12 @@ public void setPathInfo(@Nullable String pathInfo) { } @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 void setQueryString(@Nullable String queryString) { } @Override - @Nullable - public String getQueryString() { + public @Nullable String getQueryString() { return this.queryString; } @@ -1252,8 +1219,7 @@ public void setRemoteUser(@Nullable String remoteUser) { } @Override - @Nullable - public String getRemoteUser() { + public @Nullable String getRemoteUser() { return this.remoteUser; } @@ -1273,8 +1239,7 @@ public void setUserPrincipal(@Nullable Principal userPrincipal) { } @Override - @Nullable - public Principal getUserPrincipal() { + public @Nullable Principal getUserPrincipal() { return this.userPrincipal; } @@ -1283,8 +1248,7 @@ public void setRequestedSessionId(@Nullable String requestedSessionId) { } @Override - @Nullable - public String getRequestedSessionId() { + public @Nullable String getRequestedSessionId() { return this.requestedSessionId; } @@ -1301,8 +1265,7 @@ public void setUriTemplate(@Nullable String uriTemplate) { * 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 void setRequestURI(@Nullable String requestURI) { } @Override - @Nullable - public String getRequestURI() { + public @Nullable String getRequestURI() { return this.requestURI; } @@ -1351,8 +1313,7 @@ public void setSession(HttpSession session) { } @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 HttpSession getSession(boolean create) { } @Override - @Nullable - public HttpSession getSession() { + public @Nullable HttpSession getSession() { return getSession(true); } @@ -1435,8 +1395,7 @@ public void addPart(Part part) { } @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 HttpServletMapping getHttpServletMapping() { * 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 18df83dbf6aa..feed71a5e030 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 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 @@ else if (mediaType.isCompatibleWith(MediaType.APPLICATION_JSON) || } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -510,8 +505,7 @@ public Cookie[] getCookies() { 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 Collection getHeaderNames() { * @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 List getHeaders(String name) { * @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 void sendRedirect(String url, int sc, boolean clearBuffer) throws IOExcep setCommitted(true); } - @Nullable - public String getRedirectedUrl() { + public @Nullable String getRedirectedUrl() { return getHeader(HttpHeaders.LOCATION); } @@ -807,8 +798,7 @@ public int getStatus() { /** * 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 void setForwardedUrl(@Nullable String forwardedUrl) { this.forwardedUrl = forwardedUrl; } - @Nullable - public String getForwardedUrl() { + public @Nullable String getForwardedUrl() { return this.forwardedUrl; } @@ -833,8 +822,7 @@ public void setIncludedUrl(@Nullable String includedUrl) { } } - @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 1881d802bc91..e8d4e25eb90f 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.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 int getMaxInactiveInterval() { } @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 ab0c4ec51c34..272a68021069 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 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 781ab7a6e48f..cc4834d49a54 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.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 MockMultipartFile(String name, InputStream contentStream) throws IOExcept * @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 String getName() { } @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 41411d366cce..ce07775fe69a 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 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 Iterator getFileNames() { } @Override - @Nullable - public MultipartFile getFile(String name) { + public @Nullable MultipartFile getFile(String name) { return this.multipartFiles.getFirst(name); } @@ -118,8 +117,7 @@ public MultiValueMap getMultiFileMap() { } @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 HttpHeaders getRequestHeaders() { } @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 99f430ebb39b..5a6544270194 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.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 void setAttribute(String name, @Nullable Object value, int scope) { } @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 Object getAttribute(String name, int scope) { } @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 JspWriter getOut() { } @Override - @Nullable - public ELContext getELContext() { + public @Nullable ELContext getELContext() { return null; } @@ -294,8 +289,7 @@ public ServletResponse getResponse() { } @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 1ffe741b7a7a..82b679b4b264 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.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 MockPart(String name, @Nullable byte[] content) { * 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 MockPart(String name, @Nullable String filename, @Nullable byte[] content * @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 String getName() { } @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 void delete() throws IOException { } @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 9c75c2916a8d..47b1e2df91b0 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 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 void addInitParameter(String name, String value) { } @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 38e7dae2ba99..a37917abd49a 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.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 void registerContext(String contextPath, ServletContext context) { } @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 int getEffectiveMinorVersion() { } @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 void addMimeType(String fileExtension, MediaType mimeType) { } @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 Set getResourcePaths(String path) { } @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 URL getResource(String path) throws MalformedURLException { } @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 RequestDispatcher getRequestDispatcher(String path) { } @Override - @Nullable - public RequestDispatcher getNamedDispatcher(String path) { + public @Nullable RequestDispatcher getNamedDispatcher(String path) { return this.namedRequestDispatchers.get(path); } @@ -446,8 +437,7 @@ public void log(String message, Throwable ex) { } @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 String getServerInfo() { } @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 void addInitParameter(String name, String value) { } @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 String getServletContextName() { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -590,8 +577,7 @@ public void setRequestCharacterEncoding(@Nullable String requestCharacterEncodin } @Override // on Servlet 4.0 - @Nullable - public String getRequestCharacterEncoding() { + public @Nullable String getRequestCharacterEncoding() { return this.requestCharacterEncoding; } @@ -601,8 +587,7 @@ public void setResponseCharacterEncoding(@Nullable String responseCharacterEncod } @Override // on Servlet 4.0 - @Nullable - public String getResponseCharacterEncoding() { + public @Nullable String getResponseCharacterEncoding() { return this.responseCharacterEncoding; } @@ -615,8 +600,7 @@ public void addFilterRegistration(FilterRegistration registration) { } @Override - @Nullable - public FilterRegistration getFilterRegistration(String filterName) { + public @Nullable FilterRegistration getFilterRegistration(String filterName) { return this.filterRegistrations.get(filterName); } @@ -665,8 +649,7 @@ public T createServlet(Class c) throws ServletException { * @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 28c80b522b8b..30bcf6fce7dd 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.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 @@ */ 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 void setName(@Nullable String name) { } @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -71,8 +65,7 @@ public void setDomain(@Nullable String domain) { } @Override - @Nullable - public String getDomain() { + public @Nullable String getDomain() { return this.domain; } @@ -82,8 +75,7 @@ public void setPath(@Nullable String path) { } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.path; } @@ -95,8 +87,7 @@ public void setComment(@Nullable String comment) { @SuppressWarnings("removal") @Override - @Nullable - public String getComment() { + public @Nullable String getComment() { return this.comment; } @@ -136,8 +127,7 @@ public void setAttribute(String name, String value) { } @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 d0ca4ed48224..2c4158ebff54 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.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 @@ */ 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 7a01244ba4c2..4673927f82af 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 5461e4030438..32bd66ad9325 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.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.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 @@ private static class BuilderImpl implements Builder { private MultiValueMap cookies = new LinkedMultiValueMap<>(); - @Nullable - private Object body; + private @Nullable Object body; private Map attributes = new ConcurrentHashMap<>(); @@ -354,22 +347,17 @@ private static class BuilderImpl implements Builder { 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 Optional contentType() { } @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 91fe0741840d..41100d28ee8c 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 e2cf0fae8f54..19d1f7830507 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 static class Builder { 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 0a13b853ee3d..e8d795c6db91 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.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 66a15310ee18..e290525c8d79 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 d6ce0a75ea06..4121bcfeae59 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 26957c49f25e..ed2e5e08ad13 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 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 0e93e33cbd7f..84e981518d8f 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 2b22556d9ae4..4fc8214fb962 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 5a35391eafa7..8af79ed50fb1 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 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 @@ attribute or make the default bootstrapper class available.""".formatted(clazz), } } - @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 9e5def712c82..276a23620b66 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 73643729ef4f..4d0e4f013afc 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 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 boolean isInheritInitializers() { * @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 e8b35ff2c514..3541667950b7 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 @@ 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 a0f96ed47e0b..b6256787590e 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 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 26837b83f59a..4815180f7e53 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.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 MergedContextConfiguration(Class testClass, @Nullable String[] locatio * @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 MergedContextConfiguration(Class testClass, @Nullable String[] locatio * @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 MergedContextConfiguration(MergedContextConfiguration mergedConfig) { * {@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 MergedContextConfiguration(Class testClass, @Nullable String[] locatio * {@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 MergedContextConfiguration(Class testClass, @Nullable String[] locatio * @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 ContextLoader getContextLoader() { * @since 3.2.2 * @see #getParentApplicationContext() */ - @Nullable - public MergedContextConfiguration getParent() { + public @Nullable MergedContextConfiguration getParent() { return this.parent; } @@ -457,8 +455,7 @@ public MergedContextConfiguration getParent() { * @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 String toString() { } - 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 @@ private static Set processContextCustomizers( 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 247351e3b8ca..ea88c655d9c1 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 @@ 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 d7102667e0c9..e4d9568ba09b 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 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 @@ enum EnclosingConfiguration { * @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 d140bc26955c..142c62e2ca33 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 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 @@ enum AutowireMode { * @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 3e6d5109c13d..b8234f3fe163 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.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 @@ default void publishEvent(Function even * @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 6053c115726e..0f562d0c7ab3 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.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.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 static boolean hasAnnotation(Class clazz, Class * @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 static Set getMergedRepeatableAnnotations( * 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 static AnnotationDescriptor findAnnotationDescr * @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 @@ private static AnnotationDescriptor findAnnotationDesc * @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 static UntypedAnnotationDescriptor findAnnotationDescriptorForTypes( * @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 @@ Class getAnnotationType() { * @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 static class UntypedAnnotationDescriptor extends AnnotationDescriptorSpring @@ -117,8 +118,7 @@ default void setAttribute(String name, boolean value) { * @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 1414083bd66b..27c6ce61cf18 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 @@ 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 @@ */ 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 15b95e18ec3d..b0355698000d 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 @@ 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 boolean isSupportedTestClass(Class testClass) { * @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 ApplicationContextInitializer getContextI * @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 e130258a8ef2..1b742c50ae6f 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 @@ 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 @@ */ 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 966485d5b519..d3f663b018bc 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 @@ 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 @@ public void removeAttribute(String name) { } @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 65e630927ae3..3e2e63935d07 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 @@ */ 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 d673bff93ead..7339dd9e83fc 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 4d1f0f0d8532..2c815c812cac 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.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.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 @@ private void wrapBean(ConfigurableListableBeanFactory beanFactory, BeanOverrideH 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 @@ private Set getExistingBeanNamesByType(ConfigurableListableBeanFactory b * @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 e5d66ba8b0d3..0cd739a4a519 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.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 @@ 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 b11081392009..71858560d3d4 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.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.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 final ResolvableType getBeanType() { * 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 20df24ea8850..ead7bf9f6e33 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.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 59256e3fe604..cf410d0482c5 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 3e7b39275fb0..90550736ffba 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 @@ 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 64ddd2f1b029..26e9d66c435c 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.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.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 f4556a261920..094440ccc6f2 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 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.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 @@ private static void resetMocks(ConfigurableApplicationContext applicationContext } } - @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 ce929171e97d..6f2bd2fdb883 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 @@ 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.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 15330b2b514a..1d4c16cd8e74 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 4969d011ca97..4b5ab0a176d5 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 8ee994362320..712230d6627a 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 @@ 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 7d64249ce654..f4f4a6fe1983 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 c9601be99297..be0bd587a72b 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 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 99342ec4964d..6821dd8ff7d4 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 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 boolean contains(MergedContextConfiguration key) { } @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 e015cbf75881..ef6e1811eb26 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 91c4a9a8b217..c98be07fc8e1 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 @@ private 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 f2a580e6ae46..99f39ac1d3b3 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 1cee0ad6be26..2ae253aae4bd 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 db1ec2797702..54329ee89d71 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.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 1043d98cead9..c441130bd049 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 3e49b71b39cb..bda7712318e1 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 @@ 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 0b0534dd0493..f3131669a75b 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 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.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 @@ private boolean mergeSqlAnnotations(TestContext testContext) { /** * 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 @@ private static boolean sameDataSource(DataSource ds1, DataSource ds2) { .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 fe01ea1dc52b..f5158c330957 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 5e66aa58f4c8..af497e57ec7e 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.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.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 @@ private boolean supportsApplicationEvents(ParameterContext parameterContext) { * @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 c9c4800b6a12..44c237362a37 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 2f48593acb46..5fd141c9a53a 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 9c39288080b3..05e1861d01c5 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 @@ 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 24e3738254b2..c8970a91513c 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 @@ 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 d06106d74693..e98b57e6653f 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 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.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 @@ protected Statement possiblyExpectingExceptions(FrameworkMethod frameworkMethod, *

    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 b4b5883467f7..4013649ceadf 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 d1d981d2fb48..0d4dfecd907d 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 d9162ae0d4d6..293dcd0eef84 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 @@ 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 50b9815c18fa..6733a69c4ccd 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 18bf72b67214..889f3ba3fd28 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.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 fecd9bf754ed..9a43008f5659 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 af3710b4b2dc..e5bf853860b1 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 084d6ae7fffc..113353159384 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 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 df48cd626f2e..5a11d1cff04f 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 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 @@ protected ContextLoader resolveContextLoader(Class testClass, * @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 a531d0c44786..3a692987de3f 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 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 03b6a25827ed..ae9fac01eb21 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.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 final Method getTestMethod() { } @Override - @Nullable - public final Throwable getTestException() { + public final @Nullable Throwable getTestException() { return this.testException; } @@ -211,8 +208,7 @@ public void setAttribute(String name, @Nullable Object value) { } @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 T computeAttribute(String name, Function computeFunction) } @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 bc70c3606613..57254fd0548e 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.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 ddd11ffe6a96..fae55eadc5fe 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.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 @@ 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 3f24c6dd8a22..5946f0590c50 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 @@ 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.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 bbe560152eaa..2a5470bdf26f 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.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 ba76d8f19175..0501c9e30a33 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 @@ 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 564ed078a936..a1d6367d8d15 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 37ddd684708c..cbf8bdd06062 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 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 c3a43e594dc8..df41b907af67 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 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.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 700f38acd868..b8f036913864 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 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.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 @@ static MergedTestPropertySources buildMergedTestPropertySources(Class testCla 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 @@ private static class SequencedProperties extends Properties { 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 66f278fde8a9..227ccd0446e8 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 c328f59a96b9..606932c04857 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 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.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 @@ protected void springTestContextAfterTestClass() throws Exception { } - @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 d26ec301d0ba..ba01dec09c09 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 @@ 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 a3ffed50e190..fedbcb4ced32 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 01c55a153509..ac7349637d26 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 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 static DataSource retrieveDataSource(TestContext testContext, @Nullable S * @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 TestContextTransactionAttribute( } @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 73886f24129f..fde1518087b8 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 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 3d1a1bcbcc57..91ea7504d2c7 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 @@ static void setCurrentTransactionContext(TransactionContext transactionContext) 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 8322a84b605a..c19eb72f6670 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 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 @@ protected TransactionAttribute findTransactionAttribute(Class clazz) { 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 @@ else if (logger.isDebugEnabled()) { * @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 @@ protected PlatformTransactionManager getTransactionManager(TestContext testConte * 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 51a8296e4527..3cb1ecb28326 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 f4addd2e9e50..2875ad70df6c 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 79c948a30b4a..4284a5771982 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 @@ 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 WebMergedContextConfiguration(MergedContextConfiguration mergedConfig, St * {@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 WebMergedContextConfiguration(Class testClass, @Nullable String[] loca * {@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 WebMergedContextConfiguration(Class testClass, @Nullable String[] loca * @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 6db3a3351dea..ec39473b46db 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 @@ protected MergedContextConfiguration processMergedContextConfiguration(MergedCon } } - @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 e4f9b40942b2..82d61b9f0e37 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 441615cf1c68..67b6298ad393 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 667b789f8bc6..fee36dd3bdeb 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 @@ 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 8aa1072223a6..f3401796d767 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 a25b39094d85..277419daf7ee 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.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 6613b8a01284..0782d4904bf8 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 57d21d4422ba..4bfe45270a1a 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 @@ 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 e382f904625f..7f2e3d9c89aa 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 e034682b598a..78797c43e86c 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.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.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 SELF withCharset(@Nullable Charset charset) { return this.myself; } - @Nullable - private String toJsonString() { + private @Nullable String toJsonString() { return (this.actual != null ? this.actual.getJson() : null); } @@ -546,8 +542,7 @@ private class JsonPathValue { this.jsonPath = JsonPath.compile(this.path); } - @Nullable - Object assertHasPath() { + @Nullable Object assertHasPath() { return getValue(); } @@ -560,8 +555,7 @@ void assertDoesNotHavePath() { } } - @Nullable - Object getValue() { + @Nullable Object getValue() { try { return read(); } @@ -570,8 +564,7 @@ Object getValue() { } } - @Nullable - private Object read() { + private @Nullable Object read() { return this.jsonPath.read(this.json); } diff --git a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java index ffa5409d9846..792b11abfc41 100644 --- a/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java +++ b/spring-test/src/main/java/org/springframework/test/json/AbstractJsonValueAssert.java @@ -31,10 +31,10 @@ import org.assertj.core.api.ObjectArrayAssert; 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.http.converter.GenericHttpMessageConverter; -import org.springframework.lang.Nullable; import org.springframework.test.http.HttpMessageContentConverter; import org.springframework.util.ObjectUtils; import org.springframework.util.StringUtils; @@ -64,8 +64,7 @@ public abstract class AbstractJsonValueAssert 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 a8d2bf404aca..f1e1c1227445 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 bc8dae2ee8ea..2fee94ef114f 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 6930bc983335..eb2a60fe0f6f 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 Result getResult() { /** * 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 28b02082e40b..7d3eba83f13d 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 String getJson() { /** * 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 9728a762496a..b5bacb0ebf57 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 fe905c000a17..dbf5f44580bb 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.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 @@ */ 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 c30843e87c57..1dd07ba0e33e 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 cf1085f3b403..75c7dff9f87d 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 db51fb160c0a..80815647e5d8 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 f3e8841e6509..a7e8ec4e5293 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 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 @@ private String failureReason(String expectedDescription, @Nullable Object value) * @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 T evaluateJsonPath(String content, ParameterizedTypeReference targ 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 a346aa6a548f..81a57afddc9a 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 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 f63738405e9f..a924a62c4b54 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 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 static void setField(@Nullable Object targetObject, @Nullable Class ta * @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 static Object getField(Object targetObject, String name) { * @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 static Object getField(Class targetClass, String name) { * @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 static void invokeSetterMethod(Object target, String name, @Nullable Obje * @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 static Object invokeGetterMethod(Object target, String name) { * @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 static T invokeMethod(Object target, String name, Object... args) { * @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 static T invokeMethod(Class targetClass, String name, Object... ar * @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 046c0d406f22..18aabd19a994 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 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 void assertBoolean(byte[] content, @Nullable String encoding, boolean exp * @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 @@ protected Document parseXmlByteArray(byte[] xml, @Nullable String encoding) thro * @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 aa08fffb7904..12a3726e0675 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 caa3fdcadda3..d4348ea12e8a 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 7fac1976fbb3..03e63dedfa30 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.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 6e075ff93074..07c91a4afe6a 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.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 Set getExpectations() { /** * 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 d1fc550fa174..7ebbbad16caf 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.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 @@ protected List getRequestMatchers() { 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 c9eb4e9c6842..990d9b2d8910 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 @@ 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 12799b25880d..b8c66ef83208 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 @@ 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 @@ 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 de937e6051bd..fb9cb6020451 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.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.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 @@ private static class MultipartHelper { 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 da90493f25b7..a539a1b35f1d 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 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 cb8a23d931aa..e8ce5ff39570 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 ecfaf0c4a6c1..ddcf087c76b0 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 745f59e4b22b..bed82cc6e9c0 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.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.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 cbaa820b92f3..9ab07a724b57 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 @@ 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 dd84f7362496..1cf47771f3a9 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 @@ 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 242530cd1436..aaa3062c043b 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 932a82dcfa3d..79de8a4d9270 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 856fe3f71560..21dbcf3901b3 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.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 @@ 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 900a985c25a4..f01f7727429e 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.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 @@ private ApplicationContext initApplicationContext() { private static class TestWebFluxConfigurer implements WebFluxConfigurer { - @Nullable - private Consumer 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 @@ public void addFormatters(FormatterRegistry registry) { } @Override - @Nullable - public Validator getValidator() { + public @Nullable Validator getValidator() { return this.validator; } diff --git a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java index ad11d715a4b5..476da5c5a008 100644 --- a/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java +++ b/spring-test/src/main/java/org/springframework/test/web/reactive/server/DefaultWebTestClient.java @@ -34,6 +34,7 @@ import com.jayway.jsonpath.spi.mapper.MappingProvider; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Flux; @@ -44,7 +45,6 @@ import org.springframework.http.MediaType; import org.springframework.http.client.reactive.ClientHttpConnector; import org.springframework.http.client.reactive.ClientHttpRequest; -import org.springframework.lang.Nullable; import org.springframework.test.json.JsonAssert; import org.springframework.test.json.JsonComparator; import org.springframework.test.json.JsonCompareMode; @@ -78,18 +78,15 @@ class DefaultWebTestClient implements WebTestClient { private final WiretapConnector wiretapConnector; - @Nullable - private final JsonEncoderDecoder jsonEncoderDecoder; + private final @Nullable JsonEncoderDecoder jsonEncoderDecoder; private final ExchangeFunction exchangeFunction; private final UriBuilderFactory uriBuilderFactory; - @Nullable - private final HttpHeaders defaultHeaders; + private final @Nullable HttpHeaders defaultHeaders; - @Nullable - private final MultiValueMap defaultCookies; + private final @Nullable MultiValueMap defaultCookies; private final Consumer> entityResultConsumer; @@ -183,21 +180,17 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec { 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 @@ private static class DefaultResponseSpec implements ResponseSpec { private final ClientResponse response; - @Nullable - private final JsonEncoderDecoder jsonEncoderDecoder; + private final @Nullable JsonEncoderDecoder jsonEncoderDecoder; private final Consumer> entityResultConsumer; @@ -649,8 +641,7 @@ private static class DefaultBodyContentSpec implements BodyContentSpec { 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 61a5e47f5a62..8b704c7adbb7 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.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.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 f6a6dc1cddb3..fc5778eb7716 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 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.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 @@ public EncoderDecoderMappingProvider(Encoder encoder, Decoder decoder) { } - @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 d071cbf6288a..98c013e08677 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 @@ */ 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 554fddfccbb2..c68c349eebb7 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 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.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 URI getUrl() { /** * 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 HttpHeaders getRequestHeaders() { * 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 MultiValueMap getResponseCookies() { * 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 byte[] getResponseBodyContent() { * @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 @@ private String formatHeaders(HttpHeaders headers, String delimiter) { .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 fe4abf6c857a..f1c0558edfd2 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.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 ae861713ebe4..311e88a804a9 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.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.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 @@ static JsonEncoderDecoder from(Collection> messageWriters, * @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 @@ private static Encoder findJsonEncoder(Stream> stream) { * @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 6881a799bf56..2094cc6858b3 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 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 8d766d001c77..e77d49b70584 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.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.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 bf5bfb43930a..6a3144408983 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 c502d883ade6..4c13e93e773d 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.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.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 @@ public WiretapClientHttpResponse getResponse() { */ 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 @@ private void handleOnComplete() { */ private static class WiretapClientHttpRequest extends ClientHttpRequestDecorator { - @Nullable - private WiretapRecorder recorder; + private @Nullable WiretapRecorder recorder; public WiretapClientHttpRequest(ClientHttpRequest delegate) { @@ -280,8 +277,7 @@ public Flux getBody() { 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 57355a914f81..396446e500fd 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 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 681359421451..cd0345375923 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 5582235cfb38..82a5aa8e0190 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.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 @@ public void setHandler(@Nullable Object handler) { } @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 @@ public void setResolvedException(Exception resolvedException) { } @Override - @Nullable - public Exception getResolvedException() { + public @Nullable Exception getResolvedException() { return this.resolvedException; } @@ -117,8 +110,7 @@ public void setModelAndView(@Nullable ModelAndView mav) { } @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 7acf46ba1529..2d38806620e7 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.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 40403ddf60f7..dd3a48eec41d 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 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 31b2e15b4721..9688bcd32138 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 8b3b6d2d7b03..afea3bfaa4ee 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.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 @@ protected DefaultMvcResult getMvcResult(ServletRequest request) { } @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 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe } @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 6fc0dbd79aff..d1dd8e3eb1ba 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.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 @@ 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 5a0303def556..67620be77889 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 @@ */ 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 @@ public MvcResult getMvcResult() { } @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 e97be143bdc7..0f50be392622 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 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 309ee6c78a77..9c8cfcc50d03 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 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 73bcebdacccb..c58773b538c2 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 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 @@ private int getAllErrors() { .map(Errors::getErrorCount).reduce(0, Integer::sum); } - @Nullable - private BindingResult getBindingResult(String name) { + private @Nullable BindingResult getBindingResult(String name) { return BindingResultUtils.getBindingResult(this.actual, name); } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java index 20b6e942db15..a32ecffda9fa 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/MvcTestResult.java @@ -17,8 +17,8 @@ package org.springframework.test.web.servlet.assertj; import org.assertj.core.api.AssertProvider; +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.web.servlet.MvcResult; @@ -77,7 +77,6 @@ default MockHttpServletResponse getResponse() { * 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 55fd9e0ec6ad..46c50fd4d709 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.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 MvcTestResultAssert hasViewName(String viewName) { return this.myself; } - @Nullable - private Throwable getFailure() { + private @Nullable Throwable getFailure() { Exception unresolvedException = this.actual.getUnresolvedException(); if (unresolvedException != null) { return unresolvedException; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/package-info.java index 6fe626a51659..49ca44ffecdd 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/assertj/package-info.java @@ -1,9 +1,7 @@ /** * AssertJ support for MockMvc. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.assertj; -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/client/MockMvcHttpConnector.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java index e387a3b65e89..070e0c314eaa 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/MockMvcHttpConnector.java @@ -26,6 +26,7 @@ import java.util.function.Function; import jakarta.servlet.http.Cookie; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.core.ResolvableType; @@ -43,7 +44,6 @@ import org.springframework.http.codec.multipart.DefaultPartHttpMessageReader; import org.springframework.http.codec.multipart.FilePart; import org.springframework.http.codec.multipart.Part; -import org.springframework.lang.Nullable; import org.springframework.mock.http.client.reactive.MockClientHttpRequest; import org.springframework.mock.http.client.reactive.MockClientHttpResponse; import org.springframework.mock.http.server.reactive.MockServerHttpRequest; @@ -151,7 +151,7 @@ private RequestBuilder adaptRequest( } private AbstractMockHttpServletRequestBuilder 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 MockHttpServletResponse getResponse() { 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 28df853a01ea..bab99a0a4131 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 @@ 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 @@ interface ControllerSpec extends MockMvcServerSpec { * {@link StandaloneMockMvcBuilder#addMappedInterceptors(String[], HandlerInterceptor...)}. */ ControllerSpec mappedInterceptors( - @Nullable String[] pathPatterns, HandlerInterceptor... interceptors); + String @Nullable [] pathPatterns, HandlerInterceptor... interceptors); /** * Set a ContentNegotiationManager. @@ -414,7 +414,7 @@ interface RouterFunctionSpec extends MockMvcServerSpec { * {@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 5ff3e1dfc2b8..6a53caa81b11 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 @@ public MockMvcWebTestClient.RouterFunctionSpec interceptors(HandlerInterceptor.. } @Override - public MockMvcWebTestClient.RouterFunctionSpec mappedInterceptors(@Nullable String[] pathPatterns, HandlerInterceptor... interceptors) { + public MockMvcWebTestClient.RouterFunctionSpec mappedInterceptors(String @Nullable [] pathPatterns, HandlerInterceptor... interceptors) { this.mockMvcBuilder.addMappedInterceptors(pathPatterns, interceptors); return this; } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java index 52f811c01c13..b4a2e9c0e10a 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/StandaloneMockMvcSpec.java @@ -18,9 +18,10 @@ import java.util.function.Supplier; +import org.jspecify.annotations.Nullable; + import org.springframework.format.support.FormattingConversionService; 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.StandaloneMockMvcBuilder; @@ -86,7 +87,7 @@ public StandaloneMockMvcSpec interceptors(HandlerInterceptor... interceptors) { @Override public StandaloneMockMvcSpec mappedInterceptors( - @Nullable String[] pathPatterns, HandlerInterceptor... interceptors) { + String @Nullable [] pathPatterns, HandlerInterceptor... interceptors) { this.mockMvcBuilder.addMappedInterceptors(pathPatterns, interceptors); return this; diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/client/package-info.java b/spring-test/src/main/java/org/springframework/test/web/servlet/client/package-info.java index 7323682c55dd..ed071659d10b 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/client/package-info.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/client/package-info.java @@ -5,9 +5,7 @@ * handling. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.test.web.servlet.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/servlet/htmlunit/HtmlUnitRequestBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java index 4c370d5727be..d717ca3c86b3 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java @@ -39,10 +39,10 @@ import org.htmlunit.WebRequest; import org.htmlunit.util.KeyDataPair; import org.htmlunit.util.NameValuePair; +import org.jspecify.annotations.Nullable; import org.springframework.beans.Mergeable; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpSession; import org.springframework.mock.web.MockPart; @@ -79,17 +79,13 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable { private final WebRequest webRequest; - @Nullable - private String contextPath; + private @Nullable String contextPath; - @Nullable - private RequestBuilder parentBuilder; + private @Nullable RequestBuilder parentBuilder; - @Nullable - private SmartRequestBuilder parentPostProcessor; + private @Nullable SmartRequestBuilder parentPostProcessor; - @Nullable - private RequestPostProcessor forwardPostProcessor; + private @Nullable RequestPostProcessor forwardPostProcessor; /** @@ -234,8 +230,7 @@ private void authType(MockHttpServletRequest request) { } } - @Nullable - private String getHeader(String headerName) { + private @Nullable String getHeader(String headerName) { return this.webRequest.getAdditionalHeaders().get(headerName); } @@ -451,8 +446,7 @@ public HtmlUnitMockHttpServletRequest(ServletContext servletContext, String meth } @Override - @Nullable - public HttpSession getSession(boolean create) { + public @Nullable HttpSession getSession(boolean create) { HttpSession session = super.getSession(false); if (session == null && create) { HtmlUnitMockHttpSession newSession = new HtmlUnitMockHttpSession(this); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilder.java index cab9933e02cc..5a40b8541fc4 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/MockMvcWebClientBuilder.java @@ -17,8 +17,8 @@ package org.springframework.test.web.servlet.htmlunit; import org.htmlunit.WebClient; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcConfigurer; import org.springframework.util.Assert; @@ -43,8 +43,7 @@ */ public class MockMvcWebClientBuilder extends MockMvcWebConnectionBuilderSupport { - @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 165a9c0c5687..c79f231e7101 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.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 9219e76328df..98757e378737 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 4092859f8fe6..219a5f8ab60d 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 @@ 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 @@ */ 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 e314c09e6f5f..85aa06c1165f 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 63a7fb0faa3d..46cbb3de8fc5 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 84e7cb47ef4e..44e45bdfbe84 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.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.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 9b9de5adb5cc..3fb7a6d1270b 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 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 4ec50f72c0c3..a07eadbee664 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.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 4817e7fb4905..d55417c1127f 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 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 35a802a763d6..46d993389918 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 ce66b0449906..5c711971e294 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 01e722fffd8b..7222894da3ec 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 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 f03d6c6ef305..7edc99343580 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 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 a3392535bbbf..a5cc5e036a2a 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 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 599c05f09b5a..68edeec65213 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 61952f737389..c155895175ca 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 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 @@ protected void printAsyncResult(MvcResult result) throws Exception { /** * 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 2cd6f3b9fc28..415d07373c22 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 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 3925b5ccab67..bc7107a43341 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 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 ResultMatcher nodeList(Matcher matcher) { /** * 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 67057faef948..4c1c13105c8e 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 1180d5a4a42b..bf95cfee92b0 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.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 40de7774f21d..109280cd538f 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 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 b7707efde915..bc00d50a1a96 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 @@ default void afterConfigurerAdded(ConfigurableMockMvcBuilder builder) { * @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 be680aef9b98..2e18d12005a9 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 void afterConfigurerAdded(ConfigurableMockMvcBuilder builder) { } @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 f07720d4abc3..2204277e2de5 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.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 079b363a2695..716657637d11 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.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 RouterFunctionMockMvcBuilder addInterceptors(HandlerInterceptor... interc /** * Add interceptors mapped to a set of path patterns. */ - public RouterFunctionMockMvcBuilder addMappedInterceptors(@Nullable String[] pathPatterns, + public RouterFunctionMockMvcBuilder addMappedInterceptors(String @Nullable [] pathPatterns, HandlerInterceptor... interceptors) { for (HandlerInterceptor interceptor : interceptors) { diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/SharedHttpSessionConfigurer.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/SharedHttpSessionConfigurer.java index d12bca60d824..defde9465bbe 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/SharedHttpSessionConfigurer.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/SharedHttpSessionConfigurer.java @@ -17,8 +17,8 @@ package org.springframework.test.web.servlet.setup; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; -import org.springframework.lang.Nullable; import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.web.context.WebApplicationContext; @@ -44,8 +44,7 @@ */ public class SharedHttpSessionConfigurer implements MockMvcConfigurer { - @Nullable - private HttpSession session; + private @Nullable HttpSession session; @Override diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java index 917557b88a5e..3b465eceeb63 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java @@ -25,6 +25,7 @@ import java.util.function.Supplier; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; @@ -35,7 +36,6 @@ import org.springframework.format.support.DefaultFormattingConversionService; 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.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver; @@ -91,8 +91,7 @@ public class StandaloneMockMvcBuilder 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 StandaloneMockMvcBuilder addInterceptors(HandlerInterceptor... intercepto * Add interceptors mapped to a set of path patterns. */ public StandaloneMockMvcBuilder addMappedInterceptors( - @Nullable String[] pathPatterns, HandlerInterceptor... interceptors) { + String @Nullable [] pathPatterns, HandlerInterceptor... interceptors) { for (HandlerInterceptor interceptor : interceptors) { this.mappedInterceptors.add(new MappedInterceptor(pathPatterns, null, interceptor)); diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StaticViewResolver.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StaticViewResolver.java index 87c4bc37bfdc..60dd37dda67a 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StaticViewResolver.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StaticViewResolver.java @@ -18,7 +18,8 @@ import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.servlet.View; import org.springframework.web.servlet.ViewResolver; @@ -37,8 +38,7 @@ public StaticViewResolver(View view) { } @Override - @Nullable - public View resolveViewName(String viewName, Locale locale) { + public @Nullable View resolveViewName(String viewName, Locale locale) { return this.view; } } diff --git a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java index 8e8f6476b62d..93664bc94b61 100644 --- a/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java +++ b/spring-test/src/main/java/org/springframework/test/web/servlet/setup/StubWebApplicationContext.java @@ -24,6 +24,7 @@ import java.util.Set; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.BeanUtils; import org.springframework.beans.BeansException; @@ -47,7 +48,6 @@ import org.springframework.core.env.StandardEnvironment; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourcePatternResolver; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.context.WebApplicationContext; @@ -130,8 +130,7 @@ public long getStartupDate() { } @Override - @Nullable - public ApplicationContext getParent() { + public @Nullable ApplicationContext getParent() { return null; } @@ -169,7 +168,7 @@ public T getBean(String name, Class requiredType) throws BeansException { } @Override - public Object getBean(String name, Object... args) throws BeansException { + public Object getBean(String name, @Nullable Object @Nullable ... args) throws BeansException { return this.beanFactory.getBean(name, args); } @@ -179,7 +178,7 @@ public T getBean(Class requiredType) throws BeansException { } @Override - public 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 @@ public boolean isTypeMatch(String name, Class typeToMatch) throws NoSuchBeanD } @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 @@ public Map getBeansWithAnnotation(Class an } @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 @@ public Set findAllAnnotationsOnBean( //--------------------------------------------------------------------- @Override - @Nullable - public BeanFactory getParentBeanFactory() { + public @Nullable BeanFactory getParentBeanFactory() { return null; } @@ -356,13 +350,12 @@ public boolean containsLocalBean(String name) { //--------------------------------------------------------------------- @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 @@ public String getMessage(MessageSourceResolvable resolvable, Locale locale) thro //--------------------------------------------------------------------- @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -461,14 +453,12 @@ public Object resolveBeanByName(String name, DependencyDescriptor descriptor) th } @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 f030410ea827..3d1b982464e9 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 2ed2498993e2..3d1ca6027516 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 @@ 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 @@ private Consumer dummyHandler(@Nullable String beanName, Cl }; } - @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 9e01f72ca87e..9e05c0499b34 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 @@ 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 8944aeb2be3f..03886cf570a1 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.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 1a64107989f1..7b75f1343f6b 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.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 d6beaf4ba306..b2855102190d 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.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 c5cacb9472d9..4d04b9543594 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 @@ 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 d93fafb7837d..519c009dbef2 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 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 c642f01155f6..e140d79198de 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 fccb4b25eecc..94acd25191f8 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 @@ 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 @@ void otherAnnotationThrows() throws NoSuchFieldException { } 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 d75e512170e4..45846a83b2c1 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.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 @@ void factoryBeanSecondEnsuringMockReset(ApplicationContext ctx) { } 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 9a4e52c53b9a..27edfb51f246 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 @@ 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 9b97c17a4b10..504b32c65de7 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.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 994f34915885..6873a2d341e5 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.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.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 3e0536dfdd55..dc5175957dff 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 @@ void isCompatibleWhenDifferentTypeShouldFail() { } - @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 1c276b2463a2..307ab69fd2b5 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.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.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 60a30b779970..12a41c164ffb 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 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 17f294d4edaf..01b082a075cc 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 @@ 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 c3f11753b7b8..ac0df63ba311 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 @@ 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 d90c55690c55..c2ec58631d20 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 @@ 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 9092a82cef11..7b4a5724a0a9 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 @@ 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 1ca87ca3d425..ec3625f08ef6 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 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.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 c385798a0ff9..65ebc3bb490f 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 5487ffa670dd..ffeaa08da35a 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 9664399b13ab..e69f542dcd1b 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 d4847037856f..3953829bd3a3 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 a4044aa64830..32c1cb9f3fc8 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 67e055adb3d1..a0c70c5eb661 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 06051f6e6e77..94b8f229c591 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 f3308118b74b..61293d8b1432 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 66b5d79a230f..919c5bc896e7 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 dbf1b536ddb1..ffb80ae25a5b 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 e13fc2db7bb9..fd7a7febeb49 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 7620c039f20f..e682d47246c8 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 5d8a8ebfbfac..d750a9070568 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 09f16de1d7f6..fa8f685d0629 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 82749d877856..e7840f072cab 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 6787815eba27..6783352bdf0e 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 761baabca126..1bb388327471 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 ac8c75651f28..45560a00c22d 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 c8f1ff2a4969..d987869fa0a1 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 17d23ed157a1..4bf6941a4648 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 da3fd7911e4e..b0ed420b866c 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 0496afe5eac9..58b033e3f993 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 @@ 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 final PersistenceExceptionTranslator[] getDelegates() { @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 6d610a946608..a35d5a117b4a 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.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 static T singleResult(@Nullable Collection results) throws Incorre * 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 static T singleResult(@Nullable Stream results) throws IncorrectRe * 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 static T requiredSingleResult(@Nullable Collection results) throws * 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 static T nullableSingleResult(@Nullable Collection results) throws * 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 5844eb1c70c9..564f11649dd7 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 @@ 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.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 @@ 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 void afterPropertiesSet() { @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 282d6c5c1a04..6640ee14bae8 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 1efd755dd17c..fc49b288be68 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 e6b8eae942e9..9ec48e76ac60 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.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 void setBeanName(String beanName) { * @see #setBeanName */ @Override - @Nullable - public String getActivationName() { + public @Nullable String getActivationName() { return this.beanName; } @@ -151,8 +147,7 @@ public String getActivationName() { * 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 MessageEndpoint createEndpoint(XAResource xaResource, long timeout) throw */ 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 void release() { */ 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 7ac7272c766e..874471dc8b3c 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.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 @@ */ public class GenericMessageEndpointFactory extends AbstractMessageEndpointFactory { - @Nullable - private Object messageListener; + private @Nullable Object messageListener; /** @@ -108,8 +107,7 @@ protected AbstractMessageEndpoint createEndpointInternal() throws UnavailableExc 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 8ae0cbd2741f..5512f638fa9e 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.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 @@ */ 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 void setResourceAdapter(@Nullable ResourceAdapter resourceAdapter) { /** * Return the JCA ResourceAdapter to manage endpoints for. */ - @Nullable - public ResourceAdapter getResourceAdapter() { + public @Nullable ResourceAdapter getResourceAdapter() { return this.resourceAdapter; } @@ -200,8 +196,7 @@ public void setMessageEndpointFactory(@Nullable MessageEndpointFactory messageEn /** * Return the JCA MessageEndpointFactory to activate. */ - @Nullable - public MessageEndpointFactory getMessageEndpointFactory() { + public @Nullable MessageEndpointFactory getMessageEndpointFactory() { return this.messageEndpointFactory; } @@ -217,8 +212,7 @@ public void setActivationSpec(@Nullable ActivationSpec activationSpec) { /** * 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 45f3610a9e7f..845c4abcc866 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 f7a0be1fe487..95edc20fffaa 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 @@ 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 @@ */ 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 void afterPropertiesSet() throws ResourceException { @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 9969c97d571d..9bec3c3e718c 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.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 @@ */ 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 void afterPropertiesSet() throws ResourceException { @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 fac8e45d5abe..2ad24cea85b3 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.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 @@ */ 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 WorkManager getWorkManager() { } @Override - @Nullable - public XATerminator getXATerminator() { + public @Nullable XATerminator getXATerminator() { return this.xaTerminator; } @@ -112,8 +108,7 @@ public boolean isContextSupported(Class workContextClass) } @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 547844092eb0..ee725852c51a 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 345b5bf27ff0..08910f4f989d 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 6be097faf7e1..a62f38bbe81e 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 5b07f2037829..2a35ced3d8f3 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 @@ default boolean isReadOnly() { * @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 768c90cbdb59..cf0ce824dedf 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 eb1e833ccf64..3615a2b15604 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 @@ @SuppressWarnings("serial") public class TransactionSystemException extends TransactionException { - @Nullable - private Throwable applicationException; + private @Nullable Throwable applicationException; /** @@ -71,8 +71,7 @@ public void initApplicationException(Throwable ex) { * 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 final Throwable getApplicationException() { * 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 178bd5640dde..8f2dfb724a1b 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 @@ 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.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 @@ @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 bc89a105111d..7d11562bd0ee 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.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 boolean isCandidateClass(Class targetClass) { } @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 @@ protected TransactionAttribute findTransactionAttribute(Method method) { * @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 52fd72c192ec..5aab3188315d 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 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 boolean isCandidateClass(Class targetClass) { } @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 ab933c6c11e6..f12133d9c61e 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.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 boolean isCandidateClass(Class targetClass) { } @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 36dd09936b32..942b50f5abb0 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.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 boolean isCandidateClass(Class targetClass) { } @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 8aa5f2b28028..14043deec437 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 @@ 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 @@ default boolean isCandidateClass(Class targetClass) { * @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 93f8114cf729..7f2ea3e9e68c 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.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.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 94f968d9514c..06918ff2bcb7 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 fdef1fa4b563..af05a2af6029 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 d7dca39ef5dc..5a0ffac962fc 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.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 7ca1edb538a2..ff807e18d4ef 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 void afterPropertiesSet() throws TransactionSystemException { } @Override - @Nullable - public JtaTransactionManager getObject() { + public @Nullable JtaTransactionManager getObject() { return this.transactionManager; } diff --git a/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java index 120413df0a66..4b63033ba41d 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/config/package-info.java @@ -2,9 +2,7 @@ * Support package for declarative transaction configuration, * with XML schema being the primary configuration format. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.config; -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/event/TransactionalApplicationListener.java b/spring-tx/src/main/java/org/springframework/transaction/event/TransactionalApplicationListener.java index 0ba5818c14ff..6ba1f6245233 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/event/TransactionalApplicationListener.java +++ b/spring-tx/src/main/java/org/springframework/transaction/event/TransactionalApplicationListener.java @@ -18,11 +18,12 @@ import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; + import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.PayloadApplicationEvent; import org.springframework.core.Ordered; -import org.springframework.lang.Nullable; /** * An {@link ApplicationListener} that is invoked according to a {@link TransactionPhase}. diff --git a/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java b/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java index 507a1af2e8b0..c4f2763f911c 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java +++ b/spring-tx/src/main/java/org/springframework/transaction/event/package-info.java @@ -1,9 +1,7 @@ /** * Spring's support for listening to transaction events. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.transaction.event; -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/interceptor/AbstractFallbackTransactionAttributeSource.java b/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java index 829680eae2fc..b927e1a7d7ae 100644 --- a/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java +++ b/spring-tx/src/main/java/org/springframework/transaction/interceptor/AbstractFallbackTransactionAttributeSource.java @@ -23,11 +23,11 @@ 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.context.EmbeddedValueResolverAware; import org.springframework.core.MethodClassKey; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringValueResolver; @@ -70,8 +70,7 @@ public String toString() { */ protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private transient StringValueResolver embeddedValueResolver; + private transient @Nullable StringValueResolver embeddedValueResolver; /** * Cache of TransactionAttributes, keyed by method on a specific target class. @@ -93,8 +92,7 @@ public boolean hasTransactionAttribute(Method method, @Nullable Class targetC } @Override - @Nullable - public TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { + public @Nullable TransactionAttribute getTransactionAttribute(Method method, @Nullable Class targetClass) { return getTransactionAttribute(method, targetClass, true); } @@ -107,8 +105,7 @@ public TransactionAttribute getTransactionAttribute(Method method, @Nullable Cla * @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 @@ protected Object getCacheKey(Method method, @Nullable Class targetClass) { * @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 @@ protected TransactionAttribute computeTransactionAttribute(Method method, @Nulla * @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 @@ protected TransactionAttribute computeTransactionAttribute(Method method, @Nulla * @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 d547829066d4..4848427aa755 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 @@ 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 boolean hasTransactionAttribute(Method method, @Nullable Class targetC } @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 c373271c28c1..875fe3f30930 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.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 @@ @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 void setDescriptor(@Nullable String descriptor) { * 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 void setTimeoutString(@Nullable String timeoutString) { * @see #getTimeout * @see #resolveAttributeStrings */ - @Nullable - public String getTimeoutString() { + public @Nullable String getTimeoutString() { return this.timeoutString; } @@ -146,8 +142,7 @@ public void setQualifier(@Nullable String qualifier) { * @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 7d74ac589766..3c8bef92aa35 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 @@ 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 DelegatingTransactionAttribute(TransactionAttribute targetAttribute) { @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 4f94d16f1998..701810770d68 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 @@ 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 void setTransactionAttribute(TransactionAttribute transactionAttribute) { @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 a4fe2cac71a1..95626e903b13 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 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 @@ protected boolean isMatch(String methodName, String mappedName) { @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 7eb89423037a..c3f733d70621 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 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 void afterPropertiesSet() { @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 2f9e23296d1c..31422c4dc775 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 @@ 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 f1425fc79809..0ee2671f7484 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.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 89dd57102573..f1c2c32a60c7 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 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.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 static TransactionStatus currentTransactionStatus() throws NoTransactionE 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 void setTransactionManagerBeanName(@Nullable String transactionManagerBea /** * 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 void setTransactionManager(@Nullable TransactionManager transactionManage *

    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 void setTransactionAttributeSource(@Nullable TransactionAttributeSource t /** * Return the transaction attribute source. */ - @Nullable - public TransactionAttributeSource getTransactionAttributeSource() { + public @Nullable TransactionAttributeSource getTransactionAttributeSource() { return this.transactionAttributeSource; } @@ -304,8 +295,7 @@ public void setBeanFactory(@Nullable BeanFactory beanFactory) { /** * 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 void afterPropertiesSet() { * @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 @@ protected void clearTransactionManagerCache() { * @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 @@ else if (targetClass != null) { * @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 @@ private TransactionManager determineQualifiedTransactionManager(BeanFactory bean 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 @@ private String methodIdentification(Method method, @Nullable Class targetClas * @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 @@ protected void cleanupTransactionInfo(@Nullable TransactionInfo txInfo) { */ 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 PlatformTransactionManager getTransactionManager() { return this.transactionManager; } - @Nullable - public TransactionAttribute getTransactionAttribute() { + public @Nullable TransactionAttribute getTransactionAttribute() { return this.transactionAttribute; } @@ -806,8 +786,7 @@ public void newTransactionStatus(@Nullable TransactionStatus status) { this.transactionStatus = status; } - @Nullable - public TransactionStatus getTransactionStatus() { + public @Nullable TransactionStatus getTransactionStatus() { return this.transactionStatus; } @@ -846,8 +825,7 @@ public String toString() { @FunctionalInterface protected interface InvocationCallback { - @Nullable - Object proceedWithInvocation() throws Throwable; + @Nullable Object proceedWithInvocation() throws Throwable; } @@ -856,8 +834,7 @@ protected interface InvocationCallback { */ private static class ThrowableHolder { - @Nullable - public Throwable throwable; + public @Nullable Throwable throwable; } @@ -1085,16 +1062,13 @@ private Throwable unwrapIfResourceCleanupFailure(Throwable ex) { */ 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 ReactiveTransactionManager getTransactionManager() { return this.transactionManager; } - @Nullable - public TransactionAttribute getTransactionAttribute() { + public @Nullable TransactionAttribute getTransactionAttribute() { return this.transactionAttribute; } @@ -1126,8 +1099,7 @@ public void newReactiveTransaction(@Nullable ReactiveTransaction transaction) { 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 afddd2f95fc3..0dd0f7934278 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 @@ 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 8514092f4f0a..9c084d22b5b5 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 @@ 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 @@ default boolean hasTransactionAttribute(Method method, @Nullable Class target * 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 bbaca68870bb..7a59b81c9fa9 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 @@ @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 319715b4562f..2814b8144f11 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 @@ 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 @@ @SuppressWarnings("serial") final class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { - @Nullable - private TransactionAttributeSource transactionAttributeSource; + private @Nullable TransactionAttributeSource transactionAttributeSource; public TransactionAttributeSourcePointcut() { @@ -89,8 +89,7 @@ public boolean matches(Class clazz) { 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 863c23506cda..dad6ba5ea687 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 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 TransactionInterceptor(PlatformTransactionManager ptm, Properties attribu @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 723d1eb877f3..ed5247bbb86e 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 @@ 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.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 44e8ff8b6ce0..5ad15b907385 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 c937dbcd3bce..9f56a2619752 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.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 void setJndiEnvironment(@Nullable Properties jndiEnvironment) { /** * 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 void setUserTransaction(@Nullable UserTransaction userTransaction) { /** * 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 void setTransactionManager(@Nullable TransactionManager transactionManage /** * 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 void setTransactionSynchronizationRegistry(@Nullable TransactionSynchroni /** * 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 @@ protected TransactionSynchronizationRegistry lookupTransactionSynchronizationReg * @see #setUserTransaction * @see #setUserTransactionName */ - @Nullable - protected UserTransaction retrieveUserTransaction() throws TransactionSystemException { + protected @Nullable UserTransaction retrieveUserTransaction() throws TransactionSystemException { return null; } @@ -649,8 +638,7 @@ protected UserTransaction retrieveUserTransaction() throws TransactionSystemExce * @see #setTransactionManager * @see #setTransactionManagerName */ - @Nullable - protected TransactionManager retrieveTransactionManager() throws TransactionSystemException { + protected @Nullable TransactionManager retrieveTransactionManager() throws TransactionSystemException { return null; } @@ -662,8 +650,7 @@ protected TransactionManager retrieveTransactionManager() throws TransactionSyst * 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 @@ protected TransactionSynchronizationRegistry retrieveTransactionSynchronizationR * @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 @@ protected UserTransaction findUserTransaction() { * @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 @@ protected TransactionManager findTransactionManager(@Nullable UserTransaction ut * 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 f0977ac25e39..030659a6bf8a 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.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 622339fcdfdc..7618f979bcf8 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.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 b0ac31420835..7b9b7a7b394c 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 @@ 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 677749eb0a4c..8be9c82a9b02 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 94ee460c5f7b..abd9c1ee27fb 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 8a3a5056b6a7..33614071f20f 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 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 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound */ 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 0cf7a5833d28..6456b2d5e53c 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 @@ */ 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 boolean isDebug() { * 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 9a6c191a916c..8fdb9c7ecf52 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.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 @@ */ 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 void setSynchronizations(@Nullable Set synchr this.synchronizations = synchronizations; } - @Nullable - public Set getSynchronizations() { + public @Nullable Set getSynchronizations() { return this.synchronizations; } @@ -86,8 +80,7 @@ public void setCurrentTransactionName(@Nullable String currentTransactionName) { this.currentTransactionName = currentTransactionName; } - @Nullable - public String getCurrentTransactionName() { + public @Nullable String getCurrentTransactionName() { return this.currentTransactionName; } @@ -103,8 +96,7 @@ public void setCurrentTransactionIsolationLevel(@Nullable Integer currentTransac 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 1c2fa3a5bf81..4b08bb60d40f 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.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 boolean hasResource(Object key) { * @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 Object getResource(Object key) { /** * 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 Object unbindResource(Object key) throws IllegalStateException { * @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 Object unbindResourceIfPossible(Object key) { /** * 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 void setCurrentTransactionName(@Nullable String name) { * 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 void setCurrentTransactionIsolationLevel(@Nullable Integer isolationLevel * @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 d812235dd9dc..c5f4654e0a11 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 @@ 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 ef3661198641..7ad37c2cb3d0 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 73b56a20152b..894580699ec4 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 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 @@ protected int determineTimeout(TransactionDefinition definition) { * @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 @@ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFound */ 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 fa7fcff4ae8f..1b3b75597ffa 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 @@ protected void setSavepoint(@Nullable Object savepoint) { /** * 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 5cc9ee59f5fb..a37af8cd14f6 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 4faabde754e6..74cc341e36e0 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 @@ 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 final void setName(String name) { } @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 1d71e544d436..bb4d07bc4291 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 @@ */ 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 boolean isDebug() { * 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 29228b6f699f..11a0adb72f3e 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 @@ 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 boolean isReadOnly() { } @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 c0b2bdaf636f..ea2b5a08067e 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 @@ 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 boolean hasTimeout() { * 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 fb0f11574afd..dacebd9119ea 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.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 Object get(String name, ObjectFactory objectFactory) { } @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 void registerDestructionCallback(String name, Runnable callback) { } @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 70b76cf96fc2..f155b117f5b4 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 4552e5796142..6a21cd926d6f 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 @@ 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 3ba6d3f2884d..c09ff5bc1ae0 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 @@ 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 0b310c99e136..08253d3190de 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.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 static boolean hasResource(Object key) { * 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 static Object getResource(Object key) { /** * 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 static Object unbindResource(Object key) throws IllegalStateException { * @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 static Object unbindResourceIfPossible(Object key) { /** * 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 static void setCurrentTransactionName(@Nullable String name) { * 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 static void setCurrentTransactionIsolationLevel(@Nullable Integer isolati * @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 8da53ffb9c1e..28709b2c156c 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 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 87c37645eaf4..2cffbe61df13 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 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 void setTransactionManager(@Nullable PlatformTransactionManager transacti /** * Return the transaction management strategy to be used. */ - @Nullable - public PlatformTransactionManager getTransactionManager() { + public @Nullable PlatformTransactionManager getTransactionManager() { return this.transactionManager; } @@ -126,8 +124,7 @@ public void afterPropertiesSet() { @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 08a4e4cd43a6..6ec914ec3359 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 @@ 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 @@ private WithoutTransactionOperations() { @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 59a310edf0a6..ba8447d39673 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 3b117b37ea1a..09d7e7efd2bc 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 655146a55e05..693b298ba159 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.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 @@ private void process(Class beanClass) { } } - @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 6d8ad6e48f72..262a6640d7e0 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 @@ */ 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 727369f4d757..13f0dd901346 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 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.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 0fd25c0a3af3..73702354ca36 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 adea2bb54a8d..6b4f22d64375 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 @@ 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 3a4dd0184f43..ef9ae00d18ef 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 @@ 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 4f2437f1be99..b560004938a4 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 6843f2e796b7..6a2e35721243 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 108c65cadbf6..f49e275dc334 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 66f9e88e6620..c626c0c7069b 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 e412ffd74daf..606e75a5aacd 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.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 @@ public HttpComponents(HttpMessage message) { @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 @@ public boolean containsValue(Object value) { 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 @@ public List get(Object key) { 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 @@ static final class Jetty implements MultiValueMap { private final HttpFields headers; - @Nullable - private final HttpFields.Mutable mutable; + private final HttpFields.@Nullable Mutable mutable; /** @@ -343,9 +338,8 @@ public boolean containsValue(Object value) { 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 @@ public List get(Object key) { 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 @@ public List put(String key, List value) { 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 @@ private final class HeaderNamesIterator implements Iterator { private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; @@ -563,8 +554,7 @@ public Netty4(io.netty.handler.codec.http.HttpHeaders headers) { @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { return this.headers.get(key); } @@ -632,25 +622,22 @@ public boolean containsValue(Object value) { } @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 @@ private final class HeaderNamesIterator implements Iterator { private final Iterator iterator; - @Nullable - private String currentName; + private @Nullable String currentName; private HeaderNamesIterator(Iterator iterator) { this.iterator = iterator; @@ -810,8 +796,7 @@ public Netty5(io.netty5.handler.codec.http.headers.HttpHeaders headers) { @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 @@ public boolean containsValue(Object value) { } @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 @@ public List get(Object key) { 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 @@ private final class HeaderNamesIterator implements Iterator { 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 00b32d8aa483..afe7bd4d36dd 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 @@ 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 @@ */ 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 CacheControl immutable() { * 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 90d91a6fbea8..c70bd822b5d0 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.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 boolean isInline() { * @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 String getName() { * 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 @@ private static class BuilderImpl implements Builder { 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 0cf6650939de..d6e66e395b7b 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 @@ 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 e85bd9f9c82a..ce7e2a954d44 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 b3203e4e05de..ffb2bf4d257a 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 HttpHeaders getHeaders() { /** * 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 4cd56579cdf7..958d1012fa88 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.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 void setAccessControlAllowOrigin(@Nullable String allowedOrigin) { /** * 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 void setAccessControlRequestMethod(@Nullable HttpMethod requestMethod) { /** * 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 void setCacheControl(@Nullable String cacheControl) { /** * 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 void setContentLanguage(@Nullable Locale locale) { * if unknown * @since 5.0 */ - @Nullable - public Locale getContentLanguage() { + public @Nullable Locale getContentLanguage() { return getValuesAsList(CONTENT_LANGUAGE) .stream() .findFirst() @@ -1042,8 +1039,7 @@ public void setContentType(@Nullable MediaType mediaType) { *

    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 void setETag(@Nullable String tag) { /** * 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 void setHost(@Nullable InetSocketAddress host) { * 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 void setLocation(@Nullable URI location) { * 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 void setOrigin(@Nullable String origin) { /** * Return the value of the {@code Origin} header. */ - @Nullable - public String getOrigin() { + public @Nullable String getOrigin() { return getFirst(ORIGIN); } @@ -1407,8 +1399,7 @@ public void setPragma(@Nullable String pragma) { /** * Return the value of the {@code Pragma} header. */ - @Nullable - public String getPragma() { + public @Nullable String getPragma() { return getFirst(PRAGMA); } @@ -1439,8 +1430,7 @@ public void setUpgrade(@Nullable String upgrade) { /** * Return the value of the {@code Upgrade} header. */ - @Nullable - public String getUpgrade() { + public @Nullable String getUpgrade() { return getFirst(UPGRADE); } @@ -1532,8 +1522,7 @@ private long getFirstDate(String headerName, boolean rejectInvalid) { * @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 ZonedDateTime getFirstZonedDateTime(String headerName) { * 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 @@ protected List getETagValuesAsList(String name) { * @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 @@ private void setOrRemove(String headerName, @Nullable String headerValue) { * @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 boolean containsValue(Object value) { } @Override - @Nullable - public List get(Object key) { + public @Nullable List get(Object key) { return this.headers.get(key); } @@ -2081,8 +2066,7 @@ private final class CaseInsensitiveIterator implements 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 e10185ecb462..95debcfbcaa2 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 @@ 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 d44cc646eecf..a842b763c01e 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 bc1d966657a2..a887e8b24ef0 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.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 @@ private static class ByteRange extends 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 94284d101d69..b29deb1414e6 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 static HttpStatus valueOf(int statusCode) { * @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 static Series valueOf(int statusCode) { * @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 905e95a0d037..f1be0ee6d721 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 e37d4ffdb976..80a545073ac2 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.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 7491e3c8767c..3194b331465b 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.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 016160acb518..4e0bf8a5949e 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.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 void setTitle(@Nullable String title) { /** * 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 void setDetail(@Nullable String detail) { /** * Return the configured {@link #setDetail(String) problem detail}. */ - @Nullable - public String getDetail() { + public @Nullable String getDetail() { return this.detail; } @@ -196,8 +191,7 @@ public void setInstance(@Nullable URI instance) { /** * Return the configured {@link #setInstance(URI) problem instance}. */ - @Nullable - public URI getInstance() { + public @Nullable URI getInstance() { return this.instance; } @@ -239,8 +233,7 @@ public void setProperties(@Nullable Map properties) { * 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 b667207f936c..e40118ad54fb 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.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 @@ public void clearContentHeaders() { } @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 d387735f8b7a..a31e78cc0345 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.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 @@ */ 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 RequestEntity(@Nullable T body, @Nullable MultiValueMap h * 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 URI getUrl() { * @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 @@ private static class DefaultBodyBuilder implements BodyBuilder { 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 static class UriTemplateRequestEntity extends RequestEntity { 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 String getUriTemplate() { 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 67d8dbea3908..5539fc60cc6a 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 @@ 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 Duration getMaxAge() { /** * 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 boolean isPartitioned() { * @since 5.1 * @see RFC6265 bis */ - @Nullable - public String getSameSite() { + public @Nullable String getSameSite() { return this.sameSite; } @@ -403,18 +398,15 @@ private static class DefaultResponseCookieBuilder implements ResponseCookieBuild 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 @@ private static class DefaultResponseCookieBuilder implements ResponseCookieBuild 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 ResponseCookieBuilder domain(@Nullable String domain) { 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 a6e16405e88d..f5ea7cfc0d1c 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.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 5404493a343f..d978f58f1edc 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.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 fa3ea1dfea4f..a280401fd08b 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 @@ 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 @@ 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 482a23e7da1d..204802ed14b9 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.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 d2559a800df3..0fa14e91ebba 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.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 @@ public long getContentLength() { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.headers.getFirst(HttpHeaders.CONTENT_TYPE); } @@ -166,14 +165,12 @@ public boolean isStreaming() { } @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 @@ public boolean isChunked() { } @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 3f3825c62f0c..f8477038d0a0 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.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 ClientHttpRequest createRequest(URI uri, HttpMethod httpMethod) throws IO * @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 @@ protected void postProcessHttpRequest(ClassicHttpRequest request) { * @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 a636deeaacc9..f7bb0814b837 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 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 d5e26381c0b0..4de6f750424a 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.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 79e0b8323f40..99c7f2ae3402 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.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 @@ private TimeoutHandler(CompletableFuture> future, Dura } - @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 6597048cb1ea..5225a32be111 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.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 8f8ce96de891..3c22f6987d89 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.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 c846684e4101..cd4d3f5ccd74 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.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 46640fed4144..80842db21f9b 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.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.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 @@ private static class DefaultPartBuilder implements PartBuilder { 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 @@ static final class PublisherEntity> extends HttpEntity * 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 8354172f68c9..553589b538e6 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.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 @@ private static final class OutputStreamSubscription extends OutputStream impl 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 b55dfee56014..fd494d1df000 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 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 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 63cfc19ffaca..2f35a367b5a8 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 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 4f92c0997937..b8bc57f4a264 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.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 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 6fe8b6c481af..0ffb5bcfd190 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.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.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 9c6932e95c16..97a1180e5109 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.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 baf2f9ef630a..ddffc4e86a58 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.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 728871cddd82..48c47926c06d 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.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 ec3834d717f9..bd7abf52c6bc 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 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 a150dc8d9555..258b889831be 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 @@ */ public class ClientRequestObservationContext extends RequestReplySenderContext { - @Nullable - private String uriTemplate; + private @Nullable String uriTemplate; /** @@ -64,8 +63,7 @@ public void setUriTemplate(@Nullable String uriTemplate) { /** * Return the URI template used for the current client exchange, {@code null} if none was used. */ - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } diff --git a/spring-web/src/main/java/org/springframework/http/client/observation/DefaultClientRequestObservationConvention.java b/spring-web/src/main/java/org/springframework/http/client/observation/DefaultClientRequestObservationConvention.java index fef77d242b0b..9ac178793867 100644 --- a/spring-web/src/main/java/org/springframework/http/client/observation/DefaultClientRequestObservationConvention.java +++ b/spring-web/src/main/java/org/springframework/http/client/observation/DefaultClientRequestObservationConvention.java @@ -22,6 +22,7 @@ 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; @@ -29,7 +30,6 @@ import org.springframework.http.client.ClientHttpResponse; import org.springframework.http.client.observation.ClientHttpObservationDocumentation.HighCardinalityKeyNames; import org.springframework.http.client.observation.ClientHttpObservationDocumentation.LowCardinalityKeyNames; -import org.springframework.lang.Nullable; import org.springframework.util.StringUtils; /** @@ -87,8 +87,7 @@ public String getName() { } @Override - @Nullable - public String getContextualName(ClientRequestObservationContext context) { + public @Nullable String getContextualName(ClientRequestObservationContext context) { ClientHttpRequest request = context.getCarrier(); return (request != null ? "http " + request.getMethod().name().toLowerCase(Locale.ROOT) : null); } diff --git a/spring-web/src/main/java/org/springframework/http/client/observation/package-info.java b/spring-web/src/main/java/org/springframework/http/client/observation/package-info.java index 6f3bbf9b9646..fed8437b8ad7 100644 --- a/spring-web/src/main/java/org/springframework/http/client/observation/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/client/observation/package-info.java @@ -2,9 +2,7 @@ * This package provides support for client HTTP * {@link io.micrometer.observation.Observation}. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.client.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/client/package-info.java b/spring-web/src/main/java/org/springframework/http/client/package-info.java index 9c9935e3e9af..6abd45ffffe2 100644 --- a/spring-web/src/main/java/org/springframework/http/client/package-info.java +++ b/spring-web/src/main/java/org/springframework/http/client/package-info.java @@ -3,9 +3,7 @@ * contains the {@code ClientHttpRequest} and {@code ClientHttpResponse}, * as well as a basic implementation of these interfaces. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.http.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/http/client/reactive/AbstractClientHttpRequest.java b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java index 63db636c0a55..fa20e11ae7bc 100644 --- a/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java +++ b/spring-web/src/main/java/org/springframework/http/client/reactive/AbstractClientHttpRequest.java @@ -24,13 +24,13 @@ 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; import org.springframework.http.HttpCookie; import org.springframework.http.HttpHeaders; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -64,8 +64,7 @@ private enum State {NEW, COMMITTING, COMMITTED} private final List>> 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 c878792c0f2a..b2ac22eade4d 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.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.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 5b6f08de1051..b0006d2267ae 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.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 9eeebb6b2755..8130238fa7ee 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.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.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 e1a742b33d86..92ed16d8e45b 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.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.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 f46fd8494ad6..734a3b819da3 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.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 @@ */ public class JdkHttpClientResourceFactory implements InitializingBean, DisposableBean { - @Nullable - private Executor executor; + private @Nullable Executor executor; private String threadPrefix = "jdk-http"; @@ -62,8 +62,7 @@ public void setExecutor(@Nullable Executor executor) { /** * 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 ca255fe97375..229e105e7fce 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 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 cef7da388e60..6f4e161f1810 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 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.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 @@ private static MultiValueMap adaptCookies(ReactiveRespon 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 5b7dbc5464f5..0e1268bf70eb 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.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 @@ */ 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 void setThreadPrefix(String threadPrefix) { /** * 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 db838d6ad066..11b1ef6cc1f3 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 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 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 411fda8f20a9..fdd915be92c8 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.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.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 @@ public MultiValueMap getCookies() { 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 2af3933d0e12..623561cfa4a5 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.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.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 @@ public MultiValueMap getCookies() { 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 @@ private static long toLong(@Nullable Long value) { 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 41fb5a3fc941..9eb8b7238495 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.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 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 b17f099cdb86..abde1debf538 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 71f09d6483b8..d812a8d31ef8 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 @@ 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 b7bd4408210c..d1971fda6618 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 @@ 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 e1b9e0c8c7fe..be9684c82b75 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.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 void afterPropertiesSet() throws IllegalArgumentException { @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 0308cb51a3d1..d6040adf7040 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 a309838cc880..1b0aa23e7014 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 @@ 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 @@ interface DefaultCodecConfig { * 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 c317651075f9..ec26ef9edd51 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 978e7f04c071..ab723681f194 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.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.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 Mono readMono(ResolvableType elementType, ReactiveHttpInputMessage mes * @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 fc791caab737..3bebe1195a8c 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.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.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 @@ private static void initLogger(Encoder encoder) { } } - @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 Mono write(Publisher inputStream, ResolvableType eleme 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 b057fea3448c..83ac2c625838 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.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.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 4b313089d774..db89918e454d 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.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.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 b968236a9c9a..05cfb52508a1 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 @@ 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 16d578b4f4a7..f042614d2273 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.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.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 46a72b0ac17e..bddb686d56ee 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.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.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 b0c05318d00c..702f1cc3cc19 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 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.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 de16320454c0..d65a9e76f3bb 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 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.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 79f42b43fb4e..89ab88630bf3 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 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.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 f9ade37bce43..000ed1eab4de 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 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.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 bded9bb17cb6..53b7b804b615 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.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 @@ private boolean supports(@Nullable MimeType mimeType) { * @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 bbcc49b9be50..5be851714dbb 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.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.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 @@ private static Mono lengthOf(Resource resource) { } } - @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 397524427898..e84a8571fd97 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 @@ 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 @@ */ 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 @@ private ServerSentEvent(@Nullable String id, @Nullable String event, @Nullable D /** * 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 interface Builder { 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 61289b03e927..e6c5f1d7a4e6 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.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.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 ServerSentEventHttpMessageReader(@Nullable Decoder decoder) { /** * Return the configured {@code Decoder}. */ - @Nullable - public Decoder getDecoder() { + public @Nullable Decoder getDecoder() { return this.decoder; } @@ -137,9 +135,8 @@ public Flux read( }); } - @Nullable @SuppressWarnings("NullAway") - private Object buildEvent(List 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 @@ else if (line.startsWith(":")) { } } - @Nullable - private Object decodeData(StringBuilder data, ResolvableType dataType, Map 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 28aac85286a9..c8edf9196989 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.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.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 ServerSentEventHttpMessageWriter(@Nullable Encoder encoder) { /** * Return the configured {@code Encoder}, if any. */ - @Nullable - public Encoder 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 7d04e82c14de..9daf3b302db6 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 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.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 bee3462e736c..92219536296c 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 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.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 9a7faa8f0efe..30159b0eea5a 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 03e5ea2c17e3..23b8b1a37fb7 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.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.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 @@ protected ObjectReader customizeReader( 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 List getDecodableMimeTypes(ResolvableType targetType) { // 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 7965a651f9bb..587d8a7ef236 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.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.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 @@ protected ObjectWriter customizeWriter(ObjectWriter writer, @Nullable MimeType m * 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 Map getEncodeHints(@Nullable ResolvableType actualType, R // 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 56dcd96ae7c4..e9388e6f5ab6 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.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.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 void registerObjectMappersForType(Class clazz, Consumer 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 @@ protected Map getHints(ResolvableType resolvableType) { 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 @@ protected MethodParameter getParameter(ResolvableType type) { * {@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 e92281bf1dc6..15a266c50bd1 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.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.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 43643fa5bf44..5276ae9e7e34 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.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 a5dfacef5757..c79fe25cceda 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 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 Jackson2SmileEncoder(ObjectMapper mapper, MimeType... mimeTypes) { * 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 92cd20e3b8c4..77b2bef777e4 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.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.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 710d9c02512e..a42d273457b8 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 eecf24215a5b..81eed555a125 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.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.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 aecd92e17056..1d84ea814f5a 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.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.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 a088729fe951..01134b6689c1 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 @@ 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 70092ba65011..f6961fb2bf8a 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.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.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 2ca17063e56d..cf7be2ea1bbe 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.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.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 List> getPartWriters() { * Return the configured form writer. * @since 5.1.13 */ - @Nullable - public HttpMessageWriter> getFormWriter() { + public @Nullable HttpMessageWriter> getFormWriter() { return this.formWriter; } @@ -315,8 +313,7 @@ private class MultipartHttpOutputMessage implements ReactiveHttpOutputMessage { 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 789a3726e470..00cad9795341 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 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.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 b7e4d07db0f5..46c5ebcab3bf 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.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 @@ public static Charset charset(HttpHeaders headers) { 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 9e78ab9a9e9b..dba5351a7310 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.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.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 68dc17e57fb7..26878ea666b4 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.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.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 86ec98662795..ae9661e85645 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 @@ 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.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 ddf92c14caa3..76cd4b675138 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 @@ 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.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 44dad3697d6e..b1dc18e1acb0 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 a4c6b8505b20..81be0978d438 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 aef7b72cbe56..3571bddae7c2 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 @@ 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 c48a4f00b98e..a06d6c0d9b17 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 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.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 @@ private class MessageDecoderFunction implements FunctionGoogle 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 05c4c0f4a4d1..85896edc3103 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.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.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 @@ public void maxInMemorySize(int byteCount) { } @Override - @Nullable - public Integer maxInMemorySize() { + public @Nullable Integer maxInMemorySize() { return this.maxInMemorySize; } @@ -392,8 +372,7 @@ void setPartWritersSupplier(Supplier>> supplier) { } @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 a494a74ccefe..87dd4ddef149 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 @@ 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 @@ */ 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 52c7bf407982..27ebcc6e68e8 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 @@ 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 @@ */ class ServerDefaultCodecsImpl extends BaseDefaultCodecs implements ServerCodecConfigurer.ServerDefaultCodecs { - @Nullable - private Encoder sseEncoder; + private @Nullable Encoder sseEncoder; ServerDefaultCodecsImpl() { @@ -55,8 +55,7 @@ protected void extendObjectWriters(List> objectWriters) { 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 d2658887ebe3..f107b92007e4 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 976e116c357f..6877ac7196a0 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.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 @@ private static class SplitHandler implements BiConsumer 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 cc67c3c758b2..100b2cef6533 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.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.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 Mono decodeToMono(Publisher input, ResolvableType ele } @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 Object decode(DataBuffer dataBuffer, ResolvableType targetType, } } - @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 b5a2b6d43043..c4f8eaaa9d4e 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.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.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 877ac5a2656f..88512621028c 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.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.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 2af5e7773e7f..8adf48afc9eb 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 e6f31e8d6b53..d8db25cdd69e 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.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 boolean canWrite(@Nullable Type type, Class clazz, @Nullable MediaType * 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 9404d8a7c869..8c3c280d4014 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.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.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 void setDefaultCharset(@Nullable Charset defaultCharset) { * 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 @@ else if (MediaType.APPLICATION_OCTET_STREAM.equals(contentType)) { * @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 @@ protected MediaType getDefaultContentType(T t) throws IOException { * @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 e5a17226f65e..a6f75e27b54e 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.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.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 @@ protected abstract void writeInternal(Object object, KSerializer seriali * @param resolvableType the type to find a serializer for * @return a resolved serializer for the given type, or {@code null} */ - @Nullable - private KSerializer 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 bcd9494ac7b7..b74352262af2 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.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 cdb4025e4021..b0ffcb3349d5 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.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 void setDefaultContentType(@Nullable MediaType defaultContentType) { * Returns the default {@code Content-Type} to be used for writing. * Called when {@link #write} is invoked without a specified content type parameter. */ - @Nullable - public MediaType getDefaultContentType() { + public @Nullable MediaType getDefaultContentType() { return this.defaultContentType; } @@ -218,7 +216,7 @@ private ImageInputStream createImageInputStream(InputStream is) throws IOExcepti } @Override - public void write(final BufferedImage image, @Nullable final MediaType contentType, + public void write(final BufferedImage image, final @Nullable MediaType contentType, final HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { diff --git a/spring-web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java index abe9a0eeb887..cf7ebf4f01a9 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/ByteArrayHttpMessageConverter.java @@ -18,10 +18,11 @@ import java.io.IOException; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java index 34062542faa4..be83a29f927a 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/FormHttpMessageConverter.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.Resource; import org.springframework.http.ContentDisposition; import org.springframework.http.HttpEntity; @@ -37,7 +39,6 @@ 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.CollectionUtils; import org.springframework.util.LinkedMultiValueMap; @@ -174,8 +175,7 @@ public class FormHttpMessageConverter implements HttpMessageConverter getHttpEntity(Object part) { * @param part the part to determine the file name for * @return the filename, or {@code null} if not known */ - @Nullable - protected String getFilename(Object part) { + protected @Nullable String getFilename(Object part) { if (part instanceof Resource resource) { return resource.getFilename(); } diff --git a/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java index 760c92ace652..4feaee031f64 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/GenericHttpMessageConverter.java @@ -19,10 +19,11 @@ import java.io.IOException; import java.lang.reflect.Type; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * A specialization of {@link HttpMessageConverter} that can convert an HTTP request diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java index 6a2f9bb8b8fc..6057f1663e7b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConversionException.java @@ -16,8 +16,9 @@ package org.springframework.http.converter; +import org.jspecify.annotations.Nullable; + import org.springframework.core.NestedRuntimeException; -import org.springframework.lang.Nullable; /** * Thrown by {@link HttpMessageConverter} implementations when a conversion attempt fails. diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java index 5c0ed6fc659f..a519828732cd 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageConverter.java @@ -20,10 +20,11 @@ import java.util.Collections; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; /** * Strategy interface for converting from and to HTTP requests and responses. diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java index 1b9c7630b3b6..693e097f730b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotReadableException.java @@ -16,8 +16,9 @@ package org.springframework.http.converter; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpInputMessage; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -31,8 +32,7 @@ @SuppressWarnings("serial") public class HttpMessageNotReadableException extends HttpMessageConversionException { - @Nullable - private final HttpInputMessage httpInputMessage; + private final @Nullable HttpInputMessage httpInputMessage; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java index b6c838fccaaa..268b9bf7959e 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java +++ b/spring-web/src/main/java/org/springframework/http/converter/HttpMessageNotWritableException.java @@ -16,7 +16,7 @@ package org.springframework.http.converter; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Thrown by {@link HttpMessageConverter} implementations when the diff --git a/spring-web/src/main/java/org/springframework/http/converter/KotlinSerializationStringHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/KotlinSerializationStringHttpMessageConverter.java index f51f81ba6761..9b803ec68a9b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/KotlinSerializationStringHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/KotlinSerializationStringHttpMessageConverter.java @@ -23,11 +23,11 @@ import kotlinx.serialization.KSerializer; import kotlinx.serialization.SerializationException; import kotlinx.serialization.StringFormat; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpInputMessage; import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/ObjectToStringHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/ObjectToStringHttpMessageConverter.java index 8ac151912744..6a51be442260 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/ObjectToStringHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/ObjectToStringHttpMessageConverter.java @@ -19,11 +19,12 @@ import java.io.IOException; import java.nio.charset.Charset; +import org.jspecify.annotations.Nullable; + import org.springframework.core.convert.ConversionService; 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; /** diff --git a/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java index c6c484bfbfaa..02bb193520e6 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/ResourceHttpMessageConverter.java @@ -21,6 +21,8 @@ import java.io.InputStream; import java.io.OutputStream; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.ByteArrayResource; import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; @@ -28,7 +30,6 @@ import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; -import org.springframework.lang.Nullable; import org.springframework.util.StreamUtils; /** @@ -82,8 +83,7 @@ protected Resource readInternal(Class clazz, HttpInputMessag if (this.supportsReadStreaming && InputStreamResource.class == clazz) { return new InputStreamResource(inputMessage.getBody()) { @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } @Override @@ -97,8 +97,7 @@ else if (Resource.class == clazz || ByteArrayResource.class.isAssignableFrom(cla byte[] body = StreamUtils.copyToByteArray(inputMessage.getBody()); return new ByteArrayResource(body) { @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return inputMessage.getHeaders().getContentDisposition().getFilename(); } }; @@ -131,8 +130,7 @@ protected MediaType getDefaultContentType(Resource resource) { } @Override - @Nullable - protected Long getContentLength(Resource resource, @Nullable MediaType contentType) throws IOException { + protected @Nullable Long getContentLength(Resource resource, @Nullable MediaType contentType) throws IOException { // Don't try to determine contentLength on InputStreamResource - cannot be read afterwards... // Note: custom InputStreamResource subclasses could provide a pre-calculated content length! if (InputStreamResource.class == resource.getClass()) { diff --git a/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java index 814be21ba14a..d39dc44aaea5 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/ResourceRegionHttpMessageConverter.java @@ -24,6 +24,8 @@ import java.nio.charset.StandardCharsets; import java.util.Collection; +import org.jspecify.annotations.Nullable; + import org.springframework.core.io.InputStreamResource; import org.springframework.core.io.Resource; import org.springframework.core.io.support.ResourceRegion; @@ -32,7 +34,6 @@ import org.springframework.http.HttpOutputMessage; import org.springframework.http.MediaType; import org.springframework.http.MediaTypeFactory; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.MimeTypeUtils; import org.springframework.util.StreamUtils; diff --git a/spring-web/src/main/java/org/springframework/http/converter/SmartHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/SmartHttpMessageConverter.java index 98b1d44448b4..4af5e68ea970 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/SmartHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/SmartHttpMessageConverter.java @@ -19,11 +19,12 @@ import java.io.IOException; import java.util.Map; +import org.jspecify.annotations.Nullable; + 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; /** * A specialization of {@link HttpMessageConverter} that can convert an HTTP request diff --git a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java index 510a049c1369..6fddcd9cda6b 100644 --- a/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java +++ b/spring-web/src/main/java/org/springframework/http/converter/StringHttpMessageConverter.java @@ -22,11 +22,12 @@ import java.util.ArrayList; import java.util.List; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpHeaders; 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.StreamUtils; @@ -51,8 +52,7 @@ public class StringHttpMessageConverter extends AbstractHttpMessageConverter 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 c8ffa9781801..fd0561aa9338 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 74d0e0656a35..088b43889969 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 89320c8656c9..6f5a551926d7 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.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.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 void registerObjectMappersForType(Class clazz, Consumer 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 boolean canWrite(Class clazz, @Nullable MediaType mediaType) { * 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 @@ protected JsonEncoding getJsonEncoding(@Nullable MediaType contentType) { } @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 @@ protected MediaType getDefaultContentType(Object object) throws IOException { } @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 10382e9d97a3..1ee9591ea35f 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.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.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 be63917f52a5..5ca15a704161 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 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 void afterPropertiesSet() { * 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 21b9a7ab2ec0..d13dea5f2861 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.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 a76e9033889e..de5314f1f7c2 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.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 63b5f3f13c6d..2a07b46acc49 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.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 f7f07a9a7f63..a3362db5d059 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 @@ 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 97c06b4b86a0..b235939ba430 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 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 ecbd9400a795..15e1927a3f34 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 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 d882f3b0bce8..aa73dc71f219 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 @@ 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 void setDeserializationView(@Nullable Class deserializationView) { 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 fad90875f2bf..2c08f45b0591 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 void setSerializationView(@Nullable Class serializationView) { * @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 void setFilters(@Nullable FilterProvider filters) { * @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 23b32eeffaca..0406a95c2349 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 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 b2b28027962d..61a268267f38 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.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 d04fda433f05..1e229245b234 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 5290f00a1c2e..97d99a6e3956 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 82ddae975e23..3ae7acb594cd 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 72029653dbb9..c8fc030aa298 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.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.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 fee55e553be7..a229e5cb74f0 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 4dbf1c570a43..b75b03e4ae55 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 5730286bafde..7a7997fc3b9b 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.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.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 8cc89318184a..9a2d2cf5e7ca 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.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.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 908b0246c5d6..3d59d9c56413 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 @@ 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 @@ */ 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 1483ea0b4c6e..be6fa00f99d1 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.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.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 @@ private StreamSource readStreamSource(InputStream body) throws IOException { } @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 34734d540353..10a7905e29bc 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 ef3a64919289..6b02aaceaee4 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 8c8e6c19f41b..58fc72a63b15 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 05497984b93e..b925bc9ddef6 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.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 0ad453024d65..ef1e435d33af 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 @@ 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 e98b9b078b52..846abfb850a4 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 @@ 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 c8b1a3a97173..ad7b31b2c232 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 @@ 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 8cb414d8c912..27d2e6d06043 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.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 39dbd08d4d2d..32da447629ee 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.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 HttpHeaders getHeaders() { } @Override - public Principal getPrincipal() { + public @Nullable Principal getPrincipal() { return this.servletRequest.getUserPrincipal(); } @@ -305,14 +301,11 @@ private InputStream getBodyFromServletRequestParameters(HttpServletRequest reque 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 int size() { } @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 Object get(Object key) { } @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 f6d3ef6cbdf5..f09d8a90189a 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.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 boolean containsKey(Object key) { } @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 String getFirst(String headerName) { } @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 bf37e01df18c..f316767a3671 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 @@ 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 @@ */ 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 ServerRequestObservationContext(HttpServletRequest request, HttpServletRe 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 aebdd17f177d..7a6083277631 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 8c7e71cd98ec..c2cd0afbf4a0 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 72d68e8b052d..75a93b8b1c8c 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.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 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 final void onError(Throwable ex) { * 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 2392f85ea924..049a113562c3 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.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 ef9b8976b1b1..8a401a644a44 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.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 9c9fea5e3ccf..19abe1646b16 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.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 String getId() { * 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 MultiValueMap getCookies() { */ 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 SslInfo getSslInfo() { * @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 fa15f6d5220d..79a169ef82e1 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.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.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 @@ private enum State {NEW, COMMITTING, COMMIT_ACTION_FAILED, COMMITTED} private final DataBufferFactory dataBufferFactory; - @Nullable - private HttpStatusCode statusCode; + private @Nullable HttpStatusCode statusCode; private final HttpHeaders headers; @@ -71,8 +70,7 @@ private enum State {NEW, COMMITTING, COMMIT_ACTION_FAILED, COMMITTED} private final List>> commitActions = new CopyOnWriteArrayList<>(); - @Nullable - private HttpHeaders readOnlyHeaders; + private @Nullable HttpHeaders readOnlyHeaders; public AbstractServerHttpResponse(DataBufferFactory dataBufferFactory) { @@ -105,8 +103,7 @@ public boolean setStatusCode(@Nullable HttpStatusCode status) { } @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 6b1bf8d7e1f9..55c3420b6e4b 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 @@ 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 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 ChannelSendOperator(Publisher source, Function, @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 @@ private class WriteBarrier implements CoreSubscriber, Subscription, Publisher 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 @@ private class WriteBarrier implements CoreSubscriber, Subscription, Publisher 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 @@ private class WriteCompletionBarrier implements CoreSubscriber, Subscripti 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 6157e38ee765..1355ecd996de 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.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 @@ private URI getUriToUse() { 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 @@ protected MultiValueMap initCookies() { } @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 4ca73c11d369..b47c09576158 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 javax.net.ssl.SSLSession; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -34,11 +35,9 @@ */ 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 @@ private static String initSessionId(SSLSession session) { 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 d97832a2ff7c..a43730b8b445 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 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.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 @@ protected MultiValueMap initCookies() { } @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 @@ protected String initId() { } @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 a53cab42190a..dc319c186201 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.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.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 @@ public long getMaxAge() { } @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 @@ public boolean isSecure() { 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 d61f634381a3..f9dadffcc908 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.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.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 @@ protected MultiValueMap initCookies() { } @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 @@ public T getNativeRequest() { } @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 b136e9bbb7b0..6f71068a9087 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.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.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 @@ protected MultiValueMap initCookies() { } @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 @@ public T getNativeRequest() { } @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 55f5fa2c654b..63bf5fdc818f 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.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 @@ default InetSocketAddress getRemoteAddress() { * @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 fbeacac71896..793b8bd05b71 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.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.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 MultiValueMap getCookies() { } @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 11194f21541c..595e81a231dd 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 f9f7fda82839..a93faf282e61 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 @@ 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.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 boolean setStatusCode(@Nullable HttpStatusCode status) { } @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 e16a4b6287b7..44416259701a 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.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.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 int getBufferSize() { * 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 String getServletInfo() { } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { return null; } @@ -357,8 +354,7 @@ private static class HandlerResultSubscriber implements Subscriber, Runnab 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 ee2b9a5014bd..c361c566f987 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.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.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 @@ protected MultiValueMap initCookies() { } @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 @@ protected void checkOnDataAvailable() { } @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 c2ccdbbcdda6..e2a5aa2043c1 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.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.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 47e4f9a1bf13..04ad09ffda1c 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 @@ 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 b5f37e7b3ca4..83aeb13933fa 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 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 @@ public boolean containsValue(Object value) { } @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 @@ public List get(Object key) { } @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 @@ public List put(String key, List value) { } @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 @@ public String getKey() { 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 @@ private final class HeaderNamesIterator implements Iterator { 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 9e249031872b..e00b1565f241 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 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 @@ public boolean containsValue(Object value) { } @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 @@ private final class HeaderNamesIterator implements Iterator { 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 324e734ad504..008023ee74fe 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.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.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 @@ protected MultiValueMap initCookies() { } @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 @@ protected void readingPaused() { } @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 65ed91a6042b..1a3f0f9ca448 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 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.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 @@ private class ResponseBodyProcessor extends AbstractListenerWriteProcessor { 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 fa7454aface1..658edf44c54c 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.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 Map getAttributes() { *

    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 d00ac21e8291..f0e8992ed03e 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 25e89a1f036b..10c41e5feb1e 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 7bb2682aec1b..9628b39c492d 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 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 HttpComponentsHeadersAdapter(HttpMessage message) { @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); } @@ -127,9 +126,8 @@ public boolean containsValue(Object value) { 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); @@ -141,17 +139,15 @@ public List get(Object key) { 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.headerNames.remove(headerName); @@ -267,8 +263,7 @@ private final class HeaderNamesIterator implements Iterator { 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/JettyHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/support/JettyHeadersAdapter.java index aa98ae422375..ee0b35e08c55 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 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 boolean containsValue(Object value) { 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 List get(Object key) { 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 List put(String key, List value) { 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 @@ private final class HeaderNamesIterator implements Iterator { 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 4a4fa8f578d2..a9ec05b7b2b3 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.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 Netty4HeadersAdapter(HttpHeaders headers) { @Override - @Nullable - public String getFirst(String key) { + public @Nullable String getFirst(String key) { return this.headers.get(key); } @@ -125,25 +124,22 @@ public boolean containsValue(Object value) { } @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 @@ private final class HeaderNamesIterator implements Iterator { 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 79f6750d760c..8b54f470fa6b 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.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 Netty5HeadersAdapter(HttpHeaders headers) { @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 boolean containsValue(Object value) { } @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 List get(Object key) { 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 @@ private final class HeaderNamesIterator implements Iterator { 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 1dbbc6c43e2a..831ecb6d26ee 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 72774ba60c31..ce92a70e0d74 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 @@ 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 @@ private static class SimpleErrorResponse implements ErrorResponse { 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 @@ public String getDetailMessageCode() { } @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 c077b83d9d41..acf73e71270e 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.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 @@ default String getDetailMessageCode() { * 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 @@ default Object[] getDetailMessageArguments() { * @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 53f3fccb49a3..fcd6e2deba06 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 @@ 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 ErrorResponseException(HttpStatusCode status, ProblemDetail body, @Nullab */ 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 String getDetailMessageCode() { } @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 870c13f65b9f..888dae7db399 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.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 String getDetailMessageCode() { } @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 4ce57138a5d3..bcba1c9953c1 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 @@ 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 HttpMediaTypeNotSupportedException(@Nullable MediaType contentType, /** * 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 3d78325f90b6..d397c2d01df6 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.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 HttpRequestMethodNotSupportedException(String method, @Nullable Collectio * @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 String getMethod() { /** * 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 String[] getSupportedMethods() { * 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 eaffd9d96b76..b311973be525 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 @@ @SuppressWarnings("serial") public class HttpSessionRequiredException extends ServletException { - @Nullable - private final String expectedAttribute; + private final @Nullable String expectedAttribute; /** @@ -58,8 +56,7 @@ public HttpSessionRequiredException(String msg, String expectedAttribute) { * 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 5ced8bf39e44..6befe1eeeaa0 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.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 ed3189bc68f5..92da6452c1e8 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 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 List resolveMediaTypeKey(NativeWebRequest webRequest, @Nullabl * 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 @@ protected void handleMatch(String key, MediaType mediaType) { * 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 dec192ca1587..023f1ac0d6a0 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.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 List getStrategies() { * @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 11f499271efb..f547cad8a8b9 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.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 @@ */ 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 ContentNegotiationManager build() { @Override - @Nullable - public ContentNegotiationManager getObject() { + public @Nullable ContentNegotiationManager getObject() { return this.contentNegotiationManager; } diff --git a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java index 7c8f705da577..2071db91f46b 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java +++ b/spring-web/src/main/java/org/springframework/web/accept/MappingMediaTypeFileExtensionResolver.java @@ -26,8 +26,9 @@ import java.util.concurrent.ConcurrentMap; import java.util.concurrent.CopyOnWriteArrayList; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.CollectionUtils; /** @@ -107,8 +108,7 @@ public List getAllFileExtensions() { * Use this method for a reverse lookup from extension to MediaType. * @return a MediaType for the extension, or {@code null} if none found */ - @Nullable - protected MediaType lookupMediaType(String extension) { + protected @Nullable MediaType lookupMediaType(String extension) { return this.mediaTypes.get(extension.toLowerCase(Locale.ROOT)); } diff --git a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java index ea5b88180419..afac8302e942 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java +++ b/spring-web/src/main/java/org/springframework/web/accept/ParameterContentNegotiationStrategy.java @@ -18,8 +18,9 @@ import java.util.Map; +import org.jspecify.annotations.Nullable; + import org.springframework.http.MediaType; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.web.context.request.NativeWebRequest; @@ -63,8 +64,7 @@ public String getParameterName() { @Override - @Nullable - protected String getMediaTypeKey(NativeWebRequest request) { + protected @Nullable String getMediaTypeKey(NativeWebRequest request) { return request.getParameter(getParameterName()); } diff --git a/spring-web/src/main/java/org/springframework/web/accept/package-info.java b/spring-web/src/main/java/org/springframework/web/accept/package-info.java index 967fe7aadd5c..a3f21d51b679 100644 --- a/spring-web/src/main/java/org/springframework/web/accept/package-info.java +++ b/spring-web/src/main/java/org/springframework/web/accept/package-info.java @@ -11,9 +11,7 @@ *

    {@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 9edffefc90e3..96e412fd8c31 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 @@ 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 void reject(String errorCode, String defaultMessage) { } @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 void rejectValue(@Nullable String field, String errorCode, String default @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 List getGlobalErrors() { } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return escapeObjectError(this.source.getGlobalError()); } @@ -174,8 +174,7 @@ public List getFieldErrors() { } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.source.getFieldError(); } @@ -195,27 +194,23 @@ public List getFieldErrors(String field) { } @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 bc606373b8f0..d5edaae85089 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 MissingRequestValueException(String msg, boolean missingAfterConversion) * @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 93480e371276..f958f47f0bb1 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 final String getParameterType() { * 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 b0ca83d61cf0..efd2d07978b9 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 ServletRequestBindingException(@Nullable String msg, @Nullable Throwable * @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 @@ protected ServletRequestBindingException( * @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 String getDetailMessageCode() { } @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 07ae35556669..9d2ea6237738 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 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 @@ protected static class ServletRequestValueResolver implements ValueResolver { 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 @@ protected ServletRequest getRequest() { 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 final Object resolveValue(String name, Class paramType) { 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 e07bc6c73dbb..b5f944d154fa 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 4b61e256af92..43c07cf6c828 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 static int[] getRequiredIntParameters(ServletRequest request, String name * @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 static long[] getRequiredLongParameters(ServletRequest request, String na * @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 static float[] getRequiredFloatParameters(ServletRequest request, String * @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 static double[] getRequiredDoubleParameters(ServletRequest request, Strin * @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 static boolean[] getRequiredBooleanParameters(ServletRequest request, Str * @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 cb907effab7c..1826f6f9ce2f 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.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 void setFieldMarkerPrefix(@Nullable String fieldMarkerPrefix) { /** * 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 void setFieldDefaultPrefix(@Nullable String fieldDefaultPrefix) { /** * 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 boolean isBindEmptyMultipartFiles() { * @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 @@ protected void adaptEmptyArrayIndices(MutablePropertyValues mpvs) { * @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 @@ protected Object getEmptyValue(String field, @Nullable Class fieldType) { * @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 564206809d40..914da4206e84 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.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.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 @@ else if (HttpEntity.class.isAssignableFrom(returnTypeParameter.getParameterType( } } - @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 c7564093cdd9..b1f5438b9048 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 static RequestMethod resolve(String method) { * @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 fb7e6cc76f61..0c9bb1c11f78 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 7b87239b23ca..f1415cca359d 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 5b50bb851553..811971c5508f 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 @@ 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 293bb83a0c9e..fe1a923344c6 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 final void setMessageCodesResolver(@Nullable MessageCodesResolver message /** * 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 final void setBindingErrorProcessor(@Nullable BindingErrorProcessor bindi /** * 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 final void setValidator(@Nullable Validator validator) { /** * 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 final void setConversionService(@Nullable ConversionService conversionSer /** * 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 final void setPropertyEditorRegistrar(PropertyEditorRegistrar propertyEdi /** * 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 void initBinder(WebDataBinder binder) { } } - @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 35bbfd51de2b..fd9c3bee398b 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 @@ 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 @@ */ 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 30952bf81fae..2e488b3d49c5 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 void storeAttribute(WebRequest request, String attributeName, Object attr } @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 42acf3bbf146..269de308f2ff 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 58574d4864e3..01318ebcd003 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 3411d363e239..c3c31ba334ec 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 d7204f7498f3..015486796ddf 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.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 void reject(String errorCode, String defaultMessage) { } @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 void rejectValue(@Nullable String field, String errorCode, String default @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 List getGlobalErrors() { } @Override - @Nullable - public ObjectError getGlobalError() { + public @Nullable ObjectError getGlobalError() { return this.bindingResult.getGlobalError(); } @@ -195,8 +195,7 @@ public List getFieldErrors() { } @Override - @Nullable - public FieldError getFieldError() { + public @Nullable FieldError getFieldError() { return this.bindingResult.getFieldError(); } @@ -216,26 +215,22 @@ public List getFieldErrors(String field) { } @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 Map getModel() { } @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 4bfeb0632646..04c3a9c28f24 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.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 @@ private static Object adaptBindValue(Object value) { 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 2d7d31264f61..1e393922f304 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 @@ 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 c55741fc04f2..40325caafe86 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 b9767b6b8394..7e6759758a9a 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.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.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 @@ */ public class DefaultResponseErrorHandler implements ResponseErrorHandler { - @Nullable - private List> messageConverters; + private @Nullable List> messageConverters; /** @@ -194,8 +194,7 @@ protected byte[] getResponseBody(ClientHttpResponse response) { * @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 @@ protected Charset getCharset(ClientHttpResponse response) { * */ 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 9e88dfdc91a0..3660a6f30b59 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.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.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 @@ public Builder mutate() { 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 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec { 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 @@ public ResponseSpec retrieve() { } @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 @@ private URI initUri() { 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 @@ private static String serializeCookies(MultiValueMap map) { 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 @@ private ResponseSpec onStatusInternal(StatusHandler statusHandler) { } @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 @@ public ResponseEntity toBodilessEntity() { 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 @@ public DefaultConvertibleClientHttpResponse(ClientHttpResponse delegate) { 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 975b1f183f9d..0c682dde9e60 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.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.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 @@ public DefaultRestClientBuilder(RestTemplate restTemplate) { 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 @@ private UriBuilderFactory initUriBuilderFactory() { return factory; } - @Nullable - private HttpHeaders copyDefaultHeaders() { + private @Nullable HttpHeaders copyDefaultHeaders() { if (this.defaultHeaders == null) { return null; } @@ -527,8 +513,7 @@ private HttpHeaders copyDefaultHeaders() { 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 e2c95a992b29..0db94b0f63d6 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.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 19a1cdb682f6..c498128763ef 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 @@ 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 HttpClientErrorException(HttpStatusCode statusCode, String statusText) { * 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 HttpClientErrorException( * 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 HttpClientErrorException(HttpStatusCode statusCode, String statusText, * @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 3f79cfa7ece2..bf1077cd88c6 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 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.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 HttpMessageConverterExtractor(Type responseType, List { * @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 1b7016d77e5a..5371bdd3931d 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.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.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 @@ interface RequestHeadersSpec> { * @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 @@ default T exchange(ExchangeFunction exchangeFunction) { * @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 @@ interface ExchangeFunction { * @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 @@ interface ConvertibleClientHttpResponse extends ClientHttpResponse { * @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 @@ interface ConvertibleClientHttpResponse extends ClientHttpResponse { * @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 @@ ResponseSpec onStatus(Predicate statusPredicate, * {@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 @@ ResponseSpec onStatus(Predicate statusPredicate, * {@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 c5d969be827d..f75de8503379 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 163c383ee869..7f96b69f0b46 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.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 RestClientResponseException( */ 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 RestClientResponseException( * 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 String getStatusText() { /** * Return the HTTP response headers. */ - @Nullable - public HttpHeaders getResponseHeaders() { + public @Nullable HttpHeaders getResponseHeaders() { return this.responseHeaders; } @@ -179,8 +175,7 @@ public String getResponseBodyAsString(Charset fallbackCharset) { * @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 E getResponseBodyAs(Class targetType) { * {@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 157d11ace424..b38f39897820 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 @@ 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 @@ public static byte[] getBody(HttpInputMessage message) { 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 5429c251963b..bcdb4214cec7 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.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 @@ ResponseEntity getForEntity(String url, Class responseType, Map ResponseEntity getForEntity(String url, Class responseType, Map uriVariables) + @Nullable URI postForLocation(String url, @Nullable Object request, Map uriVariables) throws RestClientException; /** @@ -200,8 +196,7 @@ URI postForLocation(String url, @Nullable Object request, Map uriVari * @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 @@ URI postForLocation(String url, @Nullable Object request, Map uriVari * @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 @@ T postForObject(String url, @Nullable Object request, Class responseType, * @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 @@ T postForObject(String url, @Nullable Object request, Class responseType, * @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 @@ ResponseEntity postForEntity(URI url, @Nullable Object request, Class * @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 @@ T patchForObject(String url, @Nullable Object request, Class responseType * @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 @@ T patchForObject(String url, @Nullable Object request, Class responseType * @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 @@ ResponseEntity exchange(RequestEntity requestEntity, ParameterizedType * @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 @@ T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback r * @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 @@ T execute(String uriTemplate, HttpMethod method, @Nullable RequestCallback r * @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 e9784a5e4348..6f7b992bdba9 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 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.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 void setObservationConvention(ClientRequestObservationConvention observat * 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 ClientRequestObservationConvention getObservationConvention() { // 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 T getForObject(String url, Class responseType, Object... uriVariab } @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 T getForObject(String url, Class responseType, Map uriV } @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 HttpHeaders headForHeaders(URI url) throws RestClientException { // 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 URI postForLocation(String url, @Nullable Object request, Object... uriVa } @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 URI postForLocation(String url, @Nullable Object request, Map } @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 T postForObject(String url, @Nullable Object request, Class respon } @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 T postForObject(String url, @Nullable Object request, Class respon } @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 void put(URI url, @Nullable Object request) throws RestClientException { // 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 T patchForObject(String url, @Nullable Object request, Class respo } @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 T patchForObject(String url, @Nullable Object request, Class respo } @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 @@ else if (ext.getVarsMap() != null) { } } - @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 @@ private String resolveUriTemplate(RequestEntity entity) { * */ @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 T execute(String uriTemplate, HttpMethod method, @Nullable RequestCal * */ @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 T execute(String uriTemplate, HttpMethod method, @Nullable RequestCal * */ @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 T execute(URI url, HttpMethod method, @Nullable RequestCallback reque * @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 @@ protected T doExecute(URI url, @Nullable HttpMethod method, @Nullable Reques * @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 @@ private static T nonNull(@Nullable T result) { */ 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 @@ private void logBody(Object body, @Nullable MediaType mediaType, HttpMessageConv */ 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 2b2f7ea8f611..1d5cb0bc9f8e 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.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.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 @@ public InputStream getBody() { } - 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 df9a7b36705a..89785e0fe2a5 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 @@ 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 String getStatusText() { /** * 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 a1676d530206..aaf76c0e551a 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 @@ 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 UnknownHttpStatusCodeException(int rawStatusCode, String statusText, @Nul * @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 bc1e16e248bd..917fb979a2ee 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 67c4ecca9061..2b2552e3d4f9 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.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 HttpHeaders exchangeForHeaders(HttpRequestValues values) { } @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 364caa6be326..b431575b3929 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.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 HttpHeaders exchangeForHeaders(HttpRequestValues values) { } @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 ba9c45a63fe6..858e120c13b0 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 065acbadb260..d5187a5af207 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.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 @@ protected void registerContextLoaderListener(ServletContext servletContext) { * 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 @@ protected void registerContextLoaderListener(ServletContext servletContext) { * @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 831bad5cf1aa..8d7115787841 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 @@ 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 d077036403a7..f1ed6ff1d28c 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 @@ 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 83c9297bd698..2c24db7c97ed 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 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.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 ContextLoader(WebApplicationContext rootContext) { * @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 @@ private Class> loa * @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 @@ else if (ccl != null) { * 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 e065e415261b..c6594b4e7976 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 @@ 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 @@ */ 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 cef050984829..df2de3a2aab5 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 a339a8b0e5ff..467cae834125 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 01aa3900014a..1bb64bec4492 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 89dc05ac8c3c..c02e3479ade1 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 Object get(String name, ObjectFactory objectFactory) { } @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 void registerDestructionCallback(String name, Runnable callback) { } @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 df96f1239800..441d01372d53 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.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 @@ protected Map getAttributeMap(int scope) { @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 void registerDestructionCallback(String name, Runnable callback, int scop } @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 b8163ad27381..538e432e09d9 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 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 Object getNativeResponse() { } @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 T getNativeRequest(@Nullable Class requiredType) { } @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 T getNativeResponse(@Nullable Class requiredType) { @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 Iterator getHeaderNames() { } @Override - @Nullable - public String getParameter(String paramName) { + public @Nullable String getParameter(String paramName) { return getExternalContext().getRequestParameterMap().get(paramName); } @@ -113,8 +108,7 @@ public Iterator getParameterNames() { } @Override - @Nullable - public String[] getParameterValues(String paramName) { + public String @Nullable [] getParameterValues(String paramName) { return getExternalContext().getRequestParameterValuesMap().get(paramName); } @@ -134,14 +128,12 @@ public String getContextPath() { } @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 8d90775760a0..5af8f19c1910 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 00becf5e3d97..bb268456173d 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 fcaf2b4549c0..73f06f5b1fb5 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 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 Object key() { } @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 @@ private static Map getAttributes(HttpServletRequest request) { // 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 b9e55dd6cfee..f4422e5a5c0f 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 static void setRequestAttributes(@Nullable RequestAttributes attributes, * @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 static RequestAttributes currentRequestAttributes() throws IllegalStateEx */ 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 4919ba598d12..74423d9cc1bd 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 @@ protected int getScope() { * 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 52cddccba745..25c300e1b21b 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 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 final HttpServletRequest getRequest() { /** * 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 final HttpServletResponse getResponse() { * 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 @@ private HttpSession obtainSession() { @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 void registerDestructionCallback(String name, Runnable callback, int scop } @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 64690c9495f7..dfe36b39e280 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 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 Object getNativeRequest() { } @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 HttpMethod getHttpMethod() { } @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 Iterator getHeaderNames() { } @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 String getContextPath() { } @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 3c2c9d2ad050..514783edf84a 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 Object get(String name, ObjectFactory objectFactory) { } @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 f3b597d0e4d4..08fe2abdf38b 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.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 46a75bade575..6e23b678f13a 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 f20c68d5c7b2..0444f2b83fff 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 @@ 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 282af1a50062..a78a9c9d54e2 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 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 @@ public void applyPreProcess(NativeWebRequest request, Callable task) throws E } } - @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 c5bb505befb0..e78b40e0cae0 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 @@ 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 3fbd694e8b76..4a0847cf03bf 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 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 boolean hasResult() { * 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 Object getResult() { /** * 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 855892faeb67..c89c8472bc70 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 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 @@ public void applyPreProcess(NativeWebRequest request, DeferredResult deferred } } - @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 8c79c180da29..35a3b33fffff 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 9cad8c359176..1beb9f2e60a7 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.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 @@ ReentrantLock stateLock() { */ 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 a7438441814c..c948b0b9d5e9 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 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 void setAsyncWebRequest(AsyncWebRequest asyncWebRequest) { * 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 boolean hasConcurrentResult() { * concurrent handling raised one * @see #clearConcurrentResult() */ - @Nullable - public Object getConcurrentResult() { + public @Nullable Object getConcurrentResult() { return this.concurrentResult; } @@ -171,8 +166,7 @@ public Object getConcurrentResult() { * 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 Object[] getConcurrentResultContext() { * @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 CallableProcessingInterceptor getCallableInterceptor(Object key) { * @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 5b49b79d466f..5d14b776efc0 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 @@ 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 Callable getCallable() { /** * 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 void setBeanFactory(BeanFactory beanFactory) { * 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 c9f78c659d9d..f53c1fd58de6 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 ed3aae5f0b76..bc9dfc601f73 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 b679c2185420..7626821629d6 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 @@ 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 void setServletContext(@Nullable ServletContext servletContext) { } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return this.servletContext; } @@ -124,8 +119,7 @@ public void setServletConfig(@Nullable ServletConfig servletConfig) { } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { return this.servletConfig; } @@ -138,14 +132,12 @@ public void setNamespace(@Nullable String namespace) { } @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 @@ protected void initPropertySources() { } @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 8c673266578e..feee8995f4b0 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.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.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 @@ 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 void setBeanNameGenerator(@Nullable BeanNameGenerator beanNameGenerator) * 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 void setScopeMetadataResolver(@Nullable ScopeMetadataResolver scopeMetada * 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 55b32a46cab4..766233f86200 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 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 final WebApplicationContext getWebApplicationContext() { @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 1c6a3dea00a7..2f0335dfac7c 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 @@ 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.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 @@ 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 void setServletContext(@Nullable ServletContext servletContext) { } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return this.servletContext; } @@ -213,9 +210,8 @@ protected void initPropertySources() { } @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 void setServletConfig(@Nullable ServletConfig servletConfig) { } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { throw new UnsupportedOperationException( "GenericWebApplicationContext does not support getServletConfig()"); } @@ -243,8 +238,7 @@ public void setNamespace(@Nullable String namespace) { } @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 25610fd6a3d1..99b64ee0471b 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 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.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 void setProperty(String property, Object newValue) { } @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 be1ac6857fa3..3e5785e51b81 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.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 @@ @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 bc60bb4308d2..25d23d65b65b 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 @@ 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 long getProcessingTimeMillis() { /** * 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 String getSessionId() { * (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 boolean wasFailure() { /** * 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 72266c0bb96c..b4ddfddaede5 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 String[] getPropertyNames() { } @Override - @Nullable - public String getProperty(String name) { + public @Nullable String getProperty(String name) { return this.source.getInitParameter(name); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeExporter.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeExporter.java index b1422251ab71..9f88760d70f0 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeExporter.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextAttributeExporter.java @@ -21,8 +21,8 @@ import jakarta.servlet.ServletContext; 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.ServletContextAware; /** @@ -49,8 +49,7 @@ public class ServletContextAttributeExporter implements ServletContextAware { protected final Log logger = LogFactory.getLog(getClass()); - @Nullable - private Map 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 84f927773881..1aadb79bc08c 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 @@ */ 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 void setServletContext(ServletContext servletContext) { @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 b4aa7b098462..b5945648fbb0 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 @@ 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 @@ */ 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 ServletContextAwareProcessor(@Nullable ServletContext servletContext, @Nu * 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 @@ protected ServletContext getServletContext() { * 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 c255ccbd211c..70b73713d86f 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 @@ */ 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 void setServletContext(ServletContext servletContext) { @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 ca100504c796..d620b385a717 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 String[] getPropertyNames() { } @Override - @Nullable - public String getProperty(String name) { + public @Nullable String getProperty(String name) { return this.source.getInitParameter(name); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java index 6bdaa14a9dfe..d4aecb9507b6 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java @@ -24,11 +24,11 @@ import java.net.URL; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.core.io.AbstractFileResolvingResource; import org.springframework.core.io.ContextResource; import org.springframework.core.io.Resource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ResourceUtils; import org.springframework.util.StringUtils; @@ -219,8 +219,7 @@ public Resource createRelative(String relativePath) { * @see org.springframework.util.StringUtils#getFilename(String) */ @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return StringUtils.getFilename(this.path); } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java index 3365318dfe58..b6aa02fafa6a 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextScope.java @@ -20,11 +20,11 @@ import java.util.Map; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.Scope; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** @@ -75,8 +75,7 @@ public Object get(String name, ObjectFactory objectFactory) { } @Override - @Nullable - public Object remove(String name) { + public @Nullable Object remove(String name) { Object scopedObject = this.servletContext.getAttribute(name); if (scopedObject != null) { synchronized (this.destructionCallbacks) { @@ -98,14 +97,12 @@ public void registerDestructionCallback(String name, Runnable callback) { } @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 null; } diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java index c0a5bf117a3a..258031b07b6e 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletRequestHandledEvent.java @@ -16,7 +16,7 @@ package org.springframework.web.context.support; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * Servlet-specific subclass of RequestHandledEvent, diff --git a/spring-web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java b/spring-web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java index 35c29ad0e020..64a3487263de 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/StandardServletEnvironment.java @@ -18,6 +18,7 @@ import jakarta.servlet.ServletConfig; import jakarta.servlet.ServletContext; +import org.jspecify.annotations.Nullable; import org.springframework.core.env.Environment; import org.springframework.core.env.MutablePropertySources; @@ -26,7 +27,6 @@ import org.springframework.core.env.StandardEnvironment; import org.springframework.jndi.JndiLocatorDelegate; import org.springframework.jndi.JndiPropertySource; -import org.springframework.lang.Nullable; import org.springframework.util.ClassUtils; import org.springframework.web.context.ConfigurableWebEnvironment; diff --git a/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java b/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java index 63b4b5f57ce1..d564784953e3 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/StaticWebApplicationContext.java @@ -18,13 +18,13 @@ 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.StaticApplicationContext; 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; @@ -60,17 +60,13 @@ public class StaticWebApplicationContext extends StaticApplicationContext implements ConfigurableWebApplicationContext, ThemeSource { - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; - @Nullable - private ServletConfig servletConfig; + private @Nullable ServletConfig servletConfig; - @Nullable - private String namespace; + private @Nullable String namespace; - @Nullable - private ThemeSource themeSource; + private @Nullable ThemeSource themeSource; public StaticWebApplicationContext() { @@ -87,8 +83,7 @@ public void setServletContext(@Nullable ServletContext servletContext) { } @Override - @Nullable - public ServletContext getServletContext() { + public @Nullable ServletContext getServletContext() { return this.servletContext; } @@ -101,8 +96,7 @@ public void setServletConfig(@Nullable ServletConfig servletConfig) { } @Override - @Nullable - public ServletConfig getServletConfig() { + public @Nullable ServletConfig getServletConfig() { return this.servletConfig; } @@ -115,8 +109,7 @@ public void setNamespace(@Nullable String namespace) { } @Override - @Nullable - public String getNamespace() { + public @Nullable String getNamespace() { return this.namespace; } @@ -139,8 +132,7 @@ public void setConfigLocations(String... configLocations) { } @Override - @Nullable - public String[] getConfigLocations() { + public String @Nullable [] getConfigLocations() { return null; } @@ -200,9 +192,8 @@ protected void initPropertySources() { } @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/WebApplicationContextUtils.java b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java index deaee9050f80..6b5283773b98 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/WebApplicationContextUtils.java @@ -29,12 +29,12 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.HttpSession; +import org.jspecify.annotations.Nullable; import org.springframework.beans.factory.ObjectFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.core.env.MutablePropertySources; import org.springframework.core.env.PropertySource.StubPropertySource; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.web.context.ConfigurableWebApplicationContext; @@ -96,8 +96,7 @@ public static WebApplicationContext getRequiredWebApplicationContext(ServletCont * @return the root WebApplicationContext for this web app, or {@code null} if none * @see org.springframework.web.context.WebApplicationContext#ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE */ - @Nullable - public static WebApplicationContext getWebApplicationContext(ServletContext sc) { + public static @Nullable WebApplicationContext getWebApplicationContext(ServletContext sc) { return getWebApplicationContext(sc, WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE); } @@ -107,8 +106,7 @@ public static WebApplicationContext getWebApplicationContext(ServletContext sc) * @param attrName the name of the ServletContext attribute to look for * @return the desired WebApplicationContext for this web app, or {@code null} if none */ - @Nullable - public static WebApplicationContext getWebApplicationContext(ServletContext sc, String attrName) { + public static @Nullable WebApplicationContext getWebApplicationContext(ServletContext sc, String attrName) { Assert.notNull(sc, "ServletContext must not be null"); Object attr = sc.getAttribute(attrName); if (attr == null) { @@ -144,8 +142,7 @@ public static WebApplicationContext getWebApplicationContext(ServletContext sc, * @see #getWebApplicationContext(ServletContext) * @see ServletContext#getAttributeNames() */ - @Nullable - public static WebApplicationContext findWebApplicationContext(ServletContext sc) { + public static @Nullable WebApplicationContext findWebApplicationContext(ServletContext sc) { WebApplicationContext wac = getWebApplicationContext(sc); if (wac == null) { Enumeration 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 b7035f711f01..cea2f626cec4 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 @@ 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 @@ */ public abstract class WebApplicationObjectSupport extends ApplicationObjectSupport implements ServletContextAware { - @Nullable - private ServletContext servletContext; + private @Nullable ServletContext servletContext; @Override @@ -105,8 +104,7 @@ protected void initServletContext(ServletContext servletContext) { * @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 @@ else if (isContextRequired()) { * @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 78999b0c42be..1a3d8a2aa381 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 bef29cf0e2b4..80ac063fa993 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.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 @@ private String trimTrailingSlash(String origin) { /** * 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 CorsConfiguration setAllowedOriginPatterns(@Nullable List allowed * 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 void setAllowedMethods(@Nullable List allowedMethods) { * @see #addAllowedMethod(HttpMethod) * @see #addAllowedMethod(String) */ - @Nullable - public List getAllowedMethods() { + public @Nullable List getAllowedMethods() { return this.allowedMethods; } @@ -387,8 +376,7 @@ public void setAllowedHeaders(@Nullable List allowedHeaders) { * @see #addAllowedHeader(String) * @see #setAllowedHeaders(List) */ - @Nullable - public List getAllowedHeaders() { + public @Nullable List getAllowedHeaders() { return this.allowedHeaders; } @@ -430,8 +418,7 @@ public void setExposedHeaders(@Nullable List exposedHeaders) { * @see #addExposedHeader(String) * @see #setExposedHeaders(List) */ - @Nullable - public List getExposedHeaders() { + public @Nullable List getExposedHeaders() { return this.exposedHeaders; } @@ -466,8 +453,7 @@ public void setAllowCredentials(@Nullable Boolean allowCredentials) { * 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 void setAllowPrivateNetwork(@Nullable Boolean allowPrivateNetwork) { * @since 5.3.32 * @see #setAllowPrivateNetwork(Boolean) */ - @Nullable - public Boolean getAllowPrivateNetwork() { + public @Nullable Boolean getAllowPrivateNetwork() { return this.allowPrivateNetwork; } @@ -521,8 +506,7 @@ public void setMaxAge(@Nullable Long maxAge) { * 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 @@ private List combinePatterns( * @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 String checkOrigin(@Nullable String origin) { * @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 List checkHttpMethod(@Nullable HttpMethod requestMethod) { * @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 c2111bb5b8a1..e62bf5290e31 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 4b19c35d96ad..be64e9520c6b 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 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 842c03082153..b1a46deacb98 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 158871a196d2..2bbd283c09b6 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.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.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 @@ protected boolean handleInternal(ServerHttpRequest request, ServerHttpResponse r * 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 @@ protected String checkOrigin(CorsConfiguration config, @Nullable String requestO * 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 @@ private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight * 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 ab11bae96fea..a7c81d02057c 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.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 Map getCorsConfigurations() { @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 3c92402aed24..991123eb05a9 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 98a31159ef2b..0d9a13ea9fda 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 c27a06575c9d..5a6da4d61df5 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 c5256f24d6fa..e50839398cbc 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 @@ 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 e1d2b82a6a50..369a32fd9364 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 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 @@ protected boolean handleInternal(ServerWebExchange exchange, * 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 @@ protected String checkOrigin(CorsConfiguration config, @Nullable String requestO * 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 @@ private HttpMethod getMethodToUse(ServerHttpRequest request, boolean isPreFlight * 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 af85fde0aa75..addc77194643 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 @@ 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 void registerCorsConfiguration(String path, CorsConfiguration config) { } @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 0cca26c2a03d..bcfc67015b76 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 190666c12afa..36dcaadcfbd5 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.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 void setHeaderPredicate(@Nullable Predicate headerPredicate) { * The configured {@link #setHeaderPredicate(Predicate) headerPredicate}. * @since 5.2 */ - @Nullable - protected Predicate getHeaderPredicate() { + protected @Nullable Predicate getHeaderPredicate() { return this.headerPredicate; } @@ -378,8 +376,7 @@ protected String createMessage(HttpServletRequest request, String prefix, String * {@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 d217feaaf83f..e710c44bdc67 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.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 @@ */ public class CharacterEncodingFilter extends OncePerRequestFilter { - @Nullable - private String encoding; + private @Nullable String encoding; private boolean forceRequestEncoding = false; @@ -120,8 +119,7 @@ public void setEncoding(@Nullable String encoding) { * 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 af17803cd1e2..609ad7299901 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.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 @@ */ 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 void setContextAttribute(@Nullable String contextAttribute) { * 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 void setTargetBeanName(@Nullable String targetBeanName) { /** * 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 void destroy() { * @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 bad214fb5d59..d4905d12de31 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.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 @@ protected void doFilterInternal( } } - @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 FormContentRequestWrapper(HttpServletRequest request, MultiValueMap getParameterNames() { } @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 0c2dc2a0f1d6..291232c6f2d3 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.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 @@ private static Set headerNames(HttpServletRequest request) { // 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 Enumeration getHeaderNames() { */ 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 @@ private static class ForwardedHeaderExtractingRequest extends ForwardedHeaderRem } @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 StringBuffer getRequestURL() { } @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 int getRemotePort() { @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 @@ private static class ForwardedPrefixExtractor { 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 ForwardedPrefixExtractor(Supplier delegate, String ba 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 @@ private static String initForwardedPrefix(HttpServletRequest request) { 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 @@ private void recalculatePathsIfNecessary() { } } - @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 6936a66c6b34..df9dc0e794cb 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.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.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 @@ protected void initFilterBean() throws ServletException { * @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 FilterConfig getFilterConfig() { * @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 c28e761592da..42310220d8d1 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.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 @@ private Observation createOrFetchObservation(HttpServletRequest request, HttpSer 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 9566a4faffc5..1fa8fa5e6ae2 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.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 @@ private final class DefaultTrailingSlashSpec implements TrailingSlashSpec { 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 d54e7e3d3fd8..93bf3413ed63 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 479e9ce4d63c..382cc5a603d5 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 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.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 @@ private final class DefaultTrailingSlashSpec implements TrailingSlashSpec { 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 23a7beb13a24..cdcb71975dbd 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 f80280f2234c..732d79e45337 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 @@ 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 @@ */ public abstract class DecoratingNavigationHandler extends NavigationHandler { - @Nullable - private NavigationHandler decoratedNavigationHandler; + private @Nullable NavigationHandler decoratedNavigationHandler; /** @@ -61,8 +59,7 @@ protected DecoratingNavigationHandler(NavigationHandler originalNavigationHandle * 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 0e3bac26bdda..bd7eb9b58252 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 @@ 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 69a7a7a59cf7..c0c6c1aeee09 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 @@ 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 static WebApplicationContext getRequiredWebApplicationContext(FacesContex * @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 b28883313eaf..8f92b5f0506b 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.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 @@ 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 Object getValue(ELContext elContext, @Nullable Object base, Object proper } @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 165102f7e7f2..45bb32464cf0 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.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 Object getValue(ELContext elContext, @Nullable Object base, Object proper } @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 getCommonPropertyType(ELContext elContext, Object base) { * @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 2ce617b9ae81..dcc9d25c1fa5 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 53bfeb3e1af4..4802b973200f 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 a3b45aecbdb8..b3d5ec888b01 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.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.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 int getOrder() { *

    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 static List findAnnotatedBeans(ApplicationContext c 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 41a53a5e3aad..1dde8abf20c3 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 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.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 boolean shouldValidateReturnValue() { * @since 4.3.8 * @see ResponseStatus#code() */ - @Nullable - protected HttpStatusCode getResponseStatus() { + protected @Nullable HttpStatusCode getResponseStatus() { return this.responseStatus; } @@ -293,8 +287,7 @@ protected HttpStatusCode getResponseStatus() { * @since 4.3.8 * @see ResponseStatus#reason() */ - @Nullable - protected String getResponseStatusReason() { + protected @Nullable String getResponseStatusReason() { return this.responseStatusReason; } @@ -302,8 +295,7 @@ protected String getResponseStatusReason() { * 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 427a886c62d4..a7f89457c9b4 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.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 d1f28393aa74..ff9f48a986ad 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 145d108f0ae5..017a42c3161d 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 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.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 @@ */ 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 AbstractNamedValueMethodArgumentResolver(@Nullable ConfigurableBeanFactor @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 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu * 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 @@ private Object resolveEmbeddedValuesAndExpressions(String value) { * @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 @@ protected void handleMissingValueAfterConversion(String name, MethodParameter pa /** * 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 @@ else if (paramType.isPrimitive()) { 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 @@ protected static class NamedValueInfo { 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 0d0272a373e6..5c8961ff5cef 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 @@ 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 boolean supportsParameter(MethodParameter parameter) { * 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 2e727c7975f5..0399b22df058 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 boolean supportsParameter(MethodParameter parameter) { } @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 80d6d70bdc41..0ea6217e0802 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.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 boolean hasExceptionMappings() { * @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 Method resolveMethod(Exception exception) { * @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 Method resolveMethodByThrowable(Throwable exception) { * @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 ExceptionHandlerMappingInfo resolveExceptionMapping(Throwable exception, * @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 Method resolveMethodByExceptionType(Class exceptionT * @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 ExceptionHandlerMappingInfo resolveExceptionMappingByExceptionType(Class< * 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 70f2a06e6140..3c3a120861b6 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 019576c4d1ad..ea7c33508369 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.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 e854fcab751a..bd85cb07f9bf 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.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 Class[] determineValidationGroups(Object target, Method method) { @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 void applyArgumentValidation( @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 MethodValidationResult validateReturnValue(Object target, Method method, * 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 static MethodValidator from( 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 d8446a353ac0..60f5a010308a 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 @@ 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 8f8cb85489c2..2f7f8031137a 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 @@ 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 boolean supportsParameter(MethodParameter 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 { 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 3043f3364358..6a0b79ff3b05 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 9f83ce09b331..b9c883c51b0e 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 e8e89c302723..14814abe7fe1 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 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 boolean supportsParameter(MethodParameter parameter) { * @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 final Object resolveArgument(MethodParameter parameter, @Nullable ModelAn 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 @@ private static Object wrapAsOptionalIfNecessary(MethodParameter parameter, @Null * @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 d2dbe96836fb..ec5e2304ad0b 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 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 a68931b7cbd1..930d52e2f2d9 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 boolean supportsParameter(MethodParameter 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 { 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 558d2ea06eb9..33ec1e739898 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.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 bfc79c787bba..45e9129ecd2c 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 @@ 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 7c71280f4fd4..2a8990faa839 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 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 921f7f656fad..83f43a4c78e5 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 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.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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 @@ else if (value instanceof Collection elements) { } } - @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 b9071f448436..5595c8870fc4 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.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 void cleanupAttributes(WebRequest request) { * @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 5676fa24be1b..9d577417d0e5 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 0a15dd473fb2..db2d6239187d 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 772e1ec8a093..23bd6e2bf811 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 c43de97316c8..eceea514ed3b 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 2e2ffaf8fb48..796ffdb8fa28 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.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 72b1972e1c63..00e6dff71185 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 4ca80dd52c81..1edee89c3d92 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.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 boolean supportsParameter(MethodParameter parameter) { * @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 Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC * 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 2133effcb315..6ad0a02a2807 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 c00b7923e014..ce9063794539 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.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 boolean supportsReturnType(MethodParameter returnType) { 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 void handleReturnValue(@Nullable Object returnValue, MethodParameter retu 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 6f14f487aee8..d49a6ae66bbd 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.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.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 void setMethodValidator(@Nullable MethodValidator methodValidator) { * @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 @@ protected Object[] getMethodArgumentValues(NativeWebRequest request, @Nullable M /** * 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 @@ protected Object invokeSuspendingFunction(Method method, Object target, Object[] */ 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 7f2db8d3dcdc..bf07e9c9a057 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.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 void setViewName(@Nullable String viewName) { * 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 void setView(@Nullable Object view) { * 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 void setStatus(@Nullable HttpStatusCode status) { * 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 4d4de4a0572e..6ce1127baa4e 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 5ccdf4727852..7fc0572229df 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 401cd572bd6c..b7e10e3ef43c 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 34ad8274c263..e184f0b7477a 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.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 d710062e0680..13a7afff03ca 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 @@ 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 @@ public long contentLength() { } @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 7d2237d85961..485d86e4adc3 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 f5339b471667..8c1002f5959a 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.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 8620295ce9bc..530a984363c2 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 1299f15c7f97..64fdf9ee2f1c 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 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 @@ public abstract class AbstractMultipartHttpServletRequest extends HttpServletRequestWrapper implements MultipartHttpServletRequest { - @Nullable - private MultiValueMap multipartFiles; + private @Nullable MultiValueMap multipartFiles; /** @@ -84,8 +83,7 @@ public Iterator getFileNames() { } @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 71068c296042..ad3a7fb6d8c9 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 @@ 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 609837234ba0..3789a96d19bb 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.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 DefaultMultipartHttpServletRequest(HttpServletRequest request) { @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 Map getParameterMap() { } @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 String getMultipartContentType(String paramOrFileName) { } @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 a519cd25b269..6b14989678a5 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 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 @@ private 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 static boolean isMultipartArgument(MethodParameter parameter) { (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 @@ private static boolean isPartArray(MethodParameter methodParam) { 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 424ea4e1d6dd..4082d59b2a51 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 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 InputStream getBody() throws IOException { 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 d2810985c2fe..7b7a21f5cce7 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 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 @@ */ public class StandardMultipartHttpServletRequest extends AbstractMultipartHttpServletRequest { - @Nullable - private Set multipartParameterNames; + private @Nullable Set multipartParameterNames; /** @@ -181,8 +180,7 @@ public Map getParameterMap() { } @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 String getMultipartContentType(String paramOrFileName) { } @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 32bb903a9780..1b73bf5126e8 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 @@ 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 @@ */ 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 776fdfcf0b0e..1a9a7a2b77b6 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 dd944f1f0a72..d5ad58301c8f 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 69fd78777954..8f7962ddc2cb 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 @@ 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 @@ public ServerWebExchange build() { */ 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 ca894604888c..88e2d65e900b 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.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 5dc9cf412784..a4bdf0ba95e5 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 23abc0fd3969..c2be31ec4470 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 @@ 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 @@ @SuppressWarnings("serial") public class ResponseStatusException extends ErrorResponseException { - @Nullable - private final String reason; + private final @Nullable String reason; /** @@ -92,7 +92,7 @@ public ResponseStatusException(HttpStatusCode status, @Nullable String reason, @ */ 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 @@ protected ResponseStatusException( /** * 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 e079e0f2b9af..e4713672c536 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 @@ 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 @@ @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 ServerErrorException(String reason, MethodParameter parameter, @Nullable * 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 da7a3bfb520d..7515f57b7d7b 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.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.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 @@ default Mono cleanupMultipart() { * @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 b69c18599a47..09b62204de92 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.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.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 LocaleContext getLocaleContext() { } @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 e0ba0ea2435d..6e9c18a99e04 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 @@ @SuppressWarnings("serial") public class ServerWebInputException extends ResponseStatusException { - @Nullable - private final MethodParameter parameter; + private final @Nullable MethodParameter parameter; /** @@ -62,7 +62,7 @@ public ServerWebInputException(String reason, @Nullable MethodParameter paramete * @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 @@ protected ServerWebInputException(String reason, @Nullable MethodParameter param /** * 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 58c26a32a97e..f38dd40b9501 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 @@ 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 @@ private static String initMessage(@Nullable MediaType contentType, @Nullable Res * 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 List getSupportedMediaTypes() { * @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 cfa35d9667c4..fbe863831b4d 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.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 0500180897b1..a305e1a991a0 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.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.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 @@ private Mono> initMultipartData(ServerCodecConfigure .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 @@ private static MediaType getContentType(ServerHttpRequest request) { } @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 LocaleContext getLocaleContext() { } @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 a920f17b8161..0a00a58d2876 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.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 @@ private void removeForwardedHeaders(ServerHttpRequest.Builder builder) { } - @Nullable - private static String getForwardedPrefix(ServerHttpRequest request) { + private static @Nullable String getForwardedPrefix(ServerHttpRequest request) { HttpHeaders headers = request.getHeaders(); String header = headers.getFirst("X-Forwarded-Prefix"); if (header == null) { diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java b/spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java index 10659c9bd652..089c40996f23 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/HttpWebHandlerAdapter.java @@ -23,6 +23,7 @@ import io.micrometer.observation.contextpropagation.ObservationThreadLocalAccessor; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.jspecify.annotations.Nullable; import reactor.core.observability.DefaultSignalListener; import reactor.core.publisher.Mono; import reactor.util.context.Context; @@ -41,7 +42,6 @@ import org.springframework.http.server.reactive.observation.ServerHttpObservationDocumentation; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.StringUtils; import org.springframework.web.server.ServerWebExchange; @@ -86,20 +86,17 @@ public class HttpWebHandlerAdapter extends WebHandlerDecorator implements HttpHa private WebSessionManager sessionManager = new DefaultWebSessionManager(); - @Nullable - private ServerCodecConfigurer codecConfigurer; + private @Nullable ServerCodecConfigurer codecConfigurer; private LocaleContextResolver localeContextResolver = new AcceptHeaderLocaleContextResolver(); - @Nullable - private ForwardedHeaderTransformer forwardedHeaderTransformer; + private @Nullable ForwardedHeaderTransformer forwardedHeaderTransformer; private ObservationRegistry observationRegistry = ObservationRegistry.NOOP; private ServerRequestObservationConvention observationConvention = DEFAULT_OBSERVATION_CONVENTION; - @Nullable - private ApplicationContext applicationContext; + private @Nullable ApplicationContext applicationContext; /** Whether to log potentially sensitive info (form data at DEBUG, headers at TRACE). */ private boolean enableLoggingRequestDetails = false; @@ -194,8 +191,7 @@ public void setForwardedHeaderTransformer(@Nullable ForwardedHeaderTransformer t * Return the configured {@link ForwardedHeaderTransformer}. * @since 5.1 */ - @Nullable - public ForwardedHeaderTransformer getForwardedHeaderTransformer() { + public @Nullable ForwardedHeaderTransformer getForwardedHeaderTransformer() { return this.forwardedHeaderTransformer; } @@ -250,8 +246,7 @@ public void setApplicationContext(ApplicationContext applicationContext) { * Return the configured {@code ApplicationContext}, if any. * @since 5.0.3 */ - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } diff --git a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java index b68e25a7b62c..4d26487d9084 100644 --- a/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java +++ b/spring-web/src/main/java/org/springframework/web/server/adapter/WebHttpHandlerBuilder.java @@ -23,6 +23,7 @@ import java.util.function.Function; import io.micrometer.observation.ObservationRegistry; +import org.jspecify.annotations.Nullable; import reactor.blockhound.BlockHound; import reactor.blockhound.integration.BlockHoundIntegration; @@ -34,7 +35,6 @@ import org.springframework.http.server.reactive.HttpHandlerDecoratorFactory; import org.springframework.http.server.reactive.observation.DefaultServerRequestObservationConvention; import org.springframework.http.server.reactive.observation.ServerRequestObservationConvention; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.web.server.ServerWebExchange; @@ -85,33 +85,25 @@ public final class WebHttpHandlerBuilder { private final WebHandler webHandler; - @Nullable - private final ApplicationContext applicationContext; + private final @Nullable ApplicationContext applicationContext; private final List 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 13828629a520..4795dd805caa 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 c255dd0688f6..1b529164572d 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.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 70b6c3877941..172fbd600d81 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 @@ 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 @@ private boolean updateResponse(ServerHttpResponse response, Throwable ex) { * @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 25dc942f1e76..5ec721b4a3cd 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 c5e990f10107..67a31db6cf92 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.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 void setDefaultLocale(@Nullable Locale defaultLocale) { * 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 LocaleContext resolveLocaleContext(ServerWebExchange exchange) { 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 4c731a434902..d6a61396c929 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 @@ 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 Locale getLocale() { 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 4e4f1af23cf2..7f9dfc9acab9 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 c7724d0e0b2d..3a20ca8bc9a5 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 603079df2562..bb5149cb6251 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 df661f2e9355..d2afdb7454e6 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.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 9df7670c7013..af063ef32a97 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 9839babcdf91..d13bf7443da7 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 @@ 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.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 @@ */ 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 c04c6fd7612b..30f1b0e366f0 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 3a967ed0c7d4..0a2c78ebac0f 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 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 boolean resolve( 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 @@ private NamedValueInfo getNamedValueInfo(MethodParameter parameter, HttpRequestV * 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 @@ protected static class NamedValueInfo { 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 a11e6f516731..184a6e4a5eb2 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 @@ 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 void setBlockTimeout(@Nullable Duration blockTimeout) { } @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 6b987351bdc3..80480429702a 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 CookieValueArgumentResolver(ConversionService conversionService) { @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 8e78bbe6103f..368103bc711a 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 0f0258045e26..cb83772ef7e5 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 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 7bf09599ae2b..0efa005d43f8 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.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 @@ protected HttpRequestValues(@Nullable HttpMethod httpMethod, /** * 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 HttpMethod getHttpMethod() { * 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 URI getUri() { * underlying client. * @since 6.1 */ - @Nullable - public UriBuilderFactory getUriBuilderFactory() { + public @Nullable UriBuilderFactory getUriBuilderFactory() { return this.uriBuilderFactory; } @@ -136,8 +129,7 @@ public UriBuilderFactory getUriBuilderFactory() { * 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 Map getAttributes() { /** * 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 interface Metadata { /** * 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 interface Metadata { */ 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 void setBodyValue(@Nullable Object bodyValue) { // 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 d9d045e9f090..e3f170a5af15 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 819667c7449b..99844fee8fe3 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.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.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 @@ public Method getMethod() { } - @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 @@ public static HttpRequestValuesInitializer create( 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 @@ private static HttpMethod initHttpMethod(@Nullable HttpExchange typeAnnotation, 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 @@ private static String initUrl( 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 @@ private static MediaType initContentType(@Nullable HttpExchange typeAnnotation, 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 @@ private static MultiValueMap parseHeaders(String[] headersArray, 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 @@ public String toString() { */ private interface ResponseFunction { - @Nullable - Object execute(HttpRequestValues requestValues); + @Nullable Object execute(HttpRequestValues requestValues); } @@ -458,8 +451,7 @@ private record ReactorExchangeResponseFunction( 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 863377344b16..d064cafd76af 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 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.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 static Builder builder() { */ 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 @@ private HttpServiceMethodInterceptor(List methods) { } @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 668e4fd4b5de..4a20a17f4d7d 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 PathVariableArgumentResolver(ConversionService conversionService) { @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 de5d477f2e96..b8cfdb897cf1 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.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.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 @@ */ 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 @@ private ReactiveHttpRequestValues( *

    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 static Builder builder() { */ 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 466fda215e9b..10752ddd6fe3 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 @@ 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.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 b99f6f49b846..f5b9f8e2c39e 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 a84ef532acde..311a44aec92e 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 @@ 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 40a1523de6bf..8df23e2f867d 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 RequestHeaderArgumentResolver(ConversionService conversionService) { @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 4bcf4aef779e..0b995f5ad749 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 boolean isFavorSingleValue() { @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 f4173d6e0666..46b09918f8d1 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.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 RequestPartArgumentResolver(HttpExchangeAdapter exchangeAdapter) { @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 0c89f905e593..795c269a18ce 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 @@ 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 e3840a55347c..81d71142737f 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 @@ 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 9c420bbf3f00..1e40eb8d0f68 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 4fbe50a5af80..0d90975028ca 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 9230d0fb0daa..a485bcd82a9e 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.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 @@ private static class MethodArgumentErrorMessageSource extends StaticMessageSourc } @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 fe4a465c08cb..ebbad602935e 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.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 6f150b7547d1..b8511a8f8d2c 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.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 void addIntHeader(String name, int value) { } @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 2f15c6e3d237..c334afca5cc7 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.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 void setCookieName(@Nullable String cookieName) { /** * 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 void setCookieDomain(@Nullable String cookieDomain) { /** * 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 void setCookieMaxAge(@Nullable Integer cookieMaxAge) { /** * 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 96639045e61f..b49830a09472 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.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 @@ */ 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 void setParserType(UriComponentsBuilder.ParserType parserType) { * 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 fa7df6d2827e..84900e3374c6 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.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 @@ private static void adaptForwardedHost(UriComponentsBuilder uriComponentsBuilder * {@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 3af171ebc967..02ccc8a9ca43 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.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 @@ public int hashCode() { }; - @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 @@ public int hashCode() { private final EncodeState encodeState; - @Nullable - private UnaryOperator variableEncoder; + private @Nullable UnaryOperator variableEncoder; /** @@ -167,20 +164,17 @@ private HierarchicalUriComponents(@Nullable String scheme, @Nullable String frag // 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 @@ else if (this.port.contains("{")) { } @Override - @NonNull - public String getPath() { + public @NonNull String getPath() { return this.path.getPath(); } @@ -213,8 +206,7 @@ public List getPathSegments() { } @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 @@ public QueryUriTemplateVariables(UriTemplateVariables delegate) { } @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 d28724c27d6e..045379b4c5a0 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.Map; import java.util.Properties; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.Assert; /** @@ -122,8 +123,7 @@ public boolean isMappedToReference(char character, String encoding) { /** * 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 @@ public String convertToReference(char character) { * 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 299b26ddffbb..eb05b1545d05 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 de437e6db0f7..c124ebbd5b00 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.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 @@ public int getPort() { } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return null; } @@ -86,8 +82,7 @@ public List getPathSegments() { } @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 cf4e28481576..e07f82923c7e 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.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 @@ private static class InternalParser { 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 14a8e2f7b4cb..bd05bef73d33 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 ServletContextPlaceholderResolver(String text, ServletContext servletCont } @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 4c627896589c..06683bdb7582 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.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 static RequestPath parse(HttpServletRequest request) { 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 b468038af99e..238aca79bc87 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.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 047a8ce09cf6..c8ae65a0ace5 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.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 @@ protected UriComponents(@Nullable String scheme, @Nullable String fragment) { /** * 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 final String getFragment() { /** * 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 final String getFragment() { /** * 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 final String toString() { // 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 interface UriTemplateVariables { * @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 MapTemplateVariables(Map uriVariables) { } @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 VarArgsTemplateVariables(Object... uriVariableValues) { } @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 422142082a1b..8aa36ccf1962 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.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 UriComponentsBuilder queryParam(String name, @Nullable Object... values) 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 enum ParserType { private interface PathComponentBuilder { - @Nullable - PathComponent build(); + @Nullable PathComponent build(); PathComponentBuilder cloneBuilder(); } @@ -819,8 +812,7 @@ public void addPath(String path) { } @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 void append(String path) { } @Override - @Nullable - public PathComponent build() { + public @Nullable PathComponent build() { if (this.path.isEmpty()) { return null; } @@ -920,8 +911,7 @@ public void append(String... pathSegments) { } @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 fd011edb6392..a6b622d588ea 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.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 c8faec81c9b3..9362697bf0aa 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.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 static String decode(String source, Charset charset) { * @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 c6bd2a2956dd..a7035825155e 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.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 String getPathWithinApplication(HttpServletRequest request) { * 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 dfff61eea9cb..b7572ce74272 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 b5d8fa8fc2cb..f5ff80854887 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.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 static void removeWebAppRootSystemProperty(ServletContext servletContext) * @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 static Boolean getDefaultHtmlEscape(@Nullable ServletContext servletConte * ({@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 static String getRealPath(ServletContext servletContext, String path) thr * @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 static String getSessionId(HttpServletRequest request) { * @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 static Object getSessionMutex(HttpSession session) { * 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 @@ else if (request instanceof ServletRequestWrapper wrapper) { * 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 static void clearErrorRequestAttributes(HttpServletRequest request) { * @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 static boolean hasSubmitParameter(ServletRequest request, String name) { * @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 static String findParameterValue(ServletRequest request, String name) { * @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 44cb470d30e7..cdf863701dad 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 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 @@ private static String percentDecode(String input) { } } - @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 @@ static final class UrlRecord { 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 @@ void appendToPassword(String s) { /** * Convenience method to return the full user info. */ - @Nullable - public String userInfo() { + public @Nullable String userInfo() { if (!includesCredentials()) { return null; } @@ -1853,8 +1840,7 @@ public String userInfo() { * 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 @@ public String hostname() { * 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 @@ public void shortenPath() { * 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 @@ public String search() { * 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 @@ sealed interface Path permits PathSegment, PathSegments { 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 d5cd93f8851e..b36cd157b9ee 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 d02dc686cb42..4d28e5d480d9 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 @@ 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 53e511ae0f07..00de897de8fa 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.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 b9660bf3381a..e6a17d3150d5 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 abd3157b5c5a..bdada060507e 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.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 @@ else if (!hasLength(pathContainer)) { * @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 @@ else if (!hasLength(pathContainer)) { * @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 @@ String computePatternString() { return sb.toString(); } - @Nullable - PathElement getHeadSection() { + @Nullable PathElement getHeadSection() { return this.head; } @@ -647,11 +644,9 @@ static class MatchingContext { 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 740b61152d1c..776b5f04f765 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.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 boolean match(String pattern, Route route) { } @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 f6a5f3fce8b1..4f067d584b50 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 a6234cfb1402..cefc9542eb42 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 443cb069526a..049fd5d934ed 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 @@ 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.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 @@ */ 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 209e358a5292..692f06a1085d 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.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.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 31c3b8ab7be8..466ce18325c6 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 d62a9ce02126..8a7095fddf8a 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.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 19c277a9b7d5..4ef209b2bd64 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.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.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 e6ac7463f422..325a84641111 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 @@ protected void checkOnDataAvailable() { } @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 9ad7ee09b98e..fc39bff8a185 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.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.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 @@ private void assertDetail(ErrorResponse ex, @Nullable String detail) { } 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 d5407aa73f29..2f3310af7141 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.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.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 @@ static class MultipartDataClass { 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 @@ public FilePart getPart() { 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 fbe2f9d318ca..d7f3fcbfbb36 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.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.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 e328bcfb8499..c06a22736fcd 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.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.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 @@ void buildCopiesDefaultCookiesImmutable() { ); } - @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 @@ private static Object fieldValue(String name, DefaultRestClientBuilder instance) } } - @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 b8a2ad99d313..521d5e677e9a 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.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.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 @@ static class ObservationErrorHandler implements ResponseErrorHandler { 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 2f5e87f985c7..4abb8defbd40 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 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.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 7fdc186b6a1f..fdb076bf1442 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.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 41a4f215551b..e8da060186e3 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 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 3b5178d5b438..1909164095b9 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 @@ 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 04e6c2315562..4b3aec2f5a84 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.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.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 c14791d7721b..492f70e4a1a3 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 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.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 52dd2fe975d9..e8ec8109a3de 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 @@ 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 cc0960ed5183..cd8e7567e005 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.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 @@ private void process(Class beanClass) { } } - @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 e2f87f01cca4..d1be287fee38 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 @@ 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 @@ void optionalHttpMethod() { } - @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 90932f856b12..804686bf0a69 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 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.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 4e677140b52f..3e8495f6081e 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.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 4fdb1f08e5bb..3d5149ed629b 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 2feaf15dce30..8801672bb5de 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 3b82d00164a1..7c3822eb22a2 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 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 @@ void optionalStringBody() { } - @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 b600d9d87007..2cbe5aa2c101 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 @@ 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 @@ */ 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 HttpRequestValues getRequestValues() { 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 36b8c9ec562c..7a28a5010682 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 @@ 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 2039e851a48c..205370dfe249 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 @@ 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 4ea6c2182557..144cb4c6984d 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 dfda75650d30..6aec92f14847 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 6bcd605b3c1c..78e2d4d008b4 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 d427b89565ac..e093df1d9fce 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 1cf6a68e5963..a7010b22ee8b 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.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 d153421f5c97..c0b011a84139 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 68dbdb583218..8e7f2e318bf7 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 d3c62d711e2c..4bd546ace478 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.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.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 @@ private MockServerHttpRequest(HttpMethod httpMethod, @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 @@ private static class DefaultBodyBuilder implements BodyBuilder { private final URI url; - @Nullable - private String contextPath; + private @Nullable String contextPath; private final UriComponentsBuilder queryParamsBuilder = UriComponentsBuilder.newInstance(); @@ -431,14 +424,11 @@ private static class DefaultBodyBuilder implements BodyBuilder { 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 cc95fcf042c6..2240283cbebc 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 abd6b2c05107..61cd92370d73 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 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.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 @@ private List applyFilters() { 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 Object intercept(Object object, Method method, @Nullable Object[] args, @ } @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 82635bd18133..3ede08c4d05f 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 static class Builder { 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 689418372fd3..73f127234a35 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.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 54867a24232a..1646b7468fde 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 c1659d97cd8c..3416aadf69d4 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.LinkedList; import java.util.List; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.util.CollectionUtils; /** @@ -63,13 +64,11 @@ List getStringValues() { 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 f01b2b7411e2..d403c7424ac4 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.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 ServletRequest getRequest() { } @Override - @Nullable - public ServletResponse getResponse() { + public @Nullable ServletResponse getResponse() { return this.response; } @@ -110,8 +107,7 @@ public void dispatch(@Nullable ServletContext context, String path) { } } - @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 63b566828f0f..9e068196df3c 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 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 9d01ad1c6d61..73053568d37d 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.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 void setExpires(@Nullable ZonedDateTime expires) { * @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 void setSameSite(@Nullable String sameSite) { * 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 03ed3b0d3ea6..b42d4fe7df9d 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.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 @@ */ 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 @@ private static List initFilterList(Servlet servlet, Filter... filters) { /** * 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 931f043df599..5589bb5cd4e9 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 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 9a165b1a9513..3ef3ce959028 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 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 String getName() { return this.name; } - @Nullable @Override - public String getClassName() { + public @Nullable String getClassName() { return this.className; } @@ -79,9 +77,8 @@ public boolean setInitParameter(String name, String value) { 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 b24ed628e590..3a919cb7651f 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 @@ 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 String getServletName() { } @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 c909946b92aa..28424e415075 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.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 @@ protected void checkActive() throws IllegalStateException { // --------------------------------------------------------------------- @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { checkActive(); return this.attributes.get(name); } @@ -398,8 +379,7 @@ public Enumeration getAttributeNames() { } @Override - @Nullable - public String getCharacterEncoding() { + public @Nullable String getCharacterEncoding() { return this.characterEncoding; } @@ -428,7 +408,7 @@ private void updateContentTypeHeader() { * @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 void setContent(@Nullable byte[] content) { * @see #setContent(byte[]) * @see #getContentAsString() */ - @Nullable - public byte[] getContentAsByteArray() { + public byte @Nullable [] getContentAsByteArray() { return this.content; } @@ -457,8 +436,7 @@ public byte[] getContentAsByteArray() { * @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 void setContentType(@Nullable String contentType) { } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -627,8 +604,7 @@ public void removeAllParameters() { } @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 Enumeration getParameterNames() { } @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 void setAsyncContext(@Nullable MockAsyncContext asyncContext) { } @Override - @Nullable - public AsyncContext getAsyncContext() { + public @Nullable AsyncContext getAsyncContext() { return this.asyncContext; } @@ -1020,8 +994,7 @@ public void setAuthType(@Nullable String authType) { } @Override - @Nullable - public String getAuthType() { + public @Nullable String getAuthType() { return this.authType; } @@ -1042,8 +1015,7 @@ private static String encodeCookies(Cookie... cookies) { } @Override - @Nullable - public Cookie[] getCookies() { + public @Nullable Cookie[] getCookies() { return this.cookies; } @@ -1165,8 +1137,7 @@ private long parseDateHeader(String name, String value) { } @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 void setMethod(@Nullable String method) { } @Override - @Nullable - public String getMethod() { + public @Nullable String getMethod() { return this.method; } @@ -1216,14 +1186,12 @@ public void setPathInfo(@Nullable String pathInfo) { } @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 void setQueryString(@Nullable String queryString) { } @Override - @Nullable - public String getQueryString() { + public @Nullable String getQueryString() { return this.queryString; } @@ -1251,8 +1218,7 @@ public void setRemoteUser(@Nullable String remoteUser) { } @Override - @Nullable - public String getRemoteUser() { + public @Nullable String getRemoteUser() { return this.remoteUser; } @@ -1272,8 +1238,7 @@ public void setUserPrincipal(@Nullable Principal userPrincipal) { } @Override - @Nullable - public Principal getUserPrincipal() { + public @Nullable Principal getUserPrincipal() { return this.userPrincipal; } @@ -1282,8 +1247,7 @@ public void setRequestedSessionId(@Nullable String requestedSessionId) { } @Override - @Nullable - public String getRequestedSessionId() { + public @Nullable String getRequestedSessionId() { return this.requestedSessionId; } @@ -1300,8 +1264,7 @@ public void setUriTemplate(@Nullable String uriTemplate) { * 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 void setRequestURI(@Nullable String requestURI) { } @Override - @Nullable - public String getRequestURI() { + public @Nullable String getRequestURI() { return this.requestURI; } @@ -1350,8 +1312,7 @@ public void setSession(HttpSession session) { } @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 HttpSession getSession(boolean create) { } @Override - @Nullable - public HttpSession getSession() { + public @Nullable HttpSession getSession() { return getSession(true); } @@ -1434,8 +1394,7 @@ public void addPart(Part part) { } @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 HttpServletMapping getHttpServletMapping() { * 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 c51560554e31..fe31513e9c5c 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 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 @@ else if (mediaType.isCompatibleWith(MediaType.APPLICATION_JSON) || } @Override - @Nullable - public String getContentType() { + public @Nullable String getContentType() { return this.contentType; } @@ -510,8 +505,7 @@ public Cookie[] getCookies() { 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 Collection getHeaderNames() { * @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 List getHeaders(String name) { * @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 void sendRedirect(String url, int sc, boolean clearBuffer) throws IOExcep setCommitted(true); } - @Nullable - public String getRedirectedUrl() { + public @Nullable String getRedirectedUrl() { return getHeader(HttpHeaders.LOCATION); } @@ -807,8 +798,7 @@ public int getStatus() { /** * 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 void setForwardedUrl(@Nullable String forwardedUrl) { this.forwardedUrl = forwardedUrl; } - @Nullable - public String getForwardedUrl() { + public @Nullable String getForwardedUrl() { return this.forwardedUrl; } @@ -833,8 +822,7 @@ public void setIncludedUrl(@Nullable String includedUrl) { } } - @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 0ec6fae4b8ee..f497369558dc 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.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 86c62131e82f..d0d905167a24 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 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 849731ac5a68..3a55a9c504bc 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.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 MockMultipartFile(String name, InputStream contentStream) throws IOExcept * @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 String getName() { } @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 24d2b464b598..a7c0c8b9afaa 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 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 6476710dad45..d6fab65d89ce 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.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 void setAttribute(String name, @Nullable Object value, int scope) { } @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 Object getAttribute(String name, int scope) { } @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 JspWriter getOut() { } @Override - @Nullable - public ELContext getELContext() { + public @Nullable ELContext getELContext() { return null; } @@ -294,8 +289,7 @@ public ServletResponse getResponse() { } @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 82688a6f781c..99715488dc14 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.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 MockPart(String name, @Nullable byte[] content) { * 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 MockPart(String name, @Nullable String filename, @Nullable byte[] content * @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 String getName() { } @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 void delete() throws IOException { } @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 17f4541a1384..33a970cbe426 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 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 c7f6f2814994..32bff6a2d0e3 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.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 void registerContext(String contextPath, ServletContext context) { } @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 int getEffectiveMinorVersion() { } @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 void addMimeType(String fileExtension, MediaType mimeType) { } @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 Set getResourcePaths(String path) { } @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 URL getResource(String path) throws MalformedURLException { } @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 RequestDispatcher getRequestDispatcher(String path) { } @Override - @Nullable - public RequestDispatcher getNamedDispatcher(String path) { + public @Nullable RequestDispatcher getNamedDispatcher(String path) { return this.namedRequestDispatchers.get(path); } @@ -446,8 +437,7 @@ public void log(String message, Throwable ex) { } @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 String getServerInfo() { } @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 void addInitParameter(String name, String value) { } @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 String getServletContextName() { } @Override - @Nullable - public ClassLoader getClassLoader() { + public @Nullable ClassLoader getClassLoader() { return ClassUtils.getDefaultClassLoader(); } @@ -590,8 +577,7 @@ public void setRequestCharacterEncoding(@Nullable String requestCharacterEncodin } @Override // on Servlet 4.0 - @Nullable - public String getRequestCharacterEncoding() { + public @Nullable String getRequestCharacterEncoding() { return this.requestCharacterEncoding; } @@ -601,8 +587,7 @@ public void setResponseCharacterEncoding(@Nullable String responseCharacterEncod } @Override // on Servlet 4.0 - @Nullable - public String getResponseCharacterEncoding() { + public @Nullable String getResponseCharacterEncoding() { return this.responseCharacterEncoding; } @@ -615,8 +600,7 @@ public void addFilterRegistration(FilterRegistration registration) { } @Override - @Nullable - public FilterRegistration getFilterRegistration(String filterName) { + public @Nullable FilterRegistration getFilterRegistration(String filterName) { return this.filterRegistrations.get(filterName); } @@ -665,8 +649,7 @@ public T createServlet(Class c) throws ServletException { * @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 07a76626b25c..2aed89467e69 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.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 @@ */ 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 void setName(@Nullable String name) { } @Override - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -71,8 +65,7 @@ public void setDomain(@Nullable String domain) { } @Override - @Nullable - public String getDomain() { + public @Nullable String getDomain() { return this.domain; } @@ -82,8 +75,7 @@ public void setPath(@Nullable String path) { } @Override - @Nullable - public String getPath() { + public @Nullable String getPath() { return this.path; } @@ -95,8 +87,7 @@ public void setComment(@Nullable String comment) { @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 1b54587e5640..8a1432bb0b4c 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.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 @@ */ 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 9350b3060bda..97a38a858516 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 6f9a4b95a568..3826346d3358 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.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 @@ */ 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 996c672c00d7..cda5cdfb30fc 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.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.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 @@ */ 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 DispatcherHandler(ApplicationContext applicationContext) { * 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 c9a970fbafc6..a4f4ac6691a7 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 Object getHandler() { /** * 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 HandlerResult setExceptionHandler(DispatchExceptionHandler exceptionHandl * 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 b74cc841f959..e4e6126116f1 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.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 static class ParameterResolverConfigurer { 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 a9693904f158..c37fb6c233c4 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 ca56c995493b..8fb2e2ddc859 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 @@ 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 @@ */ public class BlockingExecutionConfigurer { - @Nullable - private AsyncTaskExecutor executor; + private @Nullable AsyncTaskExecutor executor; - @Nullable - private Predicate blockingControllerMethodPredicate; + private @Nullable Predicate blockingControllerMethodPredicate; /** @@ -63,13 +62,11 @@ public BlockingExecutionConfigurer setControllerMethodPredicate(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 bc7ca8d50f99..e2aaa147bb1a 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 @@ 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 @@ protected void addFormatters(FormatterRegistry registry) { } @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 @@ protected void configureViewResolvers(ViewResolverRegistry registry) { } @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 58cc38a74487..e0fce27ff136 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.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 @@ */ public class PathMatchConfigurer { - @Nullable - private Boolean caseSensitiveMatch; + private @Nullable Boolean caseSensitiveMatch; - @Nullable - private Map>> pathPrefixes; + private @Nullable Map>> pathPrefixes; /** @@ -68,13 +66,11 @@ public PathMatchConfigurer addPathPrefix(String prefix, Predicate> pred } - @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 fe7318feb023..b152d5fe0ba6 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 @@ 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 c68e0bd81697..137b7b1b9fc2 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.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 a84fdcc6aa85..39d34aadde29 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.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 ResourceHandlerRegistry setOrder(int order) { * 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 9b603e0637ba..26bb76b49268 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.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 @@ */ 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 57b71e8a99b2..025979f0d682 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.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.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 void setApplicationContext(@Nullable ApplicationContext applicationContex } } - @Nullable - public final ApplicationContext getApplicationContext() { + public final @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -419,16 +412,14 @@ public Validator webFluxValidator() { /** * 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 @@ private WebSocketService initWebSocketService() { 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 01f244cfffa1..af14b1f4349b 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 @@ 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 @@ default void addFormatters(FormatterRegistry registry) { *

    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 @@ default Validator getValidator() { * 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 @@ default void addResourceHandlers(ResourceHandlerRegistry registry) { * {@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 e8efac6cfd31..8c7220722691 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.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 void addFormatters(FormatterRegistry registry) { } @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 void addResourceHandlers(ResourceHandlerRegistry registry) { 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 9722fd8a1448..9b5d36a81fcb 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 96fac2afbf04..205f6bd3b6f6 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.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.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 8c863c567ec0..3709a0b96d4c 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 @@ 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 @@ @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 @@ private static String initReason(@Nullable MediaType contentType, @Nullable Reso * 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 List getSupportedMediaTypes() { * @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 5c24b2ab30d6..c21e47d0d53c 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.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.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 @@ default Optional attribute(String name) { * 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 434ca9f140bc..6a3992a01edc 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 @@ */ 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 ClientRequestObservationContext(ClientRequest.Builder request) { } - private static void setRequestHeader(@Nullable ClientRequest.Builder request, String name, String value) { + private static void setRequestHeader(ClientRequest.@Nullable Builder request, String name, String value) { if (request != null) { request.headers(headers -> headers.set(name, value)); } @@ -71,8 +68,7 @@ public void setUriTemplate(@Nullable String uriTemplate) { /** * Return the URI template used for the current client exchange, {@code null} if none was used. */ - @Nullable - public String getUriTemplate() { + public @Nullable String getUriTemplate() { return this.uriTemplate; } @@ -102,8 +98,7 @@ public void setRequest(ClientRequest request) { /** * Return the immutable client request. */ - @Nullable - public ClientRequest getRequest() { + public @Nullable ClientRequest getRequest() { return this.request; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java index 5e710a9dbca1..454e28a499ce 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/DefaultClientRequestBuilder.java @@ -24,6 +24,7 @@ import java.util.Optional; import java.util.function.Consumer; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -35,7 +36,6 @@ import org.springframework.http.client.reactive.ClientHttpRequest; import org.springframework.http.codec.HttpMessageWriter; 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; @@ -64,8 +64,7 @@ final class DefaultClientRequestBuilder implements ClientRequest.Builder { private BodyInserter body = BodyInserters.empty(); - @Nullable - private Consumer httpRequestConsumer; + private @Nullable Consumer httpRequestConsumer; public DefaultClientRequestBuilder(ClientRequest other) { @@ -190,8 +189,7 @@ private static class BodyInserterRequest implements ClientRequest { private final Map attributes; - @Nullable - private final Consumer httpRequestConsumer; + private final @Nullable Consumer httpRequestConsumer; private final String logPrefix; @@ -242,8 +240,7 @@ public Map attributes() { } @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 62f5d1287dbd..d7a3f6c001f0 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 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 String getName() { } @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 6d8c2bfd2594..907d39419036 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.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.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 0a49c0897143..00075c8db44e 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.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.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 @@ public Map getAttributes() { 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 @@ private static class BuiltClientHttpResponse implements ClientHttpResponse { 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 443ba3018f9a..08109bf3ae7e 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 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.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 @@ private class DefaultRequestBodyUriSpec implements RequestBodyUriSpec { 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 @@ private Function> exceptionWrappingFunction(Cli 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 b67ace1c82f8..867bc97e547c 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.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.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 @@ private UriBuilderFactory initUriBuilderFactory() { return factory; } - @Nullable - private HttpHeaders copyDefaultHeaders() { + private @Nullable HttpHeaders copyDefaultHeaders() { if (this.defaultHeaders == null) { return null; } @@ -378,8 +364,7 @@ private HttpHeaders copyDefaultHeaders() { 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 351348431b37..991485f5e10d 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.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 34bc91483db6..a3f92b709649 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 @@ 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 afbd03701a7a..36a2f30674b1 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 6188c45a2073..9e08f919e703 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.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 WebClientResponseException( */ 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 WebClientResponseException( */ 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 @@ private static String initMessage(HttpStatusCode status, String reasonPhrase, @N */ 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 WebClientResponseException( */ 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 WebClientResponseException( */ 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 String getResponseBodyAsString(Charset defaultCharset) { * @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 E getResponseBodyAs(Class targetType) { * 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 @@ private E decodeBody(ResolvableType targetType) { * 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 7c67791d7c17..7455d3e6eab3 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 f1df06d3885d..4fb639d0197c 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 b7ef8b31baa6..8e0e49a84934 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 a947d25d1be7..c7913692f430 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.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.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 c2ba3a9ff595..caf09e15bcb7 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.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.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 @@ public Optional contentType() { } @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 11c979525116..d26c440bc5f6 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.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.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 @@ public LocaleContext getLocaleContext() { 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 684bd49e983a..d2736b05ff8e 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.Consumer; import java.util.function.Function; +import org.jspecify.annotations.Nullable; import org.reactivestreams.Publisher; import reactor.core.publisher.Mono; @@ -90,7 +91,8 @@ public DefaultServerResponseBuilder(HttpStatusCode status) { @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 3b51db369849..61e50cf04aa2 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.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 157a360aa7a8..a3b9e46a0f46 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 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.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 @@ protected static final class Result { 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 @@ private static class PathExtensionPredicate implements RequestPredicate { 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 @@ private static class QueryParamPredicate implements RequestPredicate { 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 2fa724917de2..56ea5b1fb735 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.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 @@ public Resource createRelative(String relativePath) throws IOException { } @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 af3ebeaa17d6..2cf587fdab25 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.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.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 @@ interface Headers { * {@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 @@ interface Headers { * @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 d71fa7d8e15d..3baf0dcc879c 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.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 @@ interface HeadersBuilder> { * @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 0fc2f21a0d5c..7d6ae4532477 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 4848a636bf38..5e03a488f84d 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.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 @@ */ 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 RouterFunctionMapping(RouterFunction routerFunction) { * 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 ba5ff5f6e4fd..1d9fc1f36540 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.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.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 Optional contentType() { } @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 2f4f6d650442..12193ec76b0e 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 c179d49e33e5..6cccb413cd9d 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 @@ 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.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 @@ protected boolean hasCorsConfigurationSource(Object handler) { * @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 01263e6050e6..14d5f7a6062e 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.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 Mono getHandlerInternal(ServerWebExchange exchange) { * @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 3583410aa46c..3315fa1308a4 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 @@ 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 061a4179c41f..0f2ef3cf58e8 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 549793e0e97b..fa38c269a436 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 04e347b4def4..c7d6724edb86 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 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 6542ad3042d2..718ab5524856 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 @@ 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 @@ protected AbstractPrefixVersionStrategy(String version) { @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 c862345a2c4e..ed100ad7a745 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 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 6903e989cde6..d57c890ca190 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.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 @@ protected String computeKey(@Nullable ServerWebExchange exchange, String request 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 e95c23b6822b..38aef7285421 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 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.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 be05220f9341..233d91ab4228 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.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 @@ */ 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 dc79e5d6aad8..1b1969831c86 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.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 8750d2419745..6f6b2cadfbf9 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.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 @@ protected Mono resolveResourceInternal(@Nullable ServerWebExchange exc }); } - @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 Resource createRelative(String relativePath) throws IOException { } @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 d396dbccc7f5..9aa045bbf4e4 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 @@ 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 @@ protected Mono resolveUrlPathInternal(String resourceUrlPath, })); } - @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 946be6248927..f6d0d023fed3 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.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 @@ */ 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 ca1b2a2d60e6..a7104a8c135f 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 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 610e052a7824..1b9b80c8234c 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 @@ 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 53f3fe499122..ad15a8e83549 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 @@ 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 22d4a8114ff0..fe704a747145 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 @@ 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 @@ */ public abstract class ResourceTransformerSupport implements ResourceTransformer { - @Nullable - private ResourceUrlProvider resourceUrlProvider; + private @Nullable ResourceUrlProvider resourceUrlProvider; /** @@ -53,8 +52,7 @@ public void setResourceUrlProvider(@Nullable ResourceUrlProvider resourceUrlProv /** * 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 c03b6f78086e..cf1140f07588 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 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.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 cd624891b5c7..9ca35449c527 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 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.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 void setResourceHttpMessageWriter(@Nullable ResourceHttpMessageWriter htt /** * Return the configured resource message writer. */ - @Nullable - public ResourceHttpMessageWriter getResourceHttpMessageWriter() { + public @Nullable ResourceHttpMessageWriter getResourceHttpMessageWriter() { return this.resourceHttpMessageWriter; } @@ -252,8 +244,7 @@ public void setCacheControl(@Nullable CacheControl cacheControl) { * 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 void setEtagGenerator(@Nullable Function etagGenerator) * @return the HTTP ETag generator function * @since 6.1 */ - @Nullable - public Function getEtagGenerator() { + public @Nullable Function getEtagGenerator() { return this.etagGenerator; } @@ -525,8 +515,7 @@ protected boolean isInvalidPath(String path) { 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 220dd7b56dcf..82dfb6c1b33d 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 @@ 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 @@ */ public class TransformedResource extends ByteArrayResource { - @Nullable - private final String filename; + private final @Nullable String filename; private final long lastModified; @@ -52,8 +52,7 @@ public TransformedResource(Resource original, byte[] transformedContent) { @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 7bf4af1c68c4..f17c620709d3 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.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 @@ protected Mono resolveUrlPathInternal(String resourceUrlPath, * 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 Resource createRelative(String relativePath) throws IOException { } @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 f7269bc1766b..6904d5d0ee18 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 b5baa18e0aea..5236d580a587 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 24d176948bdf..e0be34310397 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 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 int getOrder() { * 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 @@ protected ReactiveAdapter getAdapter(HandlerResult result) { * @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 @@ protected 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 88d304374db6..9989fb486e64 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 @@ 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 69739fea40a9..5a7d97ceb22e 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 @@ 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 @@ public String getName() { } @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 0f8732639073..4b54f2d511c9 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 @@ 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 40e56fb97946..364a4493a4e1 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.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 @@ private void assertNumberOfConditions(CompositeRequestCondition other) { *

    An 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 29e8a774edc2..fa70667f8217 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.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 ConsumesRequestCondition(String... consumes) { * @param consumes as described in {@link RequestMapping#consumes()} * @param headers as described in {@link RequestMapping#headers()} */ - public ConsumesRequestCondition(@Nullable String[] consumes, @Nullable String[] headers) { + public ConsumesRequestCondition(String @Nullable [] consumes, String @Nullable [] headers) { this.expressions = parseExpressions(consumes, headers); if (this.expressions.size() > 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 ConsumesRequestCondition combine(ConsumesRequestCondition other) { * or {@code null} if no expressions match. */ @Override - @Nullable - public ConsumesRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable ConsumesRequestCondition getMatchingCondition(ServerWebExchange exchange) { ServerHttpRequest request = exchange.getRequest(); if (CorsUtils.isPreFlightRequest(request)) { return EMPTY_CONDITION; @@ -217,8 +217,7 @@ private boolean hasBody(ServerHttpRequest request) { (StringUtils.hasText(contentLength) && !contentLength.trim().equals("0")); } - @Nullable - private List 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 d1135f3e379b..1e8c1a95c26a 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.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 @@ else if (isEmpty()) { * or {@code null} otherwise. */ @Override - @Nullable - public HeadersRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable HeadersRequestCondition getMatchingCondition(ServerWebExchange exchange) { if (CorsUtils.isPreFlightRequest(exchange.getRequest())) { return PRE_FLIGHT_MATCH; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/NameValueExpression.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/NameValueExpression.java index cab7ffbbd824..fcd77b3f47e7 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/NameValueExpression.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/NameValueExpression.java @@ -16,7 +16,7 @@ package org.springframework.web.reactive.result.condition; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A contract for {@code "name!=value"} style expression used to specify request @@ -30,8 +30,7 @@ public interface NameValueExpression { 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 8304a87ab5bf..487e73b4ec1c 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.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 @@ else if (isEmpty()) { * or {@code null} otherwise. */ @Override - @Nullable - public ParamsRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable ParamsRequestCondition getMatchingCondition(ServerWebExchange exchange) { for (ParamExpression expression : this.expressions) { if (!expression.match(exchange)) { return null; diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java index 81ad4c26ad15..ebc9f78bc498 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/PatternsRequestCondition.java @@ -26,8 +26,9 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.jspecify.annotations.Nullable; + import org.springframework.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.ObjectUtils; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.util.pattern.PathPattern; @@ -155,14 +156,12 @@ else if (isEmptyPathMapping()) { * or {@code null} if no patterns match. */ @Override - @Nullable - public PatternsRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable PatternsRequestCondition getMatchingCondition(ServerWebExchange exchange) { SortedSet 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 3d51b46b6cad..91431651f894 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.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 ProducesRequestCondition(String... produces) { * @param produces expressions with syntax defined by {@link RequestMapping#produces()} * @param headers expressions with syntax defined by {@link RequestMapping#headers()} */ - public ProducesRequestCondition(@Nullable String[] produces, @Nullable String[] headers) { + public ProducesRequestCondition(String @Nullable [] produces, String @Nullable [] headers) { this(produces, headers, null); } @@ -93,7 +94,7 @@ public ProducesRequestCondition(@Nullable String[] produces, @Nullable String[] * @param resolver used to determine requested content type */ public ProducesRequestCondition( - @Nullable String[] produces, @Nullable String[] headers, @Nullable RequestedContentTypeResolver resolver) { + String @Nullable [] produces, String @Nullable [] headers, @Nullable RequestedContentTypeResolver resolver) { this.expressions = parseExpressions(produces, headers); if (this.expressions.size() > 1) { @@ -102,7 +103,7 @@ public ProducesRequestCondition( this.contentTypeResolver = (resolver != null ? resolver : DEFAULT_CONTENT_TYPE_RESOLVER); } - private List 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 ProducesRequestCondition combine(ProducesRequestCondition other) { * or {@code null} if no expressions match. */ @Override - @Nullable - public ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange) { if (CorsUtils.isPreFlightRequest(exchange.getRequest())) { return EMPTY_CONDITION; } @@ -218,8 +218,7 @@ public ProducesRequestCondition getMatchingCondition(ServerWebExchange exchange) return null; } - @Nullable - private List 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 d42758de5deb..8dfb62078282 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 d255935135a7..1288b867af53 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 @@ 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 @@ */ public final class RequestConditionHolder extends AbstractRequestCondition { - @Nullable - private final RequestCondition condition; + private final @Nullable RequestCondition condition; /** @@ -55,8 +55,7 @@ public RequestConditionHolder(@Nullable RequestCondition requestCondition) { /** * Return the held request condition, or {@code null} if not holding one. */ - @Nullable - public RequestCondition getCondition() { + public @Nullable RequestCondition getCondition() { return this.condition; } @@ -99,8 +98,7 @@ else if (other.condition == null) { * holder, return the same holder instance. */ @Override - @Nullable - public RequestConditionHolder getMatchingCondition(ServerWebExchange exchange) { + public @Nullable RequestConditionHolder getMatchingCondition(ServerWebExchange exchange) { if (this.condition == null) { return this; } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestMethodsRequestCondition.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestMethodsRequestCondition.java index e8f0cd32d00d..9289aee8fea0 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestMethodsRequestCondition.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/RequestMethodsRequestCondition.java @@ -23,9 +23,10 @@ import java.util.Map; import java.util.Set; +import org.jspecify.annotations.Nullable; + import org.springframework.http.HttpMethod; 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.web.bind.annotation.RequestMethod; @@ -121,8 +122,7 @@ else if (isEmpty()) { * request method is OPTIONS. */ @Override - @Nullable - public RequestMethodsRequestCondition getMatchingCondition(ServerWebExchange exchange) { + public @Nullable RequestMethodsRequestCondition getMatchingCondition(ServerWebExchange exchange) { if (CorsUtils.isPreFlightRequest(exchange.getRequest())) { return matchPreFlight(exchange.getRequest()); } @@ -140,8 +140,7 @@ public RequestMethodsRequestCondition getMatchingCondition(ServerWebExchange exc * Hence empty conditions is a match, otherwise try to match to the HTTP * method in the "Access-Control-Request-Method" header. */ - @Nullable - private RequestMethodsRequestCondition matchPreFlight(ServerHttpRequest request) { + private @Nullable RequestMethodsRequestCondition matchPreFlight(ServerHttpRequest request) { if (getMethods().isEmpty()) { return this; } @@ -149,8 +148,7 @@ private RequestMethodsRequestCondition matchPreFlight(ServerHttpRequest request) return expectedMethod != null ? matchRequestMethod(expectedMethod) : null; } - @Nullable - private RequestMethodsRequestCondition matchRequestMethod(HttpMethod httpMethod) { + private @Nullable RequestMethodsRequestCondition matchRequestMethod(HttpMethod httpMethod) { RequestMethod requestMethod = RequestMethod.resolve(httpMethod); if (requestMethod != null) { if (getMethods().contains(requestMethod)) { diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/package-info.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/package-info.java index b1185512ec04..c9a2fdefa54b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/package-info.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/package-info.java @@ -2,9 +2,7 @@ * {@link org.springframework.web.reactive.result.condition.RequestCondition} * and implementations for matching requests based on different criteria. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.reactive.result.condition; -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/AbstractHandlerMethodMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java index 4b454084b636..eb1c5fb053d6 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/AbstractHandlerMethodMapping.java @@ -31,13 +31,13 @@ import java.util.function.Function; import java.util.stream.Collectors; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.InitializingBean; import org.springframework.core.MethodIntrospector; import org.springframework.http.server.RequestPath; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; import org.springframework.util.LinkedMultiValueMap; @@ -269,8 +269,7 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) { /** * 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 Mono getHandlerInternal(ServerWebExchange exchange) { * @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 @@ protected void handleMatch(T mapping, HandlerMethod handlerMethod, ServerWebExch * @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 @@ protected boolean hasCorsConfigurationSource(Object handler) { } @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 @@ protected CorsConfiguration getCorsConfiguration(Object handler, ServerWebExchan * 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 @@ protected Set getDirectPaths(T mapping) { * @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 Map> getRegistrations() { * @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 List getMappingsByDirectPath(ServerWebExchange exchange) { /** * 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 351badb98e88..1bb79e4c6607 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.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 @@ public Mono resolveArgument( * 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 836a77530887..f6bc3fb54cc9 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.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.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 void setInvocationScheduler(@Nullable Scheduler invocationScheduler) { */ @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 Mono invoke( } 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 @@ private static class KotlinDelegate { // 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 2f3124288a7a..3d28c33b2771 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.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 RequestMappingInfo combine(RequestMappingInfo other) { methods, params, headers, consumes, produces, custom.getCondition(), this.options); } - @Nullable - private String combineNames(RequestMappingInfo other) { + private @Nullable String combineNames(RequestMappingInfo other) { if (this.name != null && other.name != null) { return this.name + "#" + other.name; } @@ -264,8 +261,7 @@ else if (this.name != null) { * @return a new instance in case all conditions match; or {@code null} otherwise */ @Override - @Nullable - public RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) { + public @Nullable RequestMappingInfo getMatchingCondition(ServerWebExchange exchange) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(exchange); if (methods == null) { return null; @@ -476,30 +472,23 @@ private static class DefaultBuilder implements Builder { private String[] paths; - @Nullable - private RequestMethod[] methods; + private RequestMethod @Nullable [] methods; - @Nullable - private String[] params; + private String @Nullable [] params; - @Nullable - private String[] headers; + private String @Nullable [] headers; - @Nullable - private String[] consumes; + private String @Nullable [] consumes; - @Nullable - private String[] produces; + private String @Nullable [] produces; private boolean hasContentType; private boolean hasAccept; - @Nullable - private String mappingName; + private @Nullable String mappingName; - @Nullable - private RequestCondition customCondition; + private @Nullable RequestCondition customCondition; private BuilderConfiguration options = new BuilderConfiguration(); @@ -618,11 +607,9 @@ static boolean isEmpty(String[] patterns) { private static class MutateBuilder implements Builder { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private PatternsRequestCondition patternsCondition; + private @Nullable PatternsRequestCondition patternsCondition; private RequestMethodsRequestCondition methodsCondition; @@ -731,18 +718,15 @@ public RequestMappingInfo build() { */ public static class BuilderConfiguration { - @Nullable - private PathPatternParser patternParser; + private @Nullable PathPatternParser patternParser; - @Nullable - private RequestedContentTypeResolver contentTypeResolver; + private @Nullable RequestedContentTypeResolver contentTypeResolver; public void setPatternParser(PathPatternParser patternParser) { this.patternParser = patternParser; } - @Nullable - public PathPatternParser getPatternParser() { + public @Nullable PathPatternParser getPatternParser() { return this.patternParser; } @@ -754,8 +738,7 @@ public void setContentTypeResolver(RequestedContentTypeResolver resolver) { this.contentTypeResolver = resolver; } - @Nullable - public RequestedContentTypeResolver getContentTypeResolver() { + public @Nullable RequestedContentTypeResolver getContentTypeResolver() { return this.contentTypeResolver; } } diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java index 53926951b9f1..caaf32d2694a 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java @@ -27,6 +27,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.jspecify.annotations.Nullable; import reactor.core.publisher.Mono; import org.springframework.http.HttpHeaders; @@ -36,7 +37,6 @@ import org.springframework.http.server.PathContainer; import org.springframework.http.server.reactive.ServerHttpRequest; import org.springframework.http.server.reactive.observation.ServerRequestObservationContext; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -88,8 +88,7 @@ protected Set getDirectPaths(RequestMappingInfo info) { * @return an info in case of a match; or {@code null} otherwise. */ @Override - @Nullable - protected RequestMappingInfo getMatchingMapping(RequestMappingInfo info, ServerWebExchange exchange) { + protected @Nullable RequestMappingInfo getMatchingMapping(RequestMappingInfo info, ServerWebExchange exchange) { return info.getMatchingCondition(exchange); } @@ -170,8 +169,7 @@ protected void handleMatch(RequestMappingInfo info, HandlerMethod handlerMethod, * method but not by query parameter conditions */ @Override - @Nullable - protected HandlerMethod handleNoMatch(Set 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 f6d7c162df9b..32d7e51fdef5 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 @@ default Mono resolveArgument( * @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 fc82786fde3d..a7d164f58e9a 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.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 ParameterNameDiscoverer getParameterNameDiscoverer() { * @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 f728423709bc..776c400be467 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.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.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 @@ private ServerWebInputException handleMissingBody(MethodParameter parameter) { * 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 763e8db2878a..af7436a8e1c6 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.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.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 25b177af66d2..0f7989209695 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 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.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 @@ */ 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 @@ private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValu * 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 @@ private Object resolveEmbeddedValuesAndExpressions(String value) { /** * 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 @@ protected void handleMissingValue(String name, MethodParameter parameter) { * 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 @@ protected static class NamedValueInfo { 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 1344d0bd3eb2..7806237ee8e0 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 @@ protected final Mono resolveName(String name, MethodParameter param, Ser /** * 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 d4011e05a8ff..58698d4be044 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 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.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 @@ private static Predicate methodParamPredicate( * 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 @@ private InvocableHandlerMethod createAttributeMethod(Object bean, Method method) * @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 75c84dee3a12..09355c28e161 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 1355c525755a..a233da80774c 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 ec3f998573ae..a0183724626f 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.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 5d9c8fc57a73..9e8b728ac864 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 @@ 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.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 c8d67038c64c..aac2b708b399 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 @@ 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 a9d179d0aa7b..d4cd7910828f 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 @@ 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 boolean supportsParameter(MethodParameter parameter) { (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 072236534759..083c83c39c44 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.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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { 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 b45c3ba0dab1..d9ea3ddb0733 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 @@ 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.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 @@ private Mono initDataBinder( } } - @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 c3c493ebe98b..67c99bd11727 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 @@ 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 537e565828d6..be8d1ff797c7 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 5a2250c8d0b8..c4b320536850 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 @@ 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 071ddc37c89c..bc857a5aee2f 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 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.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 void setWebBindingInitializer(@Nullable WebBindingInitializer webBindingI /** * 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 void setArgumentResolverConfigurer(@Nullable ArgumentResolverConfigurer c /** * Return the configured resolvers for controller method arguments. */ - @Nullable - public ArgumentResolverConfigurer getArgumentResolverConfigurer() { + public @Nullable ArgumentResolverConfigurer getArgumentResolverConfigurer() { return this.argumentResolverConfigurer; } @@ -207,8 +197,7 @@ public void setReactiveAdapterRegistry(@Nullable ReactiveAdapterRegistry registr /** * 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 6cce38b7e541..b722b9214966 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.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.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 @@ protected boolean isHandler(Class beanType) { * @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 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class handler 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 @@ private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { * @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 @@ protected RequestCondition getCustomTypeCondition(Class handlerType) { * @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 @@ private void updateConsumesCondition(RequestMappingInfo info, Method method) { } @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 17c6a868d0cc..b2f977dfcdcf 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 @@ 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 8cdf713595f7..059bce4da5a2 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.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.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 ff3474078899..4ba05d217464 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 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.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 void setMessageSource(MessageSource messageSource) { * 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 @@ protected Mono> handleMethodValidationException( */ 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 3d91c62a7de7..1961429a1d66 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.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.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 3231b4a87ebc..f648bb21b80f 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.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.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 boolean supportsParameter(MethodParameter parameter) { } @Override - @Nullable - public Object resolveArgumentValue( + public @Nullable Object resolveArgumentValue( MethodParameter methodParameter, BindingContext context, ServerWebExchange exchange) { Class paramType = methodParameter.getParameterType(); @@ -122,8 +122,7 @@ else if (UriBuilder.class == paramType || UriComponentsBuilder.class == paramTyp } } - @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 5a9d37d89df8..c2d1f90b8038 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 boolean supportsParameter(MethodParameter parameter) { 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 01e8df69bd5b..4fc8082a2e85 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 e5bbb0c70375..eb754679b3b4 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 be6787715f43..3f89955b0a2e 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 b290d59649e1..e459c767b4e4 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 @@ 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 @@ */ public abstract class AbstractUrlBasedView extends AbstractView implements InitializingBean { - @Nullable - private String url; + private @Nullable String url; /** @@ -61,8 +60,7 @@ public void setUrl(@Nullable String url) { /** * 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 cd761d5bdba3..6a5353bb4620 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 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.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 void setRequestContextAttribute(@Nullable String requestContextAttribute) /** * 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 void setBeanName(@Nullable String beanName) { * 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 void setApplicationContext(@Nullable ApplicationContext applicationContex this.applicationContext = applicationContext; } - @Nullable - public ApplicationContext getApplicationContext() { + public @Nullable ApplicationContext getApplicationContext() { return this.applicationContext; } @@ -315,8 +309,7 @@ protected RequestContext createRequestContext(ServerWebExchange exchange, Map 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 String getPath() { * 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 String getExpression() { *

    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 Object getValue() { * '{@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 getValueType() { * 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 @@ private String[] initErrorMessages() throws NoSuchMessageException { * @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 Errors getErrors() { * 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 PropertyEditor getEditor() { * @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 cbdb6c9dd413..86c79e8350a7 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.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 @@ */ 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 82d139630ae6..7b6ef2c3d774 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 @@ 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 @@ public Map modelAttributes() { } @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 84a264a5042b..267e91cd06e4 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 @@ 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 f999f5ae3226..c7a49a82748a 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.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 @@ */ 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 boolean isResolved() { /** * 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 2767146268cf..d2a5f196b942 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.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.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 4833987a916c..8b80773a277c 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.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.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 Mono render( 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 1ffcdd33ef27..5390a0e2dab9 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.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.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 boolean isPropagateQuery() { *

    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 73c1b6451ace..f0f039317bd0 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 @@ 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 a98a911dd050..6e69490e4370 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.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 MessageSource getMessageSource() { * 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 boolean isDefaultHtmlEscape() { * 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 Boolean getDefaultHtmlEscape() { * 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 String getMessage(String code, String defaultMessage) { * @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 String getMessage(String code, @Nullable List args, String defaultMess * @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 String getMessage(String code) throws NoSuchMessageException { * @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 String getMessage(String code, @Nullable List args) throws NoSuchMessa * @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 String getMessage(MessageSourceResolvable resolvable, boolean htmlEscape) * @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 Errors getErrors(String name) { * @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 @@ else if (!htmlEscape && errors instanceof EscapedErrors escapedErrors) { * @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 fee25884cddf..d9962f607dcb 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 @@ 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 d4eaab48cd16..d1b0c0d8be47 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 @@ 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 void setViewClass(@Nullable Class viewClass) { * 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 @@ protected String getSuffix() { * '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 void setViewNames(@Nullable String... viewNames) { * 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 void setRequestContextAttribute(@Nullable String requestContextAttribute) /** * 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 void setApplicationContext(@Nullable ApplicationContext applicationContex * 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 28cd9075dea1..c31fa3b23f19 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.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 b8d558e5fdbc..a574679df6a9 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.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.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 @@ private List getMediaTypes(List views) { */ 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 void updateResponse(ServerWebExchange exchange) { 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 1a28ff3e890f..c35676e21bcb 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.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 @@ 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 1c5ec1875647..0f1001e93c53 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.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.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 void setConfiguration(@Nullable Configuration configuration) { /** * 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 void setCharset(@Nullable Charset charset) { * 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 b46c377026d5..88b22891dfc3 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 bb7678f221ed..dc78f0cc3453 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 219125b9cdd8..9d284b14ed76 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 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 936e4cb6c351..8d0db53d4e7d 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 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 @@ */ 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 void setEngine(@Nullable ScriptEngine engine) { } @Override - @Nullable - public ScriptEngine getEngine() { + public @Nullable ScriptEngine getEngine() { return this.engine; } @@ -128,8 +118,7 @@ public void setEngineSupplier(@Nullable Supplier engineSupplier) { } @Override - @Nullable - public Supplier getEngineSupplier() { + public @Nullable Supplier getEngineSupplier() { return this.engineSupplier; } @@ -145,8 +134,7 @@ public void setEngineName(@Nullable String engineName) { } @Override - @Nullable - public String getEngineName() { + public @Nullable String getEngineName() { return this.engineName; } @@ -167,8 +155,7 @@ public void setSharedEngine(@Nullable Boolean sharedEngine) { } @Override - @Nullable - public Boolean isSharedEngine() { + public @Nullable Boolean isSharedEngine() { return this.sharedEngine; } @@ -183,13 +170,12 @@ public Boolean isSharedEngine() { * @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 void setRenderObject(@Nullable String renderObject) { } @Override - @Nullable - public String getRenderObject() { + public @Nullable String getRenderObject() { return this.renderObject; } @@ -224,8 +209,7 @@ public void setRenderFunction(@Nullable String renderFunction) { } @Override - @Nullable - public String getRenderFunction() { + public @Nullable String getRenderFunction() { return this.renderFunction; } @@ -238,8 +222,7 @@ public void setCharset(@Nullable Charset charset) { } @Override - @Nullable - public Charset getCharset() { + public @Nullable Charset getCharset() { return this.charset; } @@ -256,8 +239,7 @@ public void setResourceLoaderPath(@Nullable String resourceLoaderPath) { } @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 415b126475a2..554cb91fa516 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.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.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 @@ protected void loadScripts(ScriptEngine engine) { } } - @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 49c5ceb7dc8b..e8b98ae065a6 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 d9ad00c8d170..6069a76b00de 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 @@ 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 int getCode() { /** * 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 a12a667a31f4..f2f9d0c540e5 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.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 Mono getPrincipal() { * @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 String getSubProtocol() { * 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 Map getAttributes() { * @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 052f47f09a8c..00593dab86f2 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 @@ 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 DataBuffer getPayload() { * @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 29508c33aa1e..0cf87fdb6dea 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.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 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 AbstractListenerWebSocketSession( * 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 @@ protected void readingPaused() { } @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 36686839443e..9a915d333aaf 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 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 35aeac20a808..4943bb546ee0 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.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 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 43ca7f12b3b7..b578f6df39d5 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.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 9849ab587ec4..87df9aa5bd81 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.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 StandardWebSocketSession(Session session, HandshakeInfo info, DataBufferF } public StandardWebSocketSession(Session session, HandshakeInfo info, DataBufferFactory factory, - @Nullable Sinks.Empty 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 b80d4c1e3b12..79de37d710e9 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.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 UndertowWebSocketSession(WebSocketChannel channel, HandshakeInfo info, Da } public UndertowWebSocketSession(WebSocketChannel channel, HandshakeInfo info, - DataBufferFactory factory, @Nullable Sinks.Empty 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 825473c9bbd7..c37715865d84 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 c3eebb65bf28..d0b6f352ff00 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.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 fd9680781ca8..ff3df926b7b8 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 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 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 844853a04de5..2fbabf926a09 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 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 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 e9ed39e8638f..8b68b19c8b3f 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.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 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 @@ private static final class DefaultNegotiation extends WebSocketClientNegotiation 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 e6087f8b245e..b5d57aefeb1d 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 d45db5f96c4a..8343b6aa2b82 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 09ed2403981c..45242be902bf 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 @@ 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 3e9b796483fd..350ade5a22fc 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 d6c4940d9f54..072a006a686b 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/socket/server/support/HandshakeWebSocketService.java @@ -27,6 +27,7 @@ import org.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.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 void setSessionAttributePredicate(@Nullable Predicate predicate) * attributes from {@code WebSession} attributes. * @since 5.1 */ - @Nullable - public Predicate getSessionAttributePredicate() { + public @Nullable Predicate getSessionAttributePredicate() { return this.sessionAttributePredicate; } @@ -230,8 +228,7 @@ private Mono handleBadRequest(ServerWebExchange exchange, String reason) { 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 d931aa3ea268..c9b852588ab6 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 e9455e38ec4b..e0b4e4e0068a 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 94701d3bf0de..4f201f591cd4 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.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.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 @@ */ 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 46d8b7090365..2922852716f3 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 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.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 @@ */ 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 52b85838de69..c9eb17d4bb07 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 @@ 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 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 a7ac18a564b4..7a2f84bdc79e 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 @@ 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 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 d5341505e0b6..f29254b0306a 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.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.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 void setAsyncSendTimeout(Long timeoutInMillis) { this.asyncSendTimeout = timeoutInMillis; } - @Nullable - public Long getAsyncSendTimeout() { + public @Nullable Long getAsyncSendTimeout() { return this.asyncSendTimeout; } @@ -97,8 +91,7 @@ public void setMaxSessionIdleTimeout(Long timeoutInMillis) { this.maxSessionIdleTimeout = timeoutInMillis; } - @Nullable - public Long getMaxSessionIdleTimeout() { + public @Nullable Long getMaxSessionIdleTimeout() { return this.maxSessionIdleTimeout; } @@ -110,8 +103,7 @@ public void setMaxTextMessageBufferSize(Integer bufferSize) { this.maxTextMessageBufferSize = bufferSize; } - @Nullable - public Integer getMaxTextMessageBufferSize() { + public @Nullable Integer getMaxTextMessageBufferSize() { return this.maxTextMessageBufferSize; } @@ -123,8 +115,7 @@ public void setMaxBinaryMessageBufferSize(Integer bufferSize) { 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 60f3742318b0..7fc2863544b6 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.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 13b172cb23a8..93229dff7482 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 9d5d5ef69f35..c09cab647e2b 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 aeadb7de4154..411d955c3c30 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 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.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 a40bc25e6f44..d6f9a24dad8a 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.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.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 5ee065af5abe..9579267f94f7 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 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.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 fad717537a04..5a6d5215e307 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.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 524b4d6a3f62..1854d5fb4501 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 @@ 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 @@ public String toString() { @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 @@ public void setFoo(String foo) { this.foo = foo; } - @Nullable - public String getBar() { + public @Nullable String getBar() { return this.bar; } @@ -199,8 +195,7 @@ private static final class MixedInjection { private final String foo; - @Nullable - private String bar; + private @Nullable String bar; public MixedInjection(String foo) { this.foo = foo; @@ -210,8 +205,7 @@ public String getFoo() { 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 1282a1cd9709..f32f87799d90 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.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.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 e56acf391bdf..439e536fb146 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.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.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 b5a4e2bd4e61..cf33c0415554 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.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 6d9d35cee97a..0657ac57a8d8 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 @@ 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 @@ public Mono variables(ServerRequest request) { 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 b3e73b53e7d1..d827147e8caf 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.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.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 32064132e07e..9ff577166386 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.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.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 b1a25abaacb8..59305159d34a 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 @@ 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 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 c90601088037..dc68f8519015 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.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.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 @@ void checkNotModified() { } - @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 @@ Mono exchangeMonoVoid(ServerWebExchange exchange) { .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 0ba5b8ef598f..bbb0b7c7643d 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.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.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 8de93c7e67ed..1814c8d4d5c2 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 @@ 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.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 ecc6a7b18678..c37dc1fd6648 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.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.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 7cf05e598f7e..c73ee362c59c 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.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.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 @@ private InitBinderBindingContext getBindingContext(Object controller) { @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 f5f2ff938f45..3180154ef7d3 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.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.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 2b5a1a8db616..f7d507ee3912 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.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 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 @@ void resolveOptionalParamValue() { } - @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 0643f334a465..e125c63912f6 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 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.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 76dd1ecbfbf5..d35863b46e22 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.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.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 3c2d42c4ebb7..62140c9c1998 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 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 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 bf0e326396e3..d5ff5048645f 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.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.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 bc4249cb6210..aa11826642da 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.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.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 20cd2a36e8ba..3c0f20248e7e 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.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 8211dbb7cade..5e1673ab8a08 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 4e8df421a515..1d65b0755038 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 affb7ab9136a..110d81769324 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.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.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 @@ else if (logger.isDebugEnabled()) { * @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 final org.springframework.ui.context.ThemeSource getThemeSource() { * @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 final MultipartResolver getMultipartResolver() { * 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 @@ protected void cleanupMultipart(HttpServletRequest request) { * @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 @@ protected HandlerAdapter getHandlerAdapter(Object handler) throws ServletExcepti * @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 @@ protected void render(ModelAndView mv, HttpServletRequest request, HttpServletRe * @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 @@ protected String getDefaultViewName(HttpServletRequest request) throws Exception * (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 146034ed4fc7..4ca1870aa74c 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 @@ 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 @@ @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 void setTargetRequestPath(@Nullable String path) { /** * 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 921e1d8e7b00..39593979451d 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 @@ 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 1d73bb25f5be..b2334dcae737 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.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.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 void setContextAttribute(@Nullable String contextAttribute) { * 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 void setContextId(@Nullable String contextId) { /** * Return the custom WebApplicationContext id, if any. */ - @Nullable - public String getContextId() { + public @Nullable String getContextId() { return this.contextId; } @@ -380,8 +372,7 @@ public void setContextConfigLocation(@Nullable String contextConfigLocation) { /** * Return the explicit context config location, if any. */ - @Nullable - public String getContextConfigLocation() { + public @Nullable String getContextConfigLocation() { return this.contextConfigLocation; } @@ -392,7 +383,7 @@ public String getContextConfigLocation() { * @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 @@ protected WebApplicationContext initWebApplicationContext() { * @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 String getServletContextAttributeName() { /** * Return this servlet's WebApplicationContext. */ - @Nullable - public final WebApplicationContext getWebApplicationContext() { + public final @Nullable WebApplicationContext getWebApplicationContext() { return this.webApplicationContext; } @@ -1039,8 +1028,7 @@ protected final void processRequest(HttpServletRequest request, HttpServletRespo * @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 @@ protected LocaleContext buildLocaleContext(HttpServletRequest request) { * 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 @@ private void publishRequestHandledEvent(HttpServletRequest request, HttpServletR * @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 68ae2011c5e0..31b8176ce6d9 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 @@ 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 e6f446bb7cdd..77f0a39cacf0 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 @@ 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 f90bf35cc012..f41caf6eb542 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.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 HandlerExecutionChain(Object handler) { * @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 void addInterceptors(HandlerInterceptor... interceptors) { * 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 976fb2bdf8e0..0b63d8b148ff 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 @@ 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 081f677aebe3..6520ddd7ee5b 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 @@ 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 @@ default boolean usesPathPatterns() { * 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 1d4766cab344..69d50e34cbd1 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.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.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 @@ protected void initServletBean() throws ServletException { * @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 4331c017f887..c990b8066c8e 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 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 b4519563d6ee..a9d94bd665fe 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 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 1de142487b70..754685bbb9b5 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 @@ 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 @@ 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 void setViewName(@Nullable String viewName) { * 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 void setView(@Nullable View view) { * 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 boolean isReference() { * 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 void setStatus(@Nullable HttpStatusCode status) { * 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 df95379987ce..83b61ec0bd1b 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 e3bcf3db17a4..566a39e8f68a 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 @@ 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 3d8bb3c36973..6ec59da72578 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 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 4f797a252352..f4d3627b40de 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 @@ 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 d2518608611e..4444ee1d8bce 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 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.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 @@ private RuntimeBeanReference getConversionService(Element element, @Nullable Obj 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 @@ private Properties getDefaultMediaTypes() { 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 @@ private RuntimeBeanReference getMessageCodesResolver(Element element) { } } - @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 @@ private ManagedList getInterceptors( 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 @@ private ManagedList wrapLegacyResolvers(List list, ParserContext 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 @@ private ManagedList extractBeanSubElements(Element parentElement, Parser 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 @@ public void afterPropertiesSet() { } @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 670becc7d817..790e75dd7bc4 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.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 @@ 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 385c1010e117..a80fa756a68c 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 @@ 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.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 @@ 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 2777141be15b..c95522a097c3 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 @@ 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.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 @@ 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 e68be743bd88..b21c1b801f10 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 @@ 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.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 @@ else if (!context.getRegistry().isAlias(URL_PATH_HELPER_BEAN_NAME) && * 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 @@ else if (!context.getRegistry().isAlias(PATH_MATCHER_BEAN_NAME) && * 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 @@ private static void registerFlashMapManager(ParserContext context, @Nullable Obj * 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 8828c103e373..68276f51b651 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 @@ 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.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 @@ private void registerUrlProvider(ParserContext context, @Nullable Object source) } } - @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 5964af08ad11..a84f8dc177db 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 @@ 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.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 775107950e48..251550bf2e35 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 @@ 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.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 bdccde02a86d..a45b99bfcf88 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.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 @@ */ 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 AsyncSupportConfigurer registerDeferredResultInterceptors( } - @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 a13d9855acd9..b5fd713086e6 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.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 9279901135ce..6858cb9d9a3c 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 @@ 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 void enable(@Nullable String defaultServletName) { * 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 457ce6b291e1..1e49d23974b9 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 @@ 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 @@ protected void configureErrorResponseInterceptors(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 239dbe3e1207..24c73e6b112a 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.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 @@ protected boolean preferPathMatcher() { * 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 45621534c95c..f21b5f88aa34 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 894692fbcbfc..354173487f36 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 @@ 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 2b0e1fe0aca1..07d5312c9fca 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.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 99e132ab1adc..9bb9d4f25dff 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.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 ResourceHandlerRegistry setOrder(int order) { * 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 42dd2ef1a7dd..a4fc13ddad85 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 9189a8b1a5db..8d0a45465a2c 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.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 @@ */ 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 void setOrder(int order) { * 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 aabe17b8224d..707c03953879 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.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 @@ */ 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 4b3e18e1ec02..aa4888cb4508 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.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.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 void setApplicationContext(@Nullable ApplicationContext applicationContex * 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 void setServletContext(@Nullable ServletContext servletContext) { * 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 @@ protected void configureContentNegotiation(ContentNegotiationConfigurer configur * {@link #addViewControllers}. */ @Bean - @Nullable - public HandlerMapping viewControllerHandlerMapping( + public @Nullable HandlerMapping viewControllerHandlerMapping( @Qualifier("mvcConversionService") FormattingConversionService conversionService, @Qualifier("mvcResourceUrlProvider") ResourceUrlProvider resourceUrlProvider) { @@ -569,8 +555,7 @@ public RouterFunctionMapping routerFunctionMapping( * {@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 ResourceUrlProvider mvcResourceUrlProvider() { * 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 @@ protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer /** * Override this method to provide a custom {@link MessageCodesResolver}. */ - @Nullable - protected MessageCodesResolver getMessageCodesResolver() { + protected @Nullable MessageCodesResolver getMessageCodesResolver() { return null; } @@ -770,8 +753,7 @@ public Validator mvcValidator() { /** * 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 d55fcba9e0d5..afa3ab093abe 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 @@ 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 @@ default void addErrorResponseInterceptors(List interc * {@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 @@ default Validator getValidator() { * 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 9e58fb162796..e093d6770b89 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 @@ 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 @@ public void addErrorResponseInterceptors(List interce } @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 @@ public Validator getValidator() { } @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 8d9339ca555e..ae5e1672e886 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 45180017f3ad..85e32d51c9da 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 599e0df674b6..d2288fc3f3d2 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.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 @@ public MultiValueMap cookies() { } @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 @@ private void writeCookies(HttpServletResponse servletResponse) { .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 ade8870faa5a..b1fdb56df6e6 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.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 ba0c21199970..fee9e4e9f9cc 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.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 @@ public MultiValueMap cookies() { } @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 86a1c931776d..09b818fcbe20 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.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 @@ private R delegate(Function function) { } @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 88ff2c4fb162..c205da654381 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.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.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 @@ public T entity() { } @Override - @Nullable - protected ModelAndView writeToInternal(HttpServletRequest servletRequest, + protected @Nullable ModelAndView writeToInternal(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Context context) throws ServletException, IOException { @@ -322,8 +321,7 @@ else if (messageConverter.canWrite(entityClass, contentType)) { 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 @@ public CompletionStageEntityResponse(HttpStatusCode statusCode, HttpHeaders head } @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 @@ public PublisherEntityResponse(HttpStatusCode statusCode, HttpHeaders headers, } @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 @@ private class DeferredResultSubscriber implements Subscriber { 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 45f92fbc1a9e..69f635891458 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 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 0723b6cdabdf..2e168c72c412 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.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.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 @@ public Optional contentType() { } @Override - @Nullable - public InetSocketAddress host() { + public @Nullable InetSocketAddress host() { return this.httpHeaders.getHost(); } @@ -637,8 +635,7 @@ public int getStatus() { } @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 043400811772..920ab58fa648 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.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.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 @@ private static class BuiltServerRequest implements ServerRequest { 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 72c32d308fa7..03c60af202ab 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 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.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 @@ public DefaultServerResponseBuilder(HttpStatusCode status) { } @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 @@ public WriteFunctionResponse(HttpStatusCode statusCode, HttpHeaders headers, Mul } @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 81d9a19254f4..ed1784443ac2 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.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 @@ protected final void addErrorHandler(Predicate(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 @@ else if (t instanceof IOException ioException ) { } } - @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 446dba2cfe2c..1d5990ca3a98 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.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 aa71230ed33b..28152fe85b61 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.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.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 @@ protected static final class Result { 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 @@ private static class PathExtensionPredicate implements RequestPredicate { 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 @@ private static class ParamPredicate implements RequestPredicate { 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 3ee4a3df6012..86ccce7dec01 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.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 @@ public Resource createRelative(String relativePath) throws IOException { } @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 01ac4ad96db2..77a2e072beb5 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.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.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 @@ interface Headers { * {@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 @@ interface Headers { * @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 7d40395bf7e0..101fde0877d5 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.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.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 @@ interface HeadersBuilder> { * @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 @@ interface WriteFunction { * @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 38d5cc8ff043..9f8f87b5e9f6 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.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.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 @@ private static MultiValueMap emptyCookies() { } - @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 ee4f2001a83e..0621a4770ab2 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 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.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 @@ static ServerResponse create(HttpStatusCode statusCode, HttpHeaders headers, Mul 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 f50375d31122..4a4ac6ed1d52 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 d3e59c727766..5cd02df8c272 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.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 boolean supports(Object handler) { 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 @@ private ServerRequest getServerRequest(HttpServletRequest servletRequest) { 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 751a2d4522a5..d93579a219a2 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.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.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 @@ */ 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 void setRouterFunction(@Nullable RouterFunction routerFunction) { * 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 @@ private void initMessageConverters() { @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 @@ private void setAttributes(HttpServletRequest servletRequest, ServerRequest requ 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 a41208ab31f3..66f37f53e3ab 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 a8ccaf220f90..1071b7ffb8bb 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.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 void addMappedHandlerClass(Class mappedHandlerClass) { * 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 void setPreventResponseCaching(boolean preventResponseCaching) { * 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 @@ protected void preventCaching(HttpServletResponse response) { * @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 9eeb49d8ef6e..301196473860 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.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.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 void setDefaultHandler(@Nullable Object defaultHandler) { * 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 void setPatternParser(@Nullable PathPatternParser patternParser) { * 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 void setInterceptors(Object... interceptors) { * 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 final HandlerInterceptor[] getAdaptedInterceptors() { * 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 void setCorsConfigurationSource(CorsConfigurationSource source) { * configured} {@code CorsConfigurationSource}, if any. * @since 5.3 */ - @Nullable - public CorsConfigurationSource getCorsConfigurationSource() { + public @Nullable CorsConfigurationSource getCorsConfigurationSource() { return this.corsConfigurationSource; } @@ -504,8 +495,7 @@ public boolean usesPathPatterns() { * @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 @@ else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDisp * @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 @@ protected boolean hasCorsConfigurationSource(Object handler) { * @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 @@ protected HandlerExecutionChain getCorsHandlerExecutionChain( 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 0c5b53e9044a..e6bb1e96396d 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 @@ 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 @@ protected boolean hasGlobalExceptionHandlers() { } @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 @@ protected final ModelAndView doResolveException( * @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 62caefd2f1b6..930f94fc58ad 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 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 void setHandlerMethodMappingNamingStrategy(HandlerMethodMappingNamingStra /** * Return the configured naming strategy or {@code null}. */ - @Nullable - public HandlerMethodMappingNamingStrategy getNamingStrategy() { + public @Nullable HandlerMethodMappingNamingStrategy getNamingStrategy() { return this.namingStrategy; } @@ -162,8 +160,7 @@ public Map getHandlerMethods() { * 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 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) { /** * 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 @@ protected void handlerMethodsInitialized(Map handlerMethods) { * 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 @@ protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Ex * @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 @@ protected void handleMatch(T mapping, String lookupPath, HttpServletRequest requ * @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 @@ protected boolean hasCorsConfigurationSource(Object handler) { } @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 @@ protected CorsConfiguration getCorsConfiguration(Object handler, HttpServletRequ * 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 @@ protected Set getDirectPaths(T mapping) { * @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 Map> getRegistrations() { * 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 @@ static class MappingRegistration { private final Set directPaths; - @Nullable - private final String mappingName; + private final @Nullable String mappingName; private final boolean corsConfig; @@ -783,8 +769,7 @@ public Set getDirectPaths() { 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 93aeaef85348..586db1c0e596 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 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 @@ */ 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 void setRootHandler(@Nullable Object rootHandler) { * 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 @@ private String getHandlerDescription(Object handler) { * @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 @@ protected Object getHandlerInternal(HttpServletRequest request) throws Exception * @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 @@ protected Object lookupHandler( * @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 @@ protected Object lookupHandler(String lookupPath, HttpServletRequest request) th 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 @@ protected void exposeUriTemplateVariables(Map uriTemplateVariabl } @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 fbc49d5edbd8..089e63d4a15c 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 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 @@ */ 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 int getOrder() { *

    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 7aafffc98afa..d6067631e921 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.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.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 Filter createCacheFilter() { * @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 void resetCache(ServletRequest request, @Nullable CachedResult cachedResu * 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 @@ private MatchableHandlerMapping createMatchableHandlerMapping(HandlerMapping map } @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 CorsConfiguration getCorsConfiguration(HttpServletRequest request) { } } - @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 @@ private static CorsConfiguration getCorsConfiguration(HandlerExecutionChain chai return null; } - @Nullable - private T doWithHandlerMapping( + private @Nullable T doWithHandlerMapping( HttpServletRequest request, boolean ignoreException, BiFunction extractor) throws Exception { @@ -421,17 +414,13 @@ public static final class CachedResult { 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 boolean matches(HttpServletRequest request) { 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 String toString() { /** * 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 void setAttribute(String name, Object value) { } @Override - @Nullable - public Object getAttribute(String name) { + public @Nullable Object getAttribute(String name) { return this.attributes.get(name); } @@ -581,14 +566,12 @@ private static class LookupPathMatchableHandlerMapping implements MatchableHandl } @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 @@ private String initFullPathPattern(String pattern) { 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 39eaefd7db5a..c45967277975 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 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 MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] * {@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 MappedInterceptor(@Nullable String[] includePatterns, 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 MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] * {@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 MappedInterceptor(@Nullable String[] includePatterns, WebRequestIntercept * {@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 MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] * @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 String[] getIncludePathPatterns() { * @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 @@ private static class PatternAdapter { 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 PatternAdapter(String pattern, @Nullable PathPatternParser parser) { 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 boolean match(Object path, boolean isPathContainer, PathMatcher pathMatch 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 27ce57380c80..0fcf32a92ab9 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 @@ default PathPatternParser getPatternParser() { * @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 5df30cbc553c..18541f2e59ce 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.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 @@ public PathPatternMatchableHandlerMapping(MatchableHandlerMapping delegate) { 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 @@ public RequestMatchResult match(HttpServletRequest request, String pattern) { 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 328a0e4e0ff2..96b1aaef4644 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 @@ 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 @@ */ 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 d60f8603bb84..75eac84e8376 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 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 void setExceptionAttribute(@Nullable String exceptionAttribute) { * 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 @@ protected ModelAndView doResolveException( * @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 @@ protected String determineViewName(Exception ex, HttpServletRequest request) { * @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 @@ private int getDepth(String exceptionMapping, Class exceptionClass, int depth * @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 165688844429..522a8f934a65 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 @@ 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 boolean supports(Object handler) { } @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 e16ea6957a71..314cc1508eda 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.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 @@ private static class DelegatingServletConfig implements ServletConfig { 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 String getServletName() { } @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 90d1209c9ba4..a35824aa43e2 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 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 @@ */ 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 80ff163790ad..4d2e8ab8b8b5 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 @@ 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 6574f474fd64..104e7f6bb303 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 0b07bc682f14..6be42b7c149e 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 @@ import java.util.TimeZone; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.servlet.LocaleContextResolver; /** @@ -34,8 +35,7 @@ */ public abstract class AbstractLocaleContextResolver extends AbstractLocaleResolver implements LocaleContextResolver { - @Nullable - private TimeZone defaultTimeZone; + private @Nullable TimeZone defaultTimeZone; /** @@ -50,8 +50,7 @@ public void setDefaultTimeZone(@Nullable TimeZone defaultTimeZone) { * 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 c851ed18e065..90b31fc5c389 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 @@ import java.util.Locale; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.servlet.LocaleResolver; /** @@ -32,8 +33,7 @@ */ public abstract class AbstractLocaleResolver implements LocaleResolver { - @Nullable - private Locale defaultLocale; + private @Nullable Locale defaultLocale; /** @@ -48,8 +48,7 @@ public void setDefaultLocale(@Nullable Locale defaultLocale) { * 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 c0021688f77d..a348c5097306 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 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 Locale resolveLocale(HttpServletRequest request) { 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 a14e8bd3eb56..32c3c1bab8d8 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.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 LocaleContext resolveLocaleContext(final HttpServletRequest request) { 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 void setLocaleContext(HttpServletRequest request, @Nullable HttpServletRe * @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 @@ protected Locale determineDefaultLocale(HttpServletRequest request) { * @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 04931167889e..49070e82cb69 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 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 Locale resolveLocale(HttpServletRequest request) { 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 93996c9b946e..1b267fb73642 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.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 String getParamName() { * @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 void setHttpMethods(@Nullable String... httpMethods) { * Return the configured HTTP methods. * @since 4.2 */ - @Nullable - public String[] getHttpMethods() { + public String @Nullable [] getHttpMethods() { return this.httpMethods; } @@ -161,8 +159,7 @@ private boolean checkHttpMethod(String currentMethod) { * @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 b1bff28629fd..61865b684542 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 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 Locale getLocale() { 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 @@ protected Locale determineDefaultLocale(HttpServletRequest request) { * @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 5a2290e8bec3..424fcde3beff 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 5576d0c7ee94..4e0f204a7689 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 @@ 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 final boolean isSynchronizeOnSession() { @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 ModelAndView handleRequest(HttpServletRequest request, HttpServletRespons * 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 cc37288772d1..d63c706f34e7 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 @@ 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 835b7581f702..a7217f943363 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 @@ 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 boolean supports(Object handler) { } @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 2ecea3ad6289..2e39fbb32915 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 @@ 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 @@ */ 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 void setViewName(@Nullable String viewName) { * 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 void setView(View view) { * 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 void setStatusCode(@Nullable HttpStatusCode statusCode) { * 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 boolean isStatusOnly() { * @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 9d3516cfcf45..f8210e29095d 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.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 @@ */ 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 void setBeanName(String name) { @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 699138de92a0..1268989c66b6 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.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 @@ 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 void afterPropertiesSet() throws Exception { * @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 void destroy() { 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 58e4a5737560..f24ae82e9ce8 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 @@ 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 boolean supports(Object handler) { } @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 fc026104af0a..4a84992e461c 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.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 0ed4a41c55f3..6526fed409f6 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.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 boolean preHandle(HttpServletRequest request, HttpServletResponse respons * @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 @@ protected CacheControl lookupCacheControl(PathContainer path) { * @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 @@ protected CacheControl lookupCacheControl(String lookupPath) { * @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 @@ protected Integer lookupCacheSeconds(PathContainer path) { * @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 f162fcda12f8..f3b8a643c49f 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 @@ 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 ed9790a2dfec..2dd54673b077 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 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 @@ */ public class ResponseStatusExceptionResolver extends AbstractHandlerExceptionResolver implements MessageSourceAware { - @Nullable - private MessageSource messageSource; + private @Nullable MessageSource messageSource; @Override @@ -67,8 +66,7 @@ public void setMessageSource(@Nullable MessageSource messageSource) { @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 54698d04e4a0..862b463ffe7e 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 f13fdccd2df0..3b5d024bf6a7 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 @@ 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 9beb44238bc0..6b1578e1748e 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 @@ 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 @@ public String getName() { } @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 1dbf48535699..1c00dc4d864b 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 @@ 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 aaa8d5f04074..337db1c0c01d 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.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 @@ private void assertNumberOfConditions(CompositeRequestCondition other) { *

    An 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 d4a455b62339..628ca0d71156 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.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 ConsumesRequestCondition(String... consumes) { * @param consumes as described in {@link RequestMapping#consumes()} * @param headers as described in {@link RequestMapping#headers()} */ - public ConsumesRequestCondition(@Nullable String[] consumes, @Nullable String[] headers) { + public ConsumesRequestCondition(String @Nullable [] consumes, String @Nullable [] headers) { this.expressions = parseExpressions(consumes, headers); if (this.expressions.size() > 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 ConsumesRequestCondition combine(ConsumesRequestCondition other) { * or {@code null} if no expressions match */ @Override - @Nullable - public ConsumesRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable ConsumesRequestCondition getMatchingCondition(HttpServletRequest request) { if (CorsUtils.isPreFlightRequest(request)) { return EMPTY_CONDITION; } @@ -231,8 +230,7 @@ private boolean hasBody(HttpServletRequest request) { (StringUtils.hasText(contentLength) && !contentLength.trim().equals("0")); } - @Nullable - private List 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 4e14f65febc4..c479aca0745b 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.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 @@ else if (isEmpty()) { * or {@code null} otherwise. */ @Override - @Nullable - public HeadersRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable HeadersRequestCondition getMatchingCondition(HttpServletRequest request) { if (CorsUtils.isPreFlightRequest(request)) { return PRE_FLIGHT_MATCH; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/NameValueExpression.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/NameValueExpression.java index 2bfffa9d77cb..15970d1f2212 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/NameValueExpression.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/NameValueExpression.java @@ -16,7 +16,8 @@ package org.springframework.web.servlet.mvc.condition; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; + import org.springframework.web.bind.annotation.RequestMapping; /** @@ -33,8 +34,7 @@ public interface NameValueExpression { 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 fec74254fd51..e9e47e7b781d 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.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 @@ else if (isEmpty()) { * or {@code null} otherwise. */ @Override - @Nullable - public ParamsRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable ParamsRequestCondition getMatchingCondition(HttpServletRequest request) { for (ParamExpression expression : this.expressions) { if (!expression.match(request)) { return null; diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestCondition.java index 091ea4e53a5e..b154dc1f5616 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/PathPatternsRequestCondition.java @@ -27,9 +27,9 @@ import java.util.stream.Collectors; 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.StringUtils; import org.springframework.web.util.ServletRequestPathUtils; import org.springframework.web.util.pattern.PathPattern; @@ -187,15 +187,13 @@ else if (isEmptyPathMapping()) { * or {@code null} if no patterns match. */ @Override - @Nullable - public PathPatternsRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable PathPatternsRequestCondition getMatchingCondition(HttpServletRequest request) { PathContainer path = ServletRequestPathUtils.getParsedRequestPath(request).pathWithinApplication(); SortedSet 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 7c7596fe522d..66ae0f79c697 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.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 @@ else if (isEmptyPathMapping()) { * or {@code null} if no patterns match. */ @Override - @Nullable - public PatternsRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable PatternsRequestCondition getMatchingCondition(HttpServletRequest request) { String lookupPath = UrlPathHelper.getResolvedLookupPath(request); List matches = getMatchingPatterns(lookupPath); return !matches.isEmpty() ? new PatternsRequestCondition(new LinkedHashSet<>(matches), this) : null; @@ -235,8 +234,7 @@ public List getMatchingPatterns(String lookupPath) { return matches; } - @Nullable - private String getMatchingPattern(String pattern, String lookupPath) { + private @Nullable String getMatchingPattern(String pattern, String lookupPath) { if (pattern.equals(lookupPath)) { return pattern; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java index fbb5dc1ebf81..c331c3cb4347 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/ProducesRequestCondition.java @@ -23,9 +23,9 @@ import java.util.Set; import jakarta.servlet.http.HttpServletRequest; +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; @@ -83,7 +83,7 @@ public ProducesRequestCondition(String... produces) { * @param produces expressions with syntax defined by {@link RequestMapping#produces()} * @param headers expressions with syntax defined by {@link RequestMapping#headers()} */ - public ProducesRequestCondition(@Nullable String[] produces, @Nullable String[] headers) { + public ProducesRequestCondition(String @Nullable [] produces, String @Nullable [] headers) { this(produces, headers, null); } @@ -94,7 +94,7 @@ public ProducesRequestCondition(@Nullable String[] produces, @Nullable String[] * @param headers expressions with syntax defined by {@link RequestMapping#headers()} * @param manager used to determine requested media types */ - public ProducesRequestCondition(@Nullable String[] produces, @Nullable String[] headers, + public ProducesRequestCondition(String @Nullable [] produces, String @Nullable [] headers, @Nullable ContentNegotiationManager manager) { this.expressions = parseExpressions(produces, headers); @@ -104,7 +104,7 @@ public ProducesRequestCondition(@Nullable String[] produces, @Nullable String[] this.contentNegotiationManager = (manager != null ? manager : DEFAULT_CONTENT_NEGOTIATION_MANAGER); } - private List 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 ProducesRequestCondition combine(ProducesRequestCondition other) { * or {@code null} if no expressions match. */ @Override - @Nullable - public ProducesRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable ProducesRequestCondition getMatchingCondition(HttpServletRequest request) { if (CorsUtils.isPreFlightRequest(request)) { return EMPTY_CONDITION; } @@ -222,8 +221,7 @@ else if (MediaType.ALL.isPresentIn(acceptedMediaTypes)) { } } - @Nullable - private List 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 e93ab846d0c1..b53a569e4cb7 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 31de95e3367e..c2687fbf9733 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.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 @@ */ public final class RequestConditionHolder extends AbstractRequestCondition { - @Nullable - private final RequestCondition condition; + private final @Nullable RequestCondition condition; /** @@ -56,8 +54,7 @@ public RequestConditionHolder(@Nullable RequestCondition requestCondition) { /** * Return the held request condition, or {@code null} if not holding one. */ - @Nullable - public RequestCondition getCondition() { + public @Nullable RequestCondition getCondition() { return this.condition; } @@ -111,8 +108,7 @@ private void assertEqualConditionTypes(RequestCondition thisCondition, Reques * holder, return the same holder instance. */ @Override - @Nullable - public RequestConditionHolder getMatchingCondition(HttpServletRequest request) { + public @Nullable RequestConditionHolder getMatchingCondition(HttpServletRequest request) { if (this.condition == null) { return this; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java index 7fd5b7837248..a3d8e0f42f82 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/RequestMethodsRequestCondition.java @@ -25,10 +25,10 @@ import jakarta.servlet.DispatcherType; 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.CollectionUtils; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.RequestMethod; @@ -123,8 +123,7 @@ else if (isEmpty()) { * request method is OPTIONS. */ @Override - @Nullable - public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) { + public @Nullable RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest request) { if (CorsUtils.isPreFlightRequest(request)) { return matchPreFlight(request); } @@ -146,8 +145,7 @@ public RequestMethodsRequestCondition getMatchingCondition(HttpServletRequest re * Hence empty conditions is a match, otherwise try to match to the HTTP * method in the "Access-Control-Request-Method" header. */ - @Nullable - private RequestMethodsRequestCondition matchPreFlight(HttpServletRequest request) { + private @Nullable RequestMethodsRequestCondition matchPreFlight(HttpServletRequest request) { if (getMethods().isEmpty()) { return this; } @@ -155,8 +153,7 @@ private RequestMethodsRequestCondition matchPreFlight(HttpServletRequest request return matchRequestMethod(expectedMethod); } - @Nullable - private RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) { + private @Nullable RequestMethodsRequestCondition matchRequestMethod(String httpMethodValue) { RequestMethod requestMethod = RequestMethod.resolve(httpMethodValue); if (requestMethod != null) { if (getMethods().contains(requestMethod)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java index 28d35d952e9c..1a43206dc945 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/condition/package-info.java @@ -1,9 +1,7 @@ /** * Common MVC logic for matching incoming requests based on conditions. */ -@NonNullApi -@NonNullFields +@NullMarked package org.springframework.web.servlet.mvc.condition; -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/AbstractHandlerMethodAdapter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java index c734fe5e832a..e29472f12fb3 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/AbstractHandlerMethodAdapter.java @@ -18,9 +18,9 @@ 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.method.HandlerMethod; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.ModelAndView; @@ -80,8 +80,7 @@ public final boolean supports(Object handler) { * This implementation expects the handler to be an {@link HandlerMethod}. */ @Override - @Nullable - public final ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) + public final @Nullable ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { return handleInternal(request, response, (HandlerMethod) handler); @@ -97,8 +96,7 @@ public final ModelAndView handle(HttpServletRequest request, HttpServletResponse * or {@code null} if the request has been handled directly * @throws Exception in case of errors */ - @Nullable - protected abstract ModelAndView handleInternal(HttpServletRequest request, + protected abstract @Nullable ModelAndView handleInternal(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception; /** diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java index 4dcead08aff4..60ce3b1b428d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfo.java @@ -20,9 +20,9 @@ import jakarta.servlet.ServletRequest; import jakarta.servlet.http.HttpServletRequest; +import org.jspecify.annotations.Nullable; import org.springframework.http.HttpMethod; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.PathMatcher; @@ -80,14 +80,11 @@ public final class RequestMappingInfo implements RequestConditionThis 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 ProducesRequestCondition getProducesCondition() { /** * Return the "custom" condition of this {@link RequestMappingInfo}, or {@code null}. */ - @Nullable - public RequestCondition getCustomCondition() { + public @Nullable RequestCondition getCustomCondition() { return this.customConditionHolder.getCondition(); } @@ -354,8 +347,7 @@ public RequestMappingInfo combine(RequestMappingInfo other) { methods, params, headers, consumes, produces, custom, this.options); } - @Nullable - private String combineNames(RequestMappingInfo other) { + private @Nullable String combineNames(RequestMappingInfo other) { if (this.name != null && other.name != null) { String separator = RequestMappingInfoHandlerMethodMappingNamingStrategy.SEPARATOR; return this.name + separator + other.name; @@ -378,8 +370,7 @@ else if (this.name != null) { * @return a new instance in case of a match; or {@code null} otherwise */ @Override - @Nullable - public RequestMappingInfo getMatchingCondition(HttpServletRequest request) { + public @Nullable RequestMappingInfo getMatchingCondition(HttpServletRequest request) { RequestMethodsRequestCondition methods = this.methodsCondition.getMatchingCondition(request); if (methods == null) { return null; @@ -627,11 +618,9 @@ private static class DefaultBuilder implements Builder { private boolean hasAccept; - @Nullable - private String mappingName; + private @Nullable String mappingName; - @Nullable - private RequestCondition customCondition; + private @Nullable RequestCondition customCondition; private BuilderConfiguration options = new BuilderConfiguration(); @@ -740,14 +729,11 @@ public RequestMappingInfo build() { private static class MutateBuilder implements Builder { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private PathPatternsRequestCondition pathPatternsCondition; + private @Nullable PathPatternsRequestCondition pathPatternsCondition; - @Nullable - private PatternsRequestCondition patternsCondition; + private @Nullable PatternsRequestCondition patternsCondition; private RequestMethodsRequestCondition methodsCondition; @@ -869,14 +855,11 @@ public static class BuilderConfiguration { private static final PathPatternParser defaultPatternParser = new PathPatternParser(); - @Nullable - private PathPatternParser patternParser; + private @Nullable PathPatternParser patternParser; - @Nullable - private PathMatcher pathMatcher; + private @Nullable PathMatcher pathMatcher; - @Nullable - private ContentNegotiationManager contentNegotiationManager; + private @Nullable ContentNegotiationManager contentNegotiationManager; /** @@ -898,8 +881,7 @@ public void setPatternParser(@Nullable PathPatternParser patternParser) { * {@code PathPatternParser}, or {@code null}. * @since 5.3 */ - @Nullable - public PathPatternParser getPatternParser() { + public @Nullable PathPatternParser getPatternParser() { return this.patternParser; } @@ -920,9 +902,8 @@ public void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { * {@link ServletRequestPathUtils#getCachedPathValue(ServletRequest)}; * this method always returns {@link UrlPathHelper#defaultInstance}. */ - @Nullable @Deprecated - public UrlPathHelper getUrlPathHelper() { + public @Nullable UrlPathHelper getUrlPathHelper() { return UrlPathHelper.defaultInstance; } @@ -939,8 +920,7 @@ public void setPathMatcher(@Nullable PathMatcher pathMatcher) { /** * Return a custom PathMatcher to use for the PatternsRequestCondition, if any. */ - @Nullable - public PathMatcher getPathMatcher() { + public @Nullable PathMatcher getPathMatcher() { return this.pathMatcher; } @@ -950,8 +930,7 @@ public PathMatcher getPathMatcher() { * and {@code PathMatcher} are not set. * @since 6.1.2 */ - @Nullable - public PathPatternParser getPatternParserToUse() { + public @Nullable PathPatternParser getPatternParserToUse() { if (this.patternParser == null && this.pathMatcher == null) { return defaultPatternParser; } @@ -970,8 +949,7 @@ public void setContentNegotiationManager(ContentNegotiationManager contentNegoti * Return the ContentNegotiationManager to use for the ProducesRequestCondition, * if any. */ - @Nullable - public ContentNegotiationManager getContentNegotiationManager() { + public @Nullable ContentNegotiationManager getContentNegotiationManager() { return this.contentNegotiationManager; } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java index b98af5617652..ea06a048449d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java @@ -28,13 +28,13 @@ import jakarta.servlet.ServletException; 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.http.server.PathContainer; -import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -106,8 +106,7 @@ protected Set getDirectPaths(RequestMappingInfo info) { * @return an info in case of a match; or {@code null} otherwise. */ @Override - @Nullable - protected RequestMappingInfo getMatchingMapping(RequestMappingInfo info, HttpServletRequest request) { + protected @Nullable RequestMappingInfo getMatchingMapping(RequestMappingInfo info, HttpServletRequest request) { return info.getMatchingCondition(request); } @@ -120,8 +119,7 @@ protected Comparator getMappingComparator(final HttpServletR } @Override - @Nullable - protected HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { + protected @Nullable HandlerMethod getHandlerInternal(HttpServletRequest request) throws Exception { request.removeAttribute(PRODUCIBLE_MEDIA_TYPES_ATTRIBUTE); try { return super.getHandlerInternal(request); @@ -244,8 +242,7 @@ private Map> extractMatrixVariables( * but not by consumable/producible media types */ @Override - @Nullable - protected HandlerMethod handleNoMatch( + protected @Nullable HandlerMethod handleNoMatch( Set 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 56d831cb96f9..518d9b3f88e7 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.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 boolean supports(MethodParameter returnType, 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 b00e71e0b415..4817cb7ece3d 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 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.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 @@ RequestResponseBodyAdviceChain getAdvice() { * @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 @@ protected Object readWithMessageConverters(NativeWebRequest webRequest, MethodPa * @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 @@ protected List getSupportedMediaTypes(Class clazz) { * @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 @@ private static class EmptyBodyCheckingHttpInputMessage implements HttpInputMessa 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 798b1167d0a6..5fcf91ddb151 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 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.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 @@ private boolean safeExtension(HttpServletRequest request, @Nullable String exten 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 e9aa6a196be6..12e69e655973 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 @@ */ 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 d29a45289e68..e9cb1f21e9dd 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 @@ 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 cc1536040e04..0fe6adbdccce 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 boolean supportsParameter(MethodParameter 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 { 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 d871368aac1c..d0ada8bfe9f6 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 @@ 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 64d79f70094b..2cd1c5b72552 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 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.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 void setCustomArgumentResolvers(@Nullable List getCustomArgumentResolvers() { + public @Nullable List getCustomArgumentResolvers() { return this.customArgumentResolvers; } @@ -161,8 +155,7 @@ public void setArgumentResolvers(@Nullable List a * 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 void setCustomReturnValueHandlers(@Nullable List getCustomReturnValueHandlers() { + public @Nullable List getCustomReturnValueHandlers() { return this.customReturnValueHandlers; } @@ -201,8 +193,7 @@ public void setReturnValueHandlers(@Nullable 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 019bf9a75b12..352862fb0e63 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 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 @@ protected void addBindValues(MutablePropertyValues mpvs, ServletRequest request) } @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 @@ private static void addValueIfNotPresent(MutablePropertyValues mpvs, String labe } } - @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 @@ private class ExtendedServletRequestValueResolver extends ServletRequestValueRes } @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 fda6f3adbbda..97a97e1a3179 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 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.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 boolean supportsReturnType(MethodParameter returnType) { } @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 Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC } } - @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 224d3a17a01d..34a4ce6f6005 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 c60de4a42547..193b584f3350 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 @@ 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 boolean supportsParameter(MethodParameter parameter) { } @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 37fae80c4725..8f33d9648708 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.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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { @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 9d2b199040cd..854a255049db 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 @@ 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 @@ */ 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 void setRedirectPatterns(@Nullable String... redirectPatterns) { * 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 423a4b151310..0386f1e988cb 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 @@ 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 @@ */ 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 c66bb0652ed4..88cca2755a80 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 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.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 @@ private static String resolveEmbeddedValue(String value) { 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 @@ private static class ControllerMethodInvocationInterceptor 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 Object intercept(@Nullable Object obj, Method method, Object[] args, @Nul } @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 57486ff311b9..04fad545be82 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 @@ 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 e35b49acb7cc..876dead8b277 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.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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { @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 void contributeMethodArgument(MethodParameter parameter, Object value, 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 23ebbd3f0d4c..014f661891c0 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 @@ 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 59b6db526e35..ebeb5d0998b4 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.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.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 @@ public 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 @@ public boolean isReactiveType(Class type) { * @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 @@ public ResponseBodyEmitter handleValue(Object returnValue, MethodParameter retur * @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 @@ private abstract static class AbstractEmitterSubscriber implements Subscriber 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 9de99cc4c137..ee7a8da72690 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 @@ 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 27a1973020ad..05be76d25afc 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 4b10e1e38570..0d5f204c0947 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 @@ 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 @@ Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodParameter * @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 cdb68a7975a2..a4560931f2a4 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 @@ 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 Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodPa * 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 34b38dc2f0a4..50134833d097 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 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.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 void setCustomArgumentResolvers(@Nullable List getCustomArgumentResolvers() { + public @Nullable List getCustomArgumentResolvers() { return this.customArgumentResolvers; } @@ -250,8 +239,7 @@ public void setArgumentResolvers(@Nullable List a * 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 void setInitBinderArgumentResolvers(@Nullable List getInitBinderArgumentResolvers() { + public @Nullable List getInitBinderArgumentResolvers() { return (this.initBinderArgumentResolvers != null ? this.initBinderArgumentResolvers.getResolvers() : null); } @@ -289,8 +276,7 @@ public void setCustomReturnValueHandlers(@Nullable List getCustomReturnValueHandlers() { + public @Nullable List getCustomReturnValueHandlers() { return this.customReturnValueHandlers; } @@ -312,8 +298,7 @@ public void setReturnValueHandlers(@Nullable List getReturnValueHandlers() { + public @Nullable List getReturnValueHandlers() { return (this.returnValueHandlers != null ? this.returnValueHandlers.getHandlers() : null); } @@ -338,8 +323,7 @@ public void setModelAndViewResolvers(@Nullable List modelA /** * 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 void setWebBindingInitializer(@Nullable WebBindingInitializer webBindingI /** * 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 void setBeanFactory(BeanFactory beanFactory) { /** * 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 @@ private List initViewResolvers() { return Collections.emptyList(); } - @Nullable - private LocaleResolver initLocaleResolver() { + private @Nullable LocaleResolver initLocaleResolver() { if (getBeanFactory() != null) { try { return getBeanFactory().getBean( @@ -865,8 +846,7 @@ protected boolean supportsInternal(HandlerMethod handlerMethod) { } @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 @@ private SessionAttributesHandler getSessionAttributesHandler(HandlerMethod handl * @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 @@ protected InitBinderDataBinderFactory createDataBinderFactory(List beanType) { * @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 @@ protected RequestMappingInfo getMappingForMethod(Method method, Class handler 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 @@ String getPathPrefix(Class handlerType) { 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 @@ private RequestMappingInfo createRequestMappingInfo(AnnotatedElement element) { * @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 @@ protected RequestCondition getCustomTypeCondition(Class handlerType) { * @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 @@ private void updateConsumesCondition(RequestMappingInfo info, Method method) { } @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 RequestMatchResult match(HttpServletRequest request, String pattern) { } @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 47e21fcab2f3..c3bf08e6b683 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.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 boolean supportsParameter(MethodParameter parameter) { } @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 f5e483490781..5d7fa5ecd5c1 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.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 @@ public Object afterBodyRead(Object body, HttpInputMessage inputMessage, MethodPa } @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 @@ public Object beforeBodyWrite(@Nullable Object body, MethodParameter returnType, } @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 @@ public Object handleEmptyBody(@Nullable Object body, HttpInputMessage inputMessa @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 2e9b6b657237..3436f66878fb 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.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.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 boolean supportsReturnType(MethodParameter returnType) { * 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 Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewC } @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 b2b6d48b28f7..d8f582fadbb5 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 e4e5d0e6b7cb..845194e0b2b1 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.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 @@ */ 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 ResponseBodyEmitter(Long timeout) { /** * Return the configured timeout value, if any. */ - @Nullable - public Long getTimeout() { + public @Nullable Long getTimeout() { return this.timeout; } @@ -350,8 +347,7 @@ public static class DataWithMediaType { 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 Object getData() { 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 92a571ac449a..58caff72813d 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.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.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 void handle(ModelAndView modelAndView) throws IOException { } } - @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 f1a457ad5b5f..13edb114daf6 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 @@ 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.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 void setMessageSource(MessageSource messageSource) { * 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 @@ protected MessageSource getMessageSource() { 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 @@ else if (ex instanceof AsyncRequestNotUsableException theEx) { * @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 @@ protected ResponseEntity handleHttpRequestMethodNotSupported( * @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 @@ protected ResponseEntity handleHttpMediaTypeNotSupported( * @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 @@ protected ResponseEntity handleHttpMediaTypeNotAcceptable( * {@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 @@ protected ResponseEntity handleMissingPathVariable( * @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 @@ protected ResponseEntity handleMissingServletRequestParameter( * @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 @@ protected ResponseEntity handleMissingServletRequestPart( * @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 @@ protected ResponseEntity handleServletRequestBindingException( * @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 @@ protected ResponseEntity handleMethodArgumentNotValid( * {@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 @@ protected ResponseEntity handleHandlerMethodValidationException( * {@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 @@ protected ResponseEntity handleNoHandlerFoundException( * {@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 @@ protected ResponseEntity handleNoResourceFoundException( * {@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 @@ protected ResponseEntity handleAsyncRequestTimeoutException( * {@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 @@ protected ResponseEntity handleErrorResponseException( * {@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 @@ protected ResponseEntity handleMaxUploadSizeExceededException( * @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 @@ protected ResponseEntity handleConversionNotSupported( * @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 @@ protected ResponseEntity handleTypeMismatch( * @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 @@ protected ResponseEntity handleHttpMessageNotReadable( * @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 @@ protected ResponseEntity handleHttpMessageNotWritable( * {@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 @@ protected ResponseEntity handleMethodValidationException( * {@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 @@ protected ResponseEntity handleAsyncRequestNotUsableException( */ 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 @@ protected ProblemDetail createProblemDetail( * @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 160cd0cf3ad8..f1226fc170a5 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 @@ 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 void setUrlPathHelper(UrlPathHelper urlPathHelper) { @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 45146aa6d132..413a7adfc722 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 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.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 MethodParameter getReturnValueType(@Nullable Object returnValue) { * 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 boolean hasMethodAnnotation(Class annotationTyp */ 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 de59e9ee27c1..a1bccaa5e306 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.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 ServletModelAttributeMethodProcessor(boolean annotationNotRequired) { * @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 @@ protected final Object createAttribute(String attributeName, MethodParameter par * @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 @@ protected final Map getUriTemplateVariables(NativeWebRequest req * @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 117b9e08fdec..c67e42330f5f 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 @@ 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 319891fc1948..bbd9dc6362a1 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.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 boolean supportsParameter(MethodParameter 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(); @@ -121,9 +120,8 @@ private T resolveNativeRequest(NativeWebRequest webRequest, Class require 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 45e71a9081b9..176e2ed59a5f 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.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 c5cce648c07b..96aebd371bed 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 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) { } @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 56ce94231aa3..29ae344e57d8 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.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 @@ private static class SseEventBuilderImpl implements SseEventBuilder { 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 230aa99d108c..026bf1e80964 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 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 34fdfce6570c..eb63fd5c9150 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 dbdb4364ae75..48f36d76b02a 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 9808d90bdb9d..2c1478f67d30 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 @@ */ 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 90c9c46fb5d4..4c3bd6530e41 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 372a55d33fa2..a3cd4888b9d6 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 b6ceb3946373..1509160cfb8b 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 7de262138cb9..f44a3eb4a2fa 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.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.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 DefaultHandlerExceptionResolver() { @Override - @Nullable - protected ModelAndView doResolveException( + protected @Nullable ModelAndView doResolveException( HttpServletRequest request, HttpServletResponse response, @Nullable Object handler, Exception ex) { try { @@ -273,8 +272,7 @@ else if (DisconnectedClientHelper.isClientDisconnectedException(ex)) { * {@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 @@ protected ModelAndView handleHttpRequestMethodNotSupported(HttpRequestMethodNotS * {@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 @@ protected ModelAndView handleHttpMediaTypeNotSupported(HttpMediaTypeNotSupported * {@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 @@ protected ModelAndView handleHttpMediaTypeNotAcceptable(HttpMediaTypeNotAcceptab * @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 @@ protected ModelAndView handleMissingPathVariable(MissingPathVariableException ex * {@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 @@ protected ModelAndView handleMissingServletRequestParameter(MissingServletReques * {@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 @@ protected ModelAndView handleMissingServletRequestPartException(MissingServletRe * {@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 @@ protected ModelAndView handleServletRequestBindingException(ServletRequestBindin * {@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 @@ protected ModelAndView handleMethodArgumentNotValidException(MethodArgumentNotVa * @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 @@ protected ModelAndView handleHandlerMethodValidationException(HandlerMethodValid * @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 @@ protected ModelAndView handleNoHandlerFoundException(NoHandlerFoundException ex, * @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 @@ protected ModelAndView handleNoResourceFoundException(NoResourceFoundException e * @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 a47f582e6c77..85db63ecc0d7 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 @@ 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 de09f4be4a56..45333a62d2c5 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 @@ 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 @@ @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 RedirectAttributesModelMap addAttribute(String attributeName, @Nullable O 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 e9c3ee71b8de..2d091ef995c2 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 d2d213bb3cc3..c54c44910004 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 c4228ce0ed69..95f0e5b0c1a5 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 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 19e14d7fc85a..f8f67bc33b7a 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 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 VersionPathStrategy getVersionPathStrategy() { @Override - @Nullable - public String extractVersion(String requestPath) { + public @Nullable String extractVersion(String requestPath) { return this.pathStrategy.extractVersion(requestPath); } @@ -91,8 +90,7 @@ public PrefixVersionPathStrategy(String version) { } @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 @@ protected static class FileNameVersionPathStrategy implements VersionPathStrateg 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 2bb01786993b..57e8dd709165 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.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 List getContentCodings() { @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 @@ protected String computeKey(@Nullable HttpServletRequest request, String request 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 @@ private String getContentCodingKey(HttpServletRequest request) { } @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 96d8673d45c4..708e25c4dc78 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 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 d01e9c334411..daecc8a5200b 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.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 @@ */ 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 @@ private DefaultResourceResolverChain(@Nullable ResourceResolver resolver, @Nulla @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 @@ public Resource resolveResource( } @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 340fbc550ec8..23476e9f0553 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.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 2147c185e9e9..72846f0022a3 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.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 c3c2c452b7bb..1c12a73c6d6b 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.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 void registerExtension(String coding, String extension) { @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 @@ protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, 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 @@ private String getExtension(String coding) { } @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 Resource createRelative(String relativePath) throws IOException { } @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 dc132502f1c5..a83af81321ae 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 @@ 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 LiteWebJarsResourceResolver(WebJarVersionLocator webJarVersionLocator) { @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 @@ protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, } @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 @@ protected String resolveUrlPathInternal(String resourceUrlPath, 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 2b20a100e269..466342641831 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.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 @@ */ 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 void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { * 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 @@ private Resource getResource(String resourcePath, @Nullable HttpServletRequest r * @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 928b040d3b7b..f4d80c2b0e12 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 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 aa38801ed943..f9ffc15eb7ac 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.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.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 void setResourceHttpMessageConverter(@Nullable ResourceHttpMessageConvert * Return the configured resource converter. * @since 4.3 */ - @Nullable - public ResourceHttpMessageConverter getResourceHttpMessageConverter() { + public @Nullable ResourceHttpMessageConverter getResourceHttpMessageConverter() { return this.resourceHttpMessageConverter; } @@ -275,8 +265,7 @@ public void setResourceRegionHttpMessageConverter(@Nullable ResourceRegionHttpMe * 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 void setCorsConfiguration(CorsConfiguration corsConfiguration) { * 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 void setUrlPathHelper(@Nullable UrlPathHelper urlPathHelper) { * The configured {@link UrlPathHelper}. * @since 4.3.13 */ - @Nullable - public UrlPathHelper getUrlPathHelper() { + public @Nullable UrlPathHelper getUrlPathHelper() { return this.urlPathHelper; } @@ -379,8 +366,7 @@ public void setEtagGenerator(@Nullable Function etagGenerator) * @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 void handleRequest(HttpServletRequest request, HttpServletResponse respon } } - @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 @@ protected boolean isInvalidPath(String path) { * @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 f4417b9287c0..c315c38f2623 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 @@ 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 @@ Resource resolveResource(@Nullable HttpServletRequest request, String requestPat * @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 678164977e0c..dba86069f7f0 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 @@ 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 @@ Resource resolveResource( * @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 4ebe2899564d..e4b948a8cb91 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 @@ 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 @@ */ public abstract class ResourceTransformerSupport implements ResourceTransformer { - @Nullable - private ResourceUrlProvider resourceUrlProvider; + private @Nullable ResourceUrlProvider resourceUrlProvider; /** @@ -53,8 +52,7 @@ public void setResourceUrlProvider(@Nullable ResourceUrlProvider resourceUrlProv /** * Return the configured {@code ResourceUrlProvider}. */ - @Nullable - public ResourceUrlProvider getResourceUrlProvider() { + public @Nullable ResourceUrlProvider getResourceUrlProvider() { return this.resourceUrlProvider; } @@ -70,8 +68,7 @@ public ResourceUrlProvider getResourceUrlProvider() { * @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 @@ protected String toAbsolutePath(String path, HttpServletRequest request) { 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 5bd3de0c6d92..ea5eac1ef4ed 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.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 void doFilter(ServletRequest request, ServletResponse response, FilterCha 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 @@ private void initLookupPath(ResourceUrlProvider urlProvider) { } } - @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 688bd032443e..19896a4d066f 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 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 @@ private int getEndPathIndex(String lookupPath) { * @param lookupPath the lookup path to check * @return the resolved public URL path, or {@code null} if unresolved */ - @Nullable @SuppressWarnings("NullAway") - public final String getForLookupPath(String lookupPath) { + public final @Nullable String getForLookupPath(String lookupPath) { // Clean duplicate slashes or pathWithinPattern won't match lookupPath String previous; do { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/TransformedResource.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/TransformedResource.java index 56fec945b349..baeace953eea 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/TransformedResource.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/TransformedResource.java @@ -18,9 +18,10 @@ 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} @@ -33,8 +34,7 @@ */ public class TransformedResource extends ByteArrayResource { - @Nullable - private final String filename; + private final @Nullable String filename; private final long lastModified; @@ -53,8 +53,7 @@ public TransformedResource(Resource original, byte[] transformedContent) { @Override - @Nullable - public String getFilename() { + public @Nullable String getFilename() { return this.filename; } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionPathStrategy.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionPathStrategy.java index 144ab23f3f07..3b657b943b0d 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionPathStrategy.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionPathStrategy.java @@ -16,7 +16,7 @@ package org.springframework.web.servlet.resource; -import org.springframework.lang.Nullable; +import org.jspecify.annotations.Nullable; /** * A strategy for extracting and embedding a resource version in its URL path. @@ -32,8 +32,7 @@ public interface VersionPathStrategy { * @param requestPath the request path to check * @return the version string or {@code null} if none was found */ - @Nullable - String extractVersion(String requestPath); + @Nullable String extractVersion(String requestPath); /** * Remove the version from the request path. It is assumed that the given diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java index 2c382777b01e..e6a389668d2a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java @@ -31,11 +31,11 @@ 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.AntPathMatcher; import org.springframework.util.Assert; import org.springframework.util.StringUtils; @@ -157,8 +157,7 @@ public VersionResourceResolver addVersionStrategy(VersionStrategy strategy, Stri @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); @@ -196,8 +195,7 @@ protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, } @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 @@ protected String resolveUrlPathInternal(String resourceUrlPath, * 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 Resource createRelative(String relativePath) throws IOException { } @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 720ebf1338f0..af4537d055e8 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 6d72dfb2cc9e..e02c8c764146 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 @@ protected WebApplicationContext createServletApplicationContext() { * @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 @@ protected WebApplicationContext createServletApplicationContext() { * @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 44559ce60bc6..00335f0f092e 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.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 @@ protected FrameworkServlet createDispatcherServlet(WebApplicationContext servlet * @see DispatcherServlet#setContextInitializers * @see #getRootApplicationContextInitializers() */ - @Nullable - protected ApplicationContextInitializer[] getServletApplicationContextInitializers() { + protected ApplicationContextInitializer @Nullable [] getServletApplicationContextInitializers() { return null; } @@ -161,8 +160,7 @@ protected ApplicationContextInitializer[] getServletApplicationContextInitial * @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 38ee6c19df16..788e251c4e19 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.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 UrlPathHelper getUrlPathHelper() { @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 @@ private List getExpiredFlashMaps(List allMaps) { * 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 final void saveOutputFlashMap(FlashMap flashMap, HttpServletRequest reque } } - @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 @@ private String decodeAndNormalizePath(@Nullable String path, HttpServletRequest * @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 @@ protected abstract void updateFlashMaps( * @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 aea93c608a7a..77c793d1a3c9 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.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 String getPath() { * 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 String getExpression() { *

    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 Object getValue() { * '{@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 getValueType() { * 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 @@ private String[] initErrorMessages() throws NoSuchMessageException { * @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 Errors getErrors() { * 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 PropertyEditor getEditor() { * @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 7287685a309e..f65022136862 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.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 @@ protected Locale getFallbackLocale() { * 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 @@ protected TimeZone getFallbackTimeZone() { */ 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 25cb945b6a62..aecd51efe032 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.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 f1869b43303a..b91631fd7799 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.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.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 @@ protected final HttpServletRequest getRequest() { /** * 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 final WebApplicationContext getWebApplicationContext() { * 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 Locale getLocale() { * 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 @@ protected Locale getFallbackLocale() { * 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 @@ protected org.springframework.ui.context.Theme getFallbackTheme() { * @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 boolean isDefaultHtmlEscape() { * 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 boolean isResponseEncodedHtmlEscape() { * @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 UrlPathHelper getUrlPathHelper() { * 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 String getMessage(String code, String defaultMessage) { * @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 String getMessage(String code, @Nullable List args, String defaultMess * @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 String getMessage(String code) throws NoSuchMessageException { * @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 String getMessage(String code, @Nullable List args) throws NoSuchMessa * @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 String getThemeMessage(String code, String defaultMessage) { * @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 String getThemeMessage(String code) throws NoSuchMessageException { * @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 String getThemeMessage(MessageSourceResolvable resolvable) throws NoSuchM * @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 Errors getErrors(String name) { * @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 @@ else if (!htmlEscape && errors instanceof EscapedErrors escapedErrors) { * @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 BindStatus getBindStatus(String path, boolean htmlEscape) throws IllegalS */ 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 static Locale getJstlLocale(HttpServletRequest request, @Nullable Servlet 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 7f438a03b09e..c1c7aa87a61c 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.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 static WebApplicationContext findWebApplicationContext( * @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 static WebApplicationContext findWebApplicationContext(HttpServletRequest * @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 static Locale getLocale(HttpServletRequest request) { * @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 static TimeZone getTimeZone(HttpServletRequest request) { * @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 static org.springframework.web.servlet.ThemeResolver getThemeResolver(Htt * @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 static org.springframework.ui.context.ThemeSource getThemeSource(HttpServ * @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 static org.springframework.ui.context.Theme getTheme(HttpServletRequest r * @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 static FlashMap getOutputFlashMap(HttpServletRequest request) { * @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 dba327445530..d92e7dee84f7 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 @@ 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 55041f924e95..6098a428e128 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 @@ */ public class ServletUriComponentsBuilder extends UriComponentsBuilder { - @Nullable - private String originalPath; + private @Nullable String originalPath; /** @@ -201,8 +200,7 @@ private void initPath(String path) { * @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 faf981da8728..2880d324d3c0 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 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 cd63dd63fbc5..4f5a3f7907e2 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 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 WebContentGenerator(String... supportedMethods) { *

    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 final void setSupportedMethods(@Nullable String... methods) { /** * 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 @@ else if (this.supportedMethods.contains(HttpMethod.OPTIONS.name())) { * call to {@link #checkRequest(HttpServletRequest)}. * @since 4.3 */ - @Nullable - protected String getAllowHeader() { + protected @Nullable String getAllowHeader() { return this.allowHeader; } @@ -209,8 +203,7 @@ public final void setCacheControl(@Nullable CacheControl cacheControl) { * 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 final int getCacheSeconds() { * @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 final void setVaryByRequestHeaders(@Nullable String... varyByRequestHeade * 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 39d4c2153f4b..300ebe5b93f2 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 6e00296c1b2d..7239e2ca8f20 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 84ba71c1f7b8..56e27d157db0 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 @@ 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 @@ @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 75042ea5105f..4c6c12892184 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 @@ 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 int doEndTag() { * 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 3ed8806ff940..1e6ffaff68a9 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 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 @@ private BindStatus getStatus() { * @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 final String getProperty() { * 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 d6c9e2e773d1..447a712dd152 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 @@ 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 a0d864b278d0..c54f9e0853e1 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 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 a956ff862082..477a8555ba97 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 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.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 @@ private EvaluationContext createEvaluationContext(PageContext pageContext) { 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 @@ private static class JspPropertyAccessor implements PropertyAccessor { private final PageContext pageContext; - @Nullable - private final ELContext elContext; + private final @Nullable ELContext elContext; public JspPropertyAccessor(PageContext pageContext) { @@ -223,8 +219,7 @@ public JspPropertyAccessor(PageContext pageContext) { } @Override - @Nullable - public Class[] getSpecificTargetClasses() { + public Class @Nullable [] getSpecificTargetClasses() { return null; } @@ -253,8 +248,7 @@ public void write(EvaluationContext context, @Nullable Object target, String nam 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 11327e233f23..e4e220ec34d2 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 @@ @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 1c9fec18b619..6751d95e5686 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 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 @@ protected String resolveMessage() throws JspException, NoSuchMessageException { 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 @@ private Object[] appendArguments(@Nullable Object[] sourceArguments, Object[] ad * @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 @@ protected MessageSource getMessageSource() { /** * 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 23bc3fbcb826..e20b1658bd46 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.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 void setPath(@Nullable String path) { /** * 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 6482a254f6c4..311999e6bfb9 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 @@ */ public class Param { - @Nullable - private String name; + private @Nullable String name; - @Nullable - private String value; + private @Nullable String value; /** @@ -48,8 +46,7 @@ public void setName(@Nullable String name) { /** * Return the raw parameter name. */ - @Nullable - public String getName() { + public @Nullable String getName() { return this.name; } @@ -63,8 +60,7 @@ public void setValue(@Nullable String value) { /** * 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 513ea6bae21d..982b403103e2 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 @@ 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 af503346e07c..d80038fc004d 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.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 bc026381c776..cbf1d1e520e1 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 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 @@ 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 49c9258dbb53..3862f91a1af5 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.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 0c83f0d66252..d3cd4a5513fd 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 @@ protected void renderFromBoolean(Boolean boundValue, TagWriter tagWriter) throws * 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 fb017d822c4e..e82683391b04 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.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 void setId(@Nullable String id) { * Get the value of the '{@code id}' attribute. */ @Override - @Nullable - public String getId() { + public @Nullable String getId() { return this.id; } @@ -129,8 +125,7 @@ protected void writeDefaultAttributes(TagWriter tagWriter) throws JspException { * @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 @@ protected String resolveId() throws JspException { *

    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 @@ protected String autogenerateId() throws JspException { * 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 @@ protected BindStatus getBindStatus() throws JspException { * 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 @@ protected String getPropertyPath() throws JspException { * 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 @@ protected PropertyEditor getPropertyEditor() throws JspException { *

    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 c9dc294c0547..469a07374fb6 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 @@ 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 a35a6286d188..7362044cd0b1 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 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 @@ @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 cbb779337a89..56c62530d43a 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 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 void setCssClass(String cssClass) { * 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 void setCssErrorClass(String cssErrorClass) { * 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 void setCssStyle(String cssStyle) { * 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 void setLang(String lang) { * 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 void setTitle(String title) { * 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 void setDir(String dir) { * 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 void setTabindex(String tabindex) { * 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 void setOnclick(String onclick) { * 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 void setOndblclick(String ondblclick) { * 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 void setOnmousedown(String onmousedown) { * 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 void setOnmouseup(String onmouseup) { * 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 void setOnmouseover(String onmouseover) { * 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 void setOnmousemove(String onmousemove) { * 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 void setOnmouseout(String onmouseout) { * 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 void setOnkeypress(String onkeypress) { * 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 void setOnkeyup(String onkeyup) { * 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 void setOnkeydown(String onkeydown) { * 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 ce6a786bab1c..6c1fab686c9c 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 void setOnfocus(String onfocus) { /** * Get the value of the '{@code onfocus}' attribute. */ - @Nullable - protected String getOnfocus() { + protected @Nullable String getOnfocus() { return this.onfocus; } @@ -109,8 +103,7 @@ public void setOnblur(String onblur) { /** * Get the value of the '{@code onblur}' attribute. */ - @Nullable - protected String getOnblur() { + protected @Nullable String getOnblur() { return this.onblur; } @@ -125,8 +118,7 @@ public void setOnchange(String onchange) { /** * Get the value of the '{@code onchange}' attribute. */ - @Nullable - protected String getOnchange() { + protected @Nullable String getOnchange() { return this.onchange; } @@ -141,8 +133,7 @@ public void setAccesskey(String accesskey) { /** * 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 3547f810cf87..bb6616327b13 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.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 void setItems(Object items) { * 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 void setItemValue(String itemValue) { * 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 void setItemLabel(String itemLabel) { * 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 void setDelimiter(String delimiter) { * 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 String getElement() { * 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 e0683cc64eb8..336cb9ec5060 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 void setValue(Object value) { /** * Get the value of the '{@code value}' attribute. */ - @Nullable - protected Object getValue() { + protected @Nullable Object getValue() { return this.value; } @@ -72,8 +69,7 @@ public void setLabel(Object label) { /** * 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 ff59f33d9807..73cd155197c9 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 void setName(String name) { * 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 void setValue(@Nullable String value) { /** * 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 f2e9ec6865a6..f4221c6064d8 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 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 @@ protected String autogenerateId() throws JspException { * 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 834da17878c7..bd871b922ba6 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.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 void setName(String name) { * 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 void setAction(@Nullable String action) { /** * Get the value of the '{@code action}' attribute. */ - @Nullable - protected String getAction() { + protected @Nullable String getAction() { return this.action; } @@ -395,8 +382,7 @@ public void setServletRelativeAction(@Nullable String servletRelativeAction) { * 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 void setTarget(String target) { /** * Get the value of the '{@code target}' attribute. */ - @Nullable - public String getTarget() { + public @Nullable String getTarget() { return this.target; } @@ -442,8 +427,7 @@ public void setEnctype(String enctype) { /** * Get the value of the '{@code enctype}' attribute. */ - @Nullable - protected String getEnctype() { + protected @Nullable String getEnctype() { return this.enctype; } @@ -458,8 +442,7 @@ public void setAcceptCharset(String acceptCharset) { /** * Get the value of the '{@code acceptCharset}' attribute. */ - @Nullable - protected String getAcceptCharset() { + protected @Nullable String getAcceptCharset() { return this.acceptCharset; } @@ -474,8 +457,7 @@ public void setOnsubmit(String onsubmit) { /** * Get the value of the '{@code onsubmit}' attribute. */ - @Nullable - protected String getOnsubmit() { + protected @Nullable String getOnsubmit() { return this.onsubmit; } @@ -490,8 +472,7 @@ public void setOnreset(String onreset) { /** * Get the value of the '{@code onreset}' attribute. */ - @Nullable - protected String getOnreset() { + protected @Nullable String getOnreset() { return this.onreset; } @@ -506,8 +487,7 @@ public void setAutocomplete(String autocomplete) { /** * 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 c682c11f24af..6fa0d362eb5c 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 @@ 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 void setSize(String size) { /** * Get the value of the '{@code size}' attribute. */ - @Nullable - protected String getSize() { + protected @Nullable String getSize() { return this.size; } @@ -290,8 +283,7 @@ public void setMaxlength(String maxlength) { /** * Get the value of the '{@code maxlength}' attribute. */ - @Nullable - protected String getMaxlength() { + protected @Nullable String getMaxlength() { return this.maxlength; } @@ -306,8 +298,7 @@ public void setAlt(String alt) { /** * Get the value of the '{@code alt}' attribute. */ - @Nullable - protected String getAlt() { + protected @Nullable String getAlt() { return this.alt; } @@ -322,8 +313,7 @@ public void setOnselect(String onselect) { /** * Get the value of the '{@code onselect}' attribute. */ - @Nullable - protected String getOnselect() { + protected @Nullable String getOnselect() { return this.onselect; } @@ -338,8 +328,7 @@ public void setAutocomplete(String autocomplete) { /** * 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 2ae52eb35134..8f866d5e508b 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 void setFor(String forId) { * 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 @@ protected int writeTagContent(TagWriter tagWriter) throws JspException { * @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 void setItemValue(String itemValue) { * 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 void setItemLabel(String itemLabel) { * 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 @@ protected int writeTagContent(TagWriter tagWriter) throws JspException { * 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 @@ protected BindStatus getBindStatus() { */ 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 1aaafeaeecb4..1271211f67d7 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.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 void setItems(@Nullable Object items) { * 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 void setItemValue(String itemValue) { * 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 void setItemLabel(String itemLabel) { * 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 void setSize(String size) { /** * Get the value of the '{@code size}' attribute. */ - @Nullable - protected String getSize() { + protected @Nullable String getSize() { return this.size; } @@ -385,8 +375,7 @@ public void setMultiple(Object multiple) { * 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 f8b41e029527..8ef17458a402 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.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 ff4175ab9120..46e7b5aa1ef7 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 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 boolean isBlockTag() { */ 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 3842b835049f..dd5d8c1e4269 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