{"record":{"id":"e09ca15a98454706","repo":"apache/dolphinscheduler","slug":"expression-not-valid-e09ca1","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":612,"sourceCode":"     * @param expression expresstion\n     * @param date       date\n     * @return last day of week\n     */\n    public static Map.Entry<Date, String> calcWeekEnd(String expression, Date date) {\n        String addMonthExpr = expression.substring(WEEK_END.length() + 1, expression.length() - 1);\n        String[] params = addMonthExpr.split(COMMA);\n\n        if (params.length == 2) {\n            String dateFormat = params[0];\n            String dayExpr = params[1];\n            Integer day = calculate(dayExpr);\n            Date targetDate = DateUtils.getSunday(date);\n            targetDate = addDays(targetDate, day);\n\n            return new AbstractMap.SimpleImmutableEntry<>(targetDate, dateFormat);\n        }\n\n        throw new RuntimeException(\"Expression not valid\");\n    }\n\n    /**\n     * calc months expression\n     *\n     * @param expression expresstion\n     * @param date       date\n     * @return calc months\n     */\n    public static Map.Entry<Date, String> calcMonths(String expression, Date date) {\n        String addMonthExpr = expression.substring(ADD_MONTHS.length() + 1, expression.length() - 1);\n        String[] params = addMonthExpr.split(COMMA);\n\n        if (params.length == 2) {\n            String dateFormat = params[0];\n            String monthExpr = params[1];\n            Integer addMonth = calculate(monthExpr);\n            Date targetDate = addMonths(date, addMonth);","sourceCodeStart":594,"sourceCodeEnd":630,"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#L594-L630","documentation":"calcWeekEnd parses a $[week_end(...)] time placeholder expression. It strips the week_end prefix/suffix, splits by comma, and requires exactly two parts: a date format and a day-offset expression (relative to Sunday). Otherwise it throws an untyped RuntimeException(\"Expression not valid\") — note the capital E, so string matching on the message is unreliable across these sibling methods.","triggerScenarios":"Calling calcWeekEnd (via calcTimeExpression) with a week_end expression whose body does not split into exactly 2 comma-separated parts, e.g. '$[week_end(yyyyMMdd)]' (only format, no offset) or '$[week_end(yyyyMMdd,1,2)]' (extra argument).","commonSituations":"A user defined a weekend-based placeholder without the day offset; an extra comma slipped in during editing; expressions migrated from another scheduler (e.g. Airtime/Cron-based placeholders) use different arity.","solutions":["Provide exactly two comma-separated arguments: format then day expression, e.g. $[week_end(yyyyMMdd,0)] or $[week_end(yyyyMMdd,-7)].","Ensure the expression is fully parenthesized; the method assumes a trailing ')' is present (expression.length() - 1 strip).","Add upstream validation of placeholder arity before calling TimePlaceholderUtils.replacePlaceholder.","Do not match on the exact message string 'Expression not valid' when handling — siblings use lowercase 'expression not valid'; catch RuntimeException around the substitution call instead."],"exampleFix":"// before: extra argument -> params.length == 3 -> throws\nString expr = \"$[week_end(yyyyMMdd,1,1)]\";\n// after: exactly format + offset\nString expr = \"$[week_end(yyyyMMdd,1)]\";","handlingStrategy":"validation","validationCode":"String body = expr.substring(expr.indexOf('(') + 1, expr.length() - 1);\nif (expr.startsWith(\"$[week_end(\") && body.split(\",\").length != 2) {\n    throw new IllegalArgumentException(\"week_end needs exactly format,offset: \" + expr);\n}","typeGuard":"static boolean isValidWeekEnd(String expr) {\n    return expr != null && expr.matches(\"\\\\$\\\\[week_end\\\\([^,]+,[^,()]+\\\\)\\\\]\");\n}","tryCatchPattern":"try {\n    String value = TimePlaceholderUtils.replacePlaceholder(expr, new Date(), timezoneId);\n} catch (RuntimeException e) {\n    throw new TaskException(\"Invalid week_end placeholder: \" + expr, e);\n}","preventionTips":["Keep week_end expressions to exactly two comma-separated arguments","Do not match error messages verbatim — this sibling uses 'Expression not valid' with a capital E","Reject malformed placeholders at save time in the API layer"],"tags":["runtime-exception","placeholder-parsing","date-expression","input-validation"],"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"}