{"record":{"id":"6f035a5591c7cdc7","repo":"alibaba/spring-cloud-alibaba","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":"spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java","lineNumber":567,"sourceCode":"\t\t\tfinal TreeSet<Integer> set = getSet(type);\n\t\t\tset.add(val);\n\t\t\ti++;\n\t\t\treturn i;\n\t\t}\n\n\t\tif (c == '#') {\n\t\t\tif (type != DAY_OF_WEEK) {\n\t\t\t\tthrow new ParseException(\"'#' option is not valid here. (pos=\" + i + \")\", i);\n\t\t\t}\n\t\t\ti++;\n\t\t\ttry {\n\t\t\t\tnthdayOfWeek = Integer.parseInt(s.substring(i));\n\t\t\t\tif (nthdayOfWeek < 1 || nthdayOfWeek > 5) {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t}\n\t\t\tcatch (final Exception e) {\n\t\t\t\tthrow new ParseException(\n\t\t\t\t\t\t\"A numeric value between 1 and 5 must follow the '#' option\",\n\t\t\t\t\t\ti);\n\t\t\t}\n\n\t\t\tfinal TreeSet<Integer> set = getSet(type);\n\t\t\tset.add(val);\n\t\t\ti++;\n\t\t\treturn i;\n\t\t}\n\n\t\tif (c == '-') {\n\t\t\ti++;\n\t\t\tc = s.charAt(i);\n\t\t\tfinal int v = Integer.parseInt(String.valueOf(c));\n\t\t\tend = v;\n\t\t\ti++;\n\t\t\tif (i >= s.length()) {\n\t\t\t\taddToSet(val, end, 1, type);","sourceCodeStart":549,"sourceCodeEnd":585,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-alibaba-schedulerx/src/main/java/com/alibaba/cloud/scheduling/schedulerx/util/CronExpression.java#L549-L585","documentation":"Thrown in checkNext when '#' in day-of-week is not followed by an integer in 1-5 (guard + catch at CronExpression.java:560-569). The value after '#' selects the 1st-5th occurrence of the weekday in the month; anything else (non-numeric, or out of 1-5) is rejected.","triggerScenarios":"`new CronExpression(\"0 0 0 ? * 6#9\")` (nth=9 > 5), or `0 0 0 ? * 6#0`, or `0 0 0 ? * FRI#x` (non-numeric). Note '#' consumes the rest of the token via s.substring(i).","commonSituations":"Developer uses 0 or 6+ expecting a wider range, or appends extra characters after the nth value, or a 0-based assumption ('first' = 0).","solutions":["Use an nth value of 1-5 after '#', e.g. '6#9' -> '6#3'.","Ensure nothing trails the nth value in that field (it parses to end of token).","Use 1-based counting: 1 = first occurrence, 5 = last possible."],"exampleFix":"// before\nnew CronExpression(\"0 0 0 ? * 6#9\");\n// after\nnew CronExpression(\"0 0 0 ? * 6#3\"); // 3rd Friday of the month","handlingStrategy":"validation","validationCode":"// '<weekday>#<n>' requires 1 <= n <= 5.\nstatic boolean nthOk(String dowField) {\n    int h = dowField.indexOf('#');\n    if (h < 0) return true;\n    try {\n        int n = Integer.parseInt(dowField.substring(h + 1));\n        return n >= 1 && n <= 5;\n    } catch (NumberFormatException e) { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(raw);\n} catch (ParseException e) {\n    throw new IllegalArgumentException(\"Invalid cron expression: \" + raw, e);\n}","preventionTips":["The nth value after '#' is 1-5 (1-based).","Nothing may trail the nth value in that field.","Use 5 to mean 'the last possible occurrence'."],"tags":["cron","schedulerx","spring-cloud-alibaba","configuration","parsing","validation","range-check"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}