{"record":{"id":"3470c51099805d93","repo":"jeecgboot/JeecgBoot","slug":"w-option-is-not-valid-here-pos-i","errorCode":null,"errorMessage":"'W' option is not valid here. (pos=${i})","messagePattern":"'W' 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":769,"sourceCode":"        char c = s.charAt(pos);\n\n        if (c == 'L') {\n            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                }","sourceCodeStart":751,"sourceCodeEnd":787,"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#L751-L787","documentation":"Thrown when the 'W' (nearest weekday) modifier appears in any cron field other than day-of-month. The 'W' character instructs the scheduler to fire on the closest weekday (Mon–Fri) to the given day number, and it is only meaningful for the day-of-month field. Using it in second, minute, hour, day-of-week, month, or year fields is a syntax error.","triggerScenarios":"A cron expression containing 'W' after a numeric value where type != DAY_OF_MONTH — e.g., day-of-week field '5W', hour field '10W', or month field '3W'.","commonSituations":"Developer confuses day-of-week and day-of-month field positions; expression has an extra or missing field causing misalignment; copy-paste error placing 'W' in the wrong field.","solutions":["Ensure the 'W' modifier appears only in the day-of-month field (the 4th field in a 6-field cron, or 3rd of 6 before year).","Verify field count and ordering: seconds minutes hours day-of-month month day-of-week [year].","Use '?' in the day-of-week field when specifying a day-of-month with 'W'."],"exampleFix":"// before\nString cron = \"0 0 0 ? * 15W\";  // 'W' is in day-of-week position — wrong\n// after\nString cron = \"0 0 0 15W * ?\";  // 'W' in day-of-month position","handlingStrategy":"validation","validationCode":"// Ensure 'W' only appears in the day-of-month field (field index 3)\nString[] fields = cronExpr.split(\"\\\\s+\");\nfor (int f = 0; f < fields.length; f++) {\n    if (fields[f].contains(\"W\") && f != 3) {\n        throw new IllegalArgumentException(\"'W' is only valid in day-of-month field\");\n    }\n}","typeGuard":"boolean isWOnlyInDayOfMonth(String cron) {\n    String[] fields = cron.trim().split(\"\\\\s+\");\n    for (int f = 0; f < fields.length; f++) {\n        if (fields[f].contains(\"W\") && f != 3) return false;\n    }\n    return true;\n}","tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().contains(\"'W' option is not valid here\")) {\n        // 'W' was placed in a non-day-of-month field\n    }\n    throw e;\n}","preventionTips":["Use 'W' only in the day-of-month field.","Pair day-of-month 'W' with '?' in day-of-week.","Verify field count and alignment before constructing the 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"}