apache/dolphinscheduler · error · IllegalArgumentException

"Duplicate task name: " + taskDefinition.getName() + " in th

Error message

"Duplicate task name: " + taskDefinition.getName() + " in the workflow"

What it means

Thrown in the WorkflowGraph constructor when two task definitions in the supplied collection share the same name. The graph indexes tasks by name, so duplicates would make name-based lookups ambiguous; construction fails fast with IllegalArgumentException. A sibling check enforces the same for task codes.

Source

Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java:52

    private final Map<Long, TaskDefinition> taskDefinitionCodeMap;
    private final Map<String, TaskDefinition> taskDefinitionMap;

    private final Map<String, List<String>> predecessors;

    private final Map<String, List<String>> successors;

    public WorkflowGraph(List<WorkflowTaskRelation> workflowTaskRelations, List<TaskDefinition> taskDefinitions) {
        checkNotNull(taskDefinitions, "taskDefinitions can not be null");
        checkNotNull(workflowTaskRelations, "taskDefinitions can not be null");
        this.predecessors = new HashMap<>();
        this.successors = new HashMap<>();

        this.taskDefinitionMap = new HashMap<>(taskDefinitions.size());
        this.taskDefinitionCodeMap = new HashMap<>(taskDefinitions.size());
        for (TaskDefinition taskDefinition : taskDefinitions) {
            if (taskDefinitionMap.containsKey(taskDefinition.getName())) {
                throw new IllegalArgumentException(
                        "Duplicate task name: " + taskDefinition.getName() + " in the workflow");
            }
            taskDefinitionMap.put(taskDefinition.getName(), taskDefinition);
            if (taskDefinitionCodeMap.containsKey(taskDefinition.getCode())) {
                throw new IllegalArgumentException(
                        "Duplicate task code: " + taskDefinition.getCode() + " in the workflow");
            }
            taskDefinitionCodeMap.put(taskDefinition.getCode(), taskDefinition);
        }

        addTaskNodes(taskDefinitions);
        addTaskEdge(workflowTaskRelations);
    }

    @Override
    public List<String> getStartNodes() {
        return predecessors.entrySet()
                .stream()

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Rename the duplicate task in the workflow definition so every task name is unique, then save and retry.
  2. Audit the workflow import/export payload or DB rows (t_ds_task_definition) for duplicated names.
  3. Fix any client code that constructs workflow definitions to enforce unique task names before submission.

Example fix

// before: duplicate task names in definition list
new TaskDefinition("copy", ...); new TaskDefinition("copy", ...);
// after: unique names
new TaskDefinition("copy", ...); new TaskDefinition("copy_2", ...);
Defensive patterns

Strategy: validation

Validate before calling

// reject duplicate task names before constructing the graph
Set<String> seen = new HashSet<>();
for (TaskDefinition td : taskDefinitions) {
    if (!seen.add(td.getName()))
        throw new IllegalStateException("Duplicate task name: " + td.getName());
}

Try / catch

try {
    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Duplicate task name:")) {
        // deduplicate/rename tasks in the definition set
    } else throw e;
}

Prevention

When it happens

Trigger: Building a WorkflowGraph from a taskDefinitions list containing two tasks with identical names — typically when the workflow definition from the DB or API payload has duplicate task names.

Common situations: Importing a workflow JSON whose tasks were hand-copied with the same name; buggy API clients appending tasks without renaming; corrupted workflow definition data after failed merge/edit.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/0c9e16156d9ac33a. Report an issue: GitHub.