{"record":{"id":"9b85f1e091c2b689","repo":"flowable/flowable-engine","slug":"no-case-instance-found-for-id-caseinstanceid-9b85f1","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/SetVariablesAsyncCmd.java","lineNumber":50,"sourceCode":"        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        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n        CaseInstanceEntity caseInstanceEntity = cmmnEngineConfiguration.getCaseInstanceEntityManager().findById(caseInstanceId);\n        if (caseInstanceEntity == null) {\n            throw new FlowableObjectNotFoundException(\"No case instance found for id \" + caseInstanceId, CaseInstanceEntity.class);\n        }\n        \n        for (String variableName : variables.keySet()) {\n            addVariable(false, caseInstanceId, null, variableName, variables.get(variableName), caseInstanceEntity.getTenantId(), \n                    cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService());\n        }\n        \n        createSetAsyncVariablesJob(caseInstanceEntity, cmmnEngineConfiguration);\n        \n        return null;\n    }\n\n}\n","sourceCodeStart":32,"sourceCodeEnd":64,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariablesAsyncCmd.java#L32-L64","documentation":"SetVariablesAsyncCmd verifies that the given caseInstanceId references an existing case instance before adding variables asynchronously. When findById returns null, the id does not match a persisted case instance, so it throws FlowableObjectNotFoundException. This prevents writing variables for a non-existent or already-terminated case.","triggerScenarios":"Calling CmmnRuntimeService.setVariablesAsync (or the equivalent management API) with a caseInstanceId that does not exist, was mistyped, or whose case instance has already ended and been archived.","commonSituations":"Using an id from a different process/case engine; storing a stale id after case completion; a race where the case is terminated between lookup and call; passing a plan item or task id instead of the case instance id.","solutions":["Verify the caseInstanceId via runtimeService.createCaseInstanceQuery().caseInstanceId(id).singleResult() before calling setVariablesAsync.","Fix the source of the id (log and inspect what value is passed); ensure it is the case instance id, not a plan item or task id.","Handle completion: if the case has ended, fetch variables from history (historyService) instead of setting runtime variables.","Wrap the call in try-catch for FlowableObjectNotFoundException and treat it as a business-level 'case no longer active' condition."],"exampleFix":"// before\nruntimeService.setVariablesAsync(caseInstanceId, variables);\n// after\nCaseInstance ci = runtimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).singleResult();\nif (ci != null) {\n    runtimeService.setVariablesAsync(caseInstanceId, variables);\n} else {\n    LOGGER.warn(\"Case instance {} no longer active; skipping variable update\", caseInstanceId);\n}","handlingStrategy":"validation","validationCode":"boolean exists = cmmnRuntimeService.createCaseInstanceQuery().caseInstanceId(caseInstanceId).count() > 0;\nif (!exists) throw new IllegalArgumentException(\"Unknown caseInstanceId: \" + caseInstanceId);","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.setVariablesAsync(caseInstanceId, vars);\n} catch (FlowableObjectNotFoundException e) {\n    // case ended or wrong id; fall back to history-based handling\n}","preventionTips":["Resolve ids from CaseInstance objects, never from hand-typed strings","Check case state before variable updates in async flows","Distinguish runtime vs historic case ids in your data model"],"tags":["cmmn","case-instance","variables","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"}