Add nullability annotations to module/spring-boot-quartz

See gh-46587
This commit is contained in:
Moritz Halbritter
2025-08-05 08:55:58 +02:00
parent 42366b63ee
commit 5764db24a0
9 changed files with 46 additions and 23 deletions
@@ -21,6 +21,7 @@ import java.util.Properties;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.quartz.Calendar;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
@@ -120,7 +121,7 @@ public final class QuartzAutoConfiguration {
return (dataSourceIfAvailable != null) ? dataSourceIfAvailable : dataSource;
}
private PlatformTransactionManager getTransactionManager(
private @Nullable PlatformTransactionManager getTransactionManager(
ObjectProvider<PlatformTransactionManager> transactionManager,
ObjectProvider<PlatformTransactionManager> quartzTransactionManager) {
PlatformTransactionManager transactionManagerIfAvailable = quartzTransactionManager.getIfAvailable();
@@ -20,6 +20,8 @@ import java.util.List;
import javax.sql.DataSource;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.jdbc.init.DataSourceScriptDatabaseInitializer;
import org.springframework.boot.jdbc.init.PlatformPlaceholderDatabaseDriverResolver;
@@ -39,7 +41,7 @@ import org.springframework.util.StringUtils;
*/
public class QuartzDataSourceScriptDatabaseInitializer extends DataSourceScriptDatabaseInitializer {
private final List<String> commentPrefixes;
private final @Nullable List<String> commentPrefixes;
/**
* Create a new {@link QuartzDataSourceScriptDatabaseInitializer} instance.
@@ -62,7 +64,7 @@ public class QuartzDataSourceScriptDatabaseInitializer extends DataSourceScriptD
}
private QuartzDataSourceScriptDatabaseInitializer(DataSource dataSource, DatabaseInitializationSettings settings,
List<String> commentPrefixes) {
@Nullable List<String> commentPrefixes) {
super(dataSource, settings);
this.commentPrefixes = commentPrefixes;
}
@@ -20,6 +20,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.sql.init.DatabaseInitializationMode;
@@ -46,7 +48,7 @@ public class QuartzJdbcProperties {
* Platform to use in initialization scripts if the @@platform@@ placeholder is used.
* Auto-detected by default.
*/
private String platform;
private @Nullable String platform;
/**
* Database schema initialization mode.
@@ -66,11 +68,11 @@ public class QuartzJdbcProperties {
this.schema = schema;
}
public String getPlatform() {
public @Nullable String getPlatform() {
return this.platform;
}
public void setPlatform(String platform) {
public void setPlatform(@Nullable String platform) {
this.platform = platform;
}
@@ -20,6 +20,8 @@ import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import org.jspecify.annotations.Nullable;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
@@ -40,7 +42,7 @@ public class QuartzProperties {
/**
* Name of the scheduler.
*/
private String schedulerName;
private @Nullable String schedulerName;
/**
* Whether to automatically start the scheduler after initialization.
@@ -77,11 +79,11 @@ public class QuartzProperties {
this.jobStoreType = jobStoreType;
}
public String getSchedulerName() {
public @Nullable String getSchedulerName() {
return this.schedulerName;
}
public void setSchedulerName(String schedulerName) {
public void setSchedulerName(@Nullable String schedulerName) {
this.schedulerName = schedulerName;
}
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Quartz Scheduler endpoint.
*/
@NullMarked
package org.springframework.boot.quartz.autoconfigure.endpoint;
import org.jspecify.annotations.NullMarked;
@@ -17,4 +17,7 @@
/**
* Auto-configuration for Quartz Scheduler.
*/
@NullMarked
package org.springframework.boot.quartz.autoconfigure;
import org.jspecify.annotations.NullMarked;
@@ -31,6 +31,7 @@ import java.util.Map;
import java.util.Set;
import java.util.function.Function;
import org.jspecify.annotations.Nullable;
import org.quartz.CalendarIntervalTrigger;
import org.quartz.CronTrigger;
import org.quartz.DailyTimeIntervalTrigger;
@@ -55,6 +56,7 @@ import org.springframework.boot.actuate.endpoint.Sanitizer;
import org.springframework.boot.actuate.endpoint.SanitizingFunction;
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.lang.Contract;
import org.springframework.util.Assert;
/**
@@ -137,7 +139,7 @@ public class QuartzEndpoint {
* @return a summary of the jobs in the given {@code group}
* @throws SchedulerException if retrieving the information from the scheduler failed
*/
public QuartzJobGroupSummaryDescriptor quartzJobGroupSummary(String group) throws SchedulerException {
public @Nullable QuartzJobGroupSummaryDescriptor quartzJobGroupSummary(String group) throws SchedulerException {
List<JobDetail> jobs = findJobsByGroup(group);
if (jobs.isEmpty() && !this.scheduler.getJobGroupNames().contains(group)) {
return null;
@@ -165,7 +167,8 @@ public class QuartzEndpoint {
* @return a summary of the triggers in the given {@code group}
* @throws SchedulerException if retrieving the information from the scheduler failed
*/
public QuartzTriggerGroupSummaryDescriptor quartzTriggerGroupSummary(String group) throws SchedulerException {
public @Nullable QuartzTriggerGroupSummaryDescriptor quartzTriggerGroupSummary(String group)
throws SchedulerException {
List<Trigger> triggers = findTriggersByGroup(group);
if (triggers.isEmpty() && !this.scheduler.getTriggerGroupNames().contains(group)) {
return null;
@@ -199,7 +202,7 @@ public class QuartzEndpoint {
* @return the details of the job or {@code null} if such job does not exist
* @throws SchedulerException if retrieving the information from the scheduler failed
*/
public QuartzJobDetailsDescriptor quartzJob(String groupName, String jobName, boolean showUnsanitized)
public @Nullable QuartzJobDetailsDescriptor quartzJob(String groupName, String jobName, boolean showUnsanitized)
throws SchedulerException {
JobKey jobKey = JobKey.jobKey(jobName, groupName);
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
@@ -219,11 +222,12 @@ public class QuartzEndpoint {
* exist
* @throws SchedulerException if there is an error triggering the job
*/
public QuartzJobTriggerDescriptor triggerQuartzJob(String groupName, String jobName) throws SchedulerException {
public @Nullable QuartzJobTriggerDescriptor triggerQuartzJob(String groupName, String jobName)
throws SchedulerException {
return triggerQuartzJob(JobKey.jobKey(jobName, groupName));
}
private QuartzJobTriggerDescriptor triggerQuartzJob(JobKey jobKey) throws SchedulerException {
private @Nullable QuartzJobTriggerDescriptor triggerQuartzJob(JobKey jobKey) throws SchedulerException {
JobDetail jobDetail = this.scheduler.getJobDetail(jobKey);
if (jobDetail == null) {
return null;
@@ -255,7 +259,7 @@ public class QuartzEndpoint {
* @return the details of the trigger or {@code null} if such trigger does not exist
* @throws SchedulerException if retrieving the information from the scheduler failed
*/
Map<String, Object> quartzTrigger(String groupName, String triggerName, boolean showUnsanitized)
@Nullable Map<String, Object> quartzTrigger(String groupName, String triggerName, boolean showUnsanitized)
throws SchedulerException {
TriggerKey triggerKey = TriggerKey.triggerKey(triggerName, groupName);
Trigger trigger = this.scheduler.getTrigger(triggerKey);
@@ -272,12 +276,13 @@ public class QuartzEndpoint {
return temporalUnit(unit).getDuration().multipliedBy(amount);
}
private static LocalTime getLocalTime(TimeOfDay timeOfDay) {
private static @Nullable LocalTime getLocalTime(@Nullable TimeOfDay timeOfDay) {
return (timeOfDay != null) ? LocalTime.of(timeOfDay.getHour(), timeOfDay.getMinute(), timeOfDay.getSecond())
: null;
}
private Map<String, Object> sanitizeJobDataMap(JobDataMap dataMap, boolean showUnsanitized) {
@Contract("!null, _ -> !null")
private @Nullable Map<String, Object> sanitizeJobDataMap(@Nullable JobDataMap dataMap, boolean showUnsanitized) {
if (dataMap == null) {
return null;
}
@@ -286,7 +291,7 @@ public class QuartzEndpoint {
return map;
}
private Object getSanitizedValue(boolean showUnsanitized, String key, Object value) {
private @Nullable Object getSanitizedValue(boolean showUnsanitized, String key, @Nullable Object value) {
SanitizableData data = new SanitizableData(null, key, value);
return this.sanitizer.sanitize(data, showUnsanitized);
}
@@ -669,7 +674,8 @@ public class QuartzEndpoint {
* @param sanitizedDataMap a sanitized data map or {@code null}
* @return all properties of the trigger
*/
public Map<String, Object> buildDetails(TriggerState triggerState, Map<String, Object> sanitizedDataMap) {
public Map<String, Object> buildDetails(TriggerState triggerState,
@Nullable Map<String, Object> sanitizedDataMap) {
Map<String, Object> details = new LinkedHashMap<>();
details.put("group", this.trigger.getKey().getGroup());
details.put("name", this.trigger.getKey().getName());
@@ -697,7 +703,7 @@ public class QuartzEndpoint {
*/
protected abstract void appendDetails(Map<String, Object> content);
protected void putIfNoNull(Map<String, Object> content, String key, Object value) {
protected void putIfNoNull(Map<String, Object> content, String key, @Nullable Object value) {
if (value != null) {
content.put(key, value);
}
@@ -18,6 +18,7 @@ package org.springframework.boot.quartz.endpoint;
import java.util.Set;
import org.jspecify.annotations.Nullable;
import org.quartz.SchedulerException;
import org.springframework.aot.hint.BindingReflectionHintsRegistrar;
@@ -109,7 +110,7 @@ public class QuartzEndpointWebExtension {
return new WebEndpointResponse<>(WebEndpointResponse.STATUS_BAD_REQUEST);
}
private <T> WebEndpointResponse<T> handleNull(T value) {
private <T> WebEndpointResponse<T> handleNull(@Nullable T value) {
return (value != null) ? new WebEndpointResponse<>(value)
: new WebEndpointResponse<>(WebEndpointResponse.STATUS_NOT_FOUND);
}
@@ -117,7 +118,7 @@ public class QuartzEndpointWebExtension {
@FunctionalInterface
private interface ResponseSupplier<T> {
T get() throws SchedulerException;
@Nullable T get() throws SchedulerException;
}
@@ -126,7 +127,7 @@ public class QuartzEndpointWebExtension {
private final BindingReflectionHintsRegistrar bindingRegistrar = new BindingReflectionHintsRegistrar();
@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
public void registerHints(RuntimeHints hints, @Nullable ClassLoader classLoader) {
this.bindingRegistrar.registerReflectionHints(hints.reflection(), QuartzGroupsDescriptor.class,
QuartzJobDetailsDescriptor.class, QuartzJobGroupSummaryDescriptor.class,
QuartzTriggerGroupSummaryDescriptor.class);
@@ -17,4 +17,7 @@
/**
* Actuator endpoint for Quartz Scheduler.
*/
@NullMarked
package org.springframework.boot.quartz.endpoint;
import org.jspecify.annotations.NullMarked;