Cron Atlas

Spring error A range that runs backwards

Minimum value must be less than maximum value '22-2' in cron expression "0 0 22-2 * * *"

java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': Minimum value must be less than maximum value '22-2' in cron expression "0 0 22-2 * * *"
java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': Minimum value must be less than maximum value '5-1' in cron expression "0 0 9 * * FRI-MON"

Message produced by running the expression through org.springframework.scheduling.support.CronExpression from Spring Framework 7.0.10, the parser behind @Scheduled. 6.2.19 prints the same.

What it means

Every range in a Spring cron field has to run from low to high. A range that wraps past the end of the field, such as 22-2 for “10 PM to 2 AM” or FRI-MON for a long weekend, is rejected. Quartz and EventBridge accept wrapping ranges, so expressions copied from them often hit this.

The quoted range in the message is the one Spring read, after swapping names for numbers: FRI-MON appears as 5-1, because Spring counts Monday as 1 and Sunday as 7.

Rejected expressions and their fixes

Each expression opens in the tester. The message under a rejected one is what Spring Framework 7.0.10 printed for it.

  1. Rejected0 0 22-2 * * *Minimum value must be less than maximum value '22-2' in cron expression "0 0 22-2 * * *"
    Use
    0 0 22-23,0-2 * * *At 00:00, 01:00, 02:00, 22:00 and 23:00.

    Hourly from 22:00 to 02:00. Split the range at midnight into a list. Each day’s early hours belong to that day, not to the night before.

  2. Rejected0 0 9 * * FRI-MONMinimum value must be less than maximum value '5-1' in cron expression "0 0 9 * * FRI-MON"
    Use
    0 0 9 * * FRI-SUN,MONAt 09:00, on Sundays and Mondays and Fridays and Saturdays.

    Friday to Monday. FRI-SUN is fine because Sunday is 7, the end of the week.

  3. Rejected0 0 0 1 NOV-FEB *Minimum value must be less than maximum value '11-2' in cron expression "0 0 0 1 NOV-FEB *"
    Use
    0 0 0 1 NOV-DEC,JAN-FEB *At 00:00, on the 1st of the month, in January and February and November and December.

    November to February. Split at the end of the year.

Questions

Does 7-2 count as a backwards range?
No. A range that starts at 7 in day of week starts at Sunday 0 instead, so 7-2 means Sunday to Tuesday and is accepted.
Why does Quartz accept the same range?
Quartz deliberately supports ranges that overflow the field, such as 22-2 and NOV-FEB. Spring’s parser builds a java.time value range, which must run from low to high.

Other Spring errors

Reference