Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change in behaviour for cron expression with day of the week range starting with SUN #26598

Closed
andrecampanini opened this issue Feb 23, 2021 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Milestone

Comments

@andrecampanini
Copy link

andrecampanini commented Feb 23, 2021

Affects: Spring Framework 5.3


Before Spring 5.3 the parse for cron expressions had a different behaviour for the day of the week.

Example of an expression that has been working for years: "32 22/5 * ? * SUN-FRI"
Example of its use in Spring 5.3: CronExpression.parse("32 22/5 * ? * SUN-FRI");

Before the six space-separated string SUN-FRI was interpreted as 0-5.
Now in Spring 5.3 it is interpreted as 7-5 and that throws un exception:

Exception in thread "main" java.lang.IllegalArgumentException: Minimum value must be less than maximum value '7-5' in cron expression "32 22/5 * ? * SUN-FRI"
	at org.springframework.scheduling.support.CronExpression.parse(CronExpression.java:201)
	at TestCron.main(TestCron.java:8)
Caused by: java.lang.IllegalArgumentException: Minimum value must be less than maximum value '7-5'
	at org.springframework.scheduling.support.BitsCronField.parseField(BitsCronField.java:150)
	at org.springframework.scheduling.support.BitsCronField.parseDate(BitsCronField.java:117)
	at org.springframework.scheduling.support.BitsCronField.parseDaysOfWeek(BitsCronField.java:103)
	at org.springframework.scheduling.support.CronField.parseDaysOfWeek(CronField.java:105)
	at org.springframework.scheduling.support.CronExpression.parse(CronExpression.java:195)
	... 1 more
Caused by: java.lang.IllegalArgumentException: Minimum value must be less than maximum value
	at java.time.temporal.ValueRange.of(ValueRange.java:127)
	at org.springframework.scheduling.support.BitsCronField.parseRange(BitsCronField.java:169)
	at org.springframework.scheduling.support.BitsCronField.parseField(BitsCronField.java:129)
	... 5 more

A complete and very simple example of use:

import org.springframework.scheduling.support.CronExpression;

public class TestCron {

	public static void main(String[] args) throws Exception {
		CronExpression.parse("32 22/5 * ? * SUN-FRI");
	}
	
}

It seems the class org.springframework.scheduling.support.CronField always consider Monday as position 0 (zero) in its array DAYS. But the documentation https://spring.io/blog/2020/11/10/new-in-spring-5-3-improved-cron-expressions says Sunday is zero (or seven).

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Feb 23, 2021
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Feb 24, 2021
@sbrannen sbrannen changed the title Different behaviour for string with six space-separated string for day of the week Change in behaviour for cron expression with day of the week range starting with SUN Feb 24, 2021
@poutsma poutsma self-assigned this Feb 24, 2021
@poutsma poutsma added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Feb 25, 2021
@poutsma poutsma added this to the 5.3.5 milestone Feb 25, 2021
This was referenced Mar 16, 2021
This was referenced Mar 17, 2021
lxbzmy pushed a commit to lxbzmy/spring-framework that referenced this issue Mar 26, 2022
This commit makes sure that SUN can be used at the beginning of a range,
 like SUN-FRI.

Closes spring-projectsgh-26598
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants