{"record":{"id":"83ad4b3e8a6a9abb","repo":"flowable/flowable-engine","slug":"the-case-instance-with-id-could-not-be-found-or-i","errorCode":null,"errorMessage":"The case instance with id  could not be found or is no longer an active case instance.","messagePattern":"The case instance with id  could not be found or is no longer an active case instance\\.","errorType":"exception","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CreateInjectedPlanItemInstanceCmd.java","lineNumber":119,"sourceCode":"        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        PlanItemInstanceEntity planItemInstanceEntity = cmmnEngineConfiguration.getPlanItemInstanceEntityManager()\n            .findById(planItemInstanceBuilder.getStagePlanItemInstanceId());\n\n        if (planItemInstanceEntity == null) {\n            throw new FlowableIllegalArgumentException(\n                \"The stage plan item instance id \" + planItemInstanceBuilder.getStagePlanItemInstanceId() + \" could not be found or is no longer active.\");\n        }\n        if (!planItemInstanceEntity.isStage()) {\n            throw new FlowableIllegalArgumentException(\"A dynamically created plan item can only be injected into a running stage plan item.\");\n        }\n        return planItemInstanceEntity;\n    }\n\n    protected CaseInstanceEntity getCaseInstanceEntity(CommandContext commandContext) {\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(planItemInstanceBuilder.getCaseInstanceId());\n        if (caseInstanceEntity == null) {\n            throw new FlowableIllegalArgumentException(\n                \"The case instance with id \" + planItemInstanceBuilder.getCaseInstanceId() + \" could not be found or is no longer an active case instance.\");\n        }\n        return caseInstanceEntity;\n    }\n}\n","sourceCodeStart":101,"sourceCodeEnd":125,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/CreateInjectedPlanItemInstanceCmd.java#L101-L125","documentation":"When building an injected plan item, the command resolves the owning case instance via CaseInstanceEntityManager.findById(caseInstanceId). If no case instance entity is returned, this FlowableIllegalArgumentException is thrown. The id is absent, wrong, or the case has ended and is no longer in the runtime tables.","triggerScenarios":"Calling planItemInstanceBuilder.caseInstanceId(id) with a null, stale, or foreign id, or after the case instance has completed/terminated and moved to history.","commonSituations":"Keeping the caseInstanceId in an external store and reusing it after case completion; pointing at another engine's database; passing a historic case instance id; typos from manual test scripts.","solutions":["Re-query CmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id) to confirm the case is active before injecting","Pass a fresh caseInstanceId obtained from the running case, not a cached or historic one","Verify the id targets the same database/engine configuration the command runs in"],"exampleFix":"// before\nbuilder.caseInstanceId(savedCaseId).inject();\n// after\nCaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(savedCaseId).singleResult();\nif (ci != null) {\n    builder.caseInstanceId(ci.getId()).inject();\n}","handlingStrategy":"validation","validationCode":"CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (ci == null) throw new IllegalStateException(\"case not active: \" + caseInstanceId);","typeGuard":null,"tryCatchPattern":"try { builder.caseInstanceId(caseId).inject(); }\ncatch (FlowableIllegalArgumentException e) { if (e.getMessage().contains(\"could not be found or is no longer an active case instance\")) { /* refresh case id */ } else throw e; }","preventionTips":["Verify case activity right before injection","Never reuse case ids after completion; store terminal state instead","Ensure ids come from the same engine/database"],"tags":["cmmn","case-instance","resource-not-found","dynamic-injection"],"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"}