{"record":{"id":"971366d2acfdfaaa","repo":"flowable/flowable-engine","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":"java.text.ParseException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java","lineNumber":985,"sourceCode":"\n        return i;\n    }\n\n    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","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java#L967-L1003","documentation":"CronExpression validates the DAY_OF_MONTH field during parsing in addToSet: the day value and the end of any day range must be between 1 and 31 (the wildcard '*' sentinel and the '?' NO_SPEC sentinel are exempt). Otherwise new CronExpression(String) throws a java.text.ParseException with this message at construction time.","triggerScenarios":"new CronExpression(cronString) with a day-of-month token of 0, negative, or >31, e.g. '0 0 0 32 * ?' or '0 0 0 0 * ?'. Also a range whose end exceeds 31 such as '0 0 0 30-32 * ?'.","commonSituations":"Typo'd cron fields in BPMN timeCycle definitions (fields shifted so a month number lands in the day slot); zero-based day generation (0-30 instead of 1-31) when converting from an API that indexes days from 0; 'day 0' meaning 'last day' confusion.","solutions":["Correct the day-of-month token to be in 1-31 (no zero-based indexing).","Verify field order in the expression (sec min hour day month dow) — a shifted field often causes out-of-range values.","For 'last day of month' use 'L' where supported, or compute the date programmatically instead of day 0/32.","Pre-validate with CronExpression.isValidExpression() and reject the configuration at startup."],"exampleFix":"// before\nCronExpression expr = new CronExpression(\"0 0 0 0 * ?\"); // day 0 invalid\n// after\nCronExpression expr = new CronExpression(\"0 0 0 1 * ?\");","handlingStrategy":"validation","validationCode":"if (!CronExpression.isValidExpression(cron)) {\n    throw new IllegalArgumentException(\"Invalid cron: day-of-month must be 1-31 in \" + cron);\n}\nCronExpression expr = new CronExpression(cron);","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression expr = new CronExpression(cron);\n} catch (ParseException e) {\n    log.error(\"Invalid day-of-month in cron '{}'\", cron, e);\n    throw new ConfigurationException(e);\n}","preventionTips":["Days are 1-based in cron: 1-31, no day 0","Check field order (sec min hour day month dow) — a shifted field often produces out-of-range days","Use 'L' or '?' conventions for last-day/no-specific semantics","Pre-validate user-entered timer definitions"],"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"}