Cron Atlas

Quartz error Both day fields are set

Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.

java.lang.RuntimeException: CronExpression '0 0 12 * * MON' is invalid.
Caused by: java.text.ParseException: Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.

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

What it means

Quartz reads six or seven fields: second, minute, hour, day of month, month, day of week and an optional year. Exactly one of the two day fields must be ?, meaning “no specific value”. Quartz has no rule for combining a day of month with a day of week, so rather than guess, it refuses any expression where both are set.

A * counts as set. That is why 0 0 12 * * *, which reads as “every day at noon” to anyone used to Unix cron or Spring, fails with this message too.

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 * * *Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.
    Use
    0 0 12 * * ?At 12:00.

    Every day at noon. * in day of month already means every day, so day of week becomes ?.

  2. Rejected0 0 12 * * MONSupport for specifying both a day-of-week AND a day-of-month parameter is not implemented.
    Use
    0 0 12 ? * MONAt 12:00, on Mondays.

    Mondays at noon. The day of week carries the meaning, so day of month becomes ?.

  3. Rejected0 0 9 1 * MONSupport for specifying both a day-of-week AND a day-of-month parameter is not implemented.
    Use both
    0 0 9 1 * ?At 09:00, on the 1st of the month.
    and
    0 0 9 ? * MONAt 09:00, on Mondays.

    Unix cron reads this as the 1st of the month or any Monday. Quartz can’t say “or” across the day fields, so give the job two triggers.

  4. Rejected0 0 9 1-7 * MONSupport for specifying both a day-of-week AND a day-of-month parameter is not implemented.
    Use
    0 0 9 ? * MON#1At 09:00, on the first Monday of the month.

    Meant as the first Monday of the month? Quartz has # for that: MON#1 is the first Monday.

Questions

Does * count as setting a day field in Quartz?
Yes. Only ? leaves a day field unset, so * in both is rejected. Put ? in one of them: 0 0 12 * * ? or 0 0 12 ? * *.
Which day field should get the ??
The one you are not using. For a schedule by weekday, put ? in day of month: 0 0 9 ? * MON-FRI. For a date, or every day, put it in day of week: 0 0 9 15 * ?.
Does AWS EventBridge have the same rule?
Yes. EventBridge cron expressions also need ? in exactly one of the two day fields, though AWS reports the problem with its own message.

Other Quartz errors

Reference