flowable/flowable-engine · error · FlowableObjectNotFoundException

Cannot find process instance with id

Error message

Cannot find process instance with id 

What it means

FlowableObjectNotFoundException thrown in AddIdentityLinkForProcessInstanceCmd.execute when no ExecutionEntity (process instance) exists for the given processInstanceId. Flowable looks the execution up via the ExecutionEntityManager and throws with the entity class ExecutionEntity attached so callers can discriminate the missing object type.

Source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/AddIdentityLinkForProcessInstanceCmd.java:75

        if (type == null) {
            throw new FlowableIllegalArgumentException("type is required when adding a new process instance identity link");
        }

        if (userId == null && groupId == null) {
            throw new FlowableIllegalArgumentException("userId and groupId cannot both be null");
        }

    }

    @Override
    public Void execute(CommandContext commandContext) {

        ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
        ExecutionEntity processInstance = executionEntityManager.findById(processInstanceId);

        if (processInstance == null) {
            throw new FlowableObjectNotFoundException("Cannot find process instance with id " + processInstanceId, ExecutionEntity.class);
        }

        if (Flowable5Util.isFlowable5ProcessDefinitionId(commandContext, processInstance.getProcessDefinitionId())) {
            Flowable5CompatibilityHandler compatibilityHandler = Flowable5Util.getFlowable5CompatibilityHandler();
            compatibilityHandler.addIdentityLinkForProcessInstance(processInstanceId, userId, groupId, type);
            return null;
        }

        IdentityLinkUtil.createProcessInstanceIdentityLink(processInstance, userId, groupId, type);
        CommandContextUtil.getHistoryManager(commandContext).createProcessInstanceIdentityLinkComment(processInstance, userId, groupId, type, true);

        return null;

    }

}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Verify the processInstanceId is a current runtime instance via runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before adding the link.
  2. If the instance may have ended, fall back to the historic API (taskService/historyService) or add identity links on the historic entity instead.
  3. Fix id plumbing: make sure the id comes from ProcessInstance.getId() of the correct deployment/database.

Example fix

// before
runtimeService.addUserIdentityLink(processInstanceId, userId, IdentityLinkType.PARTICIPANT);
// after
ProcessInstance pi = runtimeService.createProcessInstanceQuery()
    .processInstanceId(processInstanceId).singleResult();
if (pi != null) {
    runtimeService.addUserIdentityLink(processInstanceId, userId, IdentityLinkType.PARTICIPANT);
}
Defensive patterns

Strategy: validation

Validate before calling

ProcessInstance pi = runtimeService.createProcessInstanceQuery()
    .processInstanceId(processInstanceId).singleResult();
if (pi == null) {
    // instance ended or never existed; handle before adding links
}

Try / catch

try {
    runtimeService.addUserIdentityLink(piId, userId, type);
} catch (FlowableObjectNotFoundException e) {
    if (ExecutionEntity.class.equals(e.getObjectClass())) {
        // process instance not in runtime: fall back to historic API or report stale id
    }
    throw e;
}

Prevention

When it happens

Trigger: Calling addUserIdentityLink / addGroupIdentityLink / addIdentityLinkForProcessInstance with a processInstanceId that does not exist, or that refers to an already-ended (historic) process instance whose runtime execution row was deleted.

Common situations: Storing a process instance id and using it after the instance completed or was aborted; id taken from the wrong field (e.g. a task id or historic id); wrong database/tenant environment where the instance was never created; typos or stale ids from a cache.

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/7095ea980bbd6d99. Report an issue: GitHub.