Skip to content

Migrate to JSpecify annotations for nullability constraints #4864

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

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
49 changes: 10 additions & 39 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
<spring-javaformat-maven-plugin.version>0.0.47</spring-javaformat-maven-plugin.version>
<error-prone.version>2.38.0</error-prone.version>
<nullaway.version>0.12.7</nullaway.version>
</properties>

<build>
Expand Down Expand Up @@ -187,45 +188,10 @@
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
<compilerArg>
-Xplugin:ErrorProne
-Xep:AlmostJavadoc:OFF
-Xep:ByteBufferBackingArray:OFF
-Xep:ClassCanBeStatic:OFF
-Xep:CollectionUndefinedEquality:OFF
-Xep:DefaultCharset:OFF
-Xep:DirectInvocationOnMock:OFF
-Xep:DoNotCallSuggester:OFF
-Xep:EmptyCatch:OFF
-Xep:EqualsGetClass:OFF
-Xep:Finally:OFF
-Xep:FutureReturnValueIgnored:OFF
-Xep:HidingField:OFF
-Xep:ImmutableEnumChecker:OFF
-Xep:InlineMeSuggester:OFF
-Xep:InputStreamSlowMultibyteRead:OFF
-Xep:JavaTimeDefaultTimeZone:OFF
-Xep:JavaUtilDate:OFF
-Xep:JdkObsolete:OFF
-Xep:MissingSummary:OFF
-Xep:MixedMutabilityReturnType:OFF
-Xep:MutablePublicArray:OFF
-Xep:NonAtomicVolatileUpdate:OFF
-Xep:RedundantControlFlow:OFF
-Xep:ReferenceEquality:OFF
-Xep:StaticAssignmentInConstructor:OFF
-Xep:StaticAssignmentOfThrowable:OFF
-Xep:StaticMockMember:OFF
-Xep:StreamResourceLeak:OFF
-Xep:StringCaseLocaleUsage:OFF
-Xep:StringSplitter:OFF
-Xep:SynchronizeOnNonFinalField:OFF
-Xep:ThreadLocalUsage:OFF
-Xep:ThreadPriorityCheck:OFF
-Xep:TypeParameterUnusedInFormals:OFF
-Xep:UndefinedEquals:OFF
-Xep:UnnecessaryStringBuilder:OFF
-Xep:UnusedMethod:OFF
-Xep:UnusedVariable:OFF
-Xep:WaitNotInLoop:OFF
Comment on lines -190 to -228
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per discussion at 72694e6#commitcomment-159565537

