Cron Atlas

Quartz error ? in the wrong place

'?' can only be specified for Day-of-Month -OR- Day-of-Week.

java.lang.RuntimeException: CronExpression '0 0 12 ? * ?' is invalid.
Caused by: java.text.ParseException: '?' can only be specified for Day-of-Month -OR- Day-of-Week.
java.lang.RuntimeException: CronExpression '0 0 ? * * *' is invalid.
Caused by: java.text.ParseException: '?' can only be specified for Day-of-Month or Day-of-Week.

Message produced by running the expression through org.quartz.CronExpression from Quartz 2.5.2.

What it means

Quartz has two messages about ?, which means “no specific value”. The one with “-OR-” in capitals means both day fields hold ?. One of them has to carry the schedule, so only one can be left open. The other means ? is in a field that isn’t a day field, such as the hour, where Quartz doesn’t allow it.

? is not a wildcard. For “every” in any field, use *.

Rejected expressions and their fixes

Each expression opens in the tester. The message under a rejected one is what Quartz 2.5.2 printed for it.

  1. Rejected0 0 12 ? * ?'?' can only be specified for Day-of-Month -OR- Day-of-Week.
    Use
    0 0 12 * * ?At 12:00.

    Every day at noon: * in day of month, ? in day of week.

  2. Rejected0 0 ? * * *'?' can only be specified for Day-of-Month or Day-of-Week.
    Use
    0 0 * * * ?Every hour, on the hour.

    Every hour on the hour: * in the hour, and the ? moved to day of week.

Questions

What is the difference between ? and * in Quartz?
* means every value. ? means the field is deliberately left out, and it is only allowed in day of month and day of week. Quartz needs exactly one of those two to be ?.
Can both day fields be ??
No. That is what the message with “-OR-” is about. Give the field that carries the schedule a value or *.

Other Quartz errors

Reference