From 63b129a3f7586a7cd876c305cb502ef01bbb69dc Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Tue, 3 May 2022 11:09:14 -0700 Subject: [PATCH] Check that nullable annotations are from org.springframework.lang Fix a few incorrect nullable annotation imports and add a checkstyle rule to ensure they don't return. Closes gh-28410 --- .../org/aopalliance/intercept/ConstructorInterceptor.java | 6 +++--- .../org/aopalliance/intercept/ConstructorInvocation.java | 6 +++--- .../main/java/org/aopalliance/intercept/Invocation.java | 6 +++--- .../main/java/org/aopalliance/intercept/Joinpoint.java | 8 ++++---- .../java/org/aopalliance/intercept/MethodInterceptor.java | 8 ++++---- .../java/org/aopalliance/intercept/MethodInvocation.java | 6 +++--- .../aot/test/generator/file/DynamicFiles.java | 3 ++- .../aot/test/generator/file/ResourceFiles.java | 3 ++- .../aot/test/generator/file/SourceFile.java | 4 ++-- .../aot/test/generator/file/SourceFiles.java | 2 +- src/checkstyle/checkstyle-suppressions.xml | 3 +++ src/checkstyle/checkstyle.xml | 2 +- 12 files changed, 31 insertions(+), 26 deletions(-) diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInterceptor.java b/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInterceptor.java index 8ac8f65ca3f..3a074fd76e3 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInterceptor.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2022 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. @@ -16,7 +16,7 @@ package org.aopalliance.intercept; -import javax.annotation.Nonnull; +import org.springframework.lang.NonNull; /** * Intercepts the construction of a new object. @@ -56,7 +56,7 @@ public interface ConstructorInterceptor extends Interceptor { * @throws Throwable if the interceptors or the target object * throws an exception */ - @Nonnull + @NonNull Object construct(ConstructorInvocation invocation) throws Throwable; } diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInvocation.java b/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInvocation.java index 72951383e95..c63caef3c44 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInvocation.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/ConstructorInvocation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -18,7 +18,7 @@ package org.aopalliance.intercept; import java.lang.reflect.Constructor; -import javax.annotation.Nonnull; +import org.springframework.lang.NonNull; /** * Description of an invocation to a constructor, given to an @@ -38,7 +38,7 @@ public interface ConstructorInvocation extends Invocation { * {@link Joinpoint#getStaticPart()} method (same result). * @return the constructor being called */ - @Nonnull + @NonNull Constructor getConstructor(); } diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/Invocation.java b/spring-aop/src/main/java/org/aopalliance/intercept/Invocation.java index 96caaefefe0..bd316a9dd77 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/Invocation.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/Invocation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2022 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. @@ -16,7 +16,7 @@ package org.aopalliance.intercept; -import javax.annotation.Nonnull; +import org.springframework.lang.NonNull; /** * This interface represents an invocation in the program. @@ -34,7 +34,7 @@ public interface Invocation extends Joinpoint { * array to change the arguments. * @return the argument of the invocation */ - @Nonnull + @NonNull Object[] getArguments(); } diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/Joinpoint.java b/spring-aop/src/main/java/org/aopalliance/intercept/Joinpoint.java index 480d9f087cf..56a2b771187 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/Joinpoint.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/Joinpoint.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2022 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. @@ -18,8 +18,8 @@ package org.aopalliance.intercept; import java.lang.reflect.AccessibleObject; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; /** * This interface represents a generic runtime joinpoint (in the AOP @@ -65,7 +65,7 @@ public interface Joinpoint { *

The static part is an accessible object on which a chain of * interceptors are installed. */ - @Nonnull + @NonNull AccessibleObject getStaticPart(); } diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java index 9188e25e1d0..8b327568b68 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2022 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. @@ -16,8 +16,8 @@ package org.aopalliance.intercept; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; /** * Intercepts calls on an interface on its way to the target. These @@ -56,6 +56,6 @@ public interface MethodInterceptor extends Interceptor { * throws an exception */ @Nullable - Object invoke(@Nonnull MethodInvocation invocation) throws Throwable; + Object invoke(@NonNull MethodInvocation invocation) throws Throwable; } diff --git a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInvocation.java b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInvocation.java index f1f511bea4c..78a2d44cbcb 100644 --- a/spring-aop/src/main/java/org/aopalliance/intercept/MethodInvocation.java +++ b/spring-aop/src/main/java/org/aopalliance/intercept/MethodInvocation.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2022 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. @@ -18,7 +18,7 @@ package org.aopalliance.intercept; import java.lang.reflect.Method; -import javax.annotation.Nonnull; +import org.springframework.lang.NonNull; /** * Description of an invocation to a method, given to an interceptor @@ -38,7 +38,7 @@ public interface MethodInvocation extends Invocation { * {@link Joinpoint#getStaticPart()} method (same result). * @return the method being called */ - @Nonnull + @NonNull Method getMethod(); } diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFiles.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFiles.java index a0e26fc9ffb..4edff34ecc8 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFiles.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFiles.java @@ -23,7 +23,8 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.stream.Stream; -import javax.annotation.Nullable; +import org.springframework.lang.Nullable; + /** * Internal class used by {@link SourceFiles} and {@link ResourceFiles} to diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/ResourceFiles.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/ResourceFiles.java index 6e3b62829c8..c301193fccf 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/ResourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/ResourceFiles.java @@ -19,7 +19,8 @@ package org.springframework.aot.test.generator.file; import java.util.Iterator; import java.util.stream.Stream; -import javax.annotation.Nullable; +import org.springframework.lang.Nullable; + /** * An immutable collection of {@link ResourceFile} instances. diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFile.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFile.java index 5a7d4fe0dfa..f84b13208c0 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFile.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFile.java @@ -18,8 +18,6 @@ package org.springframework.aot.test.generator.file; import java.io.StringReader; -import javax.annotation.Nullable; - import com.thoughtworks.qdox.JavaProjectBuilder; import com.thoughtworks.qdox.model.JavaClass; import com.thoughtworks.qdox.model.JavaPackage; @@ -27,6 +25,8 @@ import com.thoughtworks.qdox.model.JavaSource; import org.assertj.core.api.AssertProvider; import org.assertj.core.util.Strings; +import org.springframework.lang.Nullable; + /** * {@link DynamicFile} that holds Java source code and provides * {@link SourceFileAssert} support. Usually created from an AOT generated type, diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFiles.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFiles.java index e9eaf3e463b..b5d54ccfdd2 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFiles.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/SourceFiles.java @@ -19,7 +19,7 @@ package org.springframework.aot.test.generator.file; import java.util.Iterator; import java.util.stream.Stream; -import javax.annotation.Nullable; +import org.springframework.lang.Nullable; /** * An immutable collection of {@link SourceFile} instances. diff --git a/src/checkstyle/checkstyle-suppressions.xml b/src/checkstyle/checkstyle-suppressions.xml index 6e27de7f072..b0a4d983741 100644 --- a/src/checkstyle/checkstyle-suppressions.xml +++ b/src/checkstyle/checkstyle-suppressions.xml @@ -27,6 +27,9 @@ + + + diff --git a/src/checkstyle/checkstyle.xml b/src/checkstyle/checkstyle.xml index 3ea64aef027..d588b785849 100644 --- a/src/checkstyle/checkstyle.xml +++ b/src/checkstyle/checkstyle.xml @@ -106,7 +106,7 @@ + value="^reactor\.core\.support\.Assert,^org\.slf4j\.LoggerFactory,^(?!org\.springframework).*(NonNull|Nonnull|NonNullApi|NonNullFields|Nullable)$" />