I am using quartz-scheduler to schedule my jobs. I have a cron expression which is wrong:
1 15 10 ? * *ssddddfd
When I do:
String cronExpression = "1 15 10 ? * *ssdddfd";
boolean checkCronExpression = CronExpression.isValidExpression(cronExpression);
checkCronExpression
is true
. However when I look at the expression it is obviously wrong. Has anyone else also faced similar issue?
Note: The package is: package org.quartz;
Version of quartz is: 2.2.3
Please check the CronExpression class from http://www.javadoc.io/doc/org.quartz-scheduler/quartz/2.2.3
I also tried validateExpression
method of CronExpression
class with no success.
This has recently been filed as a bug:
https://github.com/quartz-scheduler/quartz/issues/254
And you're right this is probably unexpected.
However being very captious one could argue that the JavaDoc of isValidCronExpression
states
Indicates whether the specified cron expression can be parsed into a valid cron expression
And actually the expression you provided can be parsed into a valid CronExpression
although the expression is not valid itself. Basically the guarantee that you get from calling CronExpression.isValidCronExpression(expression)
is, that you can safely call new CronExpression(expression)
without fearing that a ParseException
will be thrown. However as java.text.ParseException
is a checked exception, this is rather pointless.
In summary the current implementation of CronExpression
seems to be a little bit too lenient.
Maybe you want to give other libraries a try (just searched on google):
But if you want to use the expression with quartz later on your best option is to stay with the quartz validation as patterns that are valid for other libraries may not be valid for quartz and vice versa. The source code of quartz for example states that patterns with both „day of week“ and „day of month“ are currently not supported although this is supported by cron expressions in general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With