Skip to content

Commit 62c4cbf

Browse files
committed
Refine nullability checks with jSpecify
- Remove usage of nullability annotations from Spring Framework - Remove JSR305 dependency
1 parent d50c04b commit 62c4cbf

File tree

32 files changed

+76
-140
lines changed

32 files changed

+76
-140
lines changed

pom.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@
8080
<junit-jupiter.version>6.0.0</junit-jupiter.version>
8181
<junit-platform-launcher.version>6.0.0</junit-platform-launcher.version>
8282

83-
<!-- provided dependencies -->
84-
<jsr305.version>3.0.2</jsr305.version>
85-
8683
<!-- test dependencies -->
8784
<micrometer-tracing.version>1.6.0-SNAPSHOT</micrometer-tracing.version>
8885

@@ -183,7 +180,8 @@
183180
-Xplugin:ErrorProne
184181
<!-- Check JSpecify annotations -->
185182
-Xep:NullAway:ERROR
186-
-XepOpt:NullAway:OnlyNullMarked
183+
-XepOpt:NullAway:JSpecifyMode=true
184+
-XepOpt:NullAway:OnlyNullMarked
187185
<!-- FIXME Remove once https://github.com/uber/NullAway/pull/1295 is released -->
188186
-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract
189187
-XepOpt:NullAway:SuppressionNameAliases=DataFlowIssue

spring-batch-core/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,6 @@
400400
</exclusion>
401401
</exclusions>
402402
</dependency>
403-
404-
<!-- provided dependencies -->
405-
<dependency>
406-
<groupId>com.google.code.findbugs</groupId>
407-
<artifactId>jsr305</artifactId>
408-
<version>${jsr305.version}</version>
409-
<scope>provided</scope>
410-
</dependency>
411403
</dependencies>
412404

413405
</project>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import org.springframework.batch.core.job.Job;
2121
import org.springframework.batch.core.launch.NoSuchJobException;
22-
import org.springframework.lang.Nullable;
22+
import org.jspecify.annotations.Nullable;
2323

