flowable/flowable-engine · error · FlowableObjectNotFoundException

Cannot find process instance with id ${processInstanceId}

Error message

Cannot find process instance with id ${processInstanceId}

What it means

In execute(), DeleteIdentityLinkForProcessInstanceCmd loads the execution by processInstanceId. If no execution exists for that id, Flowable throws FlowableObjectNotFoundException referencing ExecutionEntity.class — the id is well-formed but no such process instance exists.

Source

Thrown at modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/DeleteIdentityLinkForProcessInstanceCmd.java:71

        if (processInstanceId == null) {
            throw new FlowableIllegalArgumentException("processInstanceId is null");
        }

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

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

    @Override
    public Void execute(CommandContext commandContext) {
        ExecutionEntity processInstance = CommandContextUtil.getExecutionEntityManager(commandContext).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.deleteIdentityLinkForProcessInstance(processInstanceId, userId, groupId, type);
            return null;
        }

        IdentityLinkUtil.deleteProcessInstanceIdentityLinks(processInstance, userId, groupId, type);
        CommandContextUtil.getHistoryManager(commandContext).createProcessInstanceIdentityLinkComment(processInstance, userId, groupId, type, false);

        return null;
    }

}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Confirm the instance is still running: runtimeService.createProcessInstanceQuery().processInstanceId(id).singleResult() before deleting links.
  2. Re-resolve the id from a fresh query instead of a cached/stale value.
  3. Catch FlowableObjectNotFoundException and treat it as idempotent success if the instance is already gone.

Example fix

// before
runtimeService.deleteProcessInstanceIdentityLink(piId, userId, groupId, type);
// after
ProcessInstance pi = runtimeService.createProcessInstanceQuery().processInstanceId(piId).singleResult();
if (pi != null) {
    runtimeService.deleteProcessInstanceIdentityLink(piId, userId, groupId, type);
}
Defensive patterns

Strategy: validation

Validate before calling

ProcessInstance pi = runtimeService.createProcessInstanceQuery()
        .processInstanceId(piId).singleResult();
if (pi == null) {
    // instance already ended or never existed; skip deletion
    return;
}

Type guard

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

Try / catch

try {
    runtimeService.deleteProcessInstanceIdentityLink(piId, userId, groupId, type);
} catch (FlowableObjectNotFoundException e) {
    log.info("Process instance {} not found; treating delete as no-op", piId);
}

Prevention

When it happens

Trigger: Calling deleteProcessInstanceIdentityLink with an id of a process instance that already ended, was deleted, or never existed in this database/tenant.

Common situations: Operating on a stale id captured before the instance completed; pointing at another environment's database; ids from an in-memory/H2 test database not present in production.

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