GH-110 - Switch to JSpecify for nullness analysis.

This commit is contained in:
Oliver Drotbohm
2025-02-14 15:39:01 +01:00
parent d3c31d46ed
commit e5021d0765
7 changed files with 96 additions and 6 deletions

10
.mvn/jvm.config Normal file
View File

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

View File

@@ -17,6 +17,7 @@ package org.springframework.plugin.core.config;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
@@ -58,8 +59,13 @@ public class PluginRegistriesBeanDefinitionRegistrar implements ImportBeanDefini
return;
}
@Nullable
Class<?>[] types = (Class<?>[]) annotationAttributes.get("value");
if (types == null) {
return;
}
for (Class<?> type : types) {
RootBeanDefinition beanDefinition = new RootBeanDefinition(PluginRegistryFactoryBean.class);

View File

@@ -1,5 +1,5 @@
/**
* This package contains configuration support classes to ease registry configuration with Spring namespaces.
*/
@org.jspecify.annotations.NullMarked
package org.springframework.plugin.core.config;

View File

@@ -2,5 +2,5 @@
* This package contains the core plugin API. It allows other modules implementing components that extend functionality
* defined by a plugin interface. Plugin clients can be equipped with plugin implementations.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.plugin.core;

View File

@@ -22,6 +22,8 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.jspecify.annotations.NonNull;
import org.jspecify.annotations.Nullable;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
@@ -30,8 +32,6 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.ListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.plugin.core.OrderAwarePluginRegistry;
import org.springframework.plugin.core.Plugin;
import org.springframework.plugin.core.PluginRegistry;
@@ -46,7 +46,7 @@ public class PluginRegistryFactoryBean<T extends Plugin<S>, S>
private Collection<Class<?>> exclusions = Collections.emptySet();
private @Nullable Class<T> type;
private ListableBeanFactory factory;
private @Nullable ListableBeanFactory factory;
/**
* Configures the type of beans to be looked up.
@@ -103,6 +103,12 @@ public class PluginRegistryFactoryBean<T extends Plugin<S>, S>
throw new IllegalStateException("No plugin type configured!");
}
var factory = this.factory;
if (factory == null) {
throw new IllegalStateException("No ListableBeanFactory configured!");
}
Supplier<List<? extends T>> plugins = () -> factory.getBeanProvider(type, false)
.stream(Predicate.not(exclusions::contains))
.toList();

View File

@@ -2,5 +2,5 @@
* This package contains support classes to create bean lists or plugin registry instances out of beans implementing a
* certain interface.
*/
@org.springframework.lang.NonNullApi
@org.jspecify.annotations.NullMarked
package org.springframework.plugin.core.support;

68
pom.xml
View File

@@ -46,10 +46,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<assertj.version>3.23.1</assertj.version>
<errorprone.version>2.36.0</errorprone.version>
<junit.version>5.9.1</junit.version>
<logback.version>1.4.4</logback.version>
<mockito.version>4.9.0</mockito.version>
<nullaway.version>0.12.3</nullaway.version>
<spring.version>7.0.0-SNAPSHOT</spring.version>
<source.level>17</source.level>
<slf4j.version>2.0.3</slf4j.version>
<artifactory-maven-plugin.version>3.4.0</artifactory-maven-plugin.version>
@@ -187,6 +190,65 @@
</distributionManagement>
</profile>
<profile>
<id>nullaway</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${source.level}</release>
<showWarnings>true</showWarnings>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone.version}</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${nullaway.version}</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: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>
<dependencies>
@@ -228,6 +290,12 @@
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>