{"record":{"id":"9355ff180effd1f7","repo":"flowable/flowable-engine","slug":"variables-is-null-9355ff","errorCode":null,"errorMessage":"variables is null","messagePattern":"variables 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":51,"sourceCode":" * @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        \n        CmmnDeploymentManager deploymentManager = CommandContextUtil.getCmmnEngineConfiguration(commandContext).getDeploymentManager();\n        CaseDefinition caseDefinition = deploymentManager.findDeployedCaseDefinitionById(caseInstanceEntity.getCaseDefinitionId());\n        boolean evaluateVariableEventListener = false;","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-cmmn-engine/src/main/java/org/flowable/cmmn/engine/impl/cmd/SetVariablesCmd.java#L33-L69","documentation":"SetVariablesCmd requires a non-null variables map because it will call caseInstanceEntity.setVariables(variables). A null map cannot be processed, so execute throws FlowableIllegalArgumentException immediately after the caseInstanceId check.","triggerScenarios":"Calling CmmnRuntimeService.setVariables(caseInstanceId, null); a method that conditionally builds the map but skips creation on some branch and passes null.","commonSituations":"Initializing a map field to null and forgetting to instantiate it; refactoring that removed map construction; passing an expression result that evaluated to null.","solutions":["Pass an empty map (Collections.emptyMap()) if there is nothing to set, or skip the call entirely when the map is null.","Instantiate the variables map (new HashMap<>()) before the call in all code paths.","Assert/map non-null at the caller boundary with a descriptive exception."],"exampleFix":"// before\nMap<String, Object> vars = null;\nruntimeService.setVariables(caseInstanceId, vars);\n// after\nMap<String, Object> vars = new HashMap<>();\nvars.put(\"status\", \"new\");\nruntimeService.setVariables(caseInstanceId, vars);","handlingStrategy":"validation","validationCode":"if (variables == null) variables = Collections.emptyMap();\nif (variables.isEmpty()) return; // nothing to set","typeGuard":null,"tryCatchPattern":"try {\n    runtimeService.setVariables(caseInstanceId, vars);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"variables is null\")) {\n        // re-initialize map or skip\n    }\n}","preventionTips":["Initialize maps at declaration, never leave them null","Skip no-op calls instead of passing null/empty collections","Cover variable-setting paths with unit tests"],"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"}