Skip to content

NullPointerException if cron expression is null [SPR-15683] #20242

@spring-projects-issues

Description

@spring-projects-issues

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 a CronSequenceGenerator instance which calls the parse() method from its constructor.
Inside this method the cron expression is first tokenized by StringUtils.tokenizeToStringArray() (which will return null if the cron expression is null) and put into the fields variable. Then, if the content of fields is considered invalid (null or not having the right number of elements), an IllegalArgumentException is thrown.
But as we are using fields.count's value to create the message of the exception, we get a NullPointerException (with no message) instead when fields 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:

Referenced from: pull request #1345

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: coreIssues in core modules (aop, beans, core, context, expression)status: duplicateA duplicate of another issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions