Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Migrate nullability annotations to JSpecify #4990

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

Closed
scordio wants to merge 2 commits into spring-projects:main from scordio:jspecify-sb-core
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
The table of contents is too big for display.
Diff view
Diff view
16 changes: 15 additions & 1 deletion pom.xml
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@
<maven-assembly-plugin.version>3.7.1</maven-assembly-plugin.version>
<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.41.0</error-prone.version>
<error-prone.version>2.42.0</error-prone.version>
<nullaway.version>0.12.10</nullaway.version>
</properties>

<build>
Expand Down Expand Up @@ -180,6 +181,14 @@
<compilerArg>--should-stop=ifError=FLOW</compilerArg>
<compilerArg>
-Xplugin:ErrorProne
<!-- Check JSpecify annotations -->
-Xep:NullAway:ERROR
-XepOpt:NullAway:OnlyNullMarked
<!-- FIXME Remove once https://github.com/uber/NullAway/pull/1295 is released -->
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
-XepOpt:NullAway:SuppressionNameAliases=DataFlowIssue
<!-- https://github.com/uber/NullAway/issues/162 -->
-XepExcludedPaths:.*/src/test/java/.*
</compilerArg>
</compilerArgs>
<annotationProcessorPaths>
Expand All @@ -188,6 +197,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 @@ -130,7 +130,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;
View file Open in desktop
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 @@ -55,7 +56,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 @@ -207,8 +207,7 @@ public void setJobParametersIncrementer(JobParametersIncrementer jobParametersIn
}

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

Expand Down
View file Open in desktop
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 @@ -66,8 +69,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
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import org.springframework.batch.core.job.parameters.JobParameters;
import org.springframework.batch.core.step.StepExecution;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.lang.Nullable;

import org.jspecify.annotations.Nullable;

/**
* Batch domain object representing the execution of a job.
Expand Down Expand Up @@ -141,8 +142,7 @@ public JobParameters getJobParameters() {
/**
* @return The current end time.
*/
@Nullable
public LocalDateTime getEndTime() {
public @Nullable LocalDateTime getEndTime() {
return endTime;
}

Expand All @@ -165,8 +165,7 @@ public void setEndTime(LocalDateTime endTime) {
/**
* @return The current start time.
*/
@Nullable
public LocalDateTime getStartTime() {
public @Nullable LocalDateTime getStartTime() {
return startTime;
}

Expand Down Expand Up @@ -208,7 +207,7 @@ public void upgradeStatus(BatchStatus status) {
* implementations.
* @return the {@code id} of the enclosing job.
*/
public Long getJobId() {
public @Nullable Long getJobId() {
if (jobInstance != null) {
return jobInstance.getId();
}
Expand Down Expand Up @@ -318,8 +317,7 @@ public void addStepExecution(StepExecution stepExecution) {
* @return a {@link LocalDateTime} object representing the last time this
* {@code JobExecution} was updated.
*/
@Nullable
public LocalDateTime getLastUpdated() {
public @Nullable LocalDateTime getLastUpdated() {
return lastUpdated;
}

Expand Down
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;

import org.springframework.batch.core.BatchStatus;

import org.jspecify.annotations.Nullable;
import org.springframework.batch.core.step.Step;
import org.springframework.batch.core.step.StepExecution;
import org.springframework.batch.core.repository.JobRestartException;
Expand Down Expand Up @@ -91,7 +93,7 @@ public void addStep(Step step) {
}

@Override
public Step getStep(String stepName) {
public @Nullable Step getStep(String stepName) {
for (Step step : this.steps) {
if (step.getName().equals(stepName)) {
return step;
Expand Down
Loading

AltStyle によって変換されたページ (->オリジナル) /