{"record":{"id":"de3edd26c0ade425","repo":"alibaba/spring-cloud-alibaba","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":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java","lineNumber":782,"sourceCode":"\t\tfinal TreeSet<Integer> set = getSet(type);\n\n\t\tif (type == SECOND || type == MINUTE) {\n\t\t\tif ((val < 0 || val > 59 || end > 59) && (val != ALL_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Minute and Second values must be between 0 and 59\",\n\t\t\t\t\t\t-1);\n\t\t\t}\n\t\t}\n\t\telse if (type == HOUR) {\n\t\t\tif ((val < 0 || val > 23 || end > 23) && (val != ALL_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Hour values must be between 0 and 23\", -1);\n\t\t\t}\n\t\t}\n\t\telse if (type == DAY_OF_MONTH) {\n\t\t\tif ((val < 1 || val > 31 || end > 31) && (val != ALL_SPEC_INT)\n\t\t\t\t\t&& (val != NO_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Day of month values must be between 1 and 31\", -1);\n\t\t\t}\n\t\t}\n\t\telse if (type == MONTH) {\n\t\t\tif ((val < 1 || val > 12 || end > 12) && (val != ALL_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Month values must be between 1 and 12\", -1);\n\t\t\t}\n\t\t}\n\t\telse if (type == DAY_OF_WEEK) {\n\t\t\tif ((val == 0 || val > 7 || end > 7) && (val != ALL_SPEC_INT)\n\t\t\t\t\t&& (val != NO_SPEC_INT)) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"Day-of-Week values must be between 1 and 7\", -1);\n\t\t\t}\n\t\t}\n\n\t\tif ((incr == 0 || incr == -1) && val != ALL_SPEC_INT) {","sourceCodeStart":764,"sourceCodeEnd":800,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java#L764-L800","documentation":"Thrown in addToSet when a DAY_OF_MONTH value (or range end) is outside 1-31, unless it is ALL_SPEC or NO_SPEC (guard at CronExpression.java:781-785). Day-of-month is 1-based; 0 and >31 are invalid.","triggerScenarios":"`new CronExpression(\"0 0 0 0 * ?\")` (day=0), or `0 0 0 32 * ?` (day=32), or a range like `0 0 0 1-32 * ?`.","commonSituations":"0-based day assumption, an off-by-one, or a field-shift placing a month/year value into day-of-month. Also 'last day' intent mistakenly written as a high literal instead of 'L'.","solutions":["Use day-of-month values 1-31, e.g. '0' -> '1' or '32' -> 'L' for last day.","For end-of-month use 'L' rather than guessing 28/29/30/31.","Recount the six fields."],"exampleFix":"// before\nnew CronExpression(\"0 0 0 0 * ?\");\n// after\nnew CronExpression(\"0 0 0 1 * ?\"); // 1st of every month","handlingStrategy":"validation","validationCode":"// Day-of-month(field 3) must be 1..31 (ignoring '*', '?', 'L').\nstatic boolean domInRange(String[] fields) {\n    if (fields.length < 4) return false;\n    String f = fields[3];\n    if (f.equals(\"*\") || f.equals(\"?\") || f.equals(\"L\") || f.startsWith(\"L\")) return true;\n    return inRange(f, 1, 31);\n}\nprivate static boolean inRange(String f, int lo, int hi) {\n    for (String part : f.split(\"[-,/LW#]\")) {\n        if (part.isEmpty()) continue;\n        try { int v = Integer.parseInt(part); if (v < lo || v > hi) return false; }\n        catch (NumberFormatException e) { /* ignore */ }\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(raw);\n} catch (ParseException e) {\n    throw new IllegalArgumentException(\"Invalid cron expression: \" + raw, e);\n}","preventionTips":["Day-of-month is 1-31; 0 is invalid.","Use 'L' for the last day instead of guessing 28/29/30/31.","Range-check day values at the configuration boundary."],"tags":["cron","schedulerx","spring-cloud-alibaba","configuration","parsing","validation","range-check"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}