{"record":{"id":"a7c1a1e01f0e1c57","repo":"apache/dolphinscheduler","slug":"the-branch-is-empty-please-check-the-switch-task","errorCode":null,"errorMessage":"The branch is empty, please check the switch task configuration","messagePattern":"The branch is empty, please check the switch task configuration","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/executor/plugin/switchtask/SwitchLogicTask.java","lineNumber":128,"sourceCode":"                    break;\n                }\n            } catch (Exception e) {\n                log.info(\"Execute switch item: {} failed\", switchResultVo, e);\n            }\n        }\n\n        if (nextBranch == null) {\n            log.info(\"All switch item is not satisfied\");\n            moveToDefaultBranch();\n        } else {\n            log.info(\"The condition is satisfied, move to the next branch: {}\", getTaskName(nextBranch));\n            taskParameters.setNextBranch(nextBranch);\n        }\n    }\n\n    private void checkIfBranchExist(Long branchNode) {\n        if (branchNode == null) {\n            throw new IllegalArgumentException(\"The branch is empty, please check the switch task configuration\");\n        }\n        if (workflowExecution.getWorkflowExecuteContext().getWorkflowGraph()\n                .getTaskNodeByCode(branchNode) == null) {\n            throw new IllegalArgumentException(\n                    \"The branch(code= \" + branchNode\n                            + \") is not in the dag, please check the switch task configuration\");\n        }\n    }\n\n    private String getTaskName(Long taskCode) {\n        return Optional.ofNullable(workflowExecution.getWorkflowExecuteContext())\n                .map(IWorkflowExecuteContext::getWorkflowGraph)\n                .map(iWorkflowGraph -> iWorkflowGraph.getTaskNodeByCode(taskCode))\n                .map(TaskDefinition::getName)\n                .orElse(null);\n    }\n\n    @Override","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/executor/plugin/switchtask/SwitchLogicTask.java#L110-L146","documentation":"Thrown by SwitchLogicTask.checkIfBranchExist when the switch task's selected branch node code is null. The switch plugin resolves which branch to take from SwitchParameters.SwitchResult; if no branch (neither a matched condition nor the default next node) was produced, it refuses to run. This is treated as a misconfiguration of the switch task, not a runtime failure, so it surfaces as IllegalArgumentException during task start.","triggerScenarios":"Calling start() on a switch logic task whose computed nextBranch is null — e.g. SwitchParameters with an empty switchResult, no dependTaskList entry whose condition matches, and no nextNode/default branch set.","commonSituations":"Users create a switch task in the UI but never configure the default branch after the last condition; JSON task params exported/edited by hand omit nextNode; conditions defined all evaluate false with no fallback branch wired in the DAG.","solutions":["Open the switch task definition and set the default branch (nextNode) so a branch always exists when no condition matches.","Verify each SwitchResult dependTaskList entry has a valid nextNode pointing at a task in the same workflow.","Re-save the task via the UI/API so taskParams JSON is regenerated correctly, then re-run the workflow."],"exampleFix":"// before: switch params with no default branch\n{\"switchResult\":{\"dependTaskList\":[{\"condition\":\"${var}>1\",\"nextNode\":null}]}}\n// after: add a default nextNode\n{\"switchResult\":{\"dependTaskList\":[{\"condition\":\"${var}>1\",\"nextNode\":1234567890}],\"nextNode\":9876543210}}","handlingStrategy":"validation","validationCode":"// before running a switch task, validate its params\nSwitchParameters p = JSONUtils.parseObject(taskInstance.getTaskParams(), SwitchParameters.class);\nboolean ok = p != null && p.getSwitchResult() != null && p.getSwitchResult().getNextNode() != null;\nif (!ok) throw new IllegalStateException(\"Switch task has no default branch configured\");","typeGuard":null,"tryCatchPattern":"try {\n    switchLogicTask.start();\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"The branch is empty\")) {\n        // alert: switch task misconfigured; fix branch config\n    } else throw e;\n}","preventionTips":["Always configure the default branch (nextNode) on switch tasks in the UI.","Validate switch task params JSON when saving via API or scripts.","Review workflow definitions for switch tasks after import/export."],"tags":["workflow","switch-task","config"],"backgroundTag":"missing-required-config-field","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"}