flowable/flowable-engine · error · FlowableObjectNotFoundException

task

Error message

task 

What it means

FlowableObjectNotFoundException (with Task.class as the referenced entity) thrown by GetTaskVariableCmd.execute after the task lookup returns null. Unlike the null guards, the taskId was supplied but does not match any persisted task. The exception carries the missing entity type so callers can distinguish task-not-found from variable-not-found.

Solutions

  1. Confirm task existence with taskService.createTaskQuery().taskId(taskId).singleResult() first
  2. Check the application connects to the same database/schema where the task lives
  3. Handle completed tasks via the history service (HistoricTaskInstanceQuery) if variables must be read after completion
  4. Catch FlowableObjectNotFoundException and treat it as a 404 in service/API layers

Example fix

// before
Object v = taskService.getTaskVariable(taskId, "amount");
// after
if (taskService.createTaskQuery().taskId(taskId).count() == 0) {
    throw new NotFoundException("Task " + taskId + " not found");
}
Object v = taskService.getTaskVariable(taskId, "amount");
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

try {
    Object v = taskService.getTaskVariable(taskId, name);
} catch (FlowableObjectNotFoundException e) {
    respond(404, "Task " + taskId + " does not exist");
}

Prevention

When it happens

Trigger: taskService.getTaskVariable(taskId, name) / getVariableLocal with a taskId that is stale, completed-and-cascaded-away, or from another database; race where the task is deleted between listing and fetching its variable.

Common situations: Async workers processing task ids from a queue after the task was already handled elsewhere; environments pointing at different DBs (test vs prod); process instances ended with history cleanup removing the task.

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/0e1c62291e4d8b28. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/GetTaskVariableCmd.java:57

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

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

        ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
        TaskEntity task = processEngineConfiguration.getTaskServiceConfiguration().getTaskService().getTask(taskId);

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

        Object value;

        if (isLocal) {
            value = task.getVariableLocal(variableName, false);
        } else {
            value = task.getVariable(variableName, false);
        }

        return value;
    }
}

View on GitHub (pinned to d6d39ce1c6)