apache/dolphinscheduler · error · IllegalArgumentException

"Cannot find task: " + taskCode

Error message

"Cannot find task: " + taskCode

What it means

getTaskNodeByCode looks up a TaskDefinition by its numeric code in the graph's code-indexed map. If no task with that code exists in this workflow's graph, it throws this IllegalArgumentException. Task codes are workflow-scoped here, so a code from another workflow will not resolve.

Source

Thrown at dolphinscheduler-master/src/main/java/org/apache/dolphinscheduler/server/master/engine/graph/WorkflowGraph.java:99

    @Override
    public Set<String> getSuccessors(String taskName) {
        return new HashSet<>(successors.get(taskName));
    }

    @Override
    public TaskDefinition getTaskNodeByName(String taskName) {
        TaskDefinition taskDefinition = taskDefinitionMap.get(taskName);
        if (taskDefinition == null) {
            throw new IllegalArgumentException("Cannot find task: " + taskName);
        }
        return taskDefinition;
    }

    @Override
    public TaskDefinition getTaskNodeByCode(Long taskCode) {
        TaskDefinition taskDefinition = taskDefinitionCodeMap.get(taskCode);
        if (taskDefinition == null) {
            throw new IllegalArgumentException("Cannot find task: " + taskCode);
        }
        return taskDefinition;
    }

    @Override
    public List<TaskDefinition> getAllTaskNodes() {
        return new ArrayList<>(taskDefinitionMap.values());
    }

    private void addTaskNodes(List<TaskDefinition> taskDefinitions) {
        taskDefinitions
                .stream()
                .map(TaskDefinition::getName)
                .forEach(taskDefinition -> {
                    if (predecessors.containsKey(taskDefinition) || successors.containsKey(taskDefinition)) {
                        throw new IllegalArgumentException("The task " + taskDefinition + " is already exists");
                    }
                    predecessors.put(taskDefinition, new ArrayList<>());

View on GitHub (pinned to 02eac45a1b)

Solutions

  1. Confirm the task code exists in the workflow definition (taskDefinitionCodeMap is populated from the workflow's tasks) before lookup
  2. Use getTaskNodeByName if only the name is reliably known
  3. Re-derive codes from the current workflow definition instead of persisting/storing old codes across re-imports
  4. Catch IllegalArgumentException when scanning historical data that may reference removed tasks

Example fix

// before
long code = 1234567890L; // from an old export
TaskDefinition td = workflowGraph.getTaskNodeByCode(code);
// after
TaskDefinition td = workflowGraph.getAllTaskNodes().stream()
        .filter(t -> t.getCode() == code).findFirst()
        .orElseThrow(() -> new IllegalStateException("Task code " + code + " is not part of this workflow"));
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = workflowGraph.getAllTaskNodes().stream()
        .anyMatch(t -> t.getCode() == taskCode);
if (!exists) throw new IllegalStateException("Task code " + taskCode + " not in this workflow");

Try / catch

try {
    TaskDefinition td = workflowGraph.getTaskNodeByCode(taskCode);
} catch (IllegalArgumentException e) {
    log.warn("Skipping historical reference to missing task code {}", taskCode);
    return null;
}

Prevention

When it happens

Trigger: Calling workflowGraph.getTaskNodeByCode(code) with a code not present in the workflow — e.g. a relation or dispatch record referencing a task that was deleted, or a code copied from a different workflow.

Common situations: Task deleted from the workflow but still referenced by old task instances, dependents, or recovery/failover records; DB migration issues mixing codes across workflows; hard-coded codes in scripts after re-importing a workflow (re-import regenerates codes).

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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