{"record":{"id":"875f4434b1df8a8d","repo":"apache/dolphinscheduler","slug":"cannot-format-the-date","errorCode":null,"errorMessage":"Cannot format the date","messagePattern":"Cannot format the date","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/parser/TimePlaceholderUtils.java","lineNumber":279,"sourceCode":"\n    }\n\n    /**\n     * Format time expression with given date, the date cannot be null.\n     * <p> If the expression is not a time expression, return the original expression.\n     *\n     */\n    public static String formatTimeExpression(final String timeExpression, final Date date,\n                                              final boolean ignoreInvalidExpression) {\n        // After N years: $[add_months(yyyyMMdd,12*N)], the first N months: $[add_months(yyyyMMdd,-N)], etc\n        if (date == null) {\n            throw new IllegalArgumentException(\"Cannot parse the expression: \" + timeExpression + \", date is null\");\n        }\n        if (StringUtils.isEmpty(timeExpression)) {\n            if (ignoreInvalidExpression) {\n                return timeExpression;\n            }\n            throw new IllegalArgumentException(\"Cannot format the date\" + date + \" with null timeExpression\");\n        }\n        try {\n            if (timeExpression.startsWith(TIMESTAMP)) {\n                return calculateTimeStamp(timeExpression, date);\n            }\n            if (timeExpression.startsWith(YEAR_WEEK)) {\n                return calculateYearWeek(timeExpression, date);\n            }\n            return calcTimeExpression(timeExpression, date);\n        } catch (Exception e) {\n            if (ignoreInvalidExpression) {\n                return timeExpression;\n            }\n            throw new IllegalArgumentException(\"Unsupported placeholder expression: \" + timeExpression, e);\n        }\n    }\n\n    /**","sourceCodeStart":261,"sourceCodeEnd":297,"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#L261-L297","documentation":"formatTimeExpression in TimePlaceholderUtils throws this IllegalArgumentException when the time placeholder expression string is empty (null or \"\") and ignoreInvalidExpression is false. The date itself was valid, but there is no expression to format, so the utility refuses to guess and fails fast. Passing ignoreInvalidExpression=true makes it silently return the original (empty) expression instead of throwing.","triggerScenarios":"Calling TimePlaceholderUtils.formatTimeExpression(date=non-null, ignoreInvalidExpression=false) with a null or empty timeExpression string. This happens when a task parameter like $[yyyyMMdd] was never filled in — e.g. an empty custom parameter value or a placeholder resolved to \"\" before being passed to formatTimeExpression.","commonSituations":"Users leave a time-placeholder parameter blank in the DolphinScheduler UI; upstream substitution produces an empty string; code paths that always call formatTimeExpression even when the expression is optional, without setting ignoreInvalidExpression=true.","solutions":["Fix the source of the empty expression: ensure the parameter value (e.g. $[yyyyMMdd], $[add_months(yyyyMMdd,-1)]) is actually populated before calling formatTimeExpression","Call formatTimeExpression with ignoreInvalidExpression=true if an empty expression is acceptable and should pass through unchanged","Guard the call site: skip formatting when the expression is null or empty","Check the task definition JSON for blank parameter values"],"exampleFix":"// before\nString result = TimePlaceholderUtils.formatTimeExpression(expression, scheduleDate, false);\n// after\nString result = StringUtils.isEmpty(expression)\n    ? expression\n    : TimePlaceholderUtils.formatTimeExpression(expression, scheduleDate, false);","handlingStrategy":"validation","validationCode":"if (date == null) throw new IllegalArgumentException(\"date must not be null\");\nif (expression == null || expression.isEmpty()) {\n    // skip formatting entirely or pass ignoreInvalidExpression=true\n    return expression;\n}\nString result = TimePlaceholderUtils.formatTimeExpression(expression, date, false);","typeGuard":"boolean isValidTimeExpression(String expr) {\n    return expr != null && !expr.trim().isEmpty();\n}","tryCatchPattern":"try {\n    return TimePlaceholderUtils.formatTimeExpression(expr, date, false);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"null timeExpression\")) {\n        log.warn(\"Empty time expression, skipping formatting\");\n        return expr;\n    }\n    throw e;\n}","preventionTips":["Never pass raw user input as timeExpression without an emptiness check","Use ignoreInvalidExpression=true for optional placeholder substitution paths","Validate parameter values at task-definition parse time, not at expression-format time","Add a unit test for empty-expression input"],"tags":["date","placeholder","empty-argument","illegal-argument"],"backgroundTag":"empty-required-field","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}