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.
-
Use0 */5 * * * ?Every 5 minutes.
Every 5 minutes. Seconds
0in front, and?in day of week. -
Use0 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 or2-6. -
Use0 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.CronExpressionalways 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
- Support for specifying both a day-of-week AND a day-of-month parameter is not implemented.Quartz: Both day fields are set
- '?' can only be specified for Day-of-Month -OR- Day-of-Week.Quartz:
?in the wrong place - Day-of-Week values must be between 1 and 7Quartz: Sunday written as 0
- Hour values must be between 0 and 23Quartz: A value out of range
- Increment >= 60 : 90Quartz: A step longer than the field
- Unexpected character: @Quartz:
@dailyand other shortcuts