{"record":{"id":"f175790494780043","repo":"apache/dolphinscheduler","slug":"expression-not-valid","errorCode":null,"errorMessage":"expression not valid","messagePattern":"expression not valid","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtils.java","lineNumber":321,"sourceCode":"    private static String calculateYearWeek(final String expression, final Date date) {\n\n        String dataFormat = expression.substring(YEAR_WEEK.length() + 1, expression.length() - 1);\n\n        String targetDate = \"\";\n        try {\n\n            if (dataFormat.contains(COMMA)) {\n                String param1 = dataFormat.split(COMMA)[0];\n                String param2 = dataFormat.split(COMMA)[1];\n                dataFormat = param1;\n\n                targetDate = transformYearWeek(date, dataFormat, calculate(param2));\n\n            } else {\n                targetDate = transformYearWeek(date, dataFormat, 1);\n            }\n        } catch (Exception e) {\n            throw new RuntimeException(\"expression not valid\");\n        }\n\n        return targetDate;\n    }\n\n    /**\n     * transform week of year\n     * @param date date\n     * @param format date_format,for example: yyyy-MM-dd / yyyyMMdd\n     * @param weekDay day of week\n     * @return date_string\n     */\n    private static String transformYearWeek(Date date, String format, int weekDay) {\n        Calendar calendar = Calendar.getInstance();\n        // Minimum number of days required for the first week of the year\n        calendar.setMinimalDaysInFirstWeek(4);\n\n        // By default ,Set Monday as the first day of the week","sourceCodeStart":303,"sourceCodeEnd":339,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtils.java#L303-L339","documentation":"calculateYearWeek wraps all failures while parsing the $[week(...)] expression — bad date format segment, non-numeric second parameter, or errors in transformYearWeek — in a bare RuntimeException(\"expression not valid\") with no cause. In formatTimeExpression this RuntimeException is then caught and rethrown as 'Unsupported placeholder expression' (or swallowed when ignoreInvalidExpression=true), but if calculateYearWeek is reached through the try-block it surfaces as this generic message.","triggerScenarios":"An expression starting with the YEAR_WEEK prefix ($[week(...)]) whose content after the prefix has no enclosing parentheses bounds (substring fails), a format part that is not a valid pattern, or a second comma-separated parameter that calculate() cannot evaluate to an int (e.g. $[week(yyyyMMdd,N+abc)]).","commonSituations":"Users write $[week(yyyy-MM-dd, 2)] with a space or extra token that breaks the comma split, or use an unsupported week-day number, or omit the format so substring produces a malformed body.","solutions":["Use the exact form $[week(fmt)] or $[week(fmt,n)] with no spaces and a numeric n, e.g. $[week(yyyyMMdd,1)]","Wrap the cause: this RuntimeException discards the original exception, so reproduce locally with the same input to see the real failure inside calculate()/transformYearWeek","Set ignoreInvalidExpression=true in formatTimeExpression so an invalid week expression returns the input unchanged rather than failing the task","Check the substring bounds — the expression must end with ')' or substring will throw StringIndexOutOfBounds before parsing"],"exampleFix":"// before\n$[week(yyyy-MM-dd, x2)]\n// calculate(\"x2\") throws -> RuntimeException(\"expression not valid\")\n// after\n$[week(yyyy-MM-dd, 2)]","handlingStrategy":"validation","validationCode":"// Validate $[week(...)] form before calling formatTimeExpression\nprivate static final Pattern WEEK_EXPR = Pattern.compile(\"\\\\$\\\\[week\\\\([A-Za-z\\-]+(,[0-9]+)?\\\\)\\\\]\");\nboolean isValidWeekExpression(String e) {\n    return e != null && WEEK_EXPR.matcher(e).matches();\n}","typeGuard":null,"tryCatchPattern":"try {\n    return TimePlaceholderUtils.formatTimeExpression(expr, date, false);\n} catch (RuntimeException e) {\n    if (\"expression not valid\".equals(e.getMessage())) {\n        throw new IllegalArgumentException(\"Invalid week expression: \" + expr, e);\n    }\n    throw e;\n}","preventionTips":["Ensure the expression ends with ')' so substring bounds are valid","Use numeric week-day parameters only (1-7)","No spaces inside the parenthesis body","Enable ignoreInvalidExpression=true for tolerant substitution"],"tags":["date","placeholder","invalid-expression","runtime-exception"],"backgroundTag":"invalid-argument-format","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}