Skip to content

Commit 99e54fe

Browse files
committed
Ensure all packages declare package-info.java with null-safety annotations
This commit picks up where the two previous commits left off. Specifically, this commit: - Removes the "severity=warning" configuration to ensure that violations actually fail the build. - Fixes regular expressions for suppressions by matching forward slashes using `[\\/]` instead of `\/`. - Moves the configuration for newly introduced checks to locations in checkstyle.xml that align with the existing organization of that file. - Renames the IDs for RegexpSinglelineJava checks from javaDocPackageNonNullApiAnnotation/javaDocPackageNonNullFieldsAnnotation to packageLevelNonNullApiAnnotation/packageLevelNonNullFieldsAnnotation, respectively, since these checks are not related to Javadoc. - Simplifies the null-safety annotation checks to match against imported annotation types, which enforces consistency across package-info.java files for the annotation declarations. - Simplifies the RegEx for JavadocPackage suppressions to only exclude packages not under src/main/java (vs src/main) and those in the framework-docs module. - Consistently suppresses all checks for the `asm`, `cglib`, `objenesis`, and `javapoet` packages in spring-core. - Adds explicit suppressions for null-safety annotations for the `lang` package in spring-core. - Adds explicit suppressions for null-safety annotations for the `org.aopalliance` package in spring-aop. - Revises the RegEx for null-safety annotation suppressions to only exclude package-info.java files not under src/main/java and additionally to exclude package-info.java files in the framework-docs module as well as those in the spring-context-indexer, spring-instrument, and spring-jcl modules. - Adds all missing package-info.java files. - Adds null-safety annotations to package-info.java files where appropriate. Closes gh-30069
1 parent 7e32f50 commit 99e54fe

File tree

22 files changed

+165
-50
lines changed

22 files changed

+165
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Support for dynamic, refreshable {@link org.springframework.aop.TargetSource}
3+
* implementations for use with Spring AOP.
4+
*/
5+
@NonNullApi
6+
@NonNullFields
7+
package org.springframework.aop.target.dynamic;
8+
9+
import org.springframework.lang.NonNullApi;
10+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* Various {@link org.springframework.aop.TargetSource} implementations for use
3+
* with Spring AOP.
4+
*/
5+
@NonNullApi
6+
@NonNullFields
7+
package org.springframework.aop.target;
8+
9+
import org.springframework.lang.NonNullApi;
10+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* AspectJ-based dependency injection support.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.beans.factory.aspectj;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* AspectJ-based caching support.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.cache.aspectj;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* AspectJ-based dependency injection support driven by the
3+
* {@link org.springframework.beans.factory.annotation.Configurable @Configurable}
4+
* annotation.
5+
*/
6+
@NonNullApi
7+
@NonNullFields
8+
package org.springframework.context.annotation.aspectj;
9+
10+
import org.springframework.lang.NonNullApi;
11+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* AspectJ-based scheduling support.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.scheduling.aspectj;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* AspectJ-based transaction management support.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.transaction.aspectj;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
22
* Support package for Groovy-based bean definitions.
33
*/
4+
@NonNullApi
5+
@NonNullFields
46
package org.springframework.beans.factory.groovy;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Core package for Spring Framework's scanned component index.
3+
*/
4+
package org.springframework.context.index.processor;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/**
2+
* Core package for byte code instrumentation.
3+
*/
4+
package org.springframework.instrument;

spring-jdbc/src/main/java/org/springframework/jdbc/support/incrementer/package-info.java

+5
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@
44
*
55
* <p>Can be used independently, for example in custom JDBC access code.
66
*/
7+
@NonNullApi
8+
@NonNullFields
79
package org.springframework.jdbc.support.incrementer;
10+
11+
import org.springframework.lang.NonNullApi;
12+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* Provides extensible support for initializing databases through scripts.
33
*/
4-
@org.springframework.lang.NonNullApi
5-
@org.springframework.lang.NonNullFields
4+
@NonNullApi
5+
@NonNullFields
66
package org.springframework.r2dbc.connection.init;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
/**
22
* Core domain types around DatabaseClient.
33
*/
4-
@org.springframework.lang.NonNullApi
5-
@org.springframework.lang.NonNullFields
4+
@NonNullApi
5+
@NonNullFields
66
package org.springframework.r2dbc.core;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
22
* Test execution event annotations for the <em>Spring TestContext Framework</em>.
33
*/
4+
@NonNullApi
5+
@NonNullFields
46
package org.springframework.test.context.event.annotation;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
22
* Test event support classes for the <em>Spring TestContext Framework</em>.
33
*/
4+
@NonNullApi
5+
@NonNullFields
46
package org.springframework.test.context.event;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;

spring-test/src/main/java/org/springframework/test/package-info.java

-6
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
22
* Helper classes for unit tests based on Spring's web support.
33
*/
4+
@NonNullApi
5+
@NonNullFields
46
package org.springframework.test.web;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* CBOR encoder and decoder support.
3+
*/
4+
@NonNullApi
5+
@NonNullFields
6+
package org.springframework.http.codec.cbor;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
/**
22
* Support for asynchronous request processing.
33
*/
4+
@NonNullApi
5+
@NonNullFields
46
package org.springframework.web.context.request.async;
7+
8+
import org.springframework.lang.NonNullApi;
9+
import org.springframework.lang.NonNullFields;

