apache/dolphinscheduler · error · IllegalArgumentException

"Duplicate task code: " + taskDefinition.getCode() + " in th

Error message

"Duplicate task code: " + taskDefinition.getCode() + " in the workflow"

What it means

WorkflowGraph is built from the workflow's task definitions and relations. During construction it indexes tasks by name and by code; if two TaskDefinitions share the same code it throws this IllegalArgumentException because task codes must be unique within a workflow.

Source

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

    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()
                .filter(entry -> entry.getValue().isEmpty())
                .map(Map.Entry::getKey)
                .collect(Collectors.toList());
    }

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Check the workflow's task definition list and ensure every task has a unique code before constructing WorkflowGraph
  2. Inspect the t_ds_task_definition table for the workflow and fix/delete duplicated code rows
  3. Regenerate the task code when copying/cloning a task definition instead of reusing the old one
  4. If importing workflow JSON, re-run code generation during import rather than trusting embedded codes

Example fix

// before
tasks.add(taskA); // code 1001
tasks.add(cloneOfTaskA); // code 1001 duplicated
// after
tasks.add(taskA); // code 1001
cloneOfTaskA.setCode(codeGenerator.nextCode());
tasks.add(cloneOfTaskA);
Defensive patterns

Strategy: validation

Validate before calling

Set<Long> codes = new HashSet<>();
for (TaskDefinition t : taskDefinitions) {
    if (!codes.add(t.getCode())) throw new IllegalStateException("Duplicate task code: " + t.getCode());
}

Try / catch

try {
    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);
} catch (IllegalArgumentException e) {
    if (e.getMessage().startsWith("Duplicate task code")) {
        log.error("Workflow definition corrupt: {}", e.getMessage());
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling the WorkflowGraph constructor (or the master engine's workflow execution graph assembly) with a List<TaskDefinition> where two entries have identical TaskDefinition.getCode() values.

Common situations: Corrupted or hand-edited workflow definition JSON in the database; import/export of a workflow that duplicated a task definition; a bug in code-generation logic that reuses a snowflake-style code; DB rows copied without regenerating the code column.

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/817ebbd283fe09dd. Report an issue: GitHub.