{"record":{"id":"cc86c531f7a8a56c","repo":"flowable/flowable-engine","slug":"cannot-find-case-instance-for-id-caseinstanceid","errorCode":null,"errorMessage":"Cannot find case instance for id ${caseInstanceId}","messagePattern":"Cannot find case instance for id (.+?)","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":404,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractNeedsCaseInstanceCmd.java","lineNumber":45,"sourceCode":" */\npublic abstract class AbstractNeedsCaseInstanceCmd implements Command<Void>, Serializable {\n    \n    protected String caseInstanceId;\n\n    public AbstractNeedsCaseInstanceCmd(String caseInstanceId) {\n        this.caseInstanceId = caseInstanceId;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"Case instance id is null\");\n        }\n        \n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(caseInstanceId);\n        if (caseInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"Cannot find case instance for id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n        \n        internalExecute(commandContext, caseInstanceEntity);\n        return null;\n    }\n    \n    protected abstract void internalExecute(CommandContext commandContext, CaseInstanceEntity caseInstanceEntity);\n   \n}\n","sourceCodeStart":27,"sourceCodeEnd":55,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/AbstractNeedsCaseInstanceCmd.java#L27-L55","documentation":"FlowableableObjectNotFoundException thrown in AbstractNeedsCaseInstanceCmd.execute after findById on the CaseInstanceEntityManager returns null. The engine verified the id was non-null but no CaseInstanceEntity with that id exists in the runtime tables. Commands like changing case state or submitting a form refuse to proceed without a live case instance.","triggerScenarios":"Calling case-level commands with a caseInstanceId that was deleted or never created; using the historic instance id after the case completed (runtime row removed); id from a different engine/database.","commonSituations":"Id stored/passed around after the case instance ended (runtime rows are removed on completion); typo or truncated id; multi-tenant setup querying the wrong tenant's engine; test using random ids without creating an instance.","solutions":["Verify the case instance is still active via cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult() before the command","Use the historical service (cmmnHistoryService) if you only need data for a completed case","Confirm the id against the ACT_CMMN_RU_CASE_INST table / Flowable admin UI","Check you are pointed at the same database and tenant the case was created in"],"exampleFix":"// before\ncmmnTaskService.completePlanItemStandaloneForm(planItemInstanceId, caseInstanceId, formInfo, variables);\n// after\nCaseInstance caseInstance = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (caseInstance == null) {\n    throw new IllegalArgumentException(\"No active case instance for id \" + caseInstanceId);\n}\ncmmnTaskService.completePlanItemStandaloneForm(planItemInstanceId, caseInstanceId, formInfo, variables);","handlingStrategy":"validation","validationCode":"CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (ci == null) throw new IllegalStateException(\"Case instance \" + caseInstanceId + \" not found or already ended\");","typeGuard":null,"tryCatchPattern":"try { cmmnTaskService.completePlanItemStandaloneForm(...); }\ncatch (FlowableObjectNotFoundException e) { log.info(\"Case instance gone: {}\", e.getMessage()); }","preventionTips":["Check case existence/state before case-scoped commands","Remember runtime rows vanish on completion — use history for ended cases","Never assume ids are valid across engines/databases/tenants","Clean up stale ids in queues when cases terminate"],"tags":["flowable","cmmn","case-instance","not-found"],"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"}