<!-- Check JSpecify annotations -->
-Xep:NullAway:ERROR
-XepOpt:NullAway:OnlyNullMarked
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
</compilerArg>
</compilerArgs>
<annotationProcessorPaths>
Expand All @@ -234,6 +200,11 @@
<artifactId>error_prone_core</artifactId>
<version>${error-prone.version}</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>${nullaway.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.springframework.batch.core;

import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

/**
* Class that exposes the Spring Batch version. Fetches the "Implementation-Version"
Expand Down Expand Up @@ -43,8 +43,7 @@ private SpringBatchVersion() {
* {@code "N/A"} if it cannot be determined.
* @see Package#getImplementationVersion()
*/
@Nullable
public static String getVersion() {
public static @Nullable String getVersion() {
Package pkg = SpringBatchVersion.class.getPackage();
if (pkg != null && pkg.getImplementationVersion() != null) {
return pkg.getImplementationVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
*/
package org.springframework.batch.core.configuration;

import org.jspecify.annotations.Nullable;

import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.lang.Nullable;

/**
* A runtime service locator interface for retrieving job configurations by
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
@NonNullApi
@NullMarked
package org.springframework.batch.core.configuration.annotation;

import org.springframework.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
@NonNullApi
@NullMarked
package org.springframework.batch.core.configuration;

import org.springframework.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.step.Step;
Expand All @@ -34,7 +35,6 @@
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -222,9 +222,9 @@ private Collection<Job> doLoad(ApplicationContextFactory factory, boolean unregi
* @return all the {@link Step} defined by the given step locator and context
* @see StepLocator
*/
private Collection<Step> getSteps(final StepLocator stepLocator, final ApplicationContext jobApplicationContext) {
final Collection<String> stepNames = stepLocator.getStepNames();
final Collection<Step> result = new ArrayList<>();
private Collection<Step> getSteps(StepLocator stepLocator, ApplicationContext jobApplicationContext) {
Collection<String> stepNames = stepLocator.getStepNames();
Collection<Step> result = new ArrayList<>();
for (String stepName : stepNames) {
result.add(stepLocator.getStep(stepName));
}
Expand All @@ -234,7 +234,7 @@ private Collection<Step> getSteps(final StepLocator stepLocator, final Applicati
// are more Step instances defined. Right now they are registered as being
// available in the
// context of the job but we have no idea if they are linked to that Job or not.
final Map<String, Step> allSteps = jobApplicationContext.getBeansOfType(Step.class);
Map<String, Step> allSteps = jobApplicationContext.getBeansOfType(Step.class);
for (Map.Entry<String, Step> entry : allSteps.entrySet()) {
if (!stepNames.contains(entry.getKey())) {
result.add(entry.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
*/
package org.springframework.batch.core.configuration.support;

import org.jspecify.annotations.Nullable;

import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.job.JobExecution;
import org.springframework.batch.core.job.parameters.JobParametersIncrementer;
import org.springframework.batch.core.job.parameters.JobParametersValidator;
import org.springframework.lang.Nullable;
import org.springframework.util.ClassUtils;

/**
Expand Down Expand Up @@ -87,8 +88,7 @@ public boolean isRestartable() {
}

@Override
@Nullable
public JobParametersIncrementer getJobParametersIncrementer() {
public @Nullable JobParametersIncrementer getJobParametersIncrementer() {
return delegate.getJobParametersIncrementer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.batch.core.job.Job;
import org.springframework.batch.core.configuration.DuplicateJobException;
import org.springframework.batch.core.configuration.JobRegistry;
Expand All @@ -31,7 +33,6 @@
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.concurrent.ConcurrentMap;

import org.springframework.batch.core.step.Step;

import org.jspecify.annotations.Nullable;
import org.springframework.batch.core.configuration.DuplicateJobException;
import org.springframework.batch.core.configuration.StepRegistry;
import org.springframework.batch.core.launch.NoSuchJobException;
Expand Down Expand Up @@ -62,7 +64,7 @@ public void unregisterStepsFromJob(String jobName) {
}

@Override
public Step getStep(String jobName, String stepName) throws NoSuchJobException {
public @Nullable Step getStep(String jobName, String stepName) throws NoSuchJobException {
Assert.notNull(jobName, "The job name cannot be null.");
Assert.notNull(stepName, "The step name cannot be null.");
if (!map.containsKey(jobName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
@NonNullApi
@NullMarked
package org.springframework.batch.core.configuration.support;

import org.springframework.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import org.springframework.beans.factory.support.ManagedMap;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.xml.DomUtils;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;

public class ExceptionElementParser {

public ManagedMap<TypedStringValue, Boolean> parse(Element element, ParserContext parserContext,
public @Nullable ManagedMap<TypedStringValue, Boolean> parse(Element element, ParserContext parserContext,
String exceptionListName) {
List<Element> children = DomUtils.getChildElementsByTagName(element, exceptionListName);
if (children.size() == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;

import org.jspecify.annotations.Nullable;
import org.w3c.dom.Element;

/**
Expand Down Expand Up @@ -158,7 +160,7 @@ else if (listenersElements.size() > 1) {
* @param parserContext The {@link ParserContext}.
* @return the {@link BeanMetadataElement} extracted from the element parameter.
*/
public BeanMetadataElement parseBeanElement(Element element, ParserContext parserContext) {
public @Nullable BeanMetadataElement parseBeanElement(Element element, ParserContext parserContext) {
String refAttribute = element.getAttribute(REF_ATTR);
Element beanElement = DomUtils.getChildElementByTagName(element, BEAN_ELE);
Element refElement = DomUtils.getChildElementByTagName(element, REF_ELE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
@NonNullApi
@NullMarked
package org.springframework.batch.core.configuration.xml;

import org.springframework.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
import java.util.Properties;

import org.springframework.batch.core.job.parameters.JobParameter;

import org.jspecify.annotations.Nullable;
import org.springframework.batch.core.job.parameters.JobParameters;
import org.springframework.batch.core.job.parameters.JobParametersBuilder;
import org.springframework.core.convert.support.ConfigurableConversionService;
import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

Expand Down Expand Up @@ -131,7 +131,7 @@ public Properties getProperties(@Nullable JobParameters jobParameters) {
* @param conversionService the conversion service to use. Must not be {@code null}.
* @since 5.0
*/
public void setConversionService(@NonNull ConfigurableConversionService conversionService) {
public void setConversionService(ConfigurableConversionService conversionService) {
Assert.notNull(conversionService, "The conversionService must not be null");
this.conversionService = conversionService;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import org.springframework.batch.core.job.parameters.JobParameters;
import org.springframework.batch.core.job.parameters.JobParametersBuilder;
import org.springframework.lang.Nullable;
import org.springframework.batch.core.JobParameters;

import org.jspecify.annotations.Nullable;
import org.springframework.batch.core.JobParametersBuilder;

/**
* A factory for {@link JobParameters} instances. A job can be executed with many possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @author Michael Minella
* @author Mahmoud Ben Hassine
*/
@NonNullApi
@NullMarked
package org.springframework.batch.core.converter;

import org.springframework.lang.NonNullApi;
import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.micrometer.observation.ObservationRegistry;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;

import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.ExitStatus;
Expand All @@ -54,7 +55,6 @@
import org.springframework.batch.repeat.RepeatException;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

Expand Down Expand Up @@ -206,8 +206,7 @@ public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIn
}

@Override
@Nullable
public JobParametersIncrementer getJobParametersIncrementer() {
public @Nullable JobParametersIncrementer getJobParametersIncrementer() {
return this.jobParametersIncrementer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import org.springframework.batch.core.job.parameters.JobParametersIncrementer;
import org.springframework.batch.core.job.parameters.JobParametersValidator;
import org.springframework.lang.Nullable;
import org.jspecify.annotations.Nullable;

import org.springframework.batch.core.job.DefaultJobParametersValidator;

/**
* Batch domain object representing a job. {@code Job} is an explicit abstraction
Expand Down Expand Up @@ -57,8 +60,7 @@ default boolean isRestartable() {
* @return an incrementer to be used for creating new parameters. Defaults to
* {@code null}.
*/
@Nullable
default JobParametersIncrementer getJobParametersIncrementer() {
default @Nullable JobParametersIncrementer getJobParametersIncrementer() {
return null;
}

Expand Down
Loading
Loading