{"record":{"id":"09bc363b01404a38","repo":"alibaba/spring-cloud-alibaba","slug":"day-of-week-values-must-be-between-1-and-7","errorCode":null,"errorMessage":"Day-of-Week values must be between 1 and 7","messagePattern":"Day-of-Week values must be between 1 and 7","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":526,"sourceCode":"\t}\n\n\tprotected int checkNext(final int pos, final String s, final int val, final int type)\n\t\t\tthrows ParseException {\n\n\t\tint end = -1;\n\t\tint i = pos;\n\n\t\tif (i >= s.length()) {\n\t\t\taddToSet(val, end, -1, type);\n\t\t\treturn i;\n\t\t}\n\n\t\tchar c = s.charAt(pos);\n\n\t\tif (c == 'L') {\n\t\t\tif (type == DAY_OF_WEEK) {\n\t\t\t\tif (val < 1 || val > 7) {\n\t\t\t\t\tthrow new ParseException(\"Day-of-Week values must be between 1 and 7\", -1);\n\t\t\t\t}\n\t\t\t\tlastdayOfWeek = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new ParseException(\"'L' option is not valid here. (pos=\" + i + \")\", i);\n\t\t\t}\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 == 'W') {\n\t\t\tif (type == DAY_OF_MONTH) {\n\t\t\t\tnearestWeekday = true;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthrow new ParseException(\"'W' option is not valid here. (pos=\" + i + \")\", i);","sourceCodeStart":508,"sourceCodeEnd":544,"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#L508-L544","documentation":"Thrown in checkNext when 'L' (last) follows a value in the DAY_OF_WEEK field but the preceding value is outside 1-7 (guard at CronExpression.java:524-526). 'NL' means 'last <weekday> of the month', so the weekday must be a valid 1-7. Note the error position passed is -1.","triggerScenarios":"`new CronExpression(\"0 0 0 ? * 9L\")` (weekday 9 with 'L'), or `0L` (value 0). Any '<n>L' in day-of-week where n < 1 or n > 7.","commonSituations":"0-based weekday assumption (using 0 for Sunday, which is invalid here — SUN=1), or a field-shift placing a non-weekday number before 'L'.","solutions":["Use a weekday value 1-7 (SUN=1 ... SAT=7), e.g. '9L' -> '6L' (last Friday).","Do not use 0 for Sunday; this parser's dayMap maps SUN=1.","Verify the value sits in the day-of-week field (6th field)."],"exampleFix":"// before\nnew CronExpression(\"0 0 0 ? * 9L\");\n// after\nnew CronExpression(\"0 0 0 ? * 6L\"); // last Friday of the month","handlingStrategy":"validation","validationCode":"// '<n>L' in day-of-week requires 1 <= n <= 7.\nstatic boolean dowLastValueOk(String dowField) {\n    if (!dowField.endsWith(\"L\") || dowField.length() < 2) return true;\n    try {\n        int v = Integer.parseInt(dowField.substring(0, dowField.length() - 1));\n        return v >= 1 && v <= 7;\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":["Day-of-week is 1-7 with SUN=1 (this parser does not accept 0).","Use names (SUN..SAT) to avoid numbering mistakes.","Validate the weekday value before 'L'."],"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"}