{"record":{"id":"0a158a72f9f6ac49","repo":"flowable/flowable-engine","slug":"a-numeric-value-between-1-and-5-must-follow-the","errorCode":null,"errorMessage":"A numeric value between 1 and 5 must follow the '#' option","messagePattern":"A numeric value between 1 and 5 must follow the '#' option","errorType":"exception","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java","lineNumber":594,"sourceCode":"                }\n                if (s.length() > i + 3) {\n                    c = s.charAt(i + 3);\n                    if (c == '-') {\n                        i += 4;\n                        sub = s.substring(i, i + 3);\n                        eval = getDayOfWeekNumber(sub);\n                        if (eval < 0) {\n                            throw new ParseException(\"Invalid Day-of-Week value: '\" + sub + \"'\", i);\n                        }\n                    } else if (c == '#') {\n                        try {\n                            i += 4;\n                            nthdayOfWeek = Integer.parseInt(s.substring(i));\n                            if (nthdayOfWeek < 1 || nthdayOfWeek > 5) {\n                                throw new Exception();\n                            }\n                        } catch (Exception e) {\n                            throw new ParseException(\"A numeric value between 1 and 5 must follow the '#' option\", i);\n                        }\n                    } else if (c == 'L') {\n                        lastdayOfWeek = true;\n                        i++;\n                    }\n                }\n\n            } else {\n                throw new ParseException(\"Illegal characters for this position: '\" + sub + \"'\", i);\n            }\n            if (eval != -1) {\n                incr = 1;\n            }\n            addToSet(sval, eval, incr, type);\n            return (i + 3);\n        }\n\n        if (c == '?') {","sourceCodeStart":576,"sourceCodeEnd":612,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java#L576-L612","documentation":"Thrown when the Day-of-Week field uses the nth-day syntax 'day#n' and the value after '#' is not an integer between 1 and 5. In Quartz-style cron 'FRI#3' means 'the 3rd Friday of the month'; n must be 1-5. The parser catches any Exception from Integer.parseInt or the range check and rethrows this ParseException.","triggerScenarios":"new CronExpression(\"0 0 12 ? * FRI#0\"), \"FRI#6\", \"FRI#\" (nothing after #), \"FRI#three\" — any nthdayOfWeek < 1 or > 5 or non-numeric remainder after '#'.","commonSituations":"Copy-pasting cron from generators that emit '#6' or '#0'; assuming the '#' value is 0-based; leaving a stray '#' with no number; expressions built dynamically where the nth variable falls outside 1-5.","solutions":["Use a value between 1 and 5 after '#': e.g. 'MON#1' = first Monday of the month.","Clamp/validate the nth value programmatically before composing the expression string.","If you need 'last day-of-week of the month', use the 'L' option instead (e.g. 'FRIL' or '6L').","Wrap construction in try-catch on ParseException to surface a user-friendly message about the '#' syntax."],"exampleFix":"// before\nnew CronExpression(\"0 0 12 ? * FRI#0\");\n// after\nnew CronExpression(\"0 0 12 ? * FRI#1\");","handlingStrategy":"validation","validationCode":"java.util.regex.Matcher m = java.util.regex.Pattern.compile(\"#(\\\\d+)\").matcher(expr);\nif (m.find()) {\n    int n = Integer.parseInt(m.group(1));\n    if (n < 1 || n > 5) throw new IllegalArgumentException(\"'#' nth must be 1-5, got \" + n);\n}","typeGuard":null,"tryCatchPattern":"try {\n    new CronExpression(expr);\n} catch (java.text.ParseException e) {\n    throw new IllegalArgumentException(\"Invalid '#' nth-day syntax in cron: \" + expr, e);\n}","preventionTips":["Remember FRI#3 = 3rd Friday; the nth value is 1-based and capped at 5","Use 'L' for last occurrence instead of guessing large n","Clamp programmatically composed nth values to 1..5"],"tags":["cron","parse-error","nth-day"],"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-14T11:17:12.474Z"}