Skip to content

Commit c502e79

Browse files
christophstroblmp911de
authored andcommitted
Migrate to JSpecify annotations for nullability constraints.
Closes #3745 Original pull request: #3781
1 parent 886efe0 commit c502e79

File tree

142 files changed

+691
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+691
-506
lines changed

.mvn/jvm.config

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
2+
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
3+
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
4+
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
5+
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
6+
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
7+
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
8+
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
9+
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
10+
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED

org/antlr/v4/tool/templates/codegen/Java/Java.stg

+30-5
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
4848
package <file.genPackage>;
4949
<endif>
5050
<namedActions.header>
51+
5152
import org.antlr.v4.runtime.atn.*;
5253
import org.antlr.v4.runtime.dfa.DFA;
5354
import org.antlr.v4.runtime.*;
5455
import org.antlr.v4.runtime.misc.*;
5556
import org.antlr.v4.runtime.tree.*;
57+
import org.jspecify.annotations.NullUnmarked;
5658
import java.util.List;
5759
import java.util.Iterator;
5860
import java.util.ArrayList;
61+
import jakarta.annotation.Generated;
62+
5963

6064
<parser>
6165
>>
@@ -67,11 +71,15 @@ package <file.genPackage>;
6771
<endif>
6872
<header>
6973
import org.antlr.v4.runtime.tree.ParseTreeListener;
74+
import org.jspecify.annotations.NullUnmarked;
75+
import jakarta.annotation.Generated;
7076

