{"record":{"id":"3706bb27b85d3291","repo":"apache/dolphinscheduler","slug":"the-task-taskdefinition-is-already-exists","errorCode":null,"errorMessage":"\"The task \" + taskDefinition + \" is already exists\"","messagePattern":"\"The task \" \\+ taskDefinition \\+ \" is already exists\"","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java","lineNumber":115,"sourceCode":"        TaskDefinition taskDefinition = taskDefinitionCodeMap.get(taskCode);\n        if (taskDefinition == null) {\n            throw new IllegalArgumentException(\"Cannot find task: \" + taskCode);\n        }\n        return taskDefinition;\n    }\n\n    @Override\n    public List<TaskDefinition> getAllTaskNodes() {\n        return new ArrayList<>(taskDefinitionMap.values());\n    }\n\n    private void addTaskNodes(List<TaskDefinition> taskDefinitions) {\n        taskDefinitions\n                .stream()\n                .map(TaskDefinition::getName)\n                .forEach(taskDefinition -> {\n                    if (predecessors.containsKey(taskDefinition) || successors.containsKey(taskDefinition)) {\n                        throw new IllegalArgumentException(\"The task \" + taskDefinition + \" is already exists\");\n                    }\n                    predecessors.put(taskDefinition, new ArrayList<>());\n                    successors.put(taskDefinition, new ArrayList<>());\n                });\n    }\n\n    private void addTaskEdge(List<WorkflowTaskRelation> workflowTaskRelations) {\n        for (WorkflowTaskRelation workflowTaskRelation : workflowTaskRelations) {\n            long pre = workflowTaskRelation.getPreTaskCode();\n            long post = workflowTaskRelation.getPostTaskCode();\n            if (pre > 0 && post > 0) {\n\n                if (!taskDefinitionCodeMap.containsKey(pre)) {\n                    throw new IllegalArgumentException(\"Cannot find task: \" + pre);\n                }\n                if (!taskDefinitionCodeMap.containsKey(post)) {\n                    throw new IllegalArgumentException(\"Cannot find task: \" + post);\n                }","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java#L97-L133","documentation":"addTaskNodes initializes the predecessor/successor adjacency lists for every task name in the graph. If a task name already has an entry, the task is being added twice and the graph would be corrupt, so it throws this IllegalArgumentException.","triggerScenarios":"Constructing a WorkflowGraph whose List<TaskDefinition> contains two definitions with the same name (streamed through TaskDefinition::getName). Internally this is reachable after the duplicate-code/name checks at lines 51-58 only if distinct names are impossible — in practice it fires on duplicate-name inputs when the earlier name check was bypassed (e.g. differing codes but the same name reaching addTaskNodes via different call paths).","commonSituations":"Duplicated task definitions with different codes but identical names in the workflow definition list; calling an overloaded constructor or add path twice with overlapping task lists; hand-built graphs in tests adding the same task twice.","solutions":["Ensure task names are unique across the workflow's task definitions before constructing the graph","Deduplicate the input list by name (or fix upstream so duplicate definitions are not produced)","If intentionally re-adding tasks, clear or rebuild the WorkflowGraph instead of mutating it","Check the workflow definition in t_ds_task_definition for duplicate name rows"],"exampleFix":"// before\nList<TaskDefinition> tasks = loadTasks(); // may contain duplicates\nWorkflowGraph g = new WorkflowGraph(tasks, relations);\n// after\nList<TaskDefinition> unique = tasks.stream()\n        .collect(Collectors.toMap(TaskDefinition::getName, t -> t, (a, b) -> a))\n        .values().stream().collect(Collectors.toList());\nWorkflowGraph g = new WorkflowGraph(unique, relations);","handlingStrategy":"validation","validationCode":"Set<String> names = new HashSet<>();\nfor (TaskDefinition t : taskDefinitions) {\n    if (!names.add(t.getName())) throw new IllegalStateException(\"Duplicate task name: \" + t.getName());\n}","typeGuard":null,"tryCatchPattern":"try {\n    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"is already exists\")) log.error(\"Duplicate task in graph: {}\", e.getMessage());\n    throw e;\n}","preventionTips":["Enforce unique task names per workflow at save/import time","Deduplicate task lists before building graphs in tests or utilities","Rebuild WorkflowGraph instances rather than incrementally adding tasks","Add a unique index on (workflow code, task name) in the definition store"],"tags":["workflow-graph","duplicate-task-name","illegal-argument"],"backgroundTag":"invalid-argument-value","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"}