Skip to content

Commit 8e2edf2

Browse files
committed
Fix NullAway findings
Signed-off-by: Stefano Cordio <[email protected]>
1 parent 140e0af commit 8e2edf2

File tree

69 files changed

+325
-242
lines changed

Some content is hidden

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

69 files changed

+325
-242
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/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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ 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)
101+
public JobExecution run(Job job, final JobParameters jobParameters)
102102
throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException,
103103
JobParametersInvalidException {
104104

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/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/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);

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/Chunk.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.batch.item;
1818

19+
import org.jspecify.annotations.Nullable;
20+
1921
import java.io.Serializable;
2022
import java.util.ArrayList;
2123
import java.util.Arrays;
@@ -34,6 +36,7 @@
3436
* @author Dave Syer
3537
* @author Mahmoud Ben Hassine
3638
* @author Jinwoo Bae
39+
* @author Stefano Cordio
3740
* @since 2.0
3841
*/
3942
public class Chunk<W> implements Iterable<W>, Serializable {
@@ -44,7 +47,7 @@ public class Chunk<W> implements Iterable<W>, Serializable {
4447

4548
private final List<Exception> errors = new ArrayList<>();
4649

47-
private Object userData;
50+
private @Nullable Object userData;
4851

4952
private boolean end;
5053

@@ -64,8 +67,7 @@ public Chunk(List<? extends W> items) {
6467
this(items, null);
6568
}
6669

67-
public Chunk(List<? extends W> items, List<SkipWrapper<W>> skips) {
68-
super();
70+
public Chunk(@Nullable List<? extends W> items, @Nullable List<SkipWrapper<W>> skips) {
6971
if (items != null) {
7072
this.items.addAll(items);
7173
}
@@ -200,7 +202,7 @@ public void clearSkips() {
200202
skips.clear();
201203
}
202204

203-
public Object getUserData() {
205+
public @Nullable Object getUserData() {
204206
return userData;
205207
}
206208

@@ -247,9 +249,9 @@ public int hashCode() {
247249
*/
248250
public class ChunkIterator implements Iterator<W> {
249251

250-
final private Iterator<W> iterator;
252+
private final Iterator<W> iterator;
251253

252-
private W next;
254+
private @Nullable W next;
253255

254256
public ChunkIterator(List<W> items) {
255257
iterator = items.iterator();

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18+
import org.jspecify.annotations.Nullable;
19+
1820
/**
1921
* Exception representing any errors encountered while processing a stream.
2022
*
2123
* @author Dave Syer
2224
* @author Lucas Ward
2325
* @author Mahmoud Ben Hassine
26+
* @author Stefano Cordio
2427
*/
2528
public class ItemStreamException extends RuntimeException {
2629

@@ -33,11 +36,10 @@ public ItemStreamException(String message) {
3336

3437
/**
3538
* Constructs a new instance with a message and nested exception.
36-
* @param msg the exception message.
39+
* @param msg the exception message (can be {@code null}).
3740
* @param nested the cause of the exception.
38-
*
3941
*/
40-
public ItemStreamException(String msg, Throwable nested) {
42+
public ItemStreamException(@Nullable String msg, Throwable nested) {
4143
super(msg, nested);
4244
}
4345

spring-batch-infrastructure/src/main/java/org/springframework/batch/item/ItemStreamSupport.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.batch.item;
1717

18+
import org.jspecify.annotations.Nullable;
1819
import org.springframework.batch.item.util.ExecutionContextUserSupport;
1920

2021
/**
@@ -23,6 +24,7 @@
2324
* @author Dave Syer
2425
* @author Dean de Bree
2526
* @author Mahmoud Ben Hassine
27+
* @author Stefano Cordio
2628
*
2729
*/
2830
public abstract class ItemStreamSupport implements ItemStream {
@@ -43,7 +45,7 @@ public void setName(String name) {
4345
* Get the name of the component
4446
* @return the name of the component
4547
*/
46-
public String getName() {
48+
public @Nullable String getName() {
4749
return executionContextUserSupport.getName();
4850
}
4951

0 commit comments

Comments
 (0)