{"record":{"id":"13db37e7d63e8101","repo":"flowable/flowable-engine","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":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java","lineNumber":754,"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                }\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                nearestWeekday = true;\n            } else {\n                throw new ParseException(\"'W' option is not valid here. (pos=\" + i + \")\", i);\n            }\n            if (val > 31) {\n                throw new ParseException(\n                        \"The 'W' option does not make sense with values larger than 31 (max number of days in a month)\",\n                        i);\n            }\n            TreeSet<Integer> set = getSet(type);\n            set.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 {","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java#L736-L772","documentation":"Parse-time guard in CronExpression.checkNext: the 'W' (nearest weekday) option was used in a field other than day-of-month (it is only valid there), so the expression is rejected at the given position.","triggerScenarios":"Expressions like \"0 0 0 ? * 5W\" (W in day-of-week) or \"0 0 0 15W * ?\" reached via checkNext after hour fields; 'W' appended to month or weekday values.","commonSituations":"Confusing 'W' semantics across cron dialects (some Unix crons reject W entirely; Quartz/Flowable only allow it in day-of-month); typos.","solutions":["Use 'nW' only in the day-of-month field, e.g. \"0 0 0 15W * ?\"","For nearest-weekday-like behavior in day-of-week, pick an explicit weekday value instead","Remove the 'W' from unsupported fields"],"exampleFix":"// before\nnew CronExpression(\"0 0 0 ? * 5W\");\n// after\nnew CronExpression(\"0 0 0 15W * ?\"); // nearest weekday to the 15th","handlingStrategy":"validation","validationCode":"boolean validWOption(String[] fields) {\n    return fields[3] != null && fields[3].matches(\"\\\\d{1,2}W\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expr);\n} catch (ParseException e) {\n    if (e.getMessage().startsWith(\"'W' option is not valid here\")) {\n        throw new ConfigurationException(\"'W' is only valid as nW in day-of-month: \" + expr, e);\n    }\n    throw e;\n}","preventionTips":["Use nW only in the day-of-month field","Use explicit weekday values instead of W when weekday-field behavior is desired","Document the supported Quartz option characters for whoever writes cron strings"],"tags":["cron","w-option","quartz","parse-error"],"backgroundTag":"invalid-argument-format","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}