{"record":{"id":"71de9ef013f29af7","repo":"flowable/flowable-engine","slug":"caseinstanceid-is-null-71de9e","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/SetVariablesCmd.java","lineNumber":48,"sourceCode":"import org.flowable.common.engine.impl.interceptor.CommandContext;\n\n/**\n * @author Joram Barrez\n */\npublic class SetVariablesCmd implements Command<Void> {\n    \n    protected String caseInstanceId;\n    protected Map<String, Object> variables;\n    \n    public SetVariablesCmd(String caseInstanceId, Map<String, Object> variables) {\n        this.caseInstanceId = caseInstanceId;\n        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        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.setVariables(variables);\n        \n        Set<String> variableNames = variables.keySet();\n        \n        CmmnEngineAgenda agenda = CommandContextUtil.getAgenda(commandContext);\n        ","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/SetVariablesCmd.java#L30-L66","documentation":"SetVariablesCmd.execute performs mandatory-argument checks before touching the engine. The caseInstanceId is the primary key of the case instance whose variables will be replaced, so a null value is rejected immediately with FlowableIllegalArgumentException.","triggerScenarios":"Calling CmmnRuntimeService.setVariables(null, variables), or building a command where caseInstanceId was never assigned (e.g., missing builder field, unbound variable).","commonSituations":"Passing the result of a lookup that returned null straight into setVariables; copying code from a task-variable call and forgetting to set the case id; deserialization produced a null field.","solutions":["Ensure a non-null caseInstanceId is passed to setVariables.","Check the code path producing the id; resolve it from a CaseInstance object or query before the call.","Fail fast in caller code with a clear message when the id is null instead of reaching the engine."],"exampleFix":"// before\nruntimeService.setVariables(caseInstanceId, variables); // caseInstanceId may be null\n// after\nObjects.requireNonNull(caseInstanceId, \"caseInstanceId must be set\");\nruntimeService.setVariables(caseInstanceId, variables);","handlingStrategy":"validation","validationCode":"if (caseInstanceId == null || caseInstanceId.trim().isEmpty()) {\n    throw new IllegalArgumentException(\"caseInstanceId must be provided\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.setVariables(caseInstanceId, vars);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"caseInstanceId is null\")) {\n        // fix caller data path\n    }\n}","preventionTips":["Use Objects.requireNonNull on ids at service boundaries","Never forward nullable lookup results directly into engine calls","Enable null-analysis/SpotBugs in CI"],"tags":["cmmn","null-argument","variables","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"}