Skip to content

Commit 5764db2

Browse files
committed
Add nullability annotations to module/spring-boot-quartz
See gh-46587
1 parent 42366b6 commit 5764db2

File tree

9 files changed

+46
-23
lines changed

9 files changed

+46
-23
lines changed

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/autoconfigure/QuartzAutoConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import javax.sql.DataSource;
2323

24+
import org.jspecify.annotations.Nullable;
2425
import org.quartz.Calendar;
2526
import org.quartz.JobDetail;
2627
import org.quartz.Scheduler;
@@ -120,7 +121,7 @@ private static DataSource getDataSource(DataSource dataSource, ObjectProvider<Da
120121
return (dataSourceIfAvailable != null) ? dataSourceIfAvailable : dataSource;
121122
}
122123

123-
private PlatformTransactionManager getTransactionManager(
124+
private @Nullable PlatformTransactionManager getTransactionManager(
124125
ObjectProvider<PlatformTransactionManager> transactionManager,
125126
ObjectProvider<PlatformTransactionManager> quartzTransactionManager) {
126127
PlatformTransactionManager transactionManagerIfAvailable = quartzTransactionManager.getIfAvailable();

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/autoconfigure/QuartzDataSourceScriptDatabaseInitializer.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import javax.sql.DataSource;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.jdbc.DatabaseDriver;
2426
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
2527
import org.springframework.boot.jdbc.init.PlatformPlaceholderDatabaseDriverResolver;
@@ -39,7 +41,7 @@
3941
*/
4042
public class QuartzDataSourceScriptDatabaseInitializer extends DataSourceScriptDatabaseInitializer {
4143

42-
private final List<String> commentPrefixes;
44+
private final @Nullable List<String> commentPrefixes;
4345

4446
/**
4547
* Create a new {@link QuartzDataSourceScriptDatabaseInitializer} instance.
@@ -62,7 +64,7 @@ public QuartzDataSourceScriptDatabaseInitializer(DataSource dataSource, Database
6264
}
6365

6466
private QuartzDataSourceScriptDatabaseInitializer(DataSource dataSource, DatabaseInitializationSettings settings,
65-
List<String> commentPrefixes) {
67+
@Nullable List<String> commentPrefixes) {
6668
super(dataSource, settings);
6769
this.commentPrefixes = commentPrefixes;
6870
}

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/autoconfigure/QuartzJdbcProperties.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.context.properties.ConfigurationProperties;
2426
import org.springframework.boot.sql.init.DatabaseInitializationMode;
2527

@@ -46,7 +48,7 @@ public class QuartzJdbcProperties {
4648
* Platform to use in initialization scripts if the @@platform@@ placeholder is used.
4749
* Auto-detected by default.
4850
*/
49-
private String platform;
51+
private @Nullable String platform;
5052

5153
/**
5254
* Database schema initialization mode.
@@ -66,11 +68,11 @@ public void setSchema(String schema) {
6668
this.schema = schema;
6769
}
6870

69-
public String getPlatform() {
71+
public @Nullable String getPlatform() {
7072
return this.platform;
7173
}
7274

73-
public void setPlatform(String platform) {
75+
public void setPlatform(@Nullable String platform) {
7476
this.platform = platform;
7577
}
7678

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/autoconfigure/QuartzProperties.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.HashMap;
2121
import java.util.Map;
2222

23+
import org.jspecify.annotations.Nullable;
24+
2325
import org.springframework.boot.context.properties.ConfigurationProperties;
2426

2527
/**
@@ -40,7 +42,7 @@ public class QuartzProperties {
4042
/**
4143
* Name of the scheduler.
4244
*/
43-
private String schedulerName;
45+
private @Nullable String schedulerName;
4446

4547
/**
4648
* Whether to automatically start the scheduler after initialization.
@@ -77,11 +79,11 @@ public void setJobStoreType(JobStoreType jobStoreType) {
7779
this.jobStoreType = jobStoreType;
7880
}
7981

80-
public String getSchedulerName() {
82+
public @Nullable String getSchedulerName() {
8183
return this.schedulerName;
8284
}
8385

84-
public void setSchedulerName(String schedulerName) {
86+
public void setSchedulerName(@Nullable String schedulerName) {
8587
this.schedulerName = schedulerName;
8688
}
8789

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/autoconfigure/endpoint/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Quartz Scheduler endpoint.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.quartz.autoconfigure.endpoint;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/autoconfigure/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Auto-configuration for Quartz Scheduler.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.quartz.autoconfigure;
22+
23+
import org.jspecify.annotations.NullMarked;

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/endpoint/QuartzEndpoint.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.Set;
3232
import java.util.function.Function;
3333

34+
import org.jspecify.annotations.Nullable;
3435
import org.quartz.CalendarIntervalTrigger;
3536
import org.quartz.CronTrigger;
3637
import org.quartz.DailyTimeIntervalTrigger;
@@ -55,6 +56,7 @@
5556
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
5657
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
5758
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
59+
import org.springframework.lang.Contract;
5860
import org.springframework.util.Assert;
5961

6062
/**
@@ -137,7 +139,7 @@ public QuartzGroupsDescriptor quartzTriggerGroups() throws SchedulerException {
137139
* @return a summary of the jobs in the given {@code group}
138140
* @throws SchedulerException if retrieving the information from the scheduler failed
139141
*/
140-
public QuartzJobGroupSummaryDescriptor quartzJobGroupSummary(String group) throws SchedulerException {
142+
public @Nullable QuartzJobGroupSummaryDescriptor quartzJobGroupSummary(String group) throws SchedulerException {
141143
List<JobDetail> jobs = findJobsByGroup(group);
142144
if (jobs.isEmpty() && !this.scheduler.getJobGroupNames().contains(group)) {
143145
return null;
@@ -165,7 +167,8 @@ private List<JobDetail> findJobsByGroup(String group) throws SchedulerException
165167
* @return a summary of the triggers in the given {@code group}
166168
* @throws SchedulerException if retrieving the information from the scheduler failed
167169
*/
168-
public QuartzTriggerGroupSummaryDescriptor quartzTriggerGroupSummary(String group) throws SchedulerException {
170+
public @Nullable QuartzTriggerGroupSummaryDescriptor quartzTriggerGroupSummary(String group)
171+
throws SchedulerException {
169172
List<Trigger> triggers = findTriggersByGroup(group);
170173
if (triggers.isEmpty() && !this.scheduler.getTriggerGroupNames().contains(group)) {
171174
return null;
@@ -199,7 +202,7 @@ private List<Trigger> findTriggersByGroup(String group) throws SchedulerExceptio
199202
* @return the details of the job or {@code null} if such job does not exist
200203
* @throws SchedulerException if retrieving the information from the scheduler failed
201204
*/
202-
public QuartzJobDetailsDescriptor quartzJob(String groupName, String jobName, boolean showUnsanitized)
205+
public @Nullable QuartzJobDetailsDescriptor quartzJob(String groupName, String jobName, boolean showUnsanitized)
203206
throws SchedulerException {
204207
JobKey jobKey = JobKey.jobKey(jobName, groupName);
205208
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
@@ -219,11 +222,12 @@ public QuartzJobDetailsDescriptor quartzJob(String groupName, String jobName, bo
219222
* exist
220223
* @throws SchedulerException if there is an error triggering the job
221224
*/
222-
public QuartzJobTriggerDescriptor triggerQuartzJob(String groupName, String jobName) throws SchedulerException {
225+
public @Nullable QuartzJobTriggerDescriptor triggerQuartzJob(String groupName, String jobName)
226+
throws SchedulerException {
223227
return triggerQuartzJob(JobKey.jobKey(jobName, groupName));
224228
}
225229

226-
private QuartzJobTriggerDescriptor triggerQuartzJob(JobKey jobKey) throws SchedulerException {
230+
private @Nullable QuartzJobTriggerDescriptor triggerQuartzJob(JobKey jobKey) throws SchedulerException {
227231
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
228232
if (jobDetail == null) {
229233
return null;
@@ -255,7 +259,7 @@ private static List<Map<String, Object>> extractTriggersSummary(List<? extends T
255259
* @return the details of the trigger or {@code null} if such trigger does not exist
256260
* @throws SchedulerException if retrieving the information from the scheduler failed
257261
*/
258-
Map<String, Object> quartzTrigger(String groupName, String triggerName, boolean showUnsanitized)
262+
@Nullable Map<String, Object> quartzTrigger(String groupName, String triggerName, boolean showUnsanitized)
259263
throws SchedulerException {
260264
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, groupName);
261265
Trigger trigger = this.scheduler.getTrigger(triggerKey);
@@ -272,12 +276,13 @@ private static Duration getIntervalDuration(long amount, IntervalUnit unit) {
272276
return temporalUnit(unit).getDuration().multipliedBy(amount);
273277
}
274278

275-
private static LocalTime getLocalTime(TimeOfDay timeOfDay) {
279+
private static @Nullable LocalTime getLocalTime(@Nullable TimeOfDay timeOfDay) {
276280
return (timeOfDay != null) ? LocalTime.of(timeOfDay.getHour(), timeOfDay.getMinute(), timeOfDay.getSecond())
277281
: null;
278282
}
279283

280-
private Map<String, Object> sanitizeJobDataMap(JobDataMap dataMap, boolean showUnsanitized) {
284+
@Contract("!null, _ -> !null")
285+
private @Nullable Map<String, Object> sanitizeJobDataMap(@Nullable JobDataMap dataMap, boolean showUnsanitized) {
281286
if (dataMap == null) {
282287
return null;
283288
}
@@ -286,7 +291,7 @@ private Map<String, Object> sanitizeJobDataMap(JobDataMap dataMap, boolean showU
286291
return map;
287292
}
288293

289-
private Object getSanitizedValue(boolean showUnsanitized, String key, Object value) {
294+
private @Nullable Object getSanitizedValue(boolean showUnsanitized, String key, @Nullable Object value) {
290295
SanitizableData data = new SanitizableData(null, key, value);
291296
return this.sanitizer.sanitize(data, showUnsanitized);
292297
}
@@ -669,7 +674,8 @@ public Map<String, Object> buildSummary(boolean addTriggerSpecificSummary) {
669674
* @param sanitizedDataMap a sanitized data map or {@code null}
670675
* @return all properties of the trigger
671676
*/
672-
public Map<String, Object> buildDetails(TriggerState triggerState, Map<String, Object> sanitizedDataMap) {
677+
public Map<String, Object> buildDetails(TriggerState triggerState,
678+
@Nullable Map<String, Object> sanitizedDataMap) {
673679
Map<String, Object> details = new LinkedHashMap<>();
674680
details.put("group", this.trigger.getKey().getGroup());
675681
details.put("name", this.trigger.getKey().getName());
@@ -697,7 +703,7 @@ public Map<String, Object> buildDetails(TriggerState triggerState, Map<String, O
697703
*/
698704
protected abstract void appendDetails(Map<String, Object> content);
699705

700-
protected void putIfNoNull(Map<String, Object> content, String key, Object value) {
706+
protected void putIfNoNull(Map<String, Object> content, String key, @Nullable Object value) {
701707
if (value != null) {
702708
content.put(key, value);
703709
}

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/endpoint/QuartzEndpointWebExtension.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Set;
2020

21+
import org.jspecify.annotations.Nullable;
2122
import org.quartz.SchedulerException;
2223

2324
import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
@@ -109,15 +110,15 @@ private <T> WebEndpointResponse<T> handle(String jobsOrTriggers, ResponseSupplie
109110
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_BAD_REQUEST);
110111
}
111112

112-
private <T> WebEndpointResponse<T> handleNull(T value) {
113+
private <T> WebEndpointResponse<T> handleNull(@Nullable T value) {
113114
return (value != null) ? new WebEndpointResponse<>(value)
114115
: new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
115116
}
116117

117118
@FunctionalInterface
118119
private interface ResponseSupplier<T> {
119120

120-
T get() throws SchedulerException;
121+
@Nullable T get() throws SchedulerException;
121122

122123
}
123124

@@ -126,7 +127,7 @@ static class QuartzEndpointWebExtensionRuntimeHints implements RuntimeHintsRegis
126127
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
127128

128129
@Override
129-
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
130+
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
130131
this.bindingRegistrar.registerReflectionHints(hints.reflection(), QuartzGroupsDescriptor.class,
131132
QuartzJobDetailsDescriptor.class, QuartzJobGroupSummaryDescriptor.class,
132133
QuartzTriggerGroupSummaryDescriptor.class);

module/spring-boot-quartz/src/main/java/org/springframework/boot/quartz/endpoint/package-info.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,7 @@
1717
/**
1818
* Actuator endpoint for Quartz Scheduler.
1919
*/
20+
@NullMarked
2021
package org.springframework.boot.quartz.endpoint;
22+
23+
import org.jspecify.annotations.NullMarked;

0 commit comments

Comments
 (0)