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
This commit is contained in:
Phillip Webb 2022-05-03 11:09:14 -07:00
parent 68bb4023eb
commit 63b129a3f7
12 changed files with 31 additions and 26 deletions

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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();
}

View File

@ -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 {
* <p>The static part is an accessible object on which a chain of
* interceptors are installed.
*/
@Nonnull
@NonNull
AccessibleObject getStaticPart();
}

View File

@ -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;
}

View File

@ -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();
}

View File

@ -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

View File

@ -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.

View File

@ -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,

View File

@ -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.

View File

@ -27,6 +27,9 @@
<!-- spring-core -->
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]asm[\\/]" checks=".*" />
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]cglib[\\/]" checks=".*" />
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]lang[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]core[\\/]annotation[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]org[\\/]springframework[\\/]core[\\/]annotation[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
<suppress files="ByteArrayEncoder" checks="SpringLambda" />
<suppress files="SocketUtils" checks="HideUtilityClassConstructor" />
<suppress files="ResolvableType" checks="FinalClass" />

View File

@ -106,7 +106,7 @@
<property name="id" value="bannedImports"/>
<property name="regexp" value="true" />
<property name="illegalClasses"
value="^reactor\.core\.support\.Assert,^org\.slf4j\.LoggerFactory" />
value="^reactor\.core\.support\.Assert,^org\.slf4j\.LoggerFactory,^(?!org\.springframework).*(NonNull|Nonnull|NonNullApi|NonNullFields|Nullable)$" />
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck">
<property name="id" value="bannedJUnit3Imports"/>