flowable/flowable-engine · error · ActivitiObjectNotFoundException

No process instance found for id = '" + processInstanceId +

Error message

No process instance found for id = '" + processInstanceId + "'.

What it means

execute() looks up the execution via ExecutionEntityManager.findExecutionById(processInstanceId) and throws ActivitiObjectNotFoundException (typed with ProcessInstance.class) when no execution with that id exists. The id passed to the command does not correspond to any execution in the engine's persistence layer.

Source

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

        }
        if (processDefinitionVersion == null) {
            throw new ActivitiIllegalArgumentException("The process definition version is mandatory, but 'null' has been provided.");
        }
        if (processDefinitionVersion < 1) {
            throw new ActivitiIllegalArgumentException("The process definition version must be positive, but '" + processDefinitionVersion + "' has been provided.");
        }
        this.processInstanceId = processInstanceId;
        this.processDefinitionVersion = processDefinitionVersion;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        // check that the new process definition is just another version of the same
        // process definition that the process instance is using
        ExecutionEntityManager executionManager = commandContext.getExecutionEntityManager();
        ExecutionEntity processInstance = executionManager.findExecutionById(processInstanceId);
        if (processInstance == null) {
            throw new ActivitiObjectNotFoundException("No process instance found for id = '" + processInstanceId + "'.", ProcessInstance.class);
        } else if (!processInstance.isProcessInstanceType()) {
            throw new ActivitiIllegalArgumentException(
                    "A process instance id is required, but the provided id " +
                            "'" + processInstanceId + "' " +
                            "points to a child execution of process instance " +
                            "'" + processInstance.getProcessInstanceId() + "'. " +
                            "Please invoke the " + getClass().getSimpleName() + " with a root execution id.");
        }
        ProcessDefinitionImpl currentProcessDefinitionImpl = processInstance.getProcessDefinition();

        DeploymentManager deploymentCache = commandContext
                .getProcessEngineConfiguration()
                .getDeploymentManager();
        ProcessDefinition currentProcessDefinition = null;
        if (currentProcessDefinitionImpl instanceof ProcessDefinitionEntity) {
            currentProcessDefinition = (ProcessDefinitionEntity) currentProcessDefinitionImpl;
        } else {
            currentProcessDefinition = deploymentCache.findDeployedProcessDefinitionById(currentProcessDefinitionImpl.getId());

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Verify the id exists before migrating: runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult() != null.
  2. If the instance already ended, use history APIs (HistoricProcessInstanceQuery) instead of runtime migration.
  3. Confirm the id comes from the same engine instance/database schema the command runs against.
  4. Catch ActivitiObjectNotFoundException around the call and surface a user-friendly 'process instance not found' message.

Example fix

// before
runtimeService.setProcessDefinitionVersion(storedPid, newVersion);
// after
if (runtimeService.createProcessInstanceQuery().processInstanceId(storedPid).count() == 0) {
    throw new IllegalStateException("Process instance " + storedPid + " no longer exists");
}
runtimeService.setProcessDefinitionVersion(storedPid, newVersion);
Defensive patterns

Strategy: try-catch

Validate before calling

boolean exists = runtimeService.createProcessInstanceQuery().processInstanceId(pid).count() > 0;

Type guard

boolean isRunningInstance(RuntimeService rs, String pid) {
    return pid != null && rs.createProcessInstanceQuery().processInstanceId(pid).count() > 0;
}

Try / catch

try {
    runtimeService.setProcessDefinitionVersion(pid, version);
} catch (org.activiti.engine.ActivitiObjectNotFoundException e) {
    // instance does not exist / already ended
}

Prevention

When it happens

Trigger: runtimeService.setProcessDefinitionVersion(pid, v) with a pid that was never created, was deleted (runtimeService.deleteProcessInstance), or belongs to a different engine/database.

Common situations: Stale ids cached after the instance completed or was cancelled; pointing at a historic (ended) instance where the runtime row is gone; multi-tenant/multi-engine setups querying the wrong data source.

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/6a6882d85153dd74. Report an issue: GitHub.