apache/dolphinscheduler · error · RuntimeException
Expression not valid
Error message
Expression not valid
What it means
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.
Source
Thrown at dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtils.java:612
* @param expression expresstion
* @param date date
* @return last day of week
*/
public static Map.Entry<Date, String> calcWeekEnd(String expression, Date date) {
String addMonthExpr = expression.substring(WEEK_END.length() + 1, expression.length() - 1);
String[] params = addMonthExpr.split(COMMA);
if (params.length == 2) {
String dateFormat = params[0];
String dayExpr = params[1];
Integer day = calculate(dayExpr);
Date targetDate = DateUtils.getSunday(date);
targetDate = addDays(targetDate, day);
return new AbstractMap.SimpleImmutableEntry<>(targetDate, dateFormat);
}
throw new RuntimeException("Expression not valid");
}
/**
* calc months expression
*
* @param expression expresstion
* @param date date
* @return calc months
*/
public static Map.Entry<Date, String> calcMonths(String expression, Date date) {
String addMonthExpr = expression.substring(ADD_MONTHS.length() + 1, expression.length() - 1);
String[] params = addMonthExpr.split(COMMA);
if (params.length == 2) {
String dateFormat = params[0];
String monthExpr = params[1];
Integer addMonth = calculate(monthExpr);
Date targetDate = addMonths(date, addMonth);View on GitHub (pinned to 02eac45a1b)
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.
Example fix
// before: extra argument -> params.length == 3 -> throws String expr = "$[week_end(yyyyMMdd,1,1)]"; // after: exactly format + offset String expr = "$[week_end(yyyyMMdd,1)]";
Defensive patterns
Strategy: validation
Validate before calling
String body = expr.substring(expr.indexOf('(') + 1, expr.length() - 1);
if (expr.startsWith("$[week_end(") && body.split(",").length != 2) {
throw new IllegalArgumentException("week_end needs exactly format,offset: " + expr);
} Type guard
static boolean isValidWeekEnd(String expr) {
return expr != null && expr.matches("\\$\\[week_end\\([^,]+,[^,()]+\\)\\]");
} Try / catch
try {
String value = TimePlaceholderUtils.replacePlaceholder(expr, new Date(), timezoneId);
} catch (RuntimeException e) {
throw new TaskException("Invalid week_end placeholder: " + expr, e);
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- java.lang.CloneNotSupportedException
- 50026
- DATA_IS_NOT_VALID
- Object json deserialization exception.
- Read file: %s error
AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06).
Data as JSON: /api/errors/e09ca15a98454706.
Report an issue: GitHub.