{"record":{"id":"f5c011ed1ff0b3aa","repo":"jeecgboot/JeecgBoot","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":"jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/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/jeecgboot/JeecgBoot/blob/96fb33f5ec68516da0b0147da06b2eb0419e063a/jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java#L987-L1023","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// month field uses 0 (Java Calendar January)\nString cron = \"0 0 0 1 0 ?\";  // 0 is invalid\n// after\nString cron = \"0 0 0 1 1 ?\";  // January (1-based)","handlingStrategy":"validation","validationCode":"// Validate month field values are 1-12\nString monthField = fields[4];\nfor (String token : monthField.split(\",\")) {\n    if (token.equals(\"*\") || token.equals(\"?\")) continue;\n    String base = token.split(\"[/\\\\-]\")[0];\n    int val = Integer.parseInt(base);\n    if (val < 1 || val > 12) throw new IllegalArgumentException(\"Month must be 1-12: \" + val);\n}","typeGuard":"boolean isValidMonth(String field) {\n    for (String token : field.split(\",\")) {\n        if (token.equals(\"*\") || token.equals(\"?\")) continue;\n        try {\n            for (String part : token.split(\"[/\\\\-]\")) {\n                int val = Integer.parseInt(part);\n                if (val < 1 || val > 12) return false;\n            }\n        } catch (NumberFormatException e) { return false; }\n    }\n    return true;\n}","tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"Month values must be between 1 and 12\")) {\n        // fix the month field value (1=January)\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["cron","validation","scheduling","xxljob","parse"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}