spring-webflux/src/main/java/org/springframework/web/reactive/result/condition/package-info.java

+5
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,9 @@
22
* {@link org.springframework.web.reactive.result.condition.RequestCondition}
33
* and implementations for matching requests based on different criteria.
44
*/
5+
@NonNullApi
6+
@NonNullFields
57
package org.springframework.web.reactive.result.condition;
8+
9+
import org.springframework.lang.NonNullApi;
10+
import org.springframework.lang.NonNullFields;

src/checkstyle/checkstyle-suppressions.xml

+14-16
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@
22
<!DOCTYPE suppressions PUBLIC "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN" "https://checkstyle.org/dtds/suppressions_1_2.dtd">
33
<suppressions>
44

5-
<!-- global -->
5+
<!-- Global: generated sources -->
6+
<suppress files="[\\/]build[\\/]generated[\\/]sources[\\/]" checks=".*"/>
7+
8+
<!-- Global: package-info.java -->
9+
<suppress files="(^(?!.+[\\/]src[\\/]main[\\/]java[\\/]).*)|(.*framework-docs.*)" checks="JavadocPackage" />
10+
<suppress files="(^(?!.+[\\/]src[\\/]main[\\/]java[\\/].*package-info\.java))|(.*framework-docs.*)|(.*spring-(context-indexer|instrument|jcl).*)" checks="RegexpSinglelineJava" id="packageLevelNonNullApiAnnotation" />
11+
<suppress files="(^(?!.+[\\/]src[\\/]main[\\/]java[\\/].*package-info\.java))|(.*framework-docs.*)|(.*spring-(context-indexer|instrument|jcl).*)" checks="RegexpSinglelineJava" id="packageLevelNonNullFieldsAnnotation" />
12+
13+
<!-- Global: tests and test fixtures -->
614
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]" checks="AnnotationLocation|AnnotationUseStyle|AtclauseOrder|AvoidNestedBlocks|FinalClass|HideUtilityClassConstructor|InnerTypeLast|JavadocStyle|JavadocType|JavadocVariable|LeftCurly|MultipleVariableDeclarations|NeedBraces|OneTopLevelClass|OuterTypeFilename|RequireThis|SpringCatch|SpringJavadoc|SpringNoThis"/>
715
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]org[\\/]springframework[\\/].+(Tests|Suite)" checks="IllegalImport" id="bannedJUnitJupiterImports"/>
816
<suppress files="[\\/]src[\\/](test|testFixtures)[\\/]java[\\/]" checks="SpringJUnit5" message="should not be public"/>
9-
<!-- generated sources -->
10-
<suppress files="[\\/]build[\\/]generated[\\/]sources[\\/]" checks=".*"/>
1117

1218
<!-- JMH benchmarks -->
1319
<suppress files="[\\/]src[\\/]jmh[\\/]java[\\/]org[\\/]springframework[\\/]" checks="JavadocVariable|JavadocStyle|InnerTypeLast"/>
@@ -17,6 +23,8 @@
1723

1824
<!-- spring-aop -->
1925
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]aopalliance[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
26+
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]aopalliance[\\/]" checks="RegexpSinglelineJava" id="packageLevelNonNullApiAnnotation"/>
27+
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]aopalliance[\\/]" checks="RegexpSinglelineJava" id="packageLevelNonNullFieldsAnnotation"/>
2028

2129
<!-- spring-beans -->
2230
<suppress files="TypeMismatchException" checks="MutableException"/>
@@ -31,9 +39,10 @@
3139
<suppress files="SpringAtInjectTckTests" checks="IllegalImportCheck" id="bannedJUnit3Imports"/>
3240

3341
<!-- spring-core -->
34-
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]asm[\\/]" checks=".*"/>
35-
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]cglib[\\/]" checks=".*"/>
42+
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/](asm|cglib|objenesis|javapoet)[\\/]" checks=".*"/>
3643
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]lang[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
44+
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]lang[\\/]" checks="RegexpSinglelineJava" id="packageLevelNonNullApiAnnotation" />
45+
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]lang[\\/]" checks="RegexpSinglelineJava" id="packageLevelNonNullFieldsAnnotation" />
3746
<suppress files="[\\/]src[\\/]main[\\/]java[\\/]org[\\/]springframework[\\/]core[\\/]annotation[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
3847
<suppress files="[\\/]src[\\/]test[\\/]java[\\/]org[\\/]springframework[\\/]core[\\/]annotation[\\/]" checks="IllegalImport" id="bannedImports" message="javax"/>
3948
<suppress files="ByteArrayEncoder" checks="SpringLambda"/>
@@ -130,15 +139,4 @@
130139
<suppress files="sockjs[\\/]transport[\\/]TransportType" checks="JavadocVariable"/>
131140
<suppress files="src[\\/]test[\\/]java[\\/]org[\\/]springframework[\\/]web[\\/]reactive[\\/]protobuf[\\/].*" checks=".*"/>
132141

