{"record":{"id":"4bda4a5201428067","repo":"apache/dolphinscheduler","slug":"failed-to-parse-switch-task-params-taskparams","errorCode":null,"errorMessage":"Failed to parse Switch task params: {taskParams}","messagePattern":"Failed to parse Switch task params: (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":1457,"sourceCode":"                    failedWorkflowList.add(workflowDefinition.getCode() + \"[\" + workflowDefinition.getName() + \"]\");\n                }\n            }\n        }\n    }\n\n    /**\n     * Replaces old task codes with new ones in the parameters of a Switch task.\n     * Used during workflow duplication or import to preserve correct task dependencies.\n     */\n    private void replaceTaskCodeForSwitchTaskParams(TaskDefinitionLog taskDefLog, Map<Long, Long> taskCodeMap) {\n        String taskParams = taskDefLog.getTaskParams();\n        SwitchParameters params;\n\n        try {\n            params = JSONUtils.parseObject(taskParams, SwitchParameters.class);\n        } catch (Exception e) {\n            log.warn(\"Invalid Switch task params: {}\", taskParams, e);\n            throw new IllegalArgumentException(\"Failed to parse Switch task params: \" + taskParams, e);\n        }\n\n        if (params == null) {\n            log.warn(\"Parsed Switch task params is null: {}\", taskParams);\n            throw new IllegalArgumentException(\"Failed to parse Switch task params: \" + taskParams);\n        }\n\n        // Update nextBranch if mapped\n        Long nextBranch = params.getNextBranch();\n        if (nextBranch != null && taskCodeMap.containsKey(nextBranch)) {\n            params.setNextBranch(taskCodeMap.get(nextBranch));\n        }\n\n        // Update switch result nodes\n        SwitchParameters.SwitchResult result = params.getSwitchResult();\n        if (result != null) {\n            Long nextNode = result.getNextNode();\n            if (nextNode != null && taskCodeMap.containsKey(nextNode)) {","sourceCodeStart":1439,"sourceCodeEnd":1475,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L1439-L1475","documentation":"Thrown by replaceTaskCodeForSwitchTaskParams when the Switch task's taskParams JSON cannot be deserialized into SwitchParameters (JSONUtils.parseObject threw). The raw taskParams string is embedded in the IllegalArgumentException message. This happens during workflow copy/import while remapping task codes, and aborts the operation because a Switch task whose branch targets cannot be read would produce a broken DAG.","triggerScenarios":"Copying or importing a workflow whose Switch task has malformed taskParams — invalid JSON, wrong field types (e.g. switchResult not an object, nextBranch as string), or a truncated JSON string.","commonSituations":"Hand-edited workflow JSON imports; workflow definitions migrated between DolphinScheduler versions where SwitchParameters fields changed; data corrupted by an old UI or by direct DB edits to t_ds_task_definition.task_params.","solutions":["Inspect the taskParams text in the error message and fix the malformed JSON before retrying the copy/import.","Open the Switch task in the UI and re-save its parameters so a valid JSON document is written.","If the definition came from another version, re-export from the source system with a matching DolphinScheduler version.","If DB-edited, correct t_ds_task_definition.task_params directly or re-create the task."],"exampleFix":"// before (taskParams)\n{\"switchResult\": {\"dependTaskList\": \"not-an-object\"}}\n// after\n{\"nextBranch\": null, \"switchResult\": {\"dependTaskList\": [], \"nextNode\": 12345}}","handlingStrategy":"validation","validationCode":"boolean validSwitchParams(String taskParams) {\n    if (taskParams == null || taskParams.trim().isEmpty()) return false;\n    try {\n      return JSONUtils.parseObject(taskParams, SwitchParameters.class) != null;\n    } catch (Exception e) { return false; }\n}\n// call for every SWITCH task before copy/import","typeGuard":"boolean isParsedSwitchParams(String raw) {\n  try { return JSONUtils.parseObject(raw, SwitchParameters.class) != null; }\n  catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n    workflowDefinitionService.batchCopyWorkflowDefinition(...);\n} catch (ServiceException | IllegalArgumentException e) {\n    log.error(\"Copy failed, check Switch taskParams JSON\", e);\n}","preventionTips":["Never hand-edit task_params JSON in exports or DB rows.","Export/import between the same DolphinScheduler versions to avoid SwitchParameters shape drift.","Pre-validate all task_params in import files against the target version's parameter classes."],"tags":["json","switch-task","workflow-copy","task-params"],"backgroundTag":"json-unmarshal-failed","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"}