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() resolves the process instance with findExecutionById and throws ActivitiObjectNotFoundException (typed ProcessInstance.class) when no execution matches the supplied processInstanceId. The engine therefore never writes a business key because the target instance does not exist at runtime.

Source

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

    public SetProcessInstanceBusinessKeyCmd(String processInstanceId, String businessKey) {
        if (processInstanceId == null || processInstanceId.length() < 1) {
            throw new ActivitiIllegalArgumentException("The process instance id is mandatory, but '" + processInstanceId + "' has been provided.");
        }
        if (businessKey == null) {
            throw new ActivitiIllegalArgumentException("The business key is mandatory, but 'null' has been provided.");
        }

        this.processInstanceId = processInstanceId;
        this.businessKey = businessKey;
    }

    @Override
    public Void execute(CommandContext commandContext) {
        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.");
        }

        processInstance.updateProcessBusinessKey(businessKey);

        return null;
    }
}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Check existence first with runtimeService.createProcessInstanceQuery().processInstanceId(pid).count().
  2. If the instance is finished, write the key to history or your own audit store instead of the runtime API.
  3. Confirm engine/database alignment in multi-engine deployments.
  4. Catch ActivitiObjectNotFoundException and treat it as a benign no-op if the instance may have completed concurrently.

Example fix

// before
runtimeService.setBusinessKey(pid, key);
// after
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(pid).singleResult();
if (pi == null) {
    log.warn("Skipping business key update; instance {} not running", pid);
    return;
}
runtimeService.setBusinessKey(pid, key);
Defensive patterns

Strategy: validation

Validate before calling

if (runtimeService.createProcessInstanceQuery().processInstanceId(pid).count() == 0) {
    throw new IllegalStateException("Process instance " + pid + " is not running");
}

Type guard

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

Try / catch

try {
    runtimeService.setBusinessKey(pid, key);
} catch (org.activiti.engine.ActivitiObjectNotFoundException e) {
    // instance ended or never existed
}

Prevention

When it happens

Trigger: runtimeService.setBusinessKey(pid, key) with a pid for an instance that already completed, was deleted, or never existed on this engine/database.

Common situations: Setting the key asynchronously after the instance finished; ids copied between test/dev and prod databases; replayed messages referencing deleted instances.

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/96cf78b0766944de. Report an issue: GitHub.