{"record":{"id":"e0b318fb29c70ede","repo":"jeecgboot/JeecgBoot","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":"jeecg-boot/jeecg-server-cloud/jeecg-visual/jeecg-cloud-xxljob/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java","lineNumber":590,"sourceCode":"                    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(\n                                    \"Invalid Day-of-Week value: '\" + sub\n                                            + \"'\", 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(\n                                    \"A numeric value between 1 and 5 must follow the '#' option\",\n                                    i);\n                        }\n                    } else if (c == 'L') {\n                        lastDayOfWeek = true;\n                        i++;\n                    }\n                }\n\n            } else {\n                throw new ParseException(\n                        \"Illegal characters for this position: '\" + sub + \"'\",\n                        i);\n            }\n            if (eval != -1) {\n                incr = 1;\n            }\n            addToSet(sval, eval, incr, type);","sourceCodeStart":572,"sourceCodeEnd":608,"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#L572-L608","documentation":"In the DAY_OF_WEEK branch, after a '#' character the parser reads the rest of the token with Integer.parseInt and requires the nth-week value to be 1-5. Any parse failure (non-numeric) or out-of-range value throws this fixed-text exception. The '#' construct means 'the Nth occurrence of weekday X in a month' (e.g. 0 0 12 ? * 6#3 = third Friday).","triggerScenarios":"Dow tokens like '6#0', '6#6' (out of 1-5), '6#' (empty -> parseInt throws), 'MON#x' (non-numeric), or '6#3x' (trailing junk after the number is consumed by parseInt of the whole remaining substring). The try block catches Exception broadly so both NumberFormatException and the range check funnel to this message.","commonSituations":"Wanting 'last weekday of month' and incorrectly using a high nth value; off-by-one confusion (0-based vs 1-based); expression generators that compute nth without clamping; leaving the '#' operand blank.","solutions":["Ensure the value after '#' is an integer strictly between 1 and 5 (1=first, 5=last possible occurrence).","Do not append extra characters after the number - parseInt reads the remainder of the token.","For 'last occurrence' semantics use 'L' (e.g. '6L') instead of '#5'.","Precompute and clamp the nth value when generating the expression programmatically."],"exampleFix":"// before - nth value out of range / blank\nString cron = \"0 0 12 ? * 6#6\";  // 6 > 5 -> error\n\n// after - valid nth (3rd Friday)\nString cron = \"0 0 12 ? * 6#3\";","handlingStrategy":"validation","validationCode":"// Validate a '#' nth-weekday token (e.g. 6#3) before assembling the cron string.\npublic static String validateNthDow(String weekday, int nth) {\n    if (weekday == null || !weekday.matches(\"[1-7]\")) return \"weekday must be 1-7\";\n    if (nth < 1 || nth > 5) return \"nth occurrence after '#' must be 1-5, got \" + nth;\n    return null;\n}","typeGuard":"public static boolean isValidNthDow(String token) {\n    // matches shapes like 6#3, MON#2\n    if (token == null) return false;\n    java.util.regex.Pattern p = java.util.regex.Pattern.compile(\"^(?:[1-7]|SUN|MON|TUE|WED|THU|FRI|SAT)#([1-5])$\");\n    return p.matcher(token.toUpperCase()).matches();\n}","tryCatchPattern":"try {\n    new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"'#' option\")) {\n        return \"After '#' use an integer 1-5 (1st..5th occurrence). For last weekday use 'L'.\";\n    }\n    throw e;\n}","preventionTips":["Clamp the nth value to 1-5 when generating '#N' tokens.","For 'last occurrence' semantics use the 'L' modifier instead of '#5'.","Do not append trailing characters after the nth digit; parseInt reads the remainder."],"tags":["cron","xxl-job","day-of-week","nth-occurrence","validation","parse-error"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}