alibaba/spring-cloud-alibaba · error · IllegalArgumentException
cronExpression cannot be null
Error message
cronExpression cannot be null
What it means
Thrown by the CronExpression(String) constructor when the argument is null. This is an IllegalArgumentException (not ParseException) fired before any parsing, guarding the field cronExpression.toUpperCase(Locale.US) from an NPE. CronExpression is a port of the Quartz cron parser used by the schedulerx starter to interpret job cron fields.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java:125
}
/**
* MIN_DATE.
*/
public static final Date MIN_DATE = MIN_CAL.getTime();
/**
* Constructs a new <CODE>CronExpression</CODE> based on the specified
* parameter.
*
* @param cronExpression String representation of the cron expression the
* new object should represent
* @throws ParseException if the string expression cannot be parsed into a valid
* <CODE>CronExpression</CODE>
*/
public CronExpression(final String cronExpression) throws ParseException {
if (cronExpression == null) {
throw new IllegalArgumentException("cronExpression cannot be null");
}
this.cronExpression = cronExpression.toUpperCase(Locale.US);
buildExpression(this.cronExpression);
}
/**
* Indicates whether the given date satisfies the cron expression. Note that
* milliseconds are ignored, so two Dates falling on different milliseconds
* of the same second will always have the same result here.
*
* @param date the date to evaluate
* @return a boolean indicating whether the given date satisfies the cron
* expression.
*/
public boolean isSatisfiedBy(final Date date) {
final Calendar testDateCal = Calendar.getInstance(getTimeZone());View on GitHub (pinned to 115d590110)
Solutions
- Ensure the String passed to new CronExpression(...) is non-null before construction.
- If the cron source may legitimately be null (no schedule), branch on nullability and skip construction.
- In starter config, leave the cron key absent rather than setting it to a null-valued placeholder.
Example fix
// before
CronExpression expr = new CronExpression(maybeNullCron);
// after
if (maybeNullCron == null) {
throw new IllegalArgumentException("cron expression must not be null");
}
CronExpression expr = new CronExpression(maybeNullCron); Defensive patterns
Strategy: type-guard
Validate before calling
java.util.Objects.requireNonNull(cron, "cron expression must not be null"); // then: new CronExpression(cron)
Type guard
// type guard / narrowing helper
static CronExpression safeCron(String cron) throws ParseException {
if (cron == null || cron.isEmpty()) {
throw new IllegalArgumentException("cron must be non-empty");
}
return new CronExpression(cron);
} Prevention
- Never pass a @Nullable cron to CronExpression; gate construction behind a null/empty check.
- Annotate the consuming method parameter with @NonNull and let static analysis (Checker/Spotbugs) flag null callers.
When it happens
Trigger: new CronExpression(null) — i.e. the constructor is invoked with a null String. Within the starter the call sites guard with 'cron != null && !cron.isEmpty()', so this surfaces mainly when CronExpression is used directly or when a future change skips the guard.
Common situations: Direct unit testing of CronExpression passing null; a custom integration that reads a cron from a nullable source and constructs CronExpression without a null check; reflection or deserialization producing a null cron.
Related errors
- Support for specifying 'L' and 'LW' with other days of the m
- Support for specifying 'L' with other days of the week is no
- Support for specifying multiple "nth" days is not implemente
- Unexpected end of expression.
- Support for specifying both a day-of-week AND a day-of-month
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/8c8488c13bb405f4.
Report an issue: GitHub.