flowable/flowable-engine · error · FlowableObjectNotFoundException

Cannot find case instance with id

Error message

Cannot find case instance with id 

What it means

AddIdentityLinkForCaseInstanceCmd.execute throws FlowableObjectNotFoundException when no case instance exists with the given id. The command looks up the CaseInstanceEntity via the CaseInstanceEntityManager and, on a null result, reports the id and the expected entity class so callers can distinguish not-found from other failures.

Source

Thrown at modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java:73

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

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

    }

    @Override
    public Void execute(CommandContext commandContext) {
        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);
        CaseInstanceEntityManager caseInstanceEntityManager = cmmnEngineConfiguration.getCaseInstanceEntityManager();
        CaseInstanceEntity caseInstance = caseInstanceEntityManager.findById(caseInstanceId);

        if (caseInstance == null) {
            throw new FlowableObjectNotFoundException("Cannot find case instance with id " + caseInstanceId, CaseInstanceEntity.class);
        }

        IdentityLinkUtil.createCaseInstanceIdentityLink(caseInstance, userId, groupId, type, cmmnEngineConfiguration);
        
        return null;

    }

}

View on GitHub (pinned to d6d39ce1c6)

Solutions

  1. Verify the caseInstanceId exists via cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult() before adding links
  2. Correct the id — ensure it is a case instance id, not a case definition id
  3. Handle FlowableObjectNotFoundException in caller code for ids coming from external input

Example fix

// before
cmmnRuntimeService.addUserIdentityLinkForCaseInstance(request.getCaseId(), user, "participant");
// after
if (cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(request.getCaseId()).count() > 0) {
    cmmnRuntimeService.addUserIdentityLinkForCaseInstance(request.getCaseId(), user, "participant");
} else {
    throw new BadRequestException("Unknown case instance: " + request.getCaseId());
}
Defensive patterns

Strategy: validation

Validate before calling

boolean exists = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).count() > 0;

Try / catch

try {
    cmmnRuntimeService.addIdentityLinkForCaseInstance(caseId, userId, type);
} catch (FlowableObjectNotFoundException e) {
    throw new NotFoundException("Case instance " + caseId + " does not exist");
}

Prevention

When it happens

Trigger: Calling addIdentityLinkForCaseInstance/addUserIdentityLinkForCaseInstance with a caseInstanceId that does not exist, was already terminated/deleted, or has a typo/whitespace issue.

Common situations: Using a case definition id instead of a case instance id; referencing a case instance from a completed and purged case; stale ids cached from a previous environment (e.g. test data reused in prod).

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