Skip to content

Commit 81181c3

Browse files
committed
Assert SimpleTriggerFactoryBean.setMisfireInstruction() values
See gh-30851
1 parent 1378cce commit 81181c3

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

spring-context-support/src/main/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBean.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ public void setPriority(int priority) {
204204
* Specify the misfire instruction for this trigger.
205205
*/
206206
public void setMisfireInstruction(int misfireInstruction) {
207+
Assert.isTrue(constants.containsValue(misfireInstruction),
208+
"Only values of misfire instruction constants allowed");
207209
this.misfireInstruction = misfireInstruction;
208210
}
209211

spring-context-support/src/test/java/org/springframework/scheduling/quartz/SimpleTriggerFactoryBeanTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
import static org.assertj.core.api.Assertions.assertThat;
2929
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
3030
import static org.assertj.core.api.Assertions.assertThatNoException;
31+
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_FIRE_NOW;
32+
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT;
33+
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT;
34+
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT;
35+
import static org.quartz.SimpleTrigger.MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT;
36+
import static org.quartz.Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY;
37+
import static org.quartz.Trigger.MISFIRE_INSTRUCTION_SMART_POLICY;
3138

3239
/**
3340
* Tests for {@link SimpleTriggerFactoryBean}.
@@ -69,6 +76,20 @@ void setMisfireInstructionNameToAllSupportedValues() {
6976
.forEach(name -> assertThatNoException().as(name).isThrownBy(() -> factory.setMisfireInstructionName(name)));
7077
}
7178

79+
@Test
80+
void setMisfireInstruction() {
81+
assertThatIllegalArgumentException().isThrownBy(() -> factory.setMisfireInstruction(999));
82+
83+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_SMART_POLICY));
84+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY));
85+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_FIRE_NOW));
86+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_EXISTING_COUNT));
87+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NEXT_WITH_REMAINING_COUNT));
88+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_EXISTING_REPEAT_COUNT));
89+
assertThatNoException().isThrownBy(() -> factory.setMisfireInstruction(MISFIRE_INSTRUCTION_RESCHEDULE_NOW_WITH_REMAINING_REPEAT_COUNT));
90+
}
91+
92+
7293
private static Stream<Field> streamMisfireInstructionConstants() {
7394
return Arrays.stream(SimpleTrigger.class.getFields())
7495
.filter(ReflectionUtils::isPublicStaticFinal)

0 commit comments

Comments
 (0)