{"record":{"id":"51b6d5866f84ff40","repo":"flowable/flowable-engine","slug":"case-instance-caseinstanceid-doesn-t-exist","errorCode":null,"errorMessage":"case instance ${caseInstanceId} doesn't exist","messagePattern":"case instance (.+?) doesn't exist","errorType":"exception","errorClass":"FlowableObjectNotFoundException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/HasCaseInstanceVariableCmd.java","lineNumber":53,"sourceCode":"    public HasCaseInstanceVariableCmd(String caseInstanceId, String variableName, boolean isLocal) {\n        this.caseInstanceId = caseInstanceId;\n        this.variableName = variableName;\n        this.isLocal = isLocal;\n    }\n\n    @Override\n    public Boolean execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variableName is null\");\n        }\n\n        CaseInstanceEntity caseInstance = CommandContextUtil.getCaseInstanceEntityManager(commandContext).findById(caseInstanceId);\n\n        if (caseInstance == null) {\n            throw new FlowableObjectNotFoundException(\"case instance \" + caseInstanceId + \" doesn't exist\", CaseInstance.class);\n        }\n\n        boolean hasVariable = false;\n\n        if (isLocal) {\n            hasVariable = caseInstance.hasVariableLocal(variableName);\n        } else {\n            hasVariable = caseInstance.hasVariable(variableName);\n        }\n\n        return hasVariable;\n    }\n}\n","sourceCodeStart":35,"sourceCodeEnd":67,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/HasCaseInstanceVariableCmd.java#L35-L67","documentation":"HasCaseInstanceVariableCmd.execute throws FlowableObjectNotFoundException when no case instance with the given id exists in the CMMN runtime tables. The id was syntactically valid (non-null) but findById returned no row, so the engine cannot evaluate variable existence for a nonexistent entity.","triggerScenarios":"Calling hasVariable/hasVariableLocal with an id of a case instance that was ended/deleted, a typo'd or truncated id, or an id from a different engine (process vs case instance).","commonSituations":"Querying variables after case completion (historical data only), hard-coded ids in tests, mixing BPMN process instance ids with CMMN case instance ids, cluster/database mismatch pointing at the wrong schema.","solutions":["Confirm the case instance exists via cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult()","If the case may have completed, use the history service (cmmnHistoryService) instead of runtime","Verify the id origin and that you are connected to the correct database/schema"],"exampleFix":"// before\nboolean has = cmmnRuntimeService.hasVariable(caseId, \"approved\");\n// after\nCaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseId).singleResult();\nboolean has = ci != null && cmmnRuntimeService.hasVariable(caseId, \"approved\");","handlingStrategy":"try-catch","validationCode":"CaseInstance ci = cmmnRuntimeService.createCaseInstanceQuery()\n    .caseInstanceId(caseInstanceId).singleResult();\nif (ci == null) {\n    // fall back to history or treat as not found\n}","typeGuard":"boolean caseInstanceExists(CmmnRuntimeService rs, String id) {\n    return id != null && rs.createCaseInstanceQuery().caseInstanceId(id).singleResult() != null;\n}","tryCatchPattern":"try {\n    return cmmnRuntimeService.hasVariable(caseInstanceId, variableName);\n} catch (FlowableObjectNotFoundException e) {\n    log.warn(\"Case instance {} not found; checking history\", caseInstanceId);\n    return cmmnHistoryService.createHistoricVariableInstanceQuery()\n        .caseInstanceId(caseInstanceId).variableName(variableName).count() > 0;\n}","preventionTips":["Expect case instances to disappear on completion; use history APIs for ended cases","Never hard-code instance ids; resolve them via business-key queries","Confirm environment/database consistency across clustered deployments"],"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-14T11:17:12.474Z"}