{"record":{"id":"02426d9c15a6c9bc","repo":"jeecgboot/JeecgBoot","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":"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":772,"sourceCode":"            if (type == DAY_OF_WEEK) {\n                if(val < 1 || val > 7)\n                    throw new ParseException(\"Day-of-Week values must be between 1 and 7\", -1);\n                lastDayOfWeek = true;\n            } else {\n                throw new ParseException(\"'L' option is not valid here. (pos=\" + i + \")\", i);\n            }\n            TreeSet<Integer> set = getSet(type);\n            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\",","sourceCodeStart":754,"sourceCodeEnd":790,"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#L754-L790","documentation":"Thrown when the 'W' (nearest weekday) modifier is used with a day-of-month value greater than 31. Since no month has more than 31 days, a value like 32W or 40W is nonsensical and rejected before the value is added to the nearestWeekdays set.","triggerScenarios":"A cron expression with a day-of-month token of the form <N>W where N > 31 — e.g., '0 0 0 32W * ?' or '0 0 0 40W * ?'.","commonSituations":"Typo in the day number; misunderstanding of 'W' semantics; variable interpolation that injects an out-of-range value.","solutions":["Change the day-of-month value preceding 'W' to a number between 1 and 31.","If you meant a specific weekday, use the day-of-week field with a number 1–7 instead.","Sanitize any dynamic/templated cron string before passing it to CronExpression."],"exampleFix":"// before\nString cron = \"0 0 0 35W * ?\";  // 35 > 31\n// after\nString cron = \"0 0 0 15W * ?\";  // nearest weekday to the 15th","handlingStrategy":"validation","validationCode":"// Validate day-of-month 'W' value is <= 31\nString domField = fields[3];\nfor (String token : domField.split(\",\")) {\n    if (token.endsWith(\"W\")) {\n        int val = Integer.parseInt(token.substring(0, token.length() - 1));\n        if (val > 31) throw new IllegalArgumentException(\"'W' value must be <= 31\");\n    }\n}","typeGuard":"boolean isValidWValue(String token) {\n    if (!token.endsWith(\"W\")) return true;\n    try {\n        int val = Integer.parseInt(token.substring(0, token.length() - 1));\n        return val >= 1 && val <= 31;\n    } catch (NumberFormatException e) {\n        return false;\n    }\n}","tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"'W' option does not make sense\")) {\n        // reduce the day-of-month number to <= 31\n    }\n    throw e;\n}","preventionTips":["Cap day-of-month 'W' values at 31.","Prefer low day numbers (1–28) with 'W' since they are valid in all months.","Validate dynamically generated cron values."],"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"}