Cron Atlas

Spring error Something that is not a number

For input string: "?" '?' in cron expression "0 ? * * * *"

java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': For input string: "?" '?' in cron expression "0 ? * * * *"
java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': For input string: "H" 'H' in cron expression "H 0 9 * * *"
java.lang.IllegalStateException: Encountered invalid @Scheduled method 'run': For input string: "l" 'l' in cron expression "0 0 9 l * *"

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

After expanding names such as MON and JAN and the special forms L, W and #, Spring reads every remaining item as a whole number. When that fails, Java’s NumberFormatException text comes straight through, quoting the piece it could not read.

The usual causes are ? outside the two day fields, Jenkins’ H, a lower-case l or w in day of month (names are case-insensitive, those letters are not), L in an hour or minute field, and W in day of week.

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 ? * * * *For input string: "?" '?' in cron expression "0 ? * * * *"
    Use
    0 * * * * *Every minute.

    Every minute. ? only means “any” in day of month and day of week; use * elsewhere.

  2. Rejected0 0 9 ? ? *For input string: "?" '?' in cron expression "0 0 9 ? ? *"
    Use
    0 0 9 ? * *At 09:00.

    Every day at 09:00. Month cannot be ?.

  3. RejectedH 0 9 * * *For input string: "H" 'H' in cron expression "H 0 9 * * *"
    Use
    0 0 9 * * *At 09:00.

    H is Jenkins’ hash syntax. Pick a fixed second instead.

  4. Rejected0 0 9 l * *For input string: "l" 'l' in cron expression "0 0 9 l * *"
    Use
    0 0 9 L * *At 09:00, on the last day of the month.

    The last day of the month. L must be a capital.

  5. Rejected0 0 9 * * 5WFor input string: "5W" '5W' in cron expression "0 0 9 * * 5W"
    Use
    0 0 9 * * FRIAt 09:00, on Fridays.

    W belongs in day of month, as in 15W. In day of week, name the day.

Questions

Can I use ? in Spring cron?
Yes, in day of month and day of week, where it means the same as *. Spring does not require it, unlike Quartz, so 0 0 9 * * MON is fine.
Are Spring cron expressions case-sensitive?
Month and day names are not: mon-fri works. The L and W in day of month must be capitals.

Other Spring errors

Reference