diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java
index 7e3ff72e52..ec0f9a3ed0 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/parsing/ParseState.java
@@ -16,13 +16,13 @@
package org.springframework.beans.factory.parsing;
-import java.util.Stack;
+import java.util.LinkedList;
import org.springframework.lang.Nullable;
/**
- * Simple {@link Stack}-based structure for tracking the logical position during
- * a parsing process. {@link Entry entries} are added to the stack at
+ * Simple {@link LinkedList}-based structure for tracking the logical position during
+ * a parsing process. {@link Entry entries} are added to the LinkedList at
* each point during the parse phase in a reader-specific manner.
*
*
Calling {@link #toString()} will render a tree-style view of the current logical
@@ -40,49 +40,49 @@ public final class ParseState {
private static final char TAB = '\t';
/**
- * Internal {@link Stack} storage.
+ * Internal {@link LinkedList} storage.
*/
- private final Stack state;
+ private final LinkedList state;
/**
- * Create a new {@code ParseState} with an empty {@link Stack}.
+ * Create a new {@code ParseState} with an empty {@link LinkedList}.
*/
public ParseState() {
- this.state = new Stack<>();
+ this.state = new LinkedList<>();
}
/**
- * Create a new {@code ParseState} whose {@link Stack} is a {@link Object#clone clone}
+ * Create a new {@code ParseState} whose {@link LinkedList} is a {@link Object#clone clone}
* of that of the passed in {@code ParseState}.
*/
@SuppressWarnings("unchecked")
private ParseState(ParseState other) {
- this.state = (Stack) other.state.clone();
+ this.state = (LinkedList) other.state.clone();
}
/**
- * Add a new {@link Entry} to the {@link Stack}.
+ * Add a new {@link Entry} to the {@link LinkedList}.
*/
public void push(Entry entry) {
this.state.push(entry);
}
/**
- * Remove an {@link Entry} from the {@link Stack}.
+ * Remove an {@link Entry} from the {@link LinkedList}.
*/
public void pop() {
this.state.pop();
}
/**
- * Return the {@link Entry} currently at the top of the {@link Stack} or
- * {@code null} if the {@link Stack} is empty.
+ * Return the {@link Entry} currently at the top of the {@link LinkedList} or
+ * {@code null} if the {@link LinkedList} is empty.
*/
@Nullable
public Entry peek() {
- return this.state.empty() ? null : this.state.peek();
+ return this.state.isEmpty() ? null : this.state.peek();
}
/**
diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java
index eaf5a9c5e2..2586ef6b42 100644
--- a/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java
+++ b/spring-beans/src/main/java/org/springframework/beans/factory/xml/ParserContext.java
@@ -16,7 +16,8 @@
package org.springframework.beans.factory.xml;
-import java.util.Stack;
+import java.util.ArrayDeque;
+import java.util.Deque;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.parsing.BeanComponentDefinition;
@@ -46,7 +47,7 @@ public final class ParserContext {
@Nullable
private BeanDefinition containingBeanDefinition;
- private final Stack containingComponents = new Stack<>();
+ private final Deque containingComponents = new ArrayDeque<>();
public ParserContext(XmlReaderContext readerContext, BeanDefinitionParserDelegate delegate) {
@@ -96,7 +97,7 @@ public final class ParserContext {
@Nullable
public CompositeComponentDefinition getContainingComponent() {
return (!this.containingComponents.isEmpty() ?
- (CompositeComponentDefinition) this.containingComponents.lastElement() : null);
+ (CompositeComponentDefinition) this.containingComponents.getLast() : null);
}
public void pushContainingComponent(CompositeComponentDefinition containingComponent) {
diff --git a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java
index f432739f02..b791889d40 100644
--- a/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java
+++ b/spring-context/src/main/java/org/springframework/validation/AbstractErrors.java
@@ -17,11 +17,12 @@
package org.springframework.validation;
import java.io.Serializable;
+import java.util.ArrayDeque;
import java.util.Collections;
+import java.util.Deque;
import java.util.EmptyStackException;
import java.util.LinkedList;
import java.util.List;
-import java.util.Stack;
import org.springframework.lang.Nullable;
import org.springframework.util.StringUtils;
@@ -40,7 +41,7 @@ public abstract class AbstractErrors implements Errors, Serializable {
private String nestedPath = "";
- private final Stack nestedPathStack = new Stack<>();
+ private final Deque nestedPathStack = new ArrayDeque<>();
@Override
diff --git a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
index dbbff571dd..0100ef333d 100644
--- a/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
+++ b/spring-expression/src/main/java/org/springframework/expression/common/TemplateAwareExpressionParser.java
@@ -16,9 +16,10 @@
package org.springframework.expression.common;
+import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.List;
-import java.util.Stack;
+import java.util.Deque;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
@@ -172,7 +173,7 @@ public abstract class TemplateAwareExpressionParser implements ExpressionParser
if (nextSuffix == -1) {
return -1; // the suffix is missing
}
- Stack stack = new Stack<>();
+ Deque stack = new ArrayDeque<>();
while (pos < maxlen) {
if (isSuffixHere(expressionString, pos, suffix) && stack.isEmpty()) {
break;
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
index 84ab1c00a3..b257f47f55 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/CodeFlow.java
@@ -18,9 +18,10 @@ package org.springframework.expression.spel;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.util.ArrayDeque;
import java.util.ArrayList;
+import java.util.Deque;
import java.util.List;
-import java.util.Stack;
import org.springframework.asm.ClassWriter;
import org.springframework.asm.MethodVisitor;
@@ -57,7 +58,7 @@ public class CodeFlow implements Opcodes {
* sub-expressions like the expressions for the argument values in a method invocation
* expression.
*/
- private final Stack> compilationScopes;
+ private final Deque> compilationScopes;
/**
* As SpEL ast nodes are called to generate code for the main evaluation method
@@ -97,7 +98,7 @@ public class CodeFlow implements Opcodes {
public CodeFlow(String className, ClassWriter classWriter) {
this.className = className;
this.classWriter = classWriter;
- this.compilationScopes = new Stack<>();
+ this.compilationScopes = new ArrayDeque<>();
this.compilationScopes.add(new ArrayList());
}
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 142a1992e8..4c930b3857 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
@@ -16,11 +16,13 @@
package org.springframework.expression.spel;
+import java.util.ArrayDeque;
import java.util.Collections;
+import java.util.Deque;
import java.util.HashMap;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Stack;
import org.springframework.core.convert.TypeDescriptor;
import org.springframework.expression.EvaluationContext;
@@ -58,20 +60,20 @@ public class ExpressionState {
private final SpelParserConfiguration configuration;
@Nullable
- private Stack contextObjects;
+ private Deque contextObjects;
@Nullable
- private Stack variableScopes;
+ private LinkedList 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 stack captures those objects at each nested scope level.
+ // This ArrayDeque captures those objects at each nested scope level.
// For example:
// #list1.?[#list2.contains(#this)]
// On entering the selection we enter a new scope, and #this is now the
// element from list1
@Nullable
- private Stack scopeRootObjects;
+ private ArrayDeque scopeRootObjects;
public ExpressionState(EvaluationContext context) {
@@ -107,14 +109,14 @@ public class ExpressionState {
public void pushActiveContextObject(TypedValue obj) {
if (this.contextObjects == null) {
- this.contextObjects = new Stack<>();
+ this.contextObjects = new ArrayDeque<>();
}
this.contextObjects.push(obj);
}
public void popActiveContextObject() {
if (this.contextObjects == null) {
- this.contextObjects = new Stack<>();
+ this.contextObjects = new ArrayDeque<>();
}
this.contextObjects.pop();
}
@@ -205,18 +207,18 @@ public class ExpressionState {
return null;
}
- private Stack initVariableScopes() {
+ private LinkedList initVariableScopes() {
if (this.variableScopes == null) {
- this.variableScopes = new Stack<>();
+ this.variableScopes = new LinkedList<>();
// top level empty variable scope
this.variableScopes.add(new VariableScope());
}
return this.variableScopes;
}
- private Stack initScopeRootObjects() {
+ private ArrayDeque initScopeRootObjects() {
if (this.scopeRootObjects == null) {
- this.scopeRootObjects = new Stack<>();
+ this.scopeRootObjects = new ArrayDeque<>();
}
return this.scopeRootObjects;
}
diff --git a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java
index d5e5198b07..0d2ce810e1 100644
--- a/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java
+++ b/spring-expression/src/main/java/org/springframework/expression/spel/standard/InternalSpelExpressionParser.java
@@ -16,11 +16,12 @@
package org.springframework.expression.spel.standard;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
-import java.util.Stack;
import java.util.regex.Pattern;
import org.springframework.expression.ParseException;
@@ -93,7 +94,7 @@ class InternalSpelExpressionParser extends TemplateAwareExpressionParser {
private final SpelParserConfiguration configuration;
// For rules that build nodes, they are stacked here for return
- private final Stack constructedNodes = new Stack<>();
+ private final Deque constructedNodes = new ArrayDeque<>();
// The expression being parsed
private String expressionString = "";
diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java
index 12876d65ff..9d17010c1e 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/TagWriter.java
@@ -18,7 +18,8 @@ package org.springframework.web.servlet.tags.form;
import java.io.IOException;
import java.io.Writer;
-import java.util.Stack;
+import java.util.ArrayDeque;
+import java.util.Deque;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
@@ -46,7 +47,7 @@ public class TagWriter {
/**
* Stores {@link TagStateEntry tag state}. Stack model naturally supports tag nesting.
*/
- private final Stack tagState = new Stack<>();
+ private final Deque tagState = new ArrayDeque<>();
/**