flowable/flowable-engine · error · ActivitiObjectNotFoundException

task " + taskId + " doesn't exist

Error message

task " + taskId + " doesn't exist

What it means

Lookup failure in flowable5 HasTaskVariableCmd.execute: both taskId and variableName passed validation, but no task entity exists with that id, so the variable-existence check cannot be performed.

Solutions

  1. Check task existence first via taskService.createTaskQuery().taskId(id).singleResult()
  2. Catch ActivitiObjectNotFoundException and treat as 'task already completed'
  3. Fix stale id sources (e.g. re-query task state instead of caching ids across transactions)

Example fix

// before
boolean has = taskService.hasVariable(taskId, name);
// after
Task t = taskService.createTaskQuery().taskId(taskId).singleResult();
boolean has = t != null && taskService.hasVariable(taskId, name);
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = taskService.createTaskQuery().taskId(taskId).count() > 0;

Try / catch

try { return taskService.hasVariable(taskId, name); } catch (ActivitiObjectNotFoundException e) { log.warn("task {} already completed", taskId); return false; }

Prevention

When it happens

Trigger: taskService.hasVariable(taskId, name) on a task that was completed and deleted, or with an invalid taskId; tasks can be removed when their process instance ends or the task is completed.

Common situations: Checking a variable on a task after it was completed in the meantime; stale task ids stored in a UI or external table; concurrent completion racing the variable check.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/d5736fc66760c541. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cmd/HasTaskVariableCmd.java:55

        this.variableName = variableName;
        this.isLocal = isLocal;
    }

    @Override
    public Boolean execute(CommandContext commandContext) {
        if (taskId == null) {
            throw new ActivitiIllegalArgumentException("taskId is null");
        }
        if (variableName == null) {
            throw new ActivitiIllegalArgumentException("variableName is null");
        }

        TaskEntity task = commandContext
                .getTaskEntityManager()
                .findTaskById(taskId);

        if (task == null) {
            throw new ActivitiObjectNotFoundException("task " + taskId + " doesn't exist", Task.class);
        }
        boolean hasVariable = false;

        if (isLocal) {
            hasVariable = task.hasVariableLocal(variableName);
        } else {
            hasVariable = task.hasVariable(variableName);
        }

        return hasVariable;
    }
}

View on GitHub (pinned to d6d39ce1c6)