{"record":{"id":"80a93196dfe924e6","repo":"alibaba/spring-cloud-alibaba","slug":"the-w-option-does-not-make-sense-with-values-lar","errorCode":null,"errorMessage":"The 'W' option does not make sense with values larger than 31 (max number of days in a month)","messagePattern":"The 'W' option does not make sense with values larger than 31 \\(max number of days in a month\\)","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":547,"sourceCode":"\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) {\n\t\t\t\t\tthrow new Exception();\n\t\t\t\t}\n\t\t\t}","sourceCodeStart":529,"sourceCodeEnd":565,"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#L529-L565","documentation":"Thrown in checkNext when 'W' (nearest weekday) is used in day-of-month but the preceding value exceeds 31 (guard at CronExpression.java:546-547). Since no month has more than 31 days, a 'W' anchor beyond 31 is nonsensical.","triggerScenarios":"`new CronExpression(\"0 0 0 32W * ?\")` (nearest weekday to the 32nd). Any '<n>W' in day-of-month with n > 31.","commonSituations":"Off-by-one or a value from another field concatenated before 'W'; also a templated day value that is not range-checked.","solutions":["Use a day value 1-31 before 'W', e.g. '32W' -> '15W'.","Range-check any injected day value before building the string."],"exampleFix":"// before\nnew CronExpression(\"0 0 0 32W * ?\");\n// after\nnew CronExpression(\"0 0 0 15W * ?\"); // nearest weekday to the 15th","handlingStrategy":"validation","validationCode":"// '<n>W' in day-of-month requires n <= 31.\nstatic boolean wAnchorOk(String domField) {\n    if (!domField.endsWith(\"W\") || domField.length() < 2) return true;\n    try {\n        int v = Integer.parseInt(domField.substring(0, domField.length() - 1));\n        return v >= 1 && v <= 31;\n    } catch (NumberFormatException e) { return false; }\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":["Cap the day anchor before 'W' at 31.","Range-check any injected day value.","Prefer 'L' for month-end rather than a high literal."],"tags":["cron","schedulerx","spring-cloud-alibaba","configuration","parsing","validation","range-check"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}