jeecgboot/JeecgBoot · error · ParseException
Month values must be between 1 and 12
Error message
Month values must be between 1 and 12
What it means
Thrown by addToSet when a value (or range end) for the MONTH field is less than 1 or greater than 12, unless the value equals ALL_SPEC_INT ('*'). Valid month values are 1–12 (January=1 through December=12).
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:1005
if ((val < 0 || val > 59 || end > 59) && (val != ALL_SPEC_INT)) {
throw new ParseException(
"Minute and Second values must be between 0 and 59",
-1);
}
} else if (type == HOUR) {
if ((val < 0 || val > 23 || end > 23) && (val != ALL_SPEC_INT)) {
throw new ParseException(
"Hour values must be between 0 and 23", -1);
}
} else if (type == DAY_OF_MONTH) {
if ((val < 1 || val > 31 || end > 31) && (val != ALL_SPEC_INT)
&& (val != NO_SPEC_INT)) {
throw new ParseException(
"Day of month values must be between 1 and 31", -1);
}
} else if (type == MONTH) {
if ((val < 1 || val > 12 || end > 12) && (val != ALL_SPEC_INT)) {
throw new ParseException(
"Month values must be between 1 and 12", -1);
}
} else if (type == DAY_OF_WEEK) {
if ((val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT)
&& (val != NO_SPEC_INT)) {
throw new ParseException(
"Day-of-Week values must be between 1 and 7", -1);
}
}
if ((incr == 0 || incr == -1) && val != ALL_SPEC_INT) {
if (val != -1) {
set.add(val);
} else {
set.add(NO_SPEC);
}
return;View on GitHub (pinned to 96fb33f5ec)
Solutions
- Ensure all month values are integers from 1 to 12 (1=January, 12=December).
- If converting from Java Calendar months (0-based), add 1 before constructing the cron string.
- If converting from JavaScript Date.getMonth() (0-based), add 1.
Example fix
// before // month field uses 0 (Java Calendar January) String cron = "0 0 0 1 0 ?"; // 0 is invalid // after String cron = "0 0 0 1 1 ?"; // January (1-based)
Defensive patterns
Strategy: validation
Validate before calling
// Validate month field values are 1-12
String monthField = fields[4];
for (String token : monthField.split(",")) {
if (token.equals("*") || token.equals("?")) continue;
String base = token.split("[/\\-]")[0];
int val = Integer.parseInt(base);
if (val < 1 || val > 12) throw new IllegalArgumentException("Month must be 1-12: " + val);
} Type guard
boolean isValidMonth(String field) {
for (String token : field.split(",")) {
if (token.equals("*") || token.equals("?")) continue;
try {
for (String part : token.split("[/\\-]")) {
int val = Integer.parseInt(part);
if (val < 1 || val > 12) return false;
}
} catch (NumberFormatException e) { return false; }
}
return true;
} Try / catch
try {
CronExpression cron = new CronExpression(expr);
} catch (ParseException e) {
if (e.getMessage().contains("Month values must be between 1 and 12")) {
// fix the month field value (1=January)
}
throw e;
} Prevention
- Month values are 1-based: 1=January through 12=December.
- When converting from Java Calendar or JS Date (0-based months), add 1.
- Bounds-check dynamically generated month values.
When it happens
Trigger: A cron expression with a month field containing a value like 0, 13, or -1 — e.g., month field '13', '0', or range '1-13'. Note: some cron implementations also accept names (JAN–DEC) but this numeric check applies to parsed integer values.
Common situations: Developer uses 0-based month numbering (0=January); uses 13 or higher; off-by-one from JavaScript Date or Java Calendar (both 0-based); dynamic value injection without bounds checking.
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})
- The 'W' option does not make sense with values larger than 3
- '#' option is not valid here. (pos=${i})
AI-assisted analysis of jeecgboot/JeecgBoot@96fb33f5ec (2026-08-14).
Data as JSON: /api/errors/f5c011ed1ff0b3aa.
Report an issue: GitHub.