{"record":{"id":"817ebbd283fe09dd","repo":"apache/dolphinscheduler","slug":"duplicate-task-code-taskdefinition-getcode","errorCode":null,"errorMessage":"\"Duplicate task code: \" + taskDefinition.getCode() + \" in the workflow\"","messagePattern":"\"Duplicate task code: \" \\+ taskDefinition\\.getCode\\(\\) \\+ \" in the workflow\"","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java","lineNumber":57,"sourceCode":"\n    private final Map<String, List<String>> successors;\n\n    public WorkflowGraph(List<WorkflowTaskRelation> workflowTaskRelations, List<TaskDefinition> taskDefinitions) {\n        checkNotNull(taskDefinitions, \"taskDefinitions can not be null\");\n        checkNotNull(workflowTaskRelations, \"taskDefinitions can not be null\");\n        this.predecessors = new HashMap<>();\n        this.successors = new HashMap<>();\n\n        this.taskDefinitionMap = new HashMap<>(taskDefinitions.size());\n        this.taskDefinitionCodeMap = new HashMap<>(taskDefinitions.size());\n        for (TaskDefinition taskDefinition : taskDefinitions) {\n            if (taskDefinitionMap.containsKey(taskDefinition.getName())) {\n                throw new IllegalArgumentException(\n                        \"Duplicate task name: \" + taskDefinition.getName() + \" in the workflow\");\n            }\n            taskDefinitionMap.put(taskDefinition.getName(), taskDefinition);\n            if (taskDefinitionCodeMap.containsKey(taskDefinition.getCode())) {\n                throw new IllegalArgumentException(\n                        \"Duplicate task code: \" + taskDefinition.getCode() + \" in the workflow\");\n            }\n            taskDefinitionCodeMap.put(taskDefinition.getCode(), taskDefinition);\n        }\n\n        addTaskNodes(taskDefinitions);\n        addTaskEdge(workflowTaskRelations);\n    }\n\n    @Override\n    public List<String> getStartNodes() {\n        return predecessors.entrySet()\n                .stream()\n                .filter(entry -> entry.getValue().isEmpty())\n                .map(Map.Entry::getKey)\n                .collect(Collectors.toList());\n    }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java#L39-L75","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the workflow's task definition list and ensure every task has a unique code before constructing WorkflowGraph","Inspect the t_ds_task_definition table for the workflow and fix/delete duplicated code rows","Regenerate the task code when copying/cloning a task definition instead of reusing the old one","If importing workflow JSON, re-run code generation during import rather than trusting embedded codes"],"exampleFix":"// before\ntasks.add(taskA); // code 1001\ntasks.add(cloneOfTaskA); // code 1001 duplicated\n// after\ntasks.add(taskA); // code 1001\ncloneOfTaskA.setCode(codeGenerator.nextCode());\ntasks.add(cloneOfTaskA);","handlingStrategy":"validation","validationCode":"Set<Long> codes = new HashSet<>();\nfor (TaskDefinition t : taskDefinitions) {\n    if (!codes.add(t.getCode())) throw new IllegalStateException(\"Duplicate task code: \" + t.getCode());\n}","typeGuard":null,"tryCatchPattern":"try {\n    WorkflowGraph graph = new WorkflowGraph(taskDefinitions, relations);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().startsWith(\"Duplicate task code\")) {\n        log.error(\"Workflow definition corrupt: {}\", e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Always regenerate task codes when copying or cloning task definitions","Never hand-edit workflow definition rows in the database","Validate uniqueness of codes (and names) in the import path before saving","Add a DB-level check or application-level set to enforce code uniqueness per workflow"],"tags":["workflow-graph","duplicate-task-code","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-14T00:17:10.932Z"}