6

Quartz 2.x documentation says

So cron expressions can be as simple as this: * * * * ? * or more complex, like this: 0/5 14,18,3-39,52 * ? JAN,MAR,SEP MON-FRI 2002-2010

But if I try

System.out.println(org.quartz.CronExpression.isValidExpression("* * * * ? * *"));

It says

false

Why?

Javadoc for the isValidExpression is http://quartz-scheduler.org/api/2.2.1/org/quartz/CronExpression.html

Ps. this question is NOT a duplicate of Verifying a cron expression is valid in Java

Community
  • 1
  • 1
Leo
  • 6,480
  • 4
  • 37
  • 52

2 Answers2

11

The linked JavaDoc mentions this structure for cron expressions:

Field Name      Allowed Values       Allowed Special Characters

Seconds         0-59                 , - * /
Minutes         0-59                 , - * /
Hours           0-23                 , - * /
Day-of-month    1-31                 , - * ? / L W
Month           1-12 or JAN-DEC      , - * /
Day-of-Week     1-7 or SUN-SAT       , - * ? / L #
Year (Optional) empty, 1970-2199     , - * /

Your cron expression is "* * * * ? * *" with a ? on the 5th position for Month. As you can see, this character is not allowed there.

Tom
  • 16,842
  • 17
  • 45
  • 54
4

The JavaDoc you mentioned states that the ? character is allowed only for day-of-month and day-of-week fields. You are using it in Month field.

Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109