Skip to content

Reject day-of-week ordinals above 5 in Quartz cron expressions - #37720

Open
Marti2203 wants to merge 1 commit into
spring-projects:mainfrom
Marti2203:quartz-cron-ordinal-range
Open

Marti2203 wants to merge 1 commit into
spring-projects:mainfrom
Marti2203:quartz-cron-ordinal-range

Conversation

@Marti2203

Copy link
Copy Markdown

QuartzCronField only rejects # ordinals that are not positive. An expression such as 0 0 0 ? * MON#6 therefore parses without error but never fires: no month has a sixth Monday, so the adjuster always returns null, and CronExpression.next() never finds a match. The mistake only shows up when the scheduled task never runs. MON#3 fires as expected.

This change accepts ordinals from 1 to 5 only, as Quartz's own CronExpression does. QuartzCronFieldTests.invalidValues now also checks 1#0, 1#6 and MON#6.

Testing: the org.springframework.scheduling.support tests (221, including CronExpressionTests, CronTriggerTests and QuartzCronFieldTests), :spring-context:checkstyleMain and checkstyleTest pass. 7.0.x and 6.2.x have the same code.

The issue was found by an LLM-assisted tool and verified manually.

QuartzCronField only rejects '#' ordinals that are not positive, so an
expression such as "0 0 0 ? * MON#6" parses without error but never
fires: no month has a sixth Monday, and the adjuster always returns
null. The mistake is only noticed when the task never runs.

Accept ordinals from 1 to 5 only, as Quartz's own CronExpression does.

Signed-off-by: Martin Mirchev <mmirchev@comp.nus.edu.sg>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 18, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants