Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to JSpecify annotations for nullability constraints. #3781

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .mvn/jvm.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED
--add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED
35 changes: 30 additions & 5 deletions org/antlr/v4/tool/templates/codegen/Java/Java.stg
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ ParserFile(file, parser, namedActions, contextSuperClass) ::= <<
package <file.genPackage>;
<endif>
<namedActions.header>

import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import org.jspecify.annotations.NullUnmarked;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
import jakarta.annotation.Generated;


<parser>
>>
Expand All @@ -67,11 +71,15 @@ package <file.genPackage>;
<endif>
<header>
import org.antlr.v4.runtime.tree.ParseTreeListener;
import org.jspecify.annotations.NullUnmarked;
import jakarta.annotation.Generated;

/**
* This interface defines a complete listener for a parse tree produced by
* {@link <file.parserName>}.
*/
@NullUnmarked
@Generated("<file.grammarName>Listener")
interface <file.grammarName>Listener extends ParseTreeListener {
<file.listenerNames:{lname |
/**
Expand Down Expand Up @@ -103,17 +111,20 @@ BaseListenerFile(file, header, namedActions) ::= <<
package <file.genPackage>;
<endif>
<header>

import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.TerminalNode;
import org.jspecify.annotations.NullUnmarked;
import jakarta.annotation.Generated;

/**
* This class provides an empty implementation of {@link <file.grammarName>Listener},
* which can be extended to create a listener which only needs to handle a subset
* of the available methods.
*/
@SuppressWarnings("CheckReturnValue")
@NullUnmarked
@Generated("<file.grammarName>BaseListener")
@SuppressWarnings({ "CheckReturnValue", "NullAway" })
class <file.grammarName>BaseListener implements <file.grammarName>Listener {
<file.listenerNames:{lname |
/**
Expand Down Expand Up @@ -163,6 +174,8 @@ package <file.genPackage>;
<endif>
<header>
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
import org.jspecify.annotations.NullUnmarked;
import jakarta.annotation.Generated;

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

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

Parser_(parser, funcs, atn, sempredFuncs, ctor, superClass) ::= <<
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
@NullUnmarked
@Generated("<parser.name>")
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "NullAway"})
class <parser.name> extends <superClass; null="Parser"> {
// Customization: Suppress version check
// static { RuntimeMetaData.checkVersion("<file.ANTLRVersion>", RuntimeMetaData.VERSION); }
Expand Down Expand Up @@ -895,12 +916,16 @@ import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.misc.*;
import org.jspecify.annotations.NullUnmarked;
import jakarta.annotation.Generated;

<lexer>
>>

Lexer(lexer, atn, actionFuncs, sempredFuncs, superClass) ::= <<
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue"})
@NullUnmarked
@Generated("<lexer.name>")
@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast", "CheckReturnValue", "NullAway"})
class <lexer.name> extends <superClass; null="Lexer"> {
// Customization: Suppress version check
// static { RuntimeMetaData.checkVersion("<lexerFile.ANTLRVersion>", RuntimeMetaData.VERSION); }
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3745-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data JPA Parent</name>
Expand Down
4 changes: 2 additions & 2 deletions spring-data-envers/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-envers</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3745-SNAPSHOT</version>

<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3745-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Classes for Envers Repositories configuration support.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.data.envers.repository.config;
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.hibernate.envers.DefaultRevisionEntity;

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

private Class<?> revisionEntityClass;
private @Nullable Class<?> revisionEntityClass;

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

super(entityManager);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Spring Data JPA specific converter infrastructure.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.data.envers.repository.support;
2 changes: 1 addition & 1 deletion spring-data-jpa-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3745-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
89 changes: 87 additions & 2 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3745-SNAPSHOT</version>

<name>Spring Data JPA</name>
<description>Spring Data module for JPA repositories.</description>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa-parent</artifactId>
<version>4.0.0-SNAPSHOT</version>
<version>4.0.x-GH-3745-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -420,4 +420,89 @@
</plugins>
</build>

<profiles>
<profile>
<id>nullaway</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
<version>${querydsl}</version>
<classifier>jakarta</classifier>
</path>
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>${hibernate}</version>
</path>
<path>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate}</version>
</path>
<path>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh}</version>
</path>
<path>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>${jakarta-persistence-api}</version>
</path>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone}</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${nullaway}</version>
</path>
</annotationProcessorPaths>
</configuration>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<compilerArgs>
<arg>-XDcompilePolicy=simple</arg>
<arg>--should-stop=ifError=FLOW</arg>
<arg>-Xplugin:ErrorProne -XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true -XepOpt:NullAway:TreatGeneratedAsUnannotated=true -XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract</arg>
</compilerArgs>
</configuration>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@
import java.util.Set;

import org.springframework.dao.InvalidDataAccessApiUsageException;

import org.jspecify.annotations.Nullable;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.ExampleMatcher.PropertyValueTransformer;
import org.springframework.data.jpa.repository.query.EscapeCharacter;
import org.springframework.data.support.ExampleMatcherAccessor;
import org.springframework.data.util.DirectFieldAccessFallbackBeanWrapper;
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;
Expand Down Expand Up @@ -78,8 +80,7 @@ public class QueryByExamplePredicateBuilder {
* @param example must not be {@literal null}.
* @return {@literal null} indicates no {@link Predicate}.
*/
@Nullable
public static <T> Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example) {
public static <T> @Nullable Predicate getPredicate(Root<T> root, CriteriaBuilder cb, Example<T> example) {
return getPredicate(root, cb, example, EscapeCharacter.DEFAULT);
}

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

Assert.notNull(root, "Root must not be null");
Expand Down Expand Up @@ -238,7 +238,6 @@ private static class PathNode {

String name;
@Nullable PathNode parent;
List<PathNode> siblings = new ArrayList<>();
@Nullable Object value;

PathNode(String edge, @Nullable PathNode parent, @Nullable Object value) {
Expand All @@ -250,9 +249,7 @@ private static class PathNode {

PathNode add(String attribute, @Nullable Object value) {

PathNode node = new PathNode(attribute, this, value);
siblings.add(node);
return node;
return new PathNode(attribute, this, value);
}

boolean spansCycle() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Spring Data JPA specific converter infrastructure.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.data.jpa.convert;
Loading