{"record":{"id":"02b4ab886dc85394","repo":"flowable/flowable-engine","slug":"cannot-find-case-instance-with-id","errorCode":null,"errorMessage":"Cannot find case instance with id ","messagePattern":"Cannot find case instance with id ","errorType":"validation","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java","lineNumber":73,"sourceCode":"\n        if (type == null) {\n            throw new FlowableIllegalArgumentException(\"type is required when adding a new case instance identity link\");\n        }\n\n        if (userId == null && groupId == null) {\n            throw new FlowableIllegalArgumentException(\"userId and groupId cannot both be null\");\n        }\n\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntityManager caseInstanceEntityManager = cmmnEngineConfiguration.getCaseInstanceEntityManager();\n        CaseInstanceEntity caseInstance = caseInstanceEntityManager.findById(caseInstanceId);\n\n        if (caseInstance == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find case instance with id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n\n        IdentityLinkUtil.createCaseInstanceIdentityLink(caseInstance, userId, groupId, type, cmmnEngineConfiguration);\n        \n        return null;\n\n    }\n\n}\n","sourceCodeStart":55,"sourceCodeEnd":83,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AddIdentityLinkForCaseInstanceCmd.java#L55-L83","documentation":"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.","triggerScenarios":"Calling addIdentityLinkForCaseInstance/addUserIdentityLinkForCaseInstance with a caseInstanceId that does not exist, was already terminated/deleted, or has a typo/whitespace issue.","commonSituations":"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).","solutions":["Verify the caseInstanceId exists via cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult() before adding links","Correct the id — ensure it is a case instance id, not a case definition id","Handle FlowableObjectNotFoundException in caller code for ids coming from external input"],"exampleFix":"// before\ncmmnRuntimeService.addUserIdentityLinkForCaseInstance(request.getCaseId(), user, \"participant\");\n// after\nif (cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(request.getCaseId()).count() > 0) {\n    cmmnRuntimeService.addUserIdentityLinkForCaseInstance(request.getCaseId(), user, \"participant\");\n} else {\n    throw new BadRequestException(\"Unknown case instance: \" + request.getCaseId());\n}","handlingStrategy":"validation","validationCode":"boolean exists = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).count() > 0;","typeGuard":null,"tryCatchPattern":"try {\n    cmmnRuntimeService.addIdentityLinkForCaseInstance(caseId, userId, type);\n} catch (FlowableObjectNotFoundException e) {\n    throw new NotFoundException(\"Case instance \" + caseId + \" does not exist\");\n}","preventionTips":["Always resolve ids from engine queries, never free-text input","Distinguish case instance ids from case definition ids in your data model","Handle deleted/completed instances gracefully in UIs holding stale references"],"tags":["flowable","cmmn","not-found","case-instance"],"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-14T05:17:10.506Z"}