{"record":{"id":"7e150a851383eba5","repo":"flowable/flowable-engine","slug":"variablescope-cannot-be-null","errorCode":null,"errorMessage":"variableScope cannot be null","messagePattern":"variableScope cannot be null","errorType":"validation","errorClass":"org.activiti.engine.ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/scripting/VariableScopeResolver.java","lineNumber":35,"sourceCode":"import org.activiti.engine.impl.persistence.entity.ExecutionEntity;\nimport org.activiti.engine.impl.persistence.entity.TaskEntity;\nimport org.activiti.engine.impl.pvm.runtime.ExecutionImpl;\nimport org.flowable.variable.api.delegate.VariableScope;\n\n/**\n * Bindings implementation using an {@link ExecutionImpl} as 'back-end'.\n * \n * @author Tom Baeyens\n * @author Joram Barrez\n */\npublic class VariableScopeResolver implements Resolver {\n\n    protected VariableScope variableScope;\n    protected String variableScopeKey = \"execution\";\n\n    public VariableScopeResolver(VariableScope variableScope) {\n        if (variableScope == null) {\n            throw new ActivitiIllegalArgumentException(\"variableScope cannot be null\");\n        }\n        if (variableScope instanceof ExecutionEntity) {\n            variableScopeKey = \"execution\";\n        } else if (variableScope instanceof TaskEntity) {\n            variableScopeKey = \"task\";\n        } else {\n            throw new ActivitiException(\"unsupported variable scope type: \" + variableScope.getClass().getName());\n        }\n        this.variableScope = variableScope;\n    }\n\n    @Override\n    public boolean containsKey(Object key) {\n        return variableScopeKey.equals(key) || variableScope.hasVariable((String) key);\n    }\n\n    @Override\n    public Object get(Object key) {","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/scripting/VariableScopeResolver.java#L17-L53","documentation":"The VariableScopeResolver constructor requires a non-null VariableScope; it exposes script variables of an execution or task to a script engine. Passing null makes the resolver meaningless, so it immediately throws ActivitiIllegalArgumentException.","triggerScenarios":"Constructing new VariableScopeResolver(null) directly, or calling the script engine evaluation path (e.g. scriptingEngines.evaluateScript(..., null, ...)) with a null variable scope.","commonSituations":"Custom scripting integrations that pass a scope retrieved from a deleted/completed execution or task; null-returning custom scope lookups; unit tests exercising script evaluation without a real scope.","solutions":["Ensure the execution/task entity is fetched and non-null before creating the resolver.","Assert the VariableScope argument before invoking the scripting API.","If the entity may legitimately be absent, guard the call site rather than passing null."],"exampleFix":"// before\nnew VariableScopeResolver(scopeMaybeNull);\n// after\nif (scopeMaybeNull == null) throw new IllegalArgumentException(\"no active execution/task scope for scripting\");\nnew VariableScopeResolver(scopeMaybeNull);","handlingStrategy":"type-guard","validationCode":"if (scope == null) throw new IllegalArgumentException(\"VariableScope required for script evaluation\");","typeGuard":"boolean hasScope(VariableScope s) { return s instanceof ExecutionEntity || s instanceof TaskEntity; }","tryCatchPattern":"try {\n    new VariableScopeResolver(scope);\n} catch (ActivitiIllegalArgumentException e) {\n    if (e.getMessage().contains(\"variableScope cannot be null\")) { /* handle missing scope */ }\n}","preventionTips":["Always obtain the scope from an active execution/task lookup and null-check it","In custom scripting integrations, assert non-null scope in your own API layer","Write unit tests covering deleted/completed execution scenarios"],"tags":["null-check","scripting","argument-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-18T11:17:12.947Z"}