diff --git a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java index 2c5477ba1..99be98b15 100644 --- a/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java +++ b/plugins/velocity/src/main/java/org/apache/struts2/views/velocity/StrutsVelocityContext.java @@ -77,7 +77,11 @@ public class StrutsVelocityContext extends VelocityContext { } protected List> contextGetterList() { - return Arrays.asList(super::internalGet, this::chainedContextGet, this::stackGet, this::stackContextGet); + return Arrays.asList(this::superGet, this::chainedContextGet, this::stackGet, this::stackContextGet); + } + + protected Object superGet(String key) { + return super.internalGet(key); } protected Object stackGet(String key) { diff --git a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/StrutsVelocityContextTest.java b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/StrutsVelocityContextTest.java index 9d78ae1d5..9f1280842 100644 --- a/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/StrutsVelocityContextTest.java +++ b/plugins/velocity/src/test/java/org/apache/struts2/views/velocity/StrutsVelocityContextTest.java @@ -74,15 +74,24 @@ public class StrutsVelocityContextTest { assertEquals("bar", strutsVelocityContext.internalGet("foo")); } + @Test + public void getSuperValue() { + strutsVelocityContext.put("foo", "bar"); + assertEquals("bar", strutsVelocityContext.internalGet("foo")); + } + @Test public void getValuePrecedence() { - when(chainedContext.internalGet("foo")).thenReturn("bar"); - assertEquals("bar", strutsVelocityContext.internalGet("foo")); + stackContext.put("foo", "quux"); + assertEquals("quux", strutsVelocityContext.internalGet("foo")); - when(stack.findValue("foo")).thenReturn("baz"); - assertEquals("bar", strutsVelocityContext.internalGet("foo")); + when(stack.findValue("foo")).thenReturn("qux"); + assertEquals("qux", strutsVelocityContext.internalGet("foo")); - stackContext.put("foo", "qux"); + when(chainedContext.internalGet("foo")).thenReturn("baz"); + assertEquals("baz", strutsVelocityContext.internalGet("foo")); + + strutsVelocityContext.put("foo", "bar"); assertEquals("bar", strutsVelocityContext.internalGet("foo")); } }