{"record":{"id":"6c3e18e2c08340de","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-6c3e18","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/SetVariableCmd.java","lineNumber":48,"sourceCode":"/**\n * @author Tijs Rademakers\n */\npublic class SetVariableCmd implements Command<Void> {\n    \n    protected String caseInstanceId;\n    protected String variableName;\n    protected Object variableValue;\n    \n    public SetVariableCmd(String caseInstanceId, String variableName, Object variableValue) {\n        this.caseInstanceId = caseInstanceId;\n        this.variableName = variableName;\n        this.variableValue = variableValue;\n    }\n    \n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (caseInstanceId == null) {\n            throw new FlowableIllegalArgumentException(\"caseInstanceId is null\");\n        }\n        if (variableName == null) {\n            throw new FlowableIllegalArgumentException(\"variable name is null\");\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.setVariable(variableName, variableValue);\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();","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariableCmd.java#L30-L66","documentation":"Thrown by SetVariableCmd.execute when caseInstanceId is null. Flowable's synchronous set-variable command validates its required arguments first and rejects a null case instance id with FlowableIllegalArgumentException before touching the database.","triggerScenarios":"Calling setVariable on the CMMN runtime service with a null id, e.g. the id variable is uninitialized or derived from a lookup that returned null.","commonSituations":"Case start result not captured, null returned by an earlier engine call and propagated, missing request parameter in a service layer.","solutions":["Populate caseInstanceId before invoking setVariable","Add an explicit null/empty check at the call site","Fix the upstream code path that produced the null id"],"exampleFix":"// before\ncmmnRuntimeService.setVariable(caseInstanceId, \"k\", \"v\");\n// after\nAssert.hasText(caseInstanceId, \"caseInstanceId required\");\ncmmnRuntimeService.setVariable(caseInstanceId, \"k\", \"v\");","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null || caseInstanceId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"caseInstanceId must not be null or empty\");\n}","typeGuard":"boolean hasCaseInstanceId(String id) { return id != null && !id.trim().isEmpty(); }","tryCatchPattern":"try {\n    cmmnRuntimeService.setVariable(caseInstanceId, name, value);\n} catch (FlowableIllegalArgumentException e) {\n    log.error(\"Invalid argument for setVariable: {}\", e.getMessage());\n}","preventionTips":["Validate required ids before calling engine commands","Never propagate possibly-null ids from upstream lookups unchecked","Add null checks in the layer that orchestrates case operations"],"tags":["flowable","cmmn","null-check","validation"],"backgroundTag":"null-argument","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"}