jeecgboot/JeecgBoot · error · ParseException
The 'W' option does not make sense with values larger than 3
Error message
The 'W' option does not make sense with values larger than 31 (max number of days in a month)
What it means
Thrown when the 'W' (nearest weekday) modifier is used with a day-of-month value greater than 31. Since no month has more than 31 days, a value like 32W or 40W is nonsensical and rejected before the value is added to the nearestWeekdays set.
Source
Thrown at jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java:772
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++;
return i;
}
if (c == '#') {
if (type != DAY_OF_WEEK) {
throw new ParseException("'#' option is not valid here. (pos=" + i + ")", i);
}
i++;
try {
nthDayOfWeek = Integer.parseInt(s.substring(i));
if (nthDayOfWeek < 1 || nthDayOfWeek > 5) {
throw new Exception();
}
} catch (Exception e) {
throw new ParseException(
"A numeric value between 1 and 5 must follow the '#' option",View on GitHub (pinned to 96fb33f5ec)
Solutions
- Change the day-of-month value preceding 'W' to a number between 1 and 31.
- If you meant a specific weekday, use the day-of-week field with a number 1–7 instead.
- Sanitize any dynamic/templated cron string before passing it to CronExpression.
Example fix
// before String cron = "0 0 0 35W * ?"; // 35 > 31 // after String cron = "0 0 0 15W * ?"; // nearest weekday to the 15th
Defensive patterns
Strategy: validation
Validate before calling
// Validate day-of-month 'W' value is <= 31
String domField = fields[3];
for (String token : domField.split(",")) {
if (token.endsWith("W")) {
int val = Integer.parseInt(token.substring(0, token.length() - 1));
if (val > 31) throw new IllegalArgumentException("'W' value must be <= 31");
}
} Type guard
boolean isValidWValue(String token) {
if (!token.endsWith("W")) return true;
try {
int val = Integer.parseInt(token.substring(0, token.length() - 1));
return val >= 1 && val <= 31;
} catch (NumberFormatException e) {
return false;
}
} Try / catch
try {
CronExpression cron = new CronExpression(expr);
} catch (ParseException e) {
if (e.getMessage().contains("'W' option does not make sense")) {
// reduce the day-of-month number to <= 31
}
throw e;
} Prevention
- Cap day-of-month 'W' values at 31.
- Prefer low day numbers (1–28) with 'W' since they are valid in all months.
- Validate dynamically generated cron values.
When it happens
Trigger: A cron expression with a day-of-month token of the form <N>W where N > 31 — e.g., '0 0 0 32W * ?' or '0 0 0 40W * ?'.
Common situations: Typo in the day number; misunderstanding of 'W' semantics; variable interpolation that injects an out-of-range value.
Related errors
- Day-of-Week values must be between 1 and 7
- 'L' option is not valid here. (pos=${i})
- 'W' option is not valid here. (pos=${i})
- '#' option is not valid here. (pos=${i})
- Unexpected character '${c}' after '/'
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/02426d9c15a6c9bc.
Report an issue: GitHub.