diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java index 2bcf6bbf75..73d12fab69 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/CronTriggerFactoryBean.java @@ -207,6 +207,8 @@ public class CronTriggerFactoryBean implements FactoryBean, BeanNam * Specify the misfire instruction for this trigger. */ public void setMisfireInstruction(int misfireInstruction) { + Assert.isTrue(constants.containsValue(misfireInstruction), + "Only values of misfire instruction constants allowed"); this.misfireInstruction = misfireInstruction; } diff --git a/spring-context-support/src/test/java/org/springframework/scheduling/quartz/CronTriggerFactoryBeanTests.java b/spring-context-support/src/test/java/org/springframework/scheduling/quartz/CronTriggerFactoryBeanTests.java index 4c96108b63..1bc8cece86 100644 --- a/spring-context-support/src/test/java/org/springframework/scheduling/quartz/CronTriggerFactoryBeanTests.java +++ b/spring-context-support/src/test/java/org/springframework/scheduling/quartz/CronTriggerFactoryBeanTests.java @@ -29,6 +29,8 @@ import org.springframework.util.ReflectionUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.assertj.core.api.Assertions.assertThatNoException; +import static org.quartz.Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY; +import static org.quartz.Trigger.MISFIRE_INSTRUCTION_SMART_POLICY; /** * Tests for {@link CronTriggerFactoryBean}. @@ -68,6 +70,17 @@ class CronTriggerFactoryBeanTests { .forEach(name -> assertThatNoException().as(name).isThrownBy(() -> factory.setMisfireInstructionName(name))); } + @Test + void setMisfireInstruction() { + assertThatIllegalArgumentException().isThrownBy(() -> factory.setMisfireInstruction(999)); + + assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_SMART_POLICY)); + assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY)); + assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_FIRE_ONCE_NOW)); + assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(CronTrigger.MISFIRE_INSTRUCTION_DO_NOTHING)); + } + + private static Stream streamMisfireInstructionConstants() { return Arrays.stream(CronTrigger.class.getFields()) .filter(ReflectionUtils::isPublicStaticFinal)