Cron Atlas

Quartz error Five fields instead of six

Unexpected end of expression.

java.lang.RuntimeException: CronExpression '*/5 * * * *' is invalid.
Caused by: java.text.ParseException: Unexpected end of expression.

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

What it means

Quartz needs at least six fields, starting with seconds: second, minute, hour, day of month, month, day of week, then an optional year. It ran out of fields before it reached day of week, which almost always means a five-field Unix, Kubernetes or GitHub Actions expression was pasted in.

Adding a 0 in front for the seconds is not quite enough. Quartz also needs ? in one day field, and it numbers the days of the week from 1 = Sunday, so weekday numbers shift by one. Names such as MON-FRI avoid that trap.

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. Rejected*/5 * * * *Unexpected end of expression.
    Use
    0 */5 * * * ?Every 5 minutes.

    Every 5 minutes. Seconds 0 in front, and ? in day of week.

  2. Rejected0 9 * * 1-5Unexpected end of expression.
    Use
    0 0 9 ? * MON-FRIAt 09:00, Monday through Friday.

    Weekdays at 09:00. Copied as 1-5, Quartz would run Sunday to Thursday, so use names or 2-6.

  3. Rejected0 0 1 * *Unexpected end of expression.
    Use
    0 0 0 1 * ?At 00:00, on the 1st of the month.

    Midnight on the 1st of each month.

Questions

Can Quartz read a five-field cron expression?
No. org.quartz.CronExpression always starts with seconds and needs at least six fields. Convert the expression instead; the tester translates between dialects.
Why is 0 */5 * * * * still rejected?
Six fields get past this error, but both day fields are now *, which Quartz rejects with “Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.” One of them must be ?: 0 */5 * * * ?.

Other Quartz errors

Reference