Defensively detect non-empty String fields in @Scheduled
Issue: SPR-11223
This commit is contained in:
parent
b6970d3504
commit
e2f85fc1d0
|
|
@ -61,12 +61,13 @@ public @interface Scheduled {
|
|||
String cron() default "";
|
||||
|
||||
/**
|
||||
* A time zone for which the cron expression will be resolved.
|
||||
* By default, the server's local time zone will be used.
|
||||
* @return a zone id accepted by {@link java.util.TimeZone#getTimeZone(String)}
|
||||
* A time zone for which the cron expression will be resolved. By default, this
|
||||
* attribute is the empty String (i.e. the server's local time zone will be used).
|
||||
* @return a zone id accepted by {@link java.util.TimeZone#getTimeZone(String)},
|
||||
* or an empty String to indicate the server's default time zone
|
||||
* @since 4.0
|
||||
* @see org.springframework.scheduling.support.CronTrigger#CronTrigger(String, java.util.TimeZone)
|
||||
* @see java.util.TimeZone
|
||||
* @since 4.0
|
||||
*/
|
||||
String zone() default "";
|
||||
|
||||
|
|
|
|||
|
|
@ -134,8 +134,8 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
|
||||
if (AopUtils.isJdkDynamicProxy(bean)) {
|
||||
try {
|
||||
// found a @Scheduled method on the target class for this JDK proxy -> is it
|
||||
// also present on the proxy itself?
|
||||
// Found a @Scheduled method on the target class for this JDK proxy ->
|
||||
// is it also present on the proxy itself?
|
||||
method = bean.getClass().getMethod(method.getName(), method.getParameterTypes());
|
||||
}
|
||||
catch (SecurityException ex) {
|
||||
|
|
@ -158,7 +158,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
// Determine initial delay
|
||||
long initialDelay = scheduled.initialDelay();
|
||||
String initialDelayString = scheduled.initialDelayString();
|
||||
if (!"".equals(initialDelayString)) {
|
||||
if (StringUtils.hasText(initialDelayString)) {
|
||||
Assert.isTrue(initialDelay < 0, "Specify 'initialDelay' or 'initialDelayString', not both");
|
||||
if (this.embeddedValueResolver != null) {
|
||||
initialDelayString = this.embeddedValueResolver.resolveStringValue(initialDelayString);
|
||||
|
|
@ -174,7 +174,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
|
||||
// Check cron expression
|
||||
String cron = scheduled.cron();
|
||||
if (!"".equals(cron)) {
|
||||
if (StringUtils.hasText(cron)) {
|
||||
Assert.isTrue(initialDelay == -1, "'initialDelay' not supported for cron triggers");
|
||||
processedSchedule = true;
|
||||
String zone = scheduled.zone();
|
||||
|
|
@ -183,7 +183,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
zone = this.embeddedValueResolver.resolveStringValue(zone);
|
||||
}
|
||||
TimeZone timeZone;
|
||||
if (!"".equals(zone)) {
|
||||
if (StringUtils.hasText(zone)) {
|
||||
timeZone = StringUtils.parseTimeZoneString(zone);
|
||||
}
|
||||
else {
|
||||
|
|
@ -205,7 +205,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
this.registrar.addFixedDelayTask(new IntervalTask(runnable, fixedDelay, initialDelay));
|
||||
}
|
||||
String fixedDelayString = scheduled.fixedDelayString();
|
||||
if (!"".equals(fixedDelayString)) {
|
||||
if (StringUtils.hasText(fixedDelayString)) {
|
||||
Assert.isTrue(!processedSchedule, errorMessage);
|
||||
processedSchedule = true;
|
||||
if (this.embeddedValueResolver != null) {
|
||||
|
|
@ -229,7 +229,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
this.registrar.addFixedRateTask(new IntervalTask(runnable, fixedRate, initialDelay));
|
||||
}
|
||||
String fixedRateString = scheduled.fixedRateString();
|
||||
if (!"".equals(fixedRateString)) {
|
||||
if (StringUtils.hasText(fixedRateString)) {
|
||||
Assert.isTrue(!processedSchedule, errorMessage);
|
||||
processedSchedule = true;
|
||||
if (this.embeddedValueResolver != null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue