{"record":{"id":"4e26a111e3724b50","repo":"flowable/flowable-engine","slug":"the-case-instance-with-id-caseinstanceid-coul","errorCode":null,"errorMessage":"The case instance with id '${caseInstanceId}' could not be found as an active case instance.","messagePattern":"The case instance with id '(.+?)' could not be found as an active case instance\\.","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractCaseInstanceIdentityLinkCmd.java","lineNumber":39,"sourceCode":"/**\n * An abstract command supporting functionality around identity link management for case instances.\n *\n * @author Micha Kiener\n */\npublic abstract class AbstractCaseInstanceIdentityLinkCmd {\n\n    /**\n     * Returns the case instance entity for the given id, if it exists, otherwise an exception will be thrown.\n     *\n     * @param commandContext the command context within which the case instance is loaded\n     * @param caseInstanceId the id of the case instance to be loaded\n     * @return the case instance entity, if found, never null\n     * @throws FlowableIllegalArgumentException if the provided case instance id is not valid (could not be found)\n     */\n    protected CaseInstanceEntity getCaseInstanceEntity(CommandContext commandContext, String caseInstanceId) {\n        CaseInstanceEntity caseInstanceEntity = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceId);\n        if (caseInstanceEntity == null) {\n            throw new FlowableIllegalArgumentException(\n                \"The case instance with id '\" + caseInstanceId + \"' could not be found as an active case instance.\");\n        }\n        return caseInstanceEntity;\n    }\n\n    /**\n     * This will remove ALL identity links with the given type, no mather whether they are user or group based.\n     *\n     * @param commandContext the command context within which to remove the identity links\n     * @param caseInstanceId the id of the case instance to remove the identity links for\n     * @param identityType the identity link type (e.g. assignee or owner, etc) to be removed\n     */\n    protected void removeIdentityLinkType(CommandContext commandContext, String caseInstanceId, String identityType) {\n        CaseInstanceEntity caseInstanceEntity = getCaseInstanceEntity(commandContext, caseInstanceId);\n\n        // this will remove ALL identity links with the given identity type (for users AND groups)\n        IdentityLinkUtil.deleteCaseInstanceIdentityLinks(caseInstanceEntity, null, null, identityType,\n            CommandContextUtil.getCmmnEngineConfiguration(commandContext));","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractCaseInstanceIdentityLinkCmd.java#L21-L57","documentation":"An identity-link command (add/remove user or group on a case instance) could not load an active case instance with the supplied id. The lookup by id returned null, so Flowable throws FlowableIllegalArgumentException rather than silently proceeding.","triggerScenarios":"Calling commands like AddCaseInstanceIdentityLinkCmd / RemoveCaseInstanceIdentityLinkCmd (via CaseService/CmmnRuntimeService identity link APIs) with a caseInstanceId that does not exist or no longer resolves via the entity manager.","commonSituations":"Case instance already terminated/completed and purged per retention; wrong id (task id or plan item id used by mistake); typo in id from external storage; different tenant/database environment.","solutions":["Query first: cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult() and handle null before invoking the identity link command","Verify the id is the case instance id (not task/plan item id)","Check the case instance hasn't been completed/terminated — identity link commands require an existing stored instance","Confirm you are connected to the same database/tenant where the instance lives"],"exampleFix":"// before\ncmmnRuntimeService.addUserIdentityLink(caseInstanceId, \"john\", \"participant\");\n// after\nif (cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).count() > 0) {\n    cmmnRuntimeService.addUserIdentityLink(caseInstanceId, \"john\", \"participant\");\n}","handlingStrategy":"try-catch","validationCode":"if (cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).count() === 0) throw new Error('case instance not found: ' + id);","typeGuard":"function caseExists(id) { return id != null && cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).count() > 0; }","tryCatchPattern":"try {\n  cmmnRuntimeService.addUserIdentityLink(id, userId, role);\n} catch (FlowableIllegalArgumentException e) {\n  if (e.getMessage().contains('could not be found as an active case instance')) { /* skip/record missing id */ }\n  else throw e;\n}","preventionTips":["Always verify case instance existence before identity link operations","Distinguish case instance ids from task/plan item ids in your data model","Handle completed/terminated instances gracefully in cleanup jobs"],"tags":["cmmn","identity-link","lookup"],"backgroundTag":"entity-not-found","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}