{"record":{"id":"724539371d072625","repo":"xuxueli/xxl-job","slug":"option-is-not-valid-here-pos","errorCode":null,"errorMessage":"'#' option is not valid here. (pos={})","messagePattern":"'#' option is not valid here\\. \\(pos=(.+?)\\)","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":780,"sourceCode":"            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++;\n            return i;\n        }\n\n        if (c == '#') {\n            if (type != DAY_OF_WEEK) {\n                throw new ParseException(\"'#' option is not valid here. (pos=\" + i + \")\", i);\n            }\n            i++;\n            try {\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\n            TreeSet<Integer> set = getSet(type);\n            set.add(val);\n            i++;\n            return i;\n        }","sourceCodeStart":762,"sourceCodeEnd":798,"githubUrl":"https://github.com/xuxueli/xxl-job/blob/e74c784f68f81fa89cb350913ef15794865d7b12/xxl-job-admin/src/main/java/com/xxl/job/admin/business/scheduler/cron/CronExpression.java#L762-L798","documentation":"In checkNext, the '#' (nth occurrence) modifier following a numeric value is only valid in the Day-of-Week field. '#N' means 'the Nth occurrence of the given weekday in the month'. This error fires when '#' appears after a number in any field other than day-of-week.","triggerScenarios":"A cron expression like '0 0 0 5#1 * ?' where '5#1' appears in the day-of-month field. The parser reads 5 as a digit, enters checkNext, finds '#', and since type != DAY_OF_WEEK, throws at line 780.","commonSituations":"Placing the '#' modifier in the wrong field, or misunderstanding that '#' is a day-of-week-only feature meaning 'Nth weekday of the month'.","solutions":["Move the '#N' modifier and its preceding weekday number to the day-of-week field: '0 0 0 ? * 5#1'.","Ensure day-of-month uses '?' or '*' when day-of-week uses '#'.","Verify the field position in the 6 or 7 field layout."],"exampleFix":"// before\n\"0 0 0 5#1 * ?\"\n// after\n\"0 0 0 ? * 5#1\"","handlingStrategy":"validation","validationCode":"// 'N#M' is only valid in day-of-week (field index 5)\nString[] parts = cron.trim().split(\"\\\\s+\");\nfor (int idx = 0; idx < parts.length; idx++) {\n    if (parts[idx].contains(\"#\") && idx != 5) {\n        throw new IllegalArgumentException(\"'#' is only valid in day-of-week (field 5): \" + parts[idx]);\n    }\n}","typeGuard":"boolean isHashInDayOfWeekOnly(String[] parts) {\n    for (int idx = 0; idx < parts.length; idx++) {\n        if (parts[idx].contains(\"#\") && idx != 5) return false;\n    }\n    return true;","tryCatchPattern":"try {\n    new CronExpression(cron);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"'#' option is not valid here\")) {\n        // move the '#N' expression to the day-of-week field\n    }\n}","preventionTips":["The '#' (nth occurrence) modifier is day-of-week only.","Ensure day-of-month uses '?' or '*' when day-of-week uses '#'.","Verify field positions in the Quartz 6 or 7 field layout."],"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"}