xuxueli/xxl-job · 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
In the checkNext method, when 'L' follows a numeric value in the Day-of-Week field (e.g., '6L' meaning 'last Friday'), the preceding number must be a valid day-of-week value between 1 and 7. This error fires when the number is outside that range.
Source
Thrown at xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java:756
}
protected int checkNext(int pos, String s, int val, 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);
}
TreeSet<Integer> set = getSet(type);
set.add(val);
i++;
return i;
}
if (c == 'W') {
if (type != DAY_OF_MONTH) {
throw new ParseException("'W' option is not valid here. (pos=" + i + ")", i);
}
if(val > 31)
throw new ParseException("The 'W' option does not make sense with values larger than 31 (max number of days in a month)", i);
nearestWeekdays.add(val);
i++;View on GitHub (pinned to e74c784f68)
Solutions
- Use a day-of-week value between 1 (Sunday) and 7 (Saturday) before 'L'.
- Confirm the Quartz numbering: SUN=1, MON=2, TUE=3, WED=4, THU=5, FRI=6, SAT=7.
- Validate the value before appending 'L'.
Example fix
// before "0 0 0 ? * 9L" // after "0 0 0 ? * 6L"
Defensive patterns
Strategy: validation
Validate before calling
// Validate 'NL' value in day-of-week (field index 5) is 1-7
String[] parts = cron.trim().split("\\s+");
if (parts.length > 5 && parts[5].contains("L")) {
String numPart = parts[5].replace("L", "").replaceAll("[^0-9].*", "");
if (!numPart.isEmpty()) {
int val = Integer.parseInt(numPart);
if (val < 1 || val > 7) throw new IllegalArgumentException("Day-of-week 'NL' value must be 1-7: " + val);
}
} Type guard
boolean isValidLastWeekdayValue(String dowField) {
if (!dowField.contains("L")) return true;
String num = dowField.replace("L", "").replaceAll("[^0-9].*", "");
if (num.isEmpty()) return true; // standalone 'L' is ok
int val = Integer.parseInt(num);
return val >= 1 && val <= 7; Try / catch
try {
new CronExpression(cron);
} catch (ParseException e) {
if (e.getMessage().contains("Day-of-Week values must be between 1 and 7")) {
// correct the weekday number to 1-7
}
} Prevention
- Remember Quartz day-of-week is 1-7 (SUN=1 ... SAT=7), not 0-6.
- Validate 'NL' values against the 1-7 range before building the expression.
- Add unit tests for each weekday with the 'L' modifier.
When it happens
Trigger: A cron expression like '0 0 0 ? * 9L' where the value before 'L' in the day-of-week field is < 1 or > 7. The check at line 755 tests val < 1 || val > 7.
Common situations: Using a 0-indexed day-of-week (0-6) instead of Quartz's 1-indexed (1-7), or a typo producing a value like 8 or 9.
Related errors
- '#' option is not valid here. (pos={})
- '?' can only be specified for Day-of-Month -OR- Day-of-Week.
- 'L' not expected in seconds, minutes or hours fields.
- Offset from last day must be <= {}
- 'L' option is not valid here. (pos={})
AI-assisted analysis of xuxueli/xxl-job@e74c784f68 (2026-08-14).
Data as JSON: /api/errors/2717f2617147de04.
Report an issue: GitHub.