{"record":{"id":"2717f2617147de04","repo":"xuxueli/xxl-job","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":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java","lineNumber":756,"sourceCode":"    }\n\n    protected int checkNext(int pos, String s, int val, int type)\n            throws ParseException {\n\n        int end = -1;\n        int i = pos;\n\n        if (i >= s.length()) {\n            addToSet(val, end, -1, type);\n            return i;\n        }\n\n        char c = s.charAt(pos);\n\n        if (c == 'L') {\n            if (type == DAY_OF_WEEK) {\n                if(val < 1 || val > 7)\n                    throw new ParseException(\"Day-of-Week values must be between 1 and 7\", -1);\n                lastDayOfWeek = true;\n            } else {\n                throw new ParseException(\"'L' option is not valid here. (pos=\" + i + \")\", i);\n            }\n            TreeSet<Integer> set = getSet(type);\n            set.add(val);\n            i++;\n            return i;\n        }\n\n        if (c == 'W') {\n            if (type != DAY_OF_MONTH) {\n                throw new ParseException(\"'W' option is not valid here. (pos=\" + i + \")\", i);\n            }\n            if(val > 31)\n                throw new ParseException(\"The 'W' option does not make sense with values larger than 31 (max number of days in a month)\", i);\n            nearestWeekdays.add(val);\n            i++;","sourceCodeStart":738,"sourceCodeEnd":774,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java#L738-L774","documentation":"In the checkNext method, when 'L' follows a numeric value in the Day-of-Week field (e.g., '6L' meaning 'last Friday'), the preceding number must be a valid day-of-week value between 1 and 7. This error fires when the number is outside that range.","triggerScenarios":"A cron expression like '0 0 0 ? * 9L' where the value before 'L' in the day-of-week field is < 1 or > 7. The check at line 755 tests val < 1 || val > 7.","commonSituations":"Using a 0-indexed day-of-week (0-6) instead of Quartz's 1-indexed (1-7), or a typo producing a value like 8 or 9.","solutions":["Use a day-of-week value between 1 (Sunday) and 7 (Saturday) before 'L'.","Confirm the Quartz numbering: SUN=1, MON=2, TUE=3, WED=4, THU=5, FRI=6, SAT=7.","Validate the value before appending 'L'."],"exampleFix":"// before\n\"0 0 0 ? * 9L\"\n// after\n\"0 0 0 ? * 6L\"","handlingStrategy":"validation","validationCode":"// Validate 'NL' value in day-of-week (field index 5) is 1-7\nString[] parts = cron.trim().split(\"\\\\s+\");\nif (parts.length > 5 && parts[5].contains(\"L\")) {\n    String numPart = parts[5].replace(\"L\", \"\").replaceAll(\"[^0-9].*\", \"\");\n    if (!numPart.isEmpty()) {\n        int val = Integer.parseInt(numPart);\n        if (val < 1 || val > 7) throw new IllegalArgumentException(\"Day-of-week 'NL' value must be 1-7: \" + val);\n    }\n}","typeGuard":"boolean isValidLastWeekdayValue(String dowField) {\n    if (!dowField.contains(\"L\")) return true;\n    String num = dowField.replace(\"L\", \"\").replaceAll(\"[^0-9].*\", \"\");\n    if (num.isEmpty()) return true; // standalone 'L' is ok\n    int val = Integer.parseInt(num);\n    return val >= 1 && val <= 7;","tryCatchPattern":"try {\n    new CronExpression(cron);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"Day-of-Week values must be between 1 and 7\")) {\n        // correct the weekday number to 1-7\n    }\n}","preventionTips":["Remember Quartz day-of-week is 1-7 (SUN=1 ... SAT=7), not 0-6.","Validate 'NL' values against the 1-7 range before building the expression.","Add unit tests for each weekday with the 'L' modifier."],"tags":["cron","validation","quartz","day-of-week"],"backgroundTag":null,"analyzedSha":"e74c784f68f81fa89cb350913ef15794865d7b12","analyzedAt":"2026-08-14T04:22:43.715Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}