{"record":{"id":"9650d1cd170d1808","repo":"xuxueli/xxl-job","slug":"day-of-month-values-must-be-between-1-and-31","errorCode":null,"errorMessage":"Day of month values must be between 1 and 31","messagePattern":"Day of month values must be between 1 and 31","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java","lineNumber":1000,"sourceCode":"            throws ParseException {\n\n        TreeSet<Integer> set = getSet(type);\n\n        if (type == SECOND || type == MINUTE) {\n            if ((val < 0 || val > 59 || end > 59) && (val != ALL_SPEC_INT)) {\n                throw new ParseException(\n                        \"Minute and Second values must be between 0 and 59\",\n                        -1);\n            }\n        } else if (type == HOUR) {\n            if ((val < 0 || val > 23 || end > 23) && (val != ALL_SPEC_INT)) {\n                throw new ParseException(\n                        \"Hour values must be between 0 and 23\", -1);\n            }\n        } else if (type == DAY_OF_MONTH) {\n            if ((val < 1 || val > 31 || end > 31) && (val != ALL_SPEC_INT)\n                    && (val != NO_SPEC_INT)) {\n                throw new ParseException(\n                        \"Day of month values must be between 1 and 31\", -1);\n            }\n        } else if (type == MONTH) {\n            if ((val < 1 || val > 12 || end > 12) && (val != ALL_SPEC_INT)) {\n                throw new ParseException(\n                        \"Month values must be between 1 and 12\", -1);\n            }\n        } else if (type == DAY_OF_WEEK) {\n            if ((val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT)\n                    && (val != NO_SPEC_INT)) {\n                throw new ParseException(\n                        \"Day-of-Week values must be between 1 and 7\", -1);\n            }\n        }\n\n        if ((incr == 0 || incr == -1) && val != ALL_SPEC_INT) {\n            if (val != -1) {\n                set.add(val);","sourceCodeStart":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java#L982-L1018","documentation":"Thrown by CronExpression's field-validation routine (addToSet) when the DAY_OF_MONTH token holds a value below 1 or above 31, or a range whose upper bound exceeds 31. Both wildcards are allowed: ALL_SPEC_INT (99, for '*') and NO_SPEC_INT (98, for '?'), so any literal day-of-month must be 1-31.","triggerScenarios":"Constructing CronExpression with a day-of-month like \"32\", \"0\", or a range \"1-35\". Raised during parsing/construction of the CronExpression.","commonSituations":"Typos in hand-written cron (e.g. day 32); calendar-generation code that emits up to 31 plus a stray increment; tools that permit 0 as a day.","solutions":["Constrain day-of-month literals to 1-31; there is no day 0.","Use '*' for any day or '?' to leave day-of-month unspecified (required when you specify day-of-week instead).","Validate generated cron strings with a parse test before saving."],"exampleFix":"// before\nnew CronExpression(\"0 0 12 32 * ?\"); // day 32 invalid\n// after\nnew CronExpression(\"0 0 12 15 * ?\"); // day 15","handlingStrategy":"validation","validationCode":"// Guard day-of-month literals 1-31 before parsing\nString[] f = expr.trim().split(\"\\\\s+\");\nString dom = (f.length >= 6) ? f[3] : f[2];\nif (dom.matches(\"\\\\d+\")) {\n    int d = Integer.parseInt(dom);\n    if (d < 1 || d > 31) throw new IllegalArgumentException(\"day-of-month out of range: \" + d);\n}","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression c = new CronExpression(expr);\n} catch (java.text.ParseException e) {\n    log.warn(\"Invalid cron '{}': {}\", expr, e.getMessage());\n}","preventionTips":["Day-of-month is 1-31; there is no day 0.","Use '?' for day-of-month when day-of-week is specified.","Parse-test generated cron strings before persisting."],"tags":["cron","validation","configuration","parse"],"backgroundTag":null,"analyzedSha":"e74c784f68f81fa89cb350913ef15794865d7b12","analyzedAt":"2026-08-14T04:22:43.715Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}