jeecgboot/JeecgBoot · error · ParseException
Day of month values must be between 1 and 31
Error message
Day of month values must be between 1 and 31
What it means
Thrown by addToSet when a value (or range end) for the DAY_OF_MONTH field is less than 1 or greater than 31, unless the value is ALL_SPEC_INT ('*') or NO_SPEC_INT ('?'). Valid day-of-month values are 1–31.
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:1000
throws ParseException {
TreeSet<Integer> set = getSet(type);
if (type == SECOND || type == MINUTE) {
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);View on GitHub (pinned to 96fb33f5ec)
Solutions
- Ensure all day-of-month values are integers from 1 to 31.
- Use '?' in the day-of-month field if you are specifying day-of-week instead.
- Note that while 29–31 are syntactically valid, they will skip months that have fewer days.
Example fix
// before String cron = "0 0 0 0 * ?"; // 0 is invalid for day-of-month // after String cron = "0 0 0 1 * ?"; // 1st of month
Defensive patterns
Strategy: validation
Validate before calling
// Validate day-of-month field values are 1-31
String domField = fields[3];
for (String token : domField.split(",")) {
if (token.equals("*") || token.equals("?")) continue;
String base = token.replaceAll("[LW#].*", "").split("[/\\-]")[0];
if (!base.isEmpty()) {
int val = Integer.parseInt(base);
if (val < 1 || val > 31) throw new IllegalArgumentException("Day-of-month must be 1-31: " + val);
}
} Type guard
boolean isValidDayOfMonth(String field) {
for (String token : field.split(",")) {
if (token.equals("*") || token.equals("?")) continue;
String base = token.replaceAll("[LW#].*", "").split("[/\\-]")[0];
try {
int val = Integer.parseInt(base);
if (val < 1 || val > 31) return false;
} catch (NumberFormatException e) { return false; }
}
return true;
} Try / catch
try {
CronExpression cron = new CronExpression(expr);
} catch (ParseException e) {
if (e.getMessage().contains("Day of month values must be between 1 and 31")) {
// fix the day-of-month field value
}
throw e;
} Prevention
- Day-of-month values start at 1, not 0.
- Values 29–31 are syntactically valid but will be skipped in shorter months.
- Use '?' for day-of-month when scheduling by day-of-week.
When it happens
Trigger: A cron expression with a day-of-month field containing a value like 0, 32, or -1 — e.g., day-of-month field '32', '0', or range '1-35'.
Common situations: Developer uses 0 as a day (days start at 1); uses 32 or higher; range endpoint exceeds 31; confusion with 0-based indexing from other systems.
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/7eaf9a139d6c4fb0.
Report an issue: GitHub.