{"record":{"id":"f12414f3452b4089","repo":"flowable/flowable-engine","slug":"option-is-not-valid-here-pos","errorCode":null,"errorMessage":"'#' option is not valid here. (pos=","messagePattern":"'#' 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":769,"sourceCode":"            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 {\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(\"A numeric value between 1 and 5 must follow the '#' option\", i);\n            }\n\n            TreeSet<Integer> set = getSet(type);\n            set.add(val);\n            i++;\n            return i;\n        }\n\n        if (c == '-') {","sourceCodeStart":751,"sourceCodeEnd":787,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/calendar/CronExpression.java#L751-L787","documentation":"The cron expression parser in Flowable's CronExpression (a Quartz-derived parser) found a '#' character, which is only allowed in the day-of-week field to mean 'the nth weekday of the month' (e.g. 'FRI#3'). A '#' appearing in any other field (second, minute, hour, day-of-month, month, year) is syntactically invalid there, so a ParseException is thrown during storeExpressionVals/checkNext. This happens at expression-parse time, before any scheduling occurs.","triggerScenarios":"Calling new CronExpression(expr) or passing a cron string to Flowable configuration (e.g. process/timer definitions) where a '#' appears outside the day-of-week field — e.g. '0 0 15#1 * *' or a '#' accidentally placed in the day-of-month field.","commonSituations":"Copy-pasted cron expressions from systems with different cron dialects (some allow different token positions); hand-edited expressions where '#' was meant for day-of-week but shifted into day-of-month; typo or leftover shell-comment '#' inside the expression (classic crontab files allow # comments, but an inline comment within the 6-7 field cron string is invalid).","solutions":["Move the '#' nth-weekday clause into the day-of-week field, e.g. '0 0 0 ? * FRI#3' instead of placing it elsewhere","Remove the '#' if it was intended as a comment — cron strings here do not support inline comments; place comments outside the expression","Validate the cron expression with CronExpression.isValidExpression(expr) before feeding it to the engine to fail fast with a clearer message","Count the fields: a Quartz-style cron has 6 or 7 fields (second minute hour day-of-month month [day-of-week] [year]); ensure each token sits in the right position"],"exampleFix":"// before\nCronExpression cron = new CronExpression(\"0 0 15#2 * *\"); // '#' in hour field\n// after\nCronExpression cron = new CronExpression(\"0 0 0 ? * FRI#2\"); // nth-Friday in day-of-week field","handlingStrategy":"validation","validationCode":"String expr = \"0 0 0 ? * FRI#2\";\nString dow = expr.split(\"\\\\s+\")[5];\nif (expr.contains(\"#\") && !dow.contains(\"#\")) {\n    throw new IllegalArgumentException(\"'#' may only appear in the day-of-week field: \" + expr);\n}\nif (!org.flowable.common.engine.impl.calendar.CronExpression.isValidExpression(expr)) {\n    throw new IllegalArgumentException(\"Invalid cron expression: \" + expr);\n}","typeGuard":null,"tryCatchPattern":"try {\n    CronExpression cron = new CronExpression(expr);\n} catch (ParseException e) {\n    log.error(\"Bad cron expression at position {}: {}\", e.getErrorOffset(), e.getMessage());\n    throw new ConfigurationException(\"Invalid cron expression: \" + expr, e);\n}","preventionTips":["Only use '#' in the day-of-week field (6th field of a Quartz cron)","Run CronExpression.isValidExpression(expr) on every expression before use, especially user- or config-supplied ones","Never place shell-style '#' comments inside a cron string","Show a field-position diagram in any UI that lets users author cron expressions"],"tags":["cron","scheduling","parsing","validation"],"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-14T05:17:10.506Z"}