From dd094b5a1724b42b6b63536a71a84c97d9ed2065 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Sun, 15 Dec 2024 15:55:38 +0100 Subject: [PATCH] Complete removal of local variable support in SpEL See gh-33809 --- .../expression/spel/ExpressionState.java | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java index 5b3deb8f2c9d..eaf5e4d9ecac 100644 --- a/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java +++ b/spring-expression/src/main/java/org/springframework/expression/spel/ExpressionState.java @@ -18,9 +18,7 @@ import java.util.ArrayDeque; import java.util.Deque; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.NoSuchElementException; import java.util.function.Supplier; @@ -64,9 +62,6 @@ public class ExpressionState { @Nullable private Deque contextObjects; - @Nullable - private Deque variableScopes; - // When entering a new scope there is a new base object which should be used // for '#this' references (or to act as a target for unqualified references). // This ArrayDeque captures those objects at each nested scope level. @@ -207,12 +202,10 @@ public Object convertValue(TypedValue value, TypeDescriptor targetTypeDescriptor * context object} and a new local variable scope. */ public void enterScope() { - initVariableScopes().push(new VariableScope()); initScopeRootObjects().push(getActiveContextObject()); } public void exitScope() { - initVariableScopes().pop(); initScopeRootObjects().pop(); } @@ -231,15 +224,6 @@ private Deque initScopeRootObjects() { return this.scopeRootObjects; } - private Deque initVariableScopes() { - if (this.variableScopes == null) { - this.variableScopes = new ArrayDeque<>(); - // top-level empty variable scope - this.variableScopes.add(new VariableScope()); - } - return this.variableScopes; - } - public TypedValue operate(Operation op, @Nullable Object left, @Nullable Object right) throws EvaluationException { OperatorOverloader overloader = this.relatedContext.getOperatorOverloader(); if (overloader.overridesOperation(op, left, right)) { @@ -265,43 +249,4 @@ public SpelParserConfiguration getConfiguration() { return this.configuration; } - - /** - * A new local variable scope is entered when a new expression scope is - * entered and exited when the corresponding expression scope is exited. - * - *

If variable names clash with those in a higher level scope, those in - * the higher level scope will not be accessible within the current scope. - */ - private static class VariableScope { - - private final Map variables = new HashMap<>(); - - VariableScope() { - } - - VariableScope(String name, Object value) { - this.variables.put(name, value); - } - - VariableScope(@Nullable Map variables) { - if (variables != null) { - this.variables.putAll(variables); - } - } - - @Nullable - Object lookupVariable(String name) { - return this.variables.get(name); - } - - void setVariable(String name, Object value) { - this.variables.put(name,value); - } - - boolean definesVariable(String name) { - return this.variables.containsKey(name); - } - } - }