Skip to content

Commit a6114ad

Browse files
committed
Fix NullAway findings
Signed-off-by: Stefano Cordio <[email protected]>
1 parent 43ee5bc commit a6114ad

File tree

94 files changed

+550
-452
lines changed

Some content is hidden

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

94 files changed

+550
-452
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@
191191
<!-- Check JSpecify annotations -->
192192
-Xep:NullAway:ERROR
193193
-XepOpt:NullAway:OnlyNullMarked
194+
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
194195
</compilerArg>
195196
</compilerArgs>
196197
<annotationProcessorPaths>

spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultJobLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ private Collection<Job> doLoad(ApplicationContextFactory factory, boolean unregi
222222
* @return all the {@link Step} defined by the given step locator and context
223223
* @see StepLocator
224224
*/
225-
private Collection<Step> getSteps(final StepLocator stepLocator, final ApplicationContext jobApplicationContext) {
225+
private Collection<Step> getSteps(StepLocator stepLocator, final ApplicationContext jobApplicationContext) {
226226
final Collection<String> stepNames = stepLocator.getStepNames();
227227
final Collection<Step> result = new ArrayList<>();
228228
for (String stepName : stepNames) {

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowExecutor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public interface FlowExecutor {
5151
/**
5252
* @return the latest {@link StepExecution} or null if there is none
5353
*/
54-
@Nullable
55-
StepExecution getStepExecution();
54+
@Nullable StepExecution getStepExecution();
5655

5756
/**
5857
* Chance to clean up resources at the end of a flow (whether it completed

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/FlowJob.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public Collection<String> getStepNames() {
127127
* @see AbstractJob#doExecute(JobExecution)
128128
*/
129129
@Override
130-
protected void doExecute(final JobExecution execution) throws JobExecutionException {
130+
protected void doExecute(JobExecution execution) throws JobExecutionException {
131131
try {
132132
JobFlowExecutor executor = new JobFlowExecutor(getJobRepository(),
133133
new SimpleStepHandler(getJobRepository()), execution);

spring-batch-core/src/main/java/org/springframework/batch/core/job/flow/support/state/SplitState.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ public Collection<Flow> getFlows() {
9797
* @see State#handle(FlowExecutor)
9898
*/
9999
@Override
100-
public FlowExecutionStatus handle(final FlowExecutor executor) throws Exception {
100+
public FlowExecutionStatus handle(FlowExecutor executor) throws Exception {
101101

102102
// TODO: collect the last StepExecution from the flows as well, so they
103103
// can be abandoned if necessary
104104
Collection<Future<FlowExecution>> tasks = new ArrayList<>();
105105

106-
for (final Flow flow : flows) {
106+
for (Flow flow : flows) {
107107

108108
final FutureTask<FlowExecution> task = new FutureTask<>(() -> flow.start(executor));
109109

spring-batch-core/src/main/java/org/springframework/batch/core/launch/support/TaskExecutorJobLauncher.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,8 @@ public class TaskExecutorJobLauncher implements JobLauncher, InitializingBean {
9898
* @throws JobParametersInvalidException thrown if jobParameters is invalid.
9999
*/
100100
@Override
101-
public JobExecution run(final Job job, final JobParameters jobParameters)
102-
throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
103-
JobParametersInvalidException {
101+
public JobExecution run(Job job, final JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
102+
JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
104103

105104
Assert.notNull(job, "The Job must not be null.");
106105
Assert.notNull(jobParameters, "The JobParameters must not be null.");

spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/AbstractPartitionHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected abstract Set<StepExecution> doHandle(StepExecution managerStepExecutio
5252
* @see PartitionHandler#handle(StepExecutionSplitter, StepExecution)
5353
*/
5454
@Override
55-
public Collection<StepExecution> handle(final StepExecutionSplitter stepSplitter,
55+
public Collection<StepExecution> handle(StepExecutionSplitter stepSplitter,
5656
final StepExecution managerStepExecution) throws Exception {
5757
final Set<StepExecution> stepExecutions = stepSplitter.split(managerStepExecution, gridSize);
5858

spring-batch-core/src/main/java/org/springframework/batch/core/partition/support/TaskExecutorPartitionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ protected Set<StepExecution> doHandle(StepExecution managerStepExecution,
9393
final Set<Future<StepExecution>> tasks = new HashSet<>(getGridSize());
9494
final Set<StepExecution> result = new HashSet<>();
9595

96-
for (final StepExecution stepExecution : partitionStepExecutions) {
96+
for (StepExecution stepExecution : partitionStepExecutions) {
9797
final FutureTask<StepExecution> task = createTask(step, stepExecution);
9898

9999
try {
@@ -127,7 +127,7 @@ protected Set<StepExecution> doHandle(StepExecution managerStepExecution,
127127
* @param stepExecution the given execution
128128
* @return the task executing the given step
129129
*/
130-
protected FutureTask<StepExecution> createTask(final Step step, final StepExecution stepExecution) {
130+
protected FutureTask<StepExecution> createTask(Step step, final StepExecution stepExecution) {
131131
return new FutureTask<>(() -> {
132132
step.execute(stepExecution);
133133
return stepExecution;

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/ExecutionContextDao.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,36 @@ public interface ExecutionContextDao {
4848
* entry for the context should not exist yet.
4949
* @param jobExecution {@link JobExecution} instance that contains the context.
5050
*/
51-
void saveExecutionContext(final JobExecution jobExecution);
51+
void saveExecutionContext(JobExecution jobExecution);
5252

5353
/**
5454
* Persist the execution context associated with the given stepExecution, persistent
5555
* entry for the context should not exist yet.
5656
* @param stepExecution {@link StepExecution} instance that contains the context.
5757
*/
58-
void saveExecutionContext(final StepExecution stepExecution);
58+
void saveExecutionContext(StepExecution stepExecution);
5959

6060
/**
6161
* Persist the execution context associated with each stepExecution in a given
6262
* collection, persistent entry for the context should not exist yet.
6363
* @param stepExecutions a collection of {@link StepExecution}s that contain the
6464
* contexts.
6565
*/
66-
void saveExecutionContexts(final Collection<StepExecution> stepExecutions);
66+
void saveExecutionContexts(Collection<StepExecution> stepExecutions);
6767

6868
/**
6969
* Persist the updates of execution context associated with the given jobExecution.
7070
* Persistent entry should already exist for this context.
7171
* @param jobExecution {@link JobExecution} instance that contains the context.
7272
*/
73-
void updateExecutionContext(final JobExecution jobExecution);
73+
void updateExecutionContext(JobExecution jobExecution);
7474

7575
/**
7676
* Persist the updates of execution context associated with the given stepExecution.
7777
* Persistent entry should already exist for this context.
7878
* @param stepExecution {@link StepExecution} instance that contains the context.
7979
*/
80-
void updateExecutionContext(final StepExecution stepExecution);
80+
void updateExecutionContext(StepExecution stepExecution);
8181

8282
/**
8383
* Delete the execution context of the given {@link JobExecution}.

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobExecutionDao.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@
1919
import java.util.List;
2020
import java.util.Set;
2121

22+
import org.jspecify.annotations.Nullable;
2223
import org.springframework.batch.core.job.JobExecution;
2324
import org.springframework.batch.core.job.JobInstance;
24-
import org.springframework.lang.Nullable;
25-
import org.springframework.batch.core.JobExecution;
26-
27-
import org.jspecify.annotations.Nullable;
28-
import org.springframework.batch.core.JobInstance;
2925

3026
/**
3127
* Data Access Object for job executions.
@@ -68,8 +64,7 @@ public interface JobExecutionDao {
6864
* @return the last {@link JobExecution} to execute for this instance or {@code null}
6965
* if no job execution is found for the given job instance.
7066
*/
71-
@Nullable
72-
JobExecution getLastJobExecution(JobInstance jobInstance);
67+
@Nullable JobExecution getLastJobExecution(JobInstance jobInstance);
7368

7469
/**
7570
* @param jobName {@link String} containing the name of the job.
@@ -82,8 +77,7 @@ public interface JobExecutionDao {
8277
* @param executionId {@link Long} containing the id of the execution.
8378
* @return the {@link JobExecution} for given identifier.
8479
*/
85-
@Nullable
86-
JobExecution getJobExecution(Long executionId);
80+
@Nullable JobExecution getJobExecution(Long executionId);
8781

8882
/**
8983
* Because it may be possible that the status of a JobExecution is updated while

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/JobInstanceDao.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,22 @@ public interface JobInstanceDao {
5858
* @return {@link JobInstance} object matching the job name and {@link JobParameters}
5959
* or {@code null}
6060
*/
61-
@Nullable
62-
JobInstance getJobInstance(String jobName, JobParameters jobParameters);
61+
@Nullable JobInstance getJobInstance(String jobName, JobParameters jobParameters);
6362

6463
/**
6564
* Fetch the job instance with the provided identifier.
6665
* @param instanceId the job identifier
6766
* @return the job instance with this identifier or {@code null} if it doesn't exist
6867
*/
69-
@Nullable
70-
JobInstance getJobInstance(@Nullable Long instanceId);
68+
@Nullable JobInstance getJobInstance(@Nullable Long instanceId);
7169

7270
/**
7371
* Fetch the JobInstance for the provided JobExecution.
7472
* @param jobExecution the JobExecution
7573
* @return the JobInstance for the provided execution or {@code null} if it doesn't
7674
* exist.
7775
*/
78-
@Nullable
79-
JobInstance getJobInstance(JobExecution jobExecution);
76+
@Nullable JobInstance getJobInstance(JobExecution jobExecution);
8077

8178
/**
8279
* Fetch the last job instances with the provided name, sorted backwards by primary

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/StepExecutionDao.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public interface StepExecutionDao {
6060
* @param stepExecutionId the step execution id
6161
* @return a {@link StepExecution}
6262
*/
63-
@Nullable
64-
StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId);
63+
@Nullable StepExecution getStepExecution(JobExecution jobExecution, Long stepExecutionId);
6564

6665
/**
6766
* Retrieve the last {@link StepExecution} for a given {@link JobInstance} ordered by

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcExecutionContextDao.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public ExecutionContext getExecutionContext(StepExecution stepExecution) {
172172
}
173173

174174
@Override
175-
public void updateExecutionContext(final JobExecution jobExecution) {
175+
public void updateExecutionContext(JobExecution jobExecution) {
176176
Long executionId = jobExecution.getId();
177177
ExecutionContext executionContext = jobExecution.getExecutionContext();
178178
Assert.notNull(executionId, "ExecutionId must not be null.");
@@ -184,7 +184,7 @@ public void updateExecutionContext(final JobExecution jobExecution) {
184184
}
185185

186186
@Override
187-
public void updateExecutionContext(final StepExecution stepExecution) {
187+
public void updateExecutionContext(StepExecution stepExecution) {
188188
// Attempt to prevent concurrent modification errors by blocking here if
189189
// someone is already trying to do it.
190190
this.lock.lock();
@@ -271,7 +271,7 @@ public void afterPropertiesSet() throws Exception {
271271
* @param serializedContext the serialized context to persist
272272
* @param sql with parameters (shortContext, longContext, executionId)
273273
*/
274-
private void persistSerializedContext(final Long executionId, String serializedContext, String sql) {
274+
private void persistSerializedContext(Long executionId, String serializedContext, String sql) {
275275

276276
final String shortContext;
277277
final String longContext;
@@ -302,7 +302,7 @@ private void persistSerializedContext(final Long executionId, String serializedC
302302
* @param serializedContexts the execution contexts to serialize
303303
* @param sql with parameters (shortContext, longContext, executionId)
304304
*/
305-
private void persistSerializedContexts(final Map<Long, String> serializedContexts, String sql) {
305+
private void persistSerializedContexts(Map<Long, String> serializedContexts, String sql) {
306306
if (!serializedContexts.isEmpty()) {
307307
final Iterator<Long> executionIdIterator = serializedContexts.keySet().iterator();
308308

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcJobExecutionDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void afterPropertiesSet() throws Exception {
207207
}
208208

209209
@Override
210-
public List<JobExecution> findJobExecutions(final JobInstance job) {
210+
public List<JobExecution> findJobExecutions(JobInstance job) {
211211

212212
Assert.notNull(job, "Job cannot be null.");
213213
Assert.notNull(job.getId(), "Job Id cannot be null.");

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcJobInstanceDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public JobInstance createJobInstance(String jobName, JobParameters jobParameters
167167
* @throws IllegalArgumentException if any {@link JobParameters} fields are null.
168168
*/
169169
@Override
170-
public @Nullable JobInstance getJobInstance(final String jobName, final JobParameters jobParameters) {
170+
public @Nullable JobInstance getJobInstance(String jobName, final JobParameters jobParameters) {
171171

172172
Assert.notNull(jobName, "Job name must not be null.");
173173
Assert.notNull(jobParameters, "JobParameters must not be null.");

spring-batch-core/src/main/java/org/springframework/batch/core/repository/dao/jdbc/JdbcStepExecutionDao.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void saveStepExecution(StepExecution stepExecution) {
176176
* @see StepExecutionDao#saveStepExecutions(Collection)
177177
*/
178178
@Override
179-
public void saveStepExecutions(final Collection<StepExecution> stepExecutions) {
179+
public void saveStepExecutions(Collection<StepExecution> stepExecutions) {
180180
Assert.notNull(stepExecutions, "Attempt to save a null collection of step executions");
181181

182182
if (!stepExecutions.isEmpty()) {

spring-batch-core/src/main/java/org/springframework/batch/core/step/item/FaultTolerantChunkProcessor.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ protected Chunk<O> getAdjustedOutputs(Chunk<I> inputs, Chunk<O> outputs) {
200200
}
201201

202202
@Override
203-
protected Chunk<O> transform(final StepContribution contribution, Chunk<I> inputs) throws Exception {
203+
protected Chunk<O> transform(StepContribution contribution, Chunk<I> inputs) throws Exception {
204204

205205
Chunk<O> outputs = new Chunk<>();
206206
@SuppressWarnings("unchecked")
@@ -211,7 +211,7 @@ protected Chunk<O> transform(final StepContribution contribution, Chunk<I> input
211211
// final int scanLimit = processorTransactional && data.scanning() ? 1 :
212212
// 0;
213213

214-
for (final Chunk<I>.ChunkIterator iterator = inputs.iterator(); iterator.hasNext();) {
214+
for (Chunk<I>.ChunkIterator iterator = inputs.iterator(); iterator.hasNext();) {
215215

216216
final I item = iterator.next();
217217

@@ -314,7 +314,7 @@ else if (shouldSkip(itemProcessSkipPolicy, e, contribution.getStepSkipCount()))
314314
}
315315

316316
@Override
317-
protected void write(final StepContribution contribution, final Chunk<I> inputs, final Chunk<O> outputs)
317+
protected void write(StepContribution contribution, final Chunk<I> inputs, final Chunk<O> outputs)
318318
throws Exception {
319319
@SuppressWarnings("unchecked")
320320
final UserData<O> data = (UserData<O>) inputs.getUserData();
@@ -432,7 +432,7 @@ protected void write(final StepContribution contribution, final Chunk<I> inputs,
432432

433433
}
434434

435-
private void callSkipListeners(final Chunk<I> inputs, final Chunk<O> outputs) {
435+
private void callSkipListeners(Chunk<I> inputs, final Chunk<O> outputs) {
436436

437437
for (SkipWrapper<I> wrapper : inputs.getSkips()) {
438438
I item = wrapper.getItem();
@@ -500,7 +500,7 @@ private Object getInputKey(I item) {
500500
return keyGenerator.getKey(item);
501501
}
502502

503-
private List<?> getInputKeys(final Chunk<I> inputs) {
503+
private List<?> getInputKeys(Chunk<I> inputs) {
504504
if (keyGenerator == null) {
505505
return inputs.getItems();
506506
}
@@ -539,7 +539,7 @@ else if (e instanceof Error error) {
539539
}
540540
}
541541

542-
private void scan(final StepContribution contribution, final Chunk<I> inputs, final Chunk<O> outputs,
542+
private void scan(StepContribution contribution, final Chunk<I> inputs, final Chunk<O> outputs,
543543
ChunkMonitor chunkMonitor, boolean recovery) throws Exception {
544544

545545
@SuppressWarnings("unchecked")

spring-batch-core/src/main/java/org/springframework/batch/core/step/item/SimpleChunkProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void registerListener(StepListener listener) {
121121
}
122122

123123
@Override
124-
public Chunk<I> provide(final StepContribution contribution) throws Exception {
124+
public Chunk<I> provide(StepContribution contribution) throws Exception {
125125

126126
final Chunk<I> inputs = new Chunk<>();
127127
repeatOperations.iterate(context -> {

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/Tasklet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public interface Tasklet {
4444
* Returning {@code null} is interpreted as {@link RepeatStatus#FINISHED}
4545
* @throws Exception thrown if error occurs during execution.
4646
*/
47-
@Nullable
48-
RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception;
47+
@Nullable RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception;
4948

5049
}

spring-batch-core/src/main/java/org/springframework/batch/core/step/tasklet/TaskletStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ private void rollback(StepExecution stepExecution) {
476476
}
477477
}
478478

479-
private void copy(final StepExecution source, final StepExecution target) {
479+
private void copy(StepExecution source, final StepExecution target) {
480480
target.setVersion(source.getVersion());
481481
target.setWriteCount(source.getWriteCount());
482482
target.setFilterCount(source.getFilterCount());

spring-batch-core/src/test/java/org/springframework/batch/core/step/StepLocatorStepFactoryBeanTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void testFoo() throws Exception {
4646
assertEquals(testStep2, stepLocatorStepFactoryBean.getObject());
4747
}
4848

49-
private Step buildTestStep(final String stepName) {
49+
private Step buildTestStep(String stepName) {
5050
return new Step() {
5151
@Override
5252
public String getName() {

spring-batch-core/src/test/java/org/springframework/batch/core/step/skip/ReprocessExceptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static class PersonProcessor implements ItemProcessor<Person, Person> {
5656
private String mostRecentFirstName;
5757

5858
@Override
59-
public @Nullable Person process(final Person person) throws Exception {
59+
public @Nullable Person process(Person person) throws Exception {
6060
if (person.getFirstName().equals(mostRecentFirstName)) {
6161
throw new RuntimeException("throwing a exception during process after a rollback");
6262
}

spring-batch-core/src/test/java/org/springframework/batch/core/step/tasklet/StepExecutorInterruptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public void release() {
211211
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
212212
}
213213

214-
private Thread createThread(final StepExecution stepExecution) {
214+
private Thread createThread(StepExecution stepExecution) {
215215
Thread processingThread = new Thread(() -> {
216216
try {
217217
jobRepository.add(stepExecution);

0 commit comments

Comments
 (0)