{"record":{"id":"31e4183017dea392","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-31e418","errorCode":null,"errorMessage":"caseInstanceId is null","messagePattern":"caseInstanceId is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetVariableCmd.java","lineNumber":39,"sourceCode":"import org.flowable.variable.service.impl.persistence.entity.VariableInstanceEntity;\n\n/**\n * @author Joram Barrez\n */\npublic class GetVariableCmd implements Command<Object> {\n    \n    protected String caseInstanceId;\n    protected String variableName;\n    \n    public GetVariableCmd(String caseInstanceId, String variableName) {\n        this.caseInstanceId = caseInstanceId;\n        this.variableName = variableName;\n    }\n    \n    @Override\n    public Object execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n\n        CmmnEngineConfiguration cmmnEngineConfiguration = CommandContextUtil.getCmmnEngineConfiguration(commandContext);\n\n        // In the BPMN engine, this is done by getting the variable on the execution.\n        // However, doing the same in CMMN will fetch the case instance and non-completed plan item instances in one query.\n        // Hence, why here a direct query is done here (which is cached).\n        VariableInstanceEntity variableInstanceEntity = cmmnEngineConfiguration.getVariableServiceConfiguration().getVariableService()\n                .createInternalVariableInstanceQuery()\n                .scopeId(caseInstanceId)\n                .withoutSubScopeId()\n                .scopeType(ScopeTypes.CMMN)\n                .name(variableName)\n                .singleResult();\n        if (variableInstanceEntity != null) {\n            return variableInstanceEntity.getValue();\n        }\n        return null;","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/GetVariableCmd.java#L21-L57","documentation":"GetVariableCmd.execute() retrieves a case-instance variable and first validates the caseInstanceId. A null caseInstanceId throws FlowableIllegalArgumentException('caseInstanceId is null') because variables are scoped to a case instance and cannot be resolved without it.","triggerScenarios":"Calling cmmnRuntimeService.getVariable(null, variableName) or getVariableLocal(null, name); constructing GetVariableCmd(null, name) and executing it; caseInstanceId taken from an unset process context.","commonSituations":"Case id stored in an application-side variable that was never populated after case start; null return from a prior getCaseInstance query reused as the id; message/correlation handler that failed to resolve the case before fetching variables.","solutions":["Null-check caseInstanceId before calling cmmnRuntimeService.getVariable/getVariableLocal.","Capture the case instance id returned by cmmnRuntimeService.startCaseInstance(...) and use it directly.","If the case id comes from another query, verify that query returned a non-null result first.","Ensure execution scoped to the case (listener, delegate) correctly carries the case instance id."],"exampleFix":"// before\nObject value = cmmnRuntimeService.getVariable(caseInstanceId, \"approvalStatus\");\n// after\nif (caseInstanceId == null) {\n    throw new IllegalStateException(\"caseInstanceId not set - start or resolve the case first\");\n}\nObject value = cmmnRuntimeService.getVariable(caseInstanceId, \"approvalStatus\");","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null) { throw new IllegalArgumentException(\"caseInstanceId is required\"); }","typeGuard":"boolean hasCaseInstance(String caseInstanceId) { return caseInstanceId != null && !caseInstanceId.isEmpty(); }","tryCatchPattern":"try { return runtimeService.getVariable(caseInstanceId, name); } catch (FlowableIllegalArgumentException e) { log.error(\"Missing caseInstanceId: {}\", e.getMessage()); throw e; }","preventionTips":["Store the caseInstanceId returned by startCaseInstance immediately","Pass case context explicitly through listeners/delegates","Null-check ids resolved via correlation or message handlers before variable access"],"tags":["flowable","cmmn","null-argument","case-instance"],"backgroundTag":"null-argument","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"}