133-
<!-- Suppress JavadocPackage checks and package null safety annotations on packages outside of src/main-->
134-
<!-- And outside 'framework-docs' module-->
135-
<!-- And outside 'spring-core/src/main/java/org/springframework/asm' package-->
136-
<!-- And outside 'spring-core/src/main/java/org/springframework/cglib' package-->
137-
<!-- And outside 'spring-core/src/main/java/org/springframework/objenesis' package-->
138-
<!-- And outside 'spring-core/src/main/java/org/springframework/javapoet' package-->
139-
<!-- And outside 'spring-core/src/main/java/org/springframework/lang' package-->
140-
<suppress checks="JavadocPackage" files="(^(?!.*src[\\/]main[\\/]).*)|(.*framework-docs.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/asm.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/cglib.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/objenesis.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/javapoet.*)|(.*spring-core\/src\/main\/java\/org\/springframework\/lang.*)"/>
141-
<suppress checks="RegexpSinglelineJava" files="^(?!.*(package-info.java))" id="javaDocPackageNonNullFieldsAnnotation"/>
142-
<suppress checks="RegexpSinglelineJava" files="^(?!.*(package-info.java))" id="javaDocPackageNonNullApiAnnotation"/>
143-
144142
</suppressions>

src/checkstyle/checkstyle.xml

+22-24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0"?>
22
<!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd">
33
<module name="com.puppycrawl.tools.checkstyle.Checker">
4+
45
<!-- Suppressions -->
56
<module name="SuppressionFilter">
67
<property name="file" value="${config_loc}/checkstyle-suppressions.xml"/>
@@ -14,9 +15,29 @@
1415
<property name="packageInfoHeaderType" value="none"/>
1516
</module>
1617
<module name="com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck"/>
18+
<module name="JavadocPackage" /><!-- package-info.java -->
1719

1820
<!-- TreeWalker Checks -->
1921
<module name="com.puppycrawl.tools.checkstyle.TreeWalker">
22+
23+
<!-- Package-level null-safety annotations -->
24+
<module name="RegexpSinglelineJavaCheck">
25+
<property name="id" value="packageLevelNonNullApiAnnotation"/>
26+
<property name="format" value="@NonNullApi"/>
27+
<property name="minimum" value="1"/>
28+
<property name="maximum" value="1"/>
29+
<property name="message" value="package-info.java is missing required null-safety annotation @NonNullApi."/>
30+
<property name="ignoreComments" value="true"/>
31+
</module>
32+
<module name="RegexpSinglelineJavaCheck">
33+
<property name="id" value="packageLevelNonNullFieldsAnnotation"/>
34+
<property name="format" value="@NonNullFields"/>
35+
<property name="minimum" value="1"/>
36+
<property name="maximum" value="1"/>
37+
<property name="message" value="package-info.java is missing required null-safety annotation @NonNullFields."/>
38+
<property name="ignoreComments" value="true"/>
39+
</module>
40+
2041
<!-- Annotations -->
2142
<module name="com.puppycrawl.tools.checkstyle.checks.annotation.AnnotationUseStyleCheck">
2243
<property name="elementStyle" value="compact"/>
@@ -239,30 +260,7 @@
239260
<module name="io.spring.javaformat.checkstyle.check.SpringCatchCheck"/>
240261
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck"/>
241262
<module name="io.spring.javaformat.checkstyle.check.SpringJUnit5Check"/>
242-
<!--package-info should contain null-safety annotations-->
243-
<!--These two modules will fail to detect multiline annotations-->
244-
<module name="RegexpSinglelineJavaCheck">
245-
<property name="id" value="javaDocPackageNonNullFieldsAnnotation"/>
246-
<property name="format" value="(@NonNullFields|@org\.springframework\.lang\.NonNullFields)"/>
247-
<property name="minimum" value="1"/>
248-
<property name="maximum" value="1"/>
249-
<property name="severity" value="warning"/>
250-
<property name="message" value="package-info.java is missing required null-safety annotation @NonNullFields."/>
251-
<property name="ignoreComments" value="true"/>
252-
</module>
253-
<module name="RegexpSinglelineJavaCheck">
254-
<property name="id" value="javaDocPackageNonNullApiAnnotation"/>
255-
<property name="format" value="(@NonNullApi|@org\.springframework\.lang\.NonNullApi)"/>
256-
<property name="minimum" value="1"/>
257-
<property name="maximum" value="1"/>
258-
<property name="severity" value="warning"/>
259-
<property name="message" value="package-info.java is missing required null-safety annotation @NonNullApi."/>
260-
<property name="ignoreComments" value="true"/>
261-
</module>
262-
</module>
263263

264-
<!--package-info checker -->
265-
<module name="JavadocPackage">
266-
<property name="severity" value="warning"/>
267264
</module>
265+
268266
</module>

0 commit comments

Comments
 (0)