{"record":{"id":"f0ff4a8e3c63ff07","repo":"flowable/flowable-engine","slug":"no-case-instance-found-for-id-caseinstanceid-f0ff4a","errorCode":null,"errorMessage":"No case instance found for id ${caseInstanceId}","messagePattern":"No case instance found for id (.+?)","errorType":"validation","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariablesCmd.java","lineNumber":59,"sourceCode":"        this.caseInstanceId = caseInstanceId;\n        this.variables = variables;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n        if (variables == null) {\n            throw new FlowableIllegalArgumentException(\"variables is null\");\n        }\n        if (variables.isEmpty()) {\n            throw new FlowableIllegalArgumentException(\"variables is empty\");\n        }\n     \n        CaseInstanceEntity caseInstanceEntity = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceId);\n        if (caseInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No case instance found for id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n        caseInstanceEntity.setVariables(variables);\n        \n        Set<String> variableNames = variables.keySet();\n        \n        CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);\n        \n        CmmnDeploymentManager deploymentManager = CommandContextUtil.getCmmnEngineConfiguration(commandContext).getDeploymentManager();\n        CaseDefinition caseDefinition = deploymentManager.findDeployedCaseDefinitionById(caseInstanceEntity.getCaseDefinitionId());\n        boolean evaluateVariableEventListener = false;\n        if (caseDefinition != null) {\n            CmmnModel cmmnModel = deploymentManager.resolveCaseDefinition(caseDefinition).getCmmnModel();\n            for (Case caze : cmmnModel.getCases()) {\n                List<VariableEventListener> variableEventListeners = caze.findPlanItemDefinitionsOfType(VariableEventListener.class);\n                for (VariableEventListener variableEventListener : variableEventListeners) {\n                    if (variableNames.contains(variableEventListener.getVariableName())) {\n                        evaluateVariableEventListener = true;\n                        break;","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariablesCmd.java#L41-L77","documentation":"SetVariablesCmd looks up the case instance by id with the CaseInstanceEntityManager; when no persisted case instance matches, it throws FlowableObjectNotFoundException. This guards the subsequent setVariables/plan-item operations from acting on a non-existent case.","triggerScenarios":"Calling CmmnRuntimeService.setVariables with an id that matches no case instance: typo, wrong id type, or the case instance already completed and removed from runtime data.","commonSituations":"Case finished between fetching the id and calling setVariables; id taken from a historic record; cross-environment copy-paste (test id used in prod).","solutions":["Confirm the id exists at call time: runtimeService.createCaseInstanceQuery().caseInstanceId(id).count() == 1.","Correct the id source; use the CaseInstance entity's getId() rather than a hand-built string.","If the case may legitimately be finished, catch FlowableObjectNotFoundException and route to history-based handling.","Add a retry/idempotency check in async flows where the case can terminate concurrently."],"exampleFix":"// before\nruntimeService.setVariables(caseInstanceId, variables);\n// after\nCaseInstance ci = runtimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (ci == null) {\n    throw new IllegalStateException(\"Case instance \" + caseInstanceId + \" not found or already ended\");\n}\nruntimeService.setVariables(caseInstanceId, variables);","handlingStrategy":"try-catch","validationCode":"CaseInstance ci = runtimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (ci == null) throw new IllegalStateException(\"Case instance not found: \" + caseInstanceId);","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.setVariables(caseInstanceId, vars);\n} catch (FlowableObjectNotFoundException e) {\n    // check history / mark record as orphaned\n    HistoricCaseInstance h = historyService.createHistoricCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\n}","preventionTips":["Always verify case existence before variable writes","Handle terminated cases explicitly in business logic","Keep runtime and historic id handling separate"],"tags":["cmmn","case-instance","not-found","variables"],"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"}