apache/dolphinscheduler · error · IllegalArgumentException

Failed to parse Switch task params: {taskParams}

Error message

Failed to parse Switch task params: {taskParams}

What it means

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.

Source

Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:1457

                    failedWorkflowList.add(workflowDefinition.getCode() + "[" + workflowDefinition.getName() + "]");
                }
            }
        }
    }

    /**
     * Replaces old task codes with new ones in the parameters of a Switch task.
     * Used during workflow duplication or import to preserve correct task dependencies.
     */
    private void replaceTaskCodeForSwitchTaskParams(TaskDefinitionLog taskDefLog, Map<Long, Long> taskCodeMap) {
        String taskParams = taskDefLog.getTaskParams();
        SwitchParameters params;

        try {
            params = JSONUtils.parseObject(taskParams, SwitchParameters.class);
        } catch (Exception e) {
            log.warn("Invalid Switch task params: {}", taskParams, e);
            throw new IllegalArgumentException("Failed to parse Switch task params: " + taskParams, e);
        }

        if (params == null) {
            log.warn("Parsed Switch task params is null: {}", taskParams);
            throw new IllegalArgumentException("Failed to parse Switch task params: " + taskParams);
        }

        // Update nextBranch if mapped
        Long nextBranch = params.getNextBranch();
        if (nextBranch != null && taskCodeMap.containsKey(nextBranch)) {
            params.setNextBranch(taskCodeMap.get(nextBranch));
        }

        // Update switch result nodes
        SwitchParameters.SwitchResult result = params.getSwitchResult();
        if (result != null) {
            Long nextNode = result.getNextNode();
            if (nextNode != null && taskCodeMap.containsKey(nextNode)) {

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Inspect the taskParams text in the error message and fix the malformed JSON before retrying the copy/import.
  2. Open the Switch task in the UI and re-save its parameters so a valid JSON document is written.
  3. If the definition came from another version, re-export from the source system with a matching DolphinScheduler version.
  4. If DB-edited, correct t_ds_task_definition.task_params directly or re-create the task.

Example fix

// before (taskParams)
{"switchResult": {"dependTaskList": "not-an-object"}}
// after
{"nextBranch": null, "switchResult": {"dependTaskList": [], "nextNode": 12345}}
Defensive patterns

Strategy: validation

Validate before calling

boolean validSwitchParams(String taskParams) {
    if (taskParams == null || taskParams.trim().isEmpty()) return false;
    try {
      return JSONUtils.parseObject(taskParams, SwitchParameters.class) != null;
    } catch (Exception e) { return false; }
}
// call for every SWITCH task before copy/import

Type guard

boolean isParsedSwitchParams(String raw) {
  try { return JSONUtils.parseObject(raw, SwitchParameters.class) != null; }
  catch (Exception e) { return false; }
}

Try / catch

try {
    workflowDefinitionService.batchCopyWorkflowDefinition(...);
} catch (ServiceException | IllegalArgumentException e) {
    log.error("Copy failed, check Switch taskParams JSON", e);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of apache/dolphinscheduler@02eac45a1b (2026-09-06). Data as JSON: /api/errors/4bda4a5201428067. Report an issue: GitHub.