2424
/**
2525
* A runtime service locator interface for retrieving job configurations by

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
@@ -35,7 +35,7 @@
3535
import org.springframework.beans.factory.InitializingBean;
3636
import org.springframework.context.ApplicationContext;
3737
import org.springframework.context.ConfigurableApplicationContext;
38-
import org.springframework.lang.Nullable;
38+
import org.jspecify.annotations.Nullable;
3939
import org.springframework.util.Assert;
4040

4141
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
import org.springframework.batch.core.step.tasklet.TaskletStep;
6262
import org.springframework.batch.infrastructure.support.PropertiesConverter;
6363
import org.springframework.beans.factory.InitializingBean;
64-
import org.springframework.lang.Nullable;
64+
import org.jspecify.annotations.Nullable;
6565
import org.springframework.util.Assert;
6666

6767
/**

spring-batch-core/src/main/java/org/springframework/batch/core/observability/BatchMetrics.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.time.LocalDateTime;
2020
import java.util.concurrent.TimeUnit;
2121

22-
import org.springframework.lang.Nullable;
22+
import org.jspecify.annotations.Nullable;
2323

2424
/**
2525
* Central class for batch metrics. It provides some utility methods like calculating
@@ -53,8 +53,7 @@ private BatchMetrics() {
5353
* @param endTime the end time
5454
* @return the duration between start time and end time
5555
*/
56-
@Nullable
57-
public static Duration calculateDuration(@Nullable LocalDateTime startTime, @Nullable LocalDateTime endTime) {
56+
@Nullable public static Duration calculateDuration(@Nullable LocalDateTime startTime, @Nullable LocalDateTime endTime) {
5857
if (startTime == null || endTime == null) {
5958
return null;
6059
}

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

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import org.springframework.batch.core.step.StepExecution;
2525
import org.springframework.batch.core.repository.explore.JobExplorer;
2626
import org.springframework.batch.infrastructure.item.ExecutionContext;
27-
import org.springframework.lang.Nullable;
27+
import org.jspecify.annotations.Nullable;
2828

2929
import java.util.Collections;
3030
import java.util.List;
@@ -102,8 +102,7 @@ default List<JobInstance> findJobInstances(String jobName) {
102102
* @param jobInstanceId The ID for the {@link JobInstance} to obtain.
103103
* @return the {@code JobInstance} that has this ID, or {@code null} if not found.
104104
*/
105-
@Nullable
106-
default JobInstance getJobInstance(long jobInstanceId) {
105+
@Nullable default JobInstance getJobInstance(long jobInstanceId) {
107106
throw new UnsupportedOperationException();
108107
}
109108

@@ -114,8 +113,7 @@ default JobInstance getJobInstance(long jobInstanceId) {
114113
*
115114
* @since 4.2
116115
*/
117-
@Nullable
118-
default JobInstance getLastJobInstance(String jobName) {
116+
@Nullable default JobInstance getLastJobInstance(String jobName) {
119117
throw new UnsupportedOperationException();
120118
}
121119

@@ -127,8 +125,7 @@ default JobInstance getLastJobInstance(String jobName) {
127125
*
128126
* @since 5.0
129127
*/
130-
@Nullable
131-
default JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
128+
@Nullable default JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
132129
throw new UnsupportedOperationException();
133130
}
134131

@@ -159,8 +156,7 @@ default long getJobInstanceCount(String jobName) throws NoSuchJobException {
159156
* @param executionId The job execution ID.
160157
* @return the {@link JobExecution} that has this ID or {@code null} if not found.
161158
*/
162-
@Nullable
163-
default JobExecution getJobExecution(long executionId) {
159+
@Nullable default JobExecution getJobExecution(long executionId) {
164160
throw new UnsupportedOperationException();
165161
}
166162

@@ -186,8 +182,7 @@ default List<JobExecution> getJobExecutions(JobInstance jobInstance) {
186182
*
187183
* @since 4.2
188184
*/
189-
@Nullable
190-
default JobExecution getLastJobExecution(JobInstance jobInstance) {
185+
@Nullable default JobExecution getLastJobExecution(JobInstance jobInstance) {
191186
throw new UnsupportedOperationException();
192187
}
193188

@@ -196,8 +191,7 @@ default JobExecution getLastJobExecution(JobInstance jobInstance) {
196191
* @param jobParameters parameters identifying the {@link JobInstance}
197192
* @return the last execution of job if exists, null otherwise
198193
*/
199-
@Nullable
200-
default JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) {
194+
@Nullable default JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) {
201195
throw new UnsupportedOperationException();
202196
}
203197

@@ -231,8 +225,7 @@ default Set<JobExecution> findRunningJobExecutions(String jobName) {
231225
* @deprecated since 6.0 in favor of {@link #getStepExecution(long)}
232226
*/
233227
@Deprecated(since = "6.0", forRemoval = true)
234-
@Nullable
235-
default StepExecution getStepExecution(long jobExecutionId, long stepExecutionId) {
228+
@Nullable default StepExecution getStepExecution(long jobExecutionId, long stepExecutionId) {
236229
throw new UnsupportedOperationException();
237230
}
238231

@@ -244,8 +237,7 @@ default StepExecution getStepExecution(long jobExecutionId, long stepExecutionId
244237
* @return the {@link StepExecution} that has this ID or {@code null} if not found.
245238
* @since 6.0
246239
*/
247-
@Nullable
248-
default StepExecution getStepExecution(long stepExecutionId) {
240+
@Nullable default StepExecution getStepExecution(long stepExecutionId) {
249241
throw new UnsupportedOperationException();
250242
}
251243

@@ -254,8 +246,7 @@ default StepExecution getStepExecution(long stepExecutionId) {
254246
* @param stepName the name of the step execution that might have run.
255247
* @return the last execution of step for the given job instance.
256248
*/
257-
@Nullable
258-
default StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
249+
@Nullable default StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
259250
throw new UnsupportedOperationException();
260251
}
261252

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.batch.core.job.JobExecution;
2323
import org.springframework.batch.core.job.JobInstance;
2424
import org.springframework.batch.core.job.parameters.JobParameters;
25-
import org.springframework.lang.Nullable;
25+
import org.jspecify.annotations.Nullable;
2626

2727
/**
2828
* Data Access Object for job executions.
@@ -70,8 +70,7 @@ default JobExecution createJobExecution(JobInstance jobInstance, JobParameters j
7070
* @return the last {@link JobExecution} to execute for this instance or {@code null}
7171
* if no job execution is found for the given job instance.
7272
*/
73-
@Nullable
74-
JobExecution getLastJobExecution(JobInstance jobInstance);
73+
@Nullable JobExecution getLastJobExecution(JobInstance jobInstance);
7574

7675
/**
7776
* @param jobName {@link String} containing the name of the job.
@@ -84,8 +83,7 @@ default JobExecution createJobExecution(JobInstance jobInstance, JobParameters j
8483
* @param executionId {@link Long} containing the id of the execution.
8584
* @return the {@link JobExecution} for given identifier.
8685
*/
87-
@Nullable
88-
JobExecution getJobExecution(long executionId);
86+
@Nullable JobExecution getJobExecution(long executionId);
8987

9088
/**
9189
* 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: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.batch.core.job.JobInstance;
2323
import org.springframework.batch.core.job.parameters.JobParameters;
2424
import org.springframework.batch.core.launch.NoSuchJobException;
25-
import org.springframework.lang.Nullable;
25+
import org.jspecify.annotations.Nullable;
2626

2727
/**
2828
* Data Access Object for job instances.
@@ -57,16 +57,14 @@ public interface JobInstanceDao {
5757
* @return {@link JobInstance} object matching the job name and {@link JobParameters}
5858
* or {@code null}
5959
*/
60-
@Nullable
61-
JobInstance getJobInstance(String jobName, JobParameters jobParameters);
60+
@Nullable JobInstance getJobInstance(String jobName, JobParameters jobParameters);
6261

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

7169
/**
7270
* Fetch the JobInstance for the provided JobExecution.
@@ -109,8 +107,7 @@ default List<JobInstance> getJobInstances(String jobName) {
109107
*
110108
* @since 4.2
111109
*/
112-
@Nullable
113-
default JobInstance getLastJobInstance(String jobName) {
110+
@Nullable default JobInstance getLastJobInstance(String jobName) {
114111
throw new UnsupportedOperationException();
115112
}
116113

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.batch.core.job.JobExecution;
2323
import org.springframework.batch.core.job.JobInstance;
2424
import org.springframework.batch.core.step.StepExecution;
25-
import org.springframework.lang.Nullable;
25+
import org.jspecify.annotations.Nullable;
2626

2727
public interface StepExecutionDao {
2828

@@ -55,8 +55,7 @@ default StepExecution createStepExecution(String stepName, JobExecution jobExecu
5555
* @return a {@link StepExecution}
5656
* @since 6.0
5757
*/
58-
@Nullable
59-
StepExecution getStepExecution(long stepExecutionId);
58+
@Nullable StepExecution getStepExecution(long stepExecutionId);
6059

6160
/**
6261
* Retrieve a {@link StepExecution} from its id.
@@ -76,8 +75,7 @@ default StepExecution createStepExecution(String stepName, JobExecution jobExecu
7675
* @param stepName the name of the step
7776
* @return a {@link StepExecution}
7877
*/
79-
@Nullable
80-
default StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
78+
@Nullable default StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
8179
throw new UnsupportedOperationException();
8280
}
8381

0 commit comments

Comments
 (0)