{"record":{"id":"e9b528264569f176","repo":"alibaba/spring-cloud-alibaba","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":"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":557,"sourceCode":"\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);\n\t\t\t}\n\t\t\tif (val > 31) {\n\t\t\t\tthrow new ParseException(\"The 'W' option does not make sense with values larger than 31 (max number of days in a month)\", 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 == '#') {\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;","sourceCodeStart":539,"sourceCodeEnd":575,"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#L539-L575","documentation":"Thrown in checkNext when '#' (nth weekday) follows a value but the field is not DAY_OF_WEEK (guard at CronExpression.java:556-557). '#N' means 'the Nth <weekday> of the month' and is only valid in day-of-week (e.g. '6#3' = 3rd Friday).","triggerScenarios":"`new CronExpression(\"0 0 0 5#1 * ?\")` ('#' in day-of-month), or `0 0 5#1 * ? *` ('#' in hours). Any '<n>#<m>' outside day-of-week.","commonSituations":"Developer confuses '#' with a list separator or places the nth-weekday expression in the day-of-month field. Field-count mistakes also relocate it.","solutions":["Use '<weekday>#<n>' only in day-of-week, e.g. '0 0 0 ? * 6#3'.","For day-of-month use plain numbers or ranges, not '#'.","Recheck the six-field ordering."],"exampleFix":"// before\nnew CronExpression(\"0 0 0 5#1 * ?\");\n// after\nnew CronExpression(\"0 0 0 ? * 6#3\"); // 3rd Friday of the month","handlingStrategy":"validation","validationCode":"// '#' is valid only in the day-of-week field.\nstatic boolean hashInDowOnly(String[] fields) {\n    if (fields.length < 6) return false;\n    return !fields[0].contains(\"#\") && !fields[1].contains(\"#\")\n        && !fields[2].contains(\"#\") && !fields[3].contains(\"#\")\n        && !fields[4].contains(\"#\");\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":["Use '#' only in day-of-week (e.g. 6#3 = 3rd Friday).","Do not use '#' as a list or separator in other fields.","Recount fields so day-of-week stays in position 6."],"tags":["cron","schedulerx","spring-cloud-alibaba","configuration","parsing","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}