alibaba/spring-cloud-alibaba · error · ParseException
Day-of-Week values must be between 1 and 7
Error message
Day-of-Week values must be between 1 and 7
What it means
Thrown in checkNext when 'L' (last) follows a value in the DAY_OF_WEEK field but the preceding value is outside 1-7 (guard at CronExpression.java:524-526). 'NL' means 'last <weekday> of the month', so the weekday must be a valid 1-7. Note the error position passed is -1.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java:526
}
protected int checkNext(final int pos, final String s, final int val, final int type)
throws ParseException {
int end = -1;
int i = pos;
if (i >= s.length()) {
addToSet(val, end, -1, type);
return i;
}
char c = s.charAt(pos);
if (c == 'L') {
if (type == DAY_OF_WEEK) {
if (val < 1 || val > 7) {
throw new ParseException("Day-of-Week values must be between 1 and 7", -1);
}
lastdayOfWeek = true;
}
else {
throw new ParseException("'L' option is not valid here. (pos=" + i + ")", i);
}
final TreeSet<Integer> set = getSet(type);
set.add(val);
i++;
return i;
}
if (c == 'W') {
if (type == DAY_OF_MONTH) {
nearestWeekday = true;
}
else {
throw new ParseException("'W' option is not valid here. (pos=" + i + ")", i);View on GitHub (pinned to 115d590110)
Solutions
- Use a weekday value 1-7 (SUN=1 ... SAT=7), e.g. '9L' -> '6L' (last Friday).
- Do not use 0 for Sunday; this parser's dayMap maps SUN=1.
- Verify the value sits in the day-of-week field (6th field).
Example fix
// before
new CronExpression("0 0 0 ? * 9L");
// after
new CronExpression("0 0 0 ? * 6L"); // last Friday of the month Defensive patterns
Strategy: validation
Validate before calling
// '<n>L' in day-of-week requires 1 <= n <= 7.
static boolean dowLastValueOk(String dowField) {
if (!dowField.endsWith("L") || dowField.length() < 2) return true;
try {
int v = Integer.parseInt(dowField.substring(0, dowField.length() - 1));
return v >= 1 && v <= 7;
} catch (NumberFormatException e) { return false; }
} Try / catch
try {
CronExpression cron = new CronExpression(raw);
} catch (ParseException e) {
throw new IllegalArgumentException("Invalid cron expression: " + raw, e);
} Prevention
- Day-of-week is 1-7 with SUN=1 (this parser does not accept 0).
- Use names (SUN..SAT) to avoid numbering mistakes.
- Validate the weekday value before 'L'.
When it happens
Trigger: `new CronExpression("0 0 0 ? * 9L")` (weekday 9 with 'L'), or `0L` (value 0). Any '<n>L' in day-of-week where n < 1 or n > 7.
Common situations: 0-based weekday assumption (using 0 for Sunday, which is invalid here — SUN=1), or a field-shift placing a non-weekday number before 'L'.
Related errors
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/09bc363b01404a38.
Report an issue: GitHub.