{"record":{"id":"27163a239c83acae","repo":"xuxueli/xxl-job","slug":"month-values-must-be-between-1-and-12","errorCode":null,"errorMessage":"Month values must be between 1 and 12","messagePattern":"Month values must be between 1 and 12","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":1005,"sourceCode":"            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);\n            } else {\n                set.add(NO_SPEC);\n            }\n\n            return;","sourceCodeStart":987,"sourceCodeEnd":1023,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java#L987-L1023","documentation":"Thrown by CronExpression's field-validation routine (addToSet) when the MONTH token holds a value below 1 or above 12, or a range whose upper bound exceeds 12. Months are 1-based (1=Jan ... 12=Dec). Only the '*' wildcard (ALL_SPEC_INT=99) is exempt; '?' is not valid for the month field.","triggerScenarios":"Constructing CronExpression with a month like \"13\", \"0\", or a range \"1-14\". Occurs during expression parsing/construction.","commonSituations":"Using 0 to mean January (it is 1 here); off-by-one from a zero-indexed month list; copy-pasting schedules from systems with different month encoding.","solutions":["Keep month literals in 1-12 (January=1, December=12).","Use '*' for every month; do not use '?' here (month has no NO_SPEC exemption).","Add a parsing test for generated cron strings before persisting."],"exampleFix":"// before\nnew CronExpression(\"0 0 12 * 13 ?\"); // month 13 invalid\n// after\nnew CronExpression(\"0 0 12 * 12 ?\"); // December = 12","handlingStrategy":"validation","validationCode":"// Guard month literals 1-12 before parsing\nString[] f = expr.trim().split(\"\\\\s+\");\nString mon = (f.length >= 6) ? f[4] : f[3];\nif (mon.matches(\"\\\\d+\")) {\n    int m = Integer.parseInt(mon);\n    if (m < 1 || m > 12) throw new IllegalArgumentException(\"month out of range: \" + m);\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":["Months are 1-based (1=Jan ... 12=Dec); '?' is not valid for month.","Validate generated cron strings with a parse test before saving.","Do not emit 0 for January."],"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"}