Skip to content

Commit 3f5a793

Browse files
committed
Refine jSpecify nullability checks
Issue #4673
1 parent 4fd9541 commit 3f5a793

28 files changed

+96
-68
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.batch.core.configuration.support;
1717

1818
import io.micrometer.observation.ObservationRegistry;
19-
import org.jspecify.annotations.NullUnmarked;
2019

2120
import org.springframework.batch.core.configuration.DuplicateJobException;
2221
import org.springframework.batch.core.configuration.annotation.BatchObservabilityBeanPostProcessor;
@@ -79,9 +78,9 @@
7978
*/
8079
@Configuration(proxyBeanMethods = false)
8180
@Import({ ScopeConfiguration.class, BatchObservabilityBeanPostProcessor.class })
82-
@NullUnmarked
8381
public class DefaultBatchConfiguration implements ApplicationContextAware {
8482

83+
@SuppressWarnings("NullAway.Init")
8584
protected ApplicationContext applicationContext;
8685

8786
@Override

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
import org.apache.commons.logging.Log;
2525
import org.apache.commons.logging.LogFactory;
26-
import org.jspecify.annotations.NullUnmarked;
26+
import org.jspecify.annotations.Nullable;
2727

2828
import org.springframework.batch.core.job.Job;
2929
import org.springframework.batch.core.configuration.DuplicateJobException;
@@ -43,7 +43,6 @@
4343
* @author Robert Fischer
4444
* @author Mahmoud Ben Hassine
4545
*/
46-
@NullUnmarked // FIXME how to fix nullability checks for the applicationContext field?
4746
public class MapJobRegistry implements JobRegistry, SmartInitializingSingleton, ApplicationContextAware {
4847

4948
protected final Log logger = LogFactory.getLog(getClass());
@@ -53,6 +52,7 @@ public class MapJobRegistry implements JobRegistry, SmartInitializingSingleton,
5352
*/
5453
private final ConcurrentMap<String, Job> map = new ConcurrentHashMap<>();
5554

55+
@SuppressWarnings("NullAway.Init")
5656
private ApplicationContext applicationContext;
5757

5858
@Override
@@ -83,6 +83,7 @@ public void unregister(String name) {
8383
this.map.remove(name);
8484
}
8585

86+
@Nullable
8687
@Override
8788
public Job getJob(String name) {
8889
return this.map.get(name);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
* @author Dave Syer
6161
* @author Mahmoud Ben Hassine
6262
*/
63-
@NullUnmarked // FIXME to remove once default constructors are removed
63+
@NullUnmarked // FIXME to remove once default constructors (required by the batch XML
64+
// namespace) are removed
6465
public abstract class AbstractJob implements Job, StepLocator, BeanNameAware, InitializingBean {
6566

6667
protected static final Log logger = LogFactory.getLog(AbstractJob.class);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@
4040
* @author Michael Minella
4141
* @author Mahmoud Ben Hassine
4242
*/
43-
@NullUnmarked // FIXME to remove once default constructors are removed
43+
@NullUnmarked // FIXME to remove once default constructors (required by the batch XML
44+
// namespace) are removed
4445
public class SimpleJob extends AbstractJob {
4546

4647
private final List<Step> steps = new ArrayList<>();

spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/FlowJobBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
* @author Mahmoud Ben Hassine
3333
* @since 2.2
3434
*/
35-
@NullUnmarked // FIXME to remove once default constructors are removed
35+
@NullUnmarked // FIXME to remove once default constructors (required by the batch XML
36+
// namespace) are removed
3637
public class FlowJobBuilder extends JobBuilderHelper<FlowJobBuilder> {
3738

3839
private Flow flow;

spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/JobBuilderHelper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
* @author Taeik Lim
4747
* @since 2.2
4848
*/
49-
@NullUnmarked // FIXME to remove once default constructors are removed
49+
@NullUnmarked // FIXME to remove once default constructors (required by the batch XML
50+
// namespace) are removed
5051
public abstract class JobBuilderHelper<B extends JobBuilderHelper<B>> {
5152

5253
protected final Log logger = LogFactory.getLog(getClass());

spring-batch-core/src/main/java/org/springframework/batch/core/job/builder/SimpleJobBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
* @since 2.2
3434
*
3535
*/
36-
@NullUnmarked // FIXME to remove once default constructors are removed
36+
@NullUnmarked // FIXME to remove once default constructors (required by the batch XML
37+
// namespace) are removed
3738
public class SimpleJobBuilder extends JobBuilderHelper<SimpleJobBuilder> {
3839

3940
private final List<Step> steps = new ArrayList<>();

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import io.micrometer.observation.ObservationRegistry;
2121
import org.apache.commons.logging.Log;
2222
import org.apache.commons.logging.LogFactory;
23-
import org.jspecify.annotations.NullUnmarked;
23+
import org.jspecify.annotations.Nullable;
2424

2525
import org.springframework.aop.framework.ProxyFactory;
2626
import org.springframework.batch.core.configuration.BatchConfigurationException;
@@ -58,26 +58,29 @@
5858
* @author Mahmoud Ben Hassine
5959
* @since 5.0
6060
*/
61-
@NullUnmarked
6261
public class JobOperatorFactoryBean implements FactoryBean<JobOperator>, ApplicationContextAware, InitializingBean {
6362

6463
protected static final Log logger = LogFactory.getLog(JobOperatorFactoryBean.class);
6564

65+
@SuppressWarnings("NullAway.Init")
6666
private ApplicationContext applicationContext;
6767

68-
private PlatformTransactionManager transactionManager;
68+
private @Nullable PlatformTransactionManager transactionManager;
6969

70-
private TransactionAttributeSource transactionAttributeSource;
70+
private @Nullable TransactionAttributeSource transactionAttributeSource;
7171

72+
@SuppressWarnings("NullAway.Init")
7273
private JobRegistry jobRegistry;
7374

75+
@SuppressWarnings("NullAway.Init")
7476
private JobRepository jobRepository;
7577

7678
private JobParametersConverter jobParametersConverter = new DefaultJobParametersConverter();
7779

80+
@SuppressWarnings("NullAway.Init")
7881
private TaskExecutor taskExecutor;
7982

80-
private ObservationRegistry observationRegistry;
83+
private @Nullable ObservationRegistry observationRegistry;
8184

8285
private final ProxyFactory proxyFactory = new ProxyFactory();
8386

@@ -192,6 +195,7 @@ public boolean isSingleton() {
192195
return true;
193196
}
194197

198+
@SuppressWarnings("DataFlowIssue")
195199
@Override
196200
public JobOperator getObject() throws Exception {
197201
TransactionInterceptor advice = new TransactionInterceptor((TransactionManager) this.transactionManager,
@@ -203,7 +207,7 @@ public JobOperator getObject() throws Exception {
203207
return (JobOperator) this.proxyFactory.getProxy(getClass().getClassLoader());
204208
}
205209

206-
@SuppressWarnings("removal")
210+
@SuppressWarnings({ "removal" })
207211
private TaskExecutorJobOperator getTarget() throws Exception {
208212
TaskExecutorJobOperator taskExecutorJobOperator = new TaskExecutorJobOperator();
209213
taskExecutorJobOperator.setJobRegistry(this.jobRegistry);

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import io.micrometer.observation.ObservationRegistry;
2020
import org.apache.commons.logging.Log;
2121
import org.apache.commons.logging.LogFactory;
22-
import org.jspecify.annotations.NullUnmarked;
22+
import org.jspecify.annotations.Nullable;
2323

2424
import org.springframework.batch.core.configuration.JobRegistry;
2525
import org.springframework.batch.core.job.Job;
@@ -60,12 +60,11 @@
6060
* @since 6.0
6161
*/
6262
@SuppressWarnings("removal")
63-
@NullUnmarked
6463
public class TaskExecutorJobOperator extends SimpleJobOperator {
6564

6665
private static final Log logger = LogFactory.getLog(TaskExecutorJobOperator.class.getName());
6766

68-
protected ObservationRegistry observationRegistry;
67+
protected @Nullable ObservationRegistry observationRegistry;
6968

7069
@Override
7170
public void afterPropertiesSet() throws Exception {

spring-batch-core/src/main/java/org/springframework/batch/core/listener/ExecutionContextPromotionListener.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.batch.core.listener;
1717

18-
import org.jspecify.annotations.NullUnmarked;
18+
import org.jspecify.annotations.Nullable;
1919

2020
import org.springframework.batch.core.ExitStatus;
2121
import org.springframework.batch.core.job.Job;
@@ -42,17 +42,19 @@
4242
* @author Mahmoud Ben Hassine
4343
* @since 2.0
4444
*/
45-
@NullUnmarked
4645
public class ExecutionContextPromotionListener implements StepExecutionListener, InitializingBean {
4746

48-
private String[] keys = null;
47+
private String @Nullable [] keys = null;
4948

5049
private String[] statuses = new String[] { ExitStatus.COMPLETED.getExitCode() };
5150

5251
private boolean strict = false;
5352

5453
@Override
5554
public ExitStatus afterStep(StepExecution stepExecution) {
55+
if (this.keys == null) {
56+
return stepExecution.getExitStatus();
57+
}
5658
ExecutionContext stepContext = stepExecution.getExecutionContext();
5759
ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
5860
String exitCode = stepExecution.getExitStatus().getExitCode();
@@ -73,7 +75,7 @@ public ExitStatus afterStep(StepExecution stepExecution) {
7375
}
7476
}
7577

76-
return null;
78+
return stepExecution.getExitStatus();
7779
}
7880

7981
@Override

0 commit comments

Comments
 (0)