{"record":{"id":"f114496fab0d1532","repo":"jeecgboot/JeecgBoot","slug":"option-is-not-valid-here-pos-i","errorCode":null,"errorMessage":"'#' option is not valid here. (pos=${i})","messagePattern":"'#' option is not valid here\\. \\(pos=(.+?)\\)","errorType":"validation","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":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/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#L762-L798","documentation":"Thrown when the '#' (nth occurrence) modifier appears in any cron field other than day-of-week. The '#' syntax (e.g., '6#3' = 3rd Friday) is exclusively a day-of-week feature. Its presence in any other field is a parse error.","triggerScenarios":"A cron expression containing '#' after a numeric value where type != DAY_OF_WEEK — e.g., day-of-month field '15#1', hour field '10#2', or minute field '0#1'.","commonSituations":"Field misalignment (extra/missing field shifts '#' into the wrong position); developer confuses day-of-month and day-of-week; copy-paste from documentation without adjusting field order.","solutions":["Ensure '#' appears only in the day-of-week field (the 6th field in a 6-field expression, or 7th if year is included).","Use '?' in the day-of-month field when using '#' in day-of-week.","Verify the full field order: seconds minutes hours day-of-month month day-of-week."],"exampleFix":"// before\nString cron = \"0 0 0 5#3 * ?\";  // '#' is in day-of-month — wrong\n// after\nString cron = \"0 0 0 ? * 6#3\";  // '#' in day-of-week = 3rd Friday","handlingStrategy":"validation","validationCode":"// Ensure '#' only appears in the day-of-week field (field index 5)\nString[] fields = cronExpr.split(\"\\\\s+\");\nfor (int f = 0; f < fields.length; f++) {\n    if (fields[f].contains(\"#\") && f != 5) {\n        throw new IllegalArgumentException(\"'#' is only valid in day-of-week field\");\n    }\n}","typeGuard":"boolean isHashOnlyInDayOfWeek(String cron) {\n    String[] fields = cron.trim().split(\"\\\\s+\");\n    for (int f = 0; f < fields.length; f++) {\n        if (fields[f].contains(\"#\") && f != 5) return false;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"'#' option is not valid here\")) {\n        // '#' must move to day-of-week field\n    }\n    throw e;\n}","preventionTips":["Place '#' exclusively in the day-of-week field.","Use '?' in day-of-month when using '#' in day-of-week.","Double-check field alignment after editing any cron expression."],"tags":["cron","validation","scheduling","xxljob","parse"],"backgroundTag":null,"analyzedSha":"96fb33f5ec68516da0b0147da06b2eb0419e063a","analyzedAt":"2026-08-14T00:04:16.786Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}