{"record":{"id":"cac788a1b30260e5","repo":"flowable/flowable-engine","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":"java.text.ParseException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java","lineNumber":989,"sourceCode":"    protected void addToSet(int val, int end, int incr, int type) 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(\"Minute and Second values must be between 0 and 59\", -1);\n            }\n        } else if (type == HOUR) {\n            if ((val < 0 || val > 23 || end > 23) && (val != ALL_SPEC_INT)) {\n                throw new ParseException(\"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) && (val != NO_SPEC_INT)) {\n                throw new ParseException(\"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(\"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) && (val != NO_SPEC_INT)) {\n                throw new ParseException(\"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;\n        }\n\n        int startAt = val;","sourceCodeStart":971,"sourceCodeEnd":1007,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java#L971-L1007","documentation":"CronExpression validates the MONTH field while parsing: month values and range ends must be 1-12 (JAN-DEC names are mapped to numbers before this check); the '*' sentinel is exempt. Out-of-range values make new CronExpression(String) throw a java.text.ParseException with this message.","triggerScenarios":"new CronExpression(cronString) with a month token of 0 or >12, e.g. '0 0 0 1 13 ?' or '0 0 0 1 0 ?'. Also a range end >12 like '0 0 0 1 10-13 ?'.","commonSituations":"Zero-based month generation from java.util.Calendar (which returns 0-11) concatenated into a cron string; confused field order (a day-of-month value in the month slot); typo'd month numbers in timer definitions.","solutions":["Correct the month token to 1-12, or use month abbreviations (JAN-DEC) to avoid ambiguity.","When building the string from java.util.Calendar, add 1 to calendar.get(Calendar.MONTH) before inserting.","Check field order: 6-field expressions are sec min hour day month dow — the month is the 5th field.","Pre-validate with CronExpression.isValidExpression() before persisting the configuration."],"exampleFix":"// before\nint monthZeroBased = Calendar.getInstance().get(Calendar.MONTH); // 0-11\nCronExpression expr = new CronExpression(\"0 0 0 1 \" + monthZeroBased + \" ?\");\n// after\nint month = Calendar.getInstance().get(Calendar.MONTH) + 1; // 1-12\nCronExpression expr = new CronExpression(\"0 0 0 1 \" + month + \" ?\");","handlingStrategy":"validation","validationCode":"int m = calendar.get(Calendar.MONTH) + 1; // Calendar months are 0-based\nif (m < 1 || m > 12) throw new IllegalStateException(\"bad month\");\nString cron = \"0 0 0 1 \" + m + \" ?\";","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression expr = new CronExpression(cron);\n} catch (ParseException e) {\n    throw new ConfigurationException(\"Invalid month field in cron: \" + cron, e);\n}","preventionTips":["Add 1 when converting java.util.Calendar's zero-based month","Use JAN-DEC abbreviations to sidestep numeric confusion","Confirm the month is the 5th field in a 6-field expression","Validate with isValidExpression() before persisting"],"tags":["cron","scheduling","validation","configuration"],"backgroundTag":"value-out-of-range","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}