7177
/**
7278
* This interface defines a complete listener for a parse tree produced by
7379
* {@link <file.parserName>}.
7480
*/
81+
@NullUnmarked
82+
@Generated("<file.grammarName>Listener")
7583
interface <file.grammarName>Listener extends ParseTreeListener {
7684
<file.listenerNames:{lname |
7785
/**
@@ -103,17 +111,20 @@ BaseListenerFile(file, header, namedActions) ::= <<
103111
package <file.genPackage>;
104112
<endif>
105113
<header>
106-
107114
import org.antlr.v4.runtime.ParserRuleContext;
108115
import org.antlr.v4.runtime.tree.ErrorNode;
109116
import org.antlr.v4.runtime.tree.TerminalNode;
117+
import org.jspecify.annotations.NullUnmarked;
118+
import jakarta.annotation.Generated;
110119

111120
/**
112121
* This class provides an empty implementation of {@link <file.grammarName>Listener},
113122
* which can be extended to create a listener which only needs to handle a subset
114123
* of the available methods.
115124
*/
116-
@SuppressWarnings("CheckReturnValue")
125+
@NullUnmarked
126+
@Generated("<file.grammarName>BaseListener")
127+
@SuppressWarnings({ "CheckReturnValue", "NullAway" })
117128
class <file.grammarName>BaseListener implements <file.grammarName>Listener {
118129
<file.listenerNames:{lname |
119130
/**
@@ -163,6 +174,8 @@ package <file.genPackage>;
163174
<endif>
164175
<header>
165176
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
177+
import org.jspecify.annotations.NullUnmarked;
178+
import jakarta.annotation.Generated;
166179

167180
/**
168181
* This interface defines a complete generic visitor for a parse tree produced
@@ -171,6 +184,8 @@ import org.antlr.v4.runtime.tree.ParseTreeVisitor;
171184
* @param \<T> The return type of the visit operation. Use {@link Void} for
172185
* operations with no return type.
173186
*/
187+
@NullUnmarked
188+
@Generated("<file.grammarName>Visitor")
174189
interface <file.grammarName>Visitor\<T> extends ParseTreeVisitor\<T> {
175190
<file.visitorNames:{lname |
176191
/**
@@ -194,6 +209,8 @@ package <file.genPackage>;
194209
<endif>
195210
<header>
196211
import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
212+
import org.jspecify.annotations.NullUnmarked;
213+
import jakarta.annotation.Generated;
197214

198215
/**
199216
* This class provides an empty implementation of {@link <file.grammarName>Visitor},
@@ -203,7 +220,9 @@ import org.antlr.v4.runtime.tree.AbstractParseTreeVisitor;
203220
* @param \<T> The return type of the visit operation. Use {@link Void} for
204221
* operations with no return type.
205222
*/
206-
@SuppressWarnings("CheckReturnValue")
223+
@NullUnmarked
224+
@Generated("<file.grammarName>BaseVisitor")
225+
@SuppressWarnings({ "CheckReturnValue", "NullAway" })
207226
class <file.grammarName>BaseVisitor\<T> extends AbstractParseTreeVisitor\<T> implements <file.grammarName>Visitor\<T> {
208227
<file.visitorNames:{lname |
209228
/**
@@ -225,7 +244,9 @@ Parser(parser, funcs, atn, sempredFuncs, superClass) ::= <<
225244
>>
226245

227246
Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= <<
228-
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
247+
@NullUnmarked
248+
@Generated("<parser.name>")
249+
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "NullAway"})
229250
class <parser.name> extends <superClass; null="Parser"> {
230251
// Customization: Suppress version check
231252
// static { RuntimeMetaData.checkVersion("<file.ANTLRVersion>", RuntimeMetaData.VERSION); }
@@ -895,12 +916,16 @@ import org.antlr.v4.runtime.*;
895916
import org.antlr.v4.runtime.atn.*;
896917
import org.antlr.v4.runtime.dfa.DFA;
897918
import org.antlr.v4.runtime.misc.*;
919+
import org.jspecify.annotations.NullUnmarked;
920+
import jakarta.annotation.Generated;
898921

899922
<lexer>
900923
>>
901924

902925
Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
903-
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
926+
@NullUnmarked
927+
@Generated("<lexer.name>")
928+
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "NullAway"})
904929
class <lexer.name> extends <superClass; null="Lexer"> {
905930
// Customization: Suppress version check
906931
// static { RuntimeMetaData.checkVersion("<lexerFile.ANTLRVersion>", RuntimeMetaData.VERSION); }
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Classes for Envers Repositories configuration support.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.envers.repository.config;

spring-data-envers/src/main/java/org/springframework/data/envers/repository/support/EnversRevisionRepositoryFactoryBean.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import org.hibernate.envers.DefaultRevisionEntity;
2323

24+
import org.jspecify.annotations.Nullable;
2425
import org.springframework.beans.factory.FactoryBean;
2526
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
2627
import org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean;
@@ -39,7 +40,7 @@
3940
public class EnversRevisionRepositoryFactoryBean<T extends RevisionRepository<S, ID, N>, S, ID, N extends Number & Comparable<N>>
4041
extends JpaRepositoryFactoryBean<T, S, ID> {
4142

42-
private Class<?> revisionEntityClass;
43+
private @Nullable Class<?> revisionEntityClass;
4344

4445
/**
4546
* Creates a new {@link EnversRevisionRepositoryFactoryBean} for the given repository interface.
@@ -81,7 +82,7 @@ private static class RevisionRepositoryFactory<T, ID, N extends Number & Compara
8182
* @param entityManager must not be {@literal null}.
8283
* @param revisionEntityClass can be {@literal null}, will default to {@link DefaultRevisionEntity}.
8384
*/
84-
public RevisionRepositoryFactory(EntityManager entityManager, Class<?> revisionEntityClass) {
85+
public RevisionRepositoryFactory(EntityManager entityManager, @Nullable Class<?> revisionEntityClass) {
8586

8687
super(entityManager);
8788

Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Spring Data JPA specific converter infrastructure.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.envers.repository.support;

spring-data-jpa/pom.xml

+85
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,89 @@
420420
</plugins>
421421
</build>
422422

423+
<profiles>
424+
<profile>
425+
<id>nullaway</id>
426+
<build>
427+
<plugins>
428+
<plugin>
429+
<groupId>org.apache.maven.plugins</groupId>
430+
<artifactId>maven-compiler-plugin</artifactId>
431+
<configuration>
432+
<annotationProcessorPaths>
433+
<path>
434+
<groupId>com.querydsl</groupId>
435+
<artifactId>querydsl-apt</artifactId>
436+
<version>${querydsl}</version>
437+
<classifier>jakarta</classifier>
438+
</path>
439+
<path>
440+
<groupId>org.hibernate.orm</groupId>
441+
<artifactId>hibernate-jpamodelgen</artifactId>
442+
<version>${hibernate}</version>
443+
</path>
444+
<path>
445+
<groupId>org.hibernate.orm</groupId>
446+
<artifactId>hibernate-core</artifactId>
447+
<version>${hibernate}</version>
448+
</path>
449+
<path>
450+
<groupId>org.openjdk.jmh</groupId>
451+
<artifactId>jmh-generator-annprocess</artifactId>
452+
<version>${jmh}</version>
453+
</path>
454+
<path>
455+
<groupId>jakarta.persistence</groupId>
456+
<artifactId>jakarta.persistence-api</artifactId>
457+
<version>${jakarta-persistence-api}</version>
458+
</path>
459+
<path>
460+
<groupId>com.google.errorprone</groupId>
461+
<artifactId>error_prone_core</artifactId>
462+
<version>${errorprone}</version>
463+
</path>
464+
<path>
465+
<groupId>com.uber.nullaway</groupId>
466+
<artifactId>nullaway</artifactId>
467+
<version>${nullaway}</version>
468+
</path>
469+
</annotationProcessorPaths>
470+
</configuration>
471+
<executions>
472+
<execution>
473+
<id>default-compile</id>
474+
<phase>none</phase>
475+
</execution>
476+
<execution>
477+
<id>default-testCompile</id>
478+
<phase>none</phase>
479+
</execution>
480+
<execution>
481+
<id>java-compile</id>
482+
<phase>compile</phase>
483+
<goals>
484+
<goal>compile</goal>
485+
</goals>
486+
<configuration>
487+
<compilerArgs>
488+
<arg>-XDcompilePolicy=simple</arg>
489+
<arg>--should-stop=ifError=FLOW</arg>
490+
<arg>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:TreatGeneratedAsUnannotated=true -XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract</arg>
491+
</compilerArgs>
492+
</configuration>
493+
</execution>
494+
<execution>
495+
<id>java-test-compile</id>
496+
<phase>test-compile</phase>
497+
<goals>
498+
<goal>testCompile</goal>
499+
</goals>
500+
</execution>
501+
</executions>
502+
</plugin>
503+
</plugins>
504+
</build>
505+
</profile>
506+
</profiles>
507+
423508
</project>

spring-data-jpa/src/main/java/org/springframework/data/jpa/convert/QueryByExamplePredicateBuilder.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
import java.util.Set;
3434

3535
import org.springframework.dao.InvalidDataAccessApiUsageException;
36+
37+
import org.jspecify.annotations.Nullable;
3638
import org.springframework.data.domain.Example;
3739
import org.springframework.data.domain.ExampleMatcher;
3840
import org.springframework.data.domain.ExampleMatcher.PropertyValueTransformer;
3941
import org.springframework.data.jpa.repository.query.EscapeCharacter;
4042
import org.springframework.data.support.ExampleMatcherAccessor;
4143
import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper;
42-
import org.springframework.lang.Nullable;
4344
import org.springframework.util.Assert;
4445
import org.springframework.util.ClassUtils;
4546
import org.springframework.util.ObjectUtils;
@@ -78,8 +79,7 @@ public class QueryByExamplePredicateBuilder {
7879
* @param example must not be {@literal null}.
7980
* @return {@literal null} indicates no {@link Predicate}.
8081
*/
81-
@Nullable
82-
public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example) {
82+
public static <T> @Nullable Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example) {
8383
return getPredicate(root, cb, example, EscapeCharacter.DEFAULT);
8484
}
8585

@@ -92,8 +92,7 @@ public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Examp
9292
* @param escapeCharacter Must not be {@literal null}.
9393
* @return {@literal null} indicates no constraints
9494
*/
95-
@Nullable
96-
public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example,
95+
public static <T> @Nullable Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example,
9796
EscapeCharacter escapeCharacter) {
9897

9998
Assert.notNull(root, "Root must not be null");
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
22
* Spring Data JPA specific converter infrastructure.
33
*/
4-
@org.springframework.lang.NonNullApi
4+
@org.jspecify.annotations.NullMarked
55
package org.springframework.data.jpa.convert;

0 commit comments

Comments
 (0)