{"record":{"id":"afd1001b61a53495","repo":"alibaba/spring-cloud-alibaba","slug":"w-option-is-not-valid-here-pos","errorCode":null,"errorMessage":"'W' option is not valid here. (pos={})","messagePattern":"'W' 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":544,"sourceCode":"\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);\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) {","sourceCodeStart":526,"sourceCodeEnd":562,"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#L526-L562","documentation":"Thrown in checkNext when 'W' (nearest weekday) follows a value but the field is not DAY_OF_MONTH (guard at CronExpression.java:543-544). 'W' is only meaningful for day-of-month ('15W' = nearest weekday to the 15th).","triggerScenarios":"`new CronExpression(\"0 0 5W * ? *\")` ('W' in hours), or `0 0 0 ? * 6W` ('W' in day-of-week). Any '<n>W' outside day-of-month.","commonSituations":"Developer thinks 'W' is a general 'weekday' suffix and applies it to the day-of-week field, or a missing seconds field shifts day-of-month content into another position.","solutions":["Use '<n>W' only in the day-of-month field, e.g. '0 0 0 15W * ?'.","For day-of-week, drop the 'W'; use plain numbers or 'L'/'#'.","Confirm field ordering (day-of-month is the 4th field)."],"exampleFix":"// before\nnew CronExpression(\"0 0 0 ? * 6W\");\n// after\nnew CronExpression(\"0 0 0 15W * ?\"); // nearest weekday to the 15th","handlingStrategy":"validation","validationCode":"// 'W' is only valid in the day-of-month field.\nstatic boolean wInDomOnly(String[] fields) {\n    if (fields.length < 6) return false;\n    return !fields[0].contains(\"W\") && !fields[1].contains(\"W\")\n        && !fields[2].contains(\"W\") && !fields[4].contains(\"W\")\n        && !fields[5].contains(\"W\");\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":["'W' (nearest weekday) applies only to day-of-month.","For day-of-week, do not use 'W'.","Keep field ordering so day-of-month is position 4."],"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-14T05:17:29.042Z"}