-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
Antoine M opened SPR-15683 and commented
While playing around with scheduled tasks and cron triggers, I realized that when you feed a null
cron expression to a CronTrigger
then a wild NullPointerException
is thrown instead of an IllegalArgumentException
with a message.
When you pass a null cron expression to the constructor of
CronTrigger
, it creates aCronSequenceGenerator
instance which calls theparse()
method from its constructor.
Inside this method the cron expression is first tokenized byStringUtils.tokenizeToStringArray()
(which will return null if the cron expression is null) and put into thefields
variable. Then, if the content offields
is considered invalid (null or not having the right number of elements), anIllegalArgumentException
is thrown.
But as we are usingfields.count
's value to create the message of the exception, we get aNullPointerException
(with no message) instead whenfields
is null.
The changes proposed in the pull request #1345 let the parse()
method throw an IllegalArgumentException
with a message when fields
is null.
Affects: 3.2.18, 4.3.9, 5.0 RC2
Issue Links:
- Cron expression validation method in CronSequenceGenerator improved [SPR-15604] #20163 Cron expression validation method in CronSequenceGenerator improved ("duplicates")
Referenced from: pull request #1345