{"record":{"id":"e0f22f66145144f1","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-e0f22f","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/HasCaseInstanceVariableCmd.java","lineNumber":44,"sourceCode":" * @author Tijs Rademakers\n */\npublic class HasCaseInstanceVariableCmd implements Command<Boolean>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected String caseInstanceId;\n    protected String variableName;\n    protected boolean isLocal;\n\n    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        }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/HasCaseInstanceVariableCmd.java#L26-L62","documentation":"HasCaseInstanceVariableCmd.execute throws FlowableIllegalArgumentException when caseInstanceId is null. The command first validates its required arguments, then checks the case instance exists, before testing whether the variable is present. A null id cannot be resolved to any case instance, so it is rejected immediately.","triggerScenarios":"Calling cmmnRuntimeService.hasVariable(null, variableName) or hasVariableLocal(null, variableName), or building the command directly with a null caseInstanceId.","commonSituations":"Chained lookups where an earlier query returned null, passing an uninitialized field from a delegation class, or copy/paste code where the id variable was renamed but not initialized.","solutions":["Verify caseInstanceId is populated before the call; trace its source","Resolve the id via a CaseInstanceQuery and handle the no-match case first","Wrap the call in a null check or use an Optional around the id"],"exampleFix":"// before\nboolean has = cmmnRuntimeService.hasVariable(caseInstanceId, \"approved\");\n// after\nboolean has = caseInstanceId != null && cmmnRuntimeService.hasVariable(caseInstanceId, \"approved\");","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null) {\n    throw new IllegalArgumentException(\"caseInstanceId is required for hasVariable\");\n}","typeGuard":"boolean validId(String id) {\n    return id != null && !id.isEmpty();\n}","tryCatchPattern":"try {\n    return cmmnRuntimeService.hasVariable(caseInstanceId, variableName);\n} catch (FlowableIllegalArgumentException e) {\n    log.warn(\"Invalid hasVariable arguments: {}\", e.getMessage());\n    return false;\n}","preventionTips":["Null-check ids resolved from previous engine calls","Prefer query-then-act: fetch the CaseInstance, then check variables","Log id provenance to catch unpopulated fields early"],"tags":["flowable","cmmn","null-argument","variables"],"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"}