This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 0861ecab3d Align Tomcat with clarifications in Jakarta EL
0861ecab3d is described below
commit 0861ecab3d19bc74c5ea65d03d45d1896a8ee03d
Author: Mark Thomas <[email protected]>
AuthorDate: Wed Dec 2 16:27:51 2026 +0000
Align Tomcat with clarifications in Jakarta EL
The requirements for calling EvaluationListener have been clarified.
Tomcat was calling the listener to often and for events where it was not
required.
---
java/jakarta/el/MethodExpression.java | 5 +-
java/jakarta/el/ValueExpression.java | 5 +-
java/org/apache/el/MethodExpressionImpl.java | 10 +-
java/org/apache/el/MethodExpressionLiteral.java | 15 +-
java/org/apache/el/ValueExpressionImpl.java | 15 +-
java/org/apache/el/ValueExpressionLiteral.java | 10 +-
java/org/apache/jasper/el/JspMethodExpression.java | 15 +-
java/org/apache/jasper/el/JspValueExpression.java | 17 +-
test/jakarta/el/TestEvaluationListener.java | 183 +++++++++++++++++++++
.../el/TestJspExpressionEvaluationListener.java | 127 ++++++++++++++
webapps/docs/changelog.xml | 13 ++
11 files changed, 343 insertions(+), 72 deletions(-)
diff --git a/java/jakarta/el/MethodExpression.java
b/java/jakarta/el/MethodExpression.java
index 5f5fea4aea..cef9a8b603 100644
--- a/java/jakarta/el/MethodExpression.java
+++ b/java/jakarta/el/MethodExpression.java
@@ -16,6 +16,8 @@
*/
package jakarta.el;
+import java.util.Objects;
+
/**
* Represents a compiled EL method expression. A MethodExpression is the
result of compiling an EL expression
* that resolves to a method, and can be invoked at a later time with a given
set of parameters.
@@ -91,8 +93,7 @@ public abstract class MethodExpression extends Expression {
*/
public MethodReference getMethodReference(ELContext context) {
// Expected to be over-ridden by implementation
- context.notifyBeforeEvaluation(getExpressionString());
- context.notifyAfterEvaluation(getExpressionString());
+ Objects.requireNonNull(context);
return null;
}
}
diff --git a/java/jakarta/el/ValueExpression.java
b/java/jakarta/el/ValueExpression.java
index 5bf5ce98d0..217d653cdb 100644
--- a/java/jakarta/el/ValueExpression.java
+++ b/java/jakarta/el/ValueExpression.java
@@ -16,6 +16,8 @@
*/
package jakarta.el;
+import java.util.Objects;
+
/**
* Represents a parsed EL expression that can be evaluated to produce a value.
* <p>
@@ -113,8 +115,7 @@ public abstract class ValueExpression extends Expression {
*/
public ValueReference getValueReference(ELContext context) {
// Expected to be over-ridden by implementation
- context.notifyBeforeEvaluation(getExpressionString());
- context.notifyAfterEvaluation(getExpressionString());
+ Objects.requireNonNull(context);
return null;
}
}
diff --git a/java/org/apache/el/MethodExpressionImpl.java
b/java/org/apache/el/MethodExpressionImpl.java
index c8a58ab83d..5150910891 100644
--- a/java/org/apache/el/MethodExpressionImpl.java
+++ b/java/org/apache/el/MethodExpressionImpl.java
@@ -188,10 +188,7 @@ public final class MethodExpressionImpl extends
MethodExpression implements Exte
throws PropertyNotFoundException, MethodNotFoundException,
ELException {
Node n = this.getNode();
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
- ctx.notifyBeforeEvaluation(getExpressionString());
- MethodInfo result = n.getMethodInfo(ctx, this.paramTypes);
- ctx.notifyAfterEvaluation(getExpressionString());
- return result;
+ return n.getMethodInfo(ctx, this.paramTypes);
}
private Node getNode() throws ELException {
@@ -290,9 +287,6 @@ public final class MethodExpressionImpl extends
MethodExpression implements Exte
@Override
public MethodReference getMethodReference(ELContext context) {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
- ctx.notifyBeforeEvaluation(getExpressionString());
- MethodReference methodReference =
this.getNode().getMethodReference(ctx);
- ctx.notifyAfterEvaluation(getExpressionString());
- return methodReference;
+ return this.getNode().getMethodReference(ctx);
}
}
diff --git a/java/org/apache/el/MethodExpressionLiteral.java
b/java/org/apache/el/MethodExpressionLiteral.java
index cdbaac73bd..d6ec75f207 100644
--- a/java/org/apache/el/MethodExpressionLiteral.java
+++ b/java/org/apache/el/MethodExpressionLiteral.java
@@ -69,17 +69,10 @@ public class MethodExpressionLiteral extends
MethodExpression implements Externa
@Override
public MethodInfo getMethodInfo(ELContext context) throws ELException {
- context.notifyBeforeEvaluation(getExpressionString());
- MethodInfo result = getMethodInfoInternal();
- context.notifyAfterEvaluation(getExpressionString());
- return result;
- }
-
-
- private MethodInfo getMethodInfoInternal() throws ELException {
return new MethodInfo(this.expr, this.expectedType, this.paramTypes);
}
+
@Override
public Object invoke(ELContext context, Object[] params) throws
ELException {
context.notifyBeforeEvaluation(getExpressionString());
@@ -99,11 +92,7 @@ public class MethodExpressionLiteral extends
MethodExpression implements Externa
if (context == null) {
throw new
NullPointerException(MessageFactory.get("error.context.null"));
}
- context.notifyBeforeEvaluation(getExpressionString());
- MethodReference result =
- new MethodReference(null, getMethodInfoInternal(),
EMPTY_ANNOTATION_ARRAY, EMPTY_OBJECT_ARRAY);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return new MethodReference(null, getMethodInfo(context),
EMPTY_ANNOTATION_ARRAY, EMPTY_OBJECT_ARRAY);
}
@Override
diff --git a/java/org/apache/el/ValueExpressionImpl.java
b/java/org/apache/el/ValueExpressionImpl.java
index 25391084ee..9881ddedee 100644
--- a/java/org/apache/el/ValueExpressionImpl.java
+++ b/java/org/apache/el/ValueExpressionImpl.java
@@ -156,10 +156,7 @@ public final class ValueExpressionImpl extends
ValueExpression implements Extern
@Override
public Class<?> getType(ELContext context) throws
PropertyNotFoundException, ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
- context.notifyBeforeEvaluation(getExpressionString());
- Class<?> result = this.getNode().getType(ctx);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.getNode().getType(ctx);
}
@SuppressWarnings("unchecked")
@@ -192,10 +189,7 @@ public final class ValueExpressionImpl extends
ValueExpression implements Extern
@Override
public boolean isReadOnly(ELContext context) throws
PropertyNotFoundException, ELException {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
- context.notifyBeforeEvaluation(getExpressionString());
- boolean result = this.getNode().isReadOnly(ctx);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.getNode().isReadOnly(ctx);
}
@Override
@@ -234,9 +228,6 @@ public final class ValueExpressionImpl extends
ValueExpression implements Extern
@Override
public ValueReference getValueReference(ELContext context) {
EvaluationContext ctx = new EvaluationContext(context, this.fnMapper,
this.varMapper);
- context.notifyBeforeEvaluation(getExpressionString());
- ValueReference result = this.getNode().getValueReference(ctx);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.getNode().getValueReference(ctx);
}
}
diff --git a/java/org/apache/el/ValueExpressionLiteral.java
b/java/org/apache/el/ValueExpressionLiteral.java
index 6dacfda832..04d5bb3f40 100644
--- a/java/org/apache/el/ValueExpressionLiteral.java
+++ b/java/org/apache/el/ValueExpressionLiteral.java
@@ -62,36 +62,28 @@ public final class ValueExpressionLiteral extends
ValueExpression implements Ext
@SuppressWarnings("unchecked")
@Override
public <T> T getValue(ELContext context) {
- context.notifyBeforeEvaluation(getExpressionString());
Object result;
if (this.expectedType != null) {
result = context.convertToType(this.value, this.expectedType);
} else {
result = this.value;
}
- context.notifyAfterEvaluation(getExpressionString());
return (T) result;
}
@Override
public void setValue(ELContext context, Object value) {
- context.notifyBeforeEvaluation(getExpressionString());
throw new
PropertyNotWritableException(MessageFactory.get("error.value.literal.write",
this.value));
}
@Override
public boolean isReadOnly(ELContext context) {
- context.notifyBeforeEvaluation(getExpressionString());
- context.notifyAfterEvaluation(getExpressionString());
return true;
}
@Override
public Class<?> getType(ELContext context) {
- context.notifyBeforeEvaluation(getExpressionString());
- Class<?> result = (this.value != null) ? this.value.getClass() : null;
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return (this.value != null) ? this.value.getClass() : null;
}
@Override
diff --git a/java/org/apache/jasper/el/JspMethodExpression.java
b/java/org/apache/jasper/el/JspMethodExpression.java
index 38e20f12a9..7ebdf6567b 100644
--- a/java/org/apache/jasper/el/JspMethodExpression.java
+++ b/java/org/apache/jasper/el/JspMethodExpression.java
@@ -63,11 +63,8 @@ public final class JspMethodExpression extends
MethodExpression implements Exter
@Override
public MethodInfo getMethodInfo(ELContext context)
throws NullPointerException, PropertyNotFoundException,
MethodNotFoundException, ELException {
- context.notifyBeforeEvaluation(getExpressionString());
try {
- MethodInfo result = this.target.getMethodInfo(context);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.target.getMethodInfo(context);
} catch (MethodNotFoundException e) {
if (e instanceof JspMethodNotFoundException) {
throw e;
@@ -89,11 +86,8 @@ public final class JspMethodExpression extends
MethodExpression implements Exter
@Override
public Object invoke(ELContext context, Object[] params)
throws NullPointerException, PropertyNotFoundException,
MethodNotFoundException, ELException {
- context.notifyBeforeEvaluation(getExpressionString());
try {
- Object result = this.target.invoke(context, params);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.target.invoke(context, params);
} catch (MethodNotFoundException e) {
if (e instanceof JspMethodNotFoundException) {
throw e;
@@ -114,11 +108,8 @@ public final class JspMethodExpression extends
MethodExpression implements Exter
@Override
public MethodReference getMethodReference(ELContext context) {
- context.notifyBeforeEvaluation(getExpressionString());
try {
- MethodReference result = this.target.getMethodReference(context);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.target.getMethodReference(context);
} catch (MethodNotFoundException e) {
if (e instanceof JspMethodNotFoundException) {
throw e;
diff --git a/java/org/apache/jasper/el/JspValueExpression.java
b/java/org/apache/jasper/el/JspValueExpression.java
index 8c8fa0a06b..ed6e0bba54 100644
--- a/java/org/apache/jasper/el/JspValueExpression.java
+++ b/java/org/apache/jasper/el/JspValueExpression.java
@@ -64,11 +64,8 @@ public final class JspValueExpression extends
ValueExpression implements Externa
@Override
public Class<?> getType(ELContext context) throws NullPointerException,
PropertyNotFoundException, ELException {
- context.notifyBeforeEvaluation(getExpressionString());
try {
- Class<?> result = this.target.getType(context);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.target.getType(context);
} catch (PropertyNotFoundException e) {
if (e instanceof JspPropertyNotFoundException) {
throw e;
@@ -84,11 +81,8 @@ public final class JspValueExpression extends
ValueExpression implements Externa
@Override
public boolean isReadOnly(ELContext context) throws NullPointerException,
PropertyNotFoundException, ELException {
- context.notifyBeforeEvaluation(getExpressionString());
try {
- boolean result = this.target.isReadOnly(context);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.target.isReadOnly(context);
} catch (PropertyNotFoundException e) {
if (e instanceof JspPropertyNotFoundException) {
throw e;
@@ -105,10 +99,8 @@ public final class JspValueExpression extends
ValueExpression implements Externa
@Override
public void setValue(ELContext context, Object value)
throws NullPointerException, PropertyNotFoundException,
PropertyNotWritableException, ELException {
- context.notifyBeforeEvaluation(getExpressionString());
try {
this.target.setValue(context, value);
- context.notifyAfterEvaluation(getExpressionString());
} catch (PropertyNotWritableException e) {
if (e instanceof JspPropertyNotWritableException) {
throw e;
@@ -129,11 +121,8 @@ public final class JspValueExpression extends
ValueExpression implements Externa
@Override
public <T> T getValue(ELContext context) throws NullPointerException,
PropertyNotFoundException, ELException {
- context.notifyBeforeEvaluation(getExpressionString());
try {
- T result = this.target.getValue(context);
- context.notifyAfterEvaluation(getExpressionString());
- return result;
+ return this.target.getValue(context);
} catch (PropertyNotFoundException e) {
if (e instanceof JspPropertyNotFoundException) {
throw e;
diff --git a/test/jakarta/el/TestEvaluationListener.java
b/test/jakarta/el/TestEvaluationListener.java
index ef0acc1e96..1696e6278b 100644
--- a/test/jakarta/el/TestEvaluationListener.java
+++ b/test/jakarta/el/TestEvaluationListener.java
@@ -129,4 +129,187 @@ public class TestEvaluationListener {
List<String> after = listener.getAfterEvaluationExpressions();
Assert.assertEquals(0, after.size());
}
+
+
+ /*
+ * Instances of ValueExpression created via
ExpressionFactory.createValueExpression(Object, Class) do not notify
+ * the listener. Using one as a variable in another expression results in
a single notification for the expression
+ * that was evaluated.
+ */
+ @Test
+ public void testInstanceVariableGetValue() {
+ VariableFixture f = new VariableFixture();
+
+ ValueExpression ve = f.factory.createValueExpression(f.context,
"${bean.name}", String.class);
+ Assert.assertEquals(0,
f.listener.getBeforeEvaluationExpressions().size());
+
+ Assert.assertEquals("test", ve.getValue(f.context));
+
+ f.assertEvaluatedOnce("${bean.name}");
+ }
+
+
+ @Test
+ public void testInstanceVariableSetValue() {
+ VariableFixture f = new VariableFixture();
+
+ ValueExpression ve = f.factory.createValueExpression(f.context,
"${bean.name}", String.class);
+ ve.setValue(f.context, "updated");
+
+ Assert.assertEquals("updated", f.bean.getName());
+ f.assertEvaluatedOnce("${bean.name}");
+ }
+
+
+ @Test
+ public void testInstanceVariableInvoke() {
+ VariableFixture f = new VariableFixture();
+
+ MethodExpression me = f.factory.createMethodExpression(f.context,
"${bean.setName}", null,
+ new Class<?>[] { String.class });
+ me.invoke(f.context, new Object[] { "invoked" });
+
+ Assert.assertEquals("invoked", f.bean.getName());
+ f.assertEvaluatedOnce("${bean.setName}");
+ }
+
+
+ @Test
+ public void testInstanceValueExpressionDoesNotNotify() {
+ VariableFixture f = new VariableFixture();
+ ValueExpression ve = f.factory.createValueExpression(f.bean,
TesterBean.class);
+
+ Assert.assertSame(f.bean, ve.getValue(f.context));
+ Assert.assertEquals(TesterBean.class, ve.getExpectedType());
+ Assert.assertTrue(ve.isReadOnly(f.context));
+ ve.getType(f.context);
+ ve.getValueReference(f.context);
+ ve.getExpressionString();
+ ve.isLiteralText();
+ ve.toString();
+ try {
+ ve.setValue(f.context, f.bean);
+ Assert.fail("Expected PropertyNotWritableException");
+ } catch (PropertyNotWritableException e) {
+ // Expected
+ }
+
+ Assert.assertEquals(0,
f.listener.getBeforeEvaluationExpressions().size());
+ Assert.assertEquals(0,
f.listener.getAfterEvaluationExpressions().size());
+ }
+
+
+ /*
+ * A variable that is a ValueExpression created from a String is a normal
expression so it notifies the listener
+ * in addition to the expression that references it.
+ */
+ @Test
+ public void testStringVariableNotifiesTwice() {
+ ExpressionFactory factory = ELManager.getExpressionFactory();
+ ELContext context = new ELManager().getELContext();
+ TesterEvaluationListener listener = new TesterEvaluationListener();
+ context.addEvaluationListener(listener);
+
+ context.getVariableMapper().setVariable("answer",
+ factory.createValueExpression(context, "${1 + 2}",
Long.class));
+ ValueExpression ve = factory.createValueExpression(context, "${answer
* 2}", Long.class);
+
+ Assert.assertEquals(Long.valueOf(6), ve.getValue(context));
+
+ Assert.assertEquals(List.of("${answer * 2}", "${1 + 2}"),
listener.getBeforeEvaluationExpressions());
+ Assert.assertEquals(List.of("${1 + 2}", "${answer * 2}"),
listener.getAfterEvaluationExpressions());
+ }
+
+
+ /*
+ * Methods other than ValueExpression.getValue(),
ValueExpression.setValue() and MethodExpression.invoke() do not
+ * notify the listener.
+ */
+ @Test
+ public void testValueExpressionOtherMethodsDoNotNotify() {
+ VariableFixture f = new VariableFixture();
+ ValueExpression ve = f.factory.createValueExpression(f.context,
"${bean.name}", String.class);
+
+ Assert.assertEquals(String.class, ve.getExpectedType());
+ Assert.assertEquals("${bean.name}", ve.getExpressionString());
+ Assert.assertFalse(ve.isLiteralText());
+ Assert.assertFalse(ve.isReadOnly(f.context));
+ Assert.assertEquals(String.class, ve.getType(f.context));
+ Assert.assertNotNull(ve.getValueReference(f.context));
+ ve.equals(ve);
+ ve.hashCode();
+ ve.toString();
+
+ Assert.assertEquals(0,
f.listener.getBeforeEvaluationExpressions().size());
+ Assert.assertEquals(0,
f.listener.getAfterEvaluationExpressions().size());
+ }
+
+
+ @Test
+ public void testMethodExpressionOtherMethodsDoNotNotify() {
+ VariableFixture f = new VariableFixture();
+ MethodExpression me = f.factory.createMethodExpression(f.context,
"${bean.setName}", null,
+ new Class<?>[] { String.class });
+ MethodExpression meWithParameters =
f.factory.createMethodExpression(f.context, "${bean.getName()}",
+ String.class, new Class<?>[0]);
+
+ Assert.assertEquals("${bean.setName}", me.getExpressionString());
+ Assert.assertFalse(me.isLiteralText());
+ Assert.assertFalse(me.isParametersProvided());
+ Assert.assertNotNull(me.getMethodInfo(f.context));
+ Assert.assertTrue(meWithParameters.isParametersProvided());
+ Assert.assertNotNull(meWithParameters.getMethodInfo(f.context));
+ Assert.assertNotNull(meWithParameters.getMethodReference(f.context));
+ me.hashCode();
+ me.toString();
+
+ Assert.assertEquals(0,
f.listener.getBeforeEvaluationExpressions().size());
+ Assert.assertEquals(0,
f.listener.getAfterEvaluationExpressions().size());
+ }
+
+
+ @Test
+ public void testLiteralMethodExpression() {
+ ExpressionFactory factory = ELManager.getExpressionFactory();
+ ELContext context = new ELManager().getELContext();
+ TesterEvaluationListener listener = new TesterEvaluationListener();
+ context.addEvaluationListener(listener);
+
+ String expression = "plain text";
+ MethodExpression me = factory.createMethodExpression(context,
expression, String.class, new Class<?>[0]);
+
+ Assert.assertTrue(me.isLiteralText());
+ Assert.assertNotNull(me.getMethodInfo(context));
+ Assert.assertNotNull(me.getMethodReference(context));
+ me.toString();
+ Assert.assertEquals(0,
listener.getBeforeEvaluationExpressions().size());
+ Assert.assertEquals(0,
listener.getAfterEvaluationExpressions().size());
+
+ Assert.assertEquals(expression, me.invoke(context, null));
+
+ Assert.assertEquals(List.of(expression),
listener.getBeforeEvaluationExpressions());
+ Assert.assertEquals(List.of(expression),
listener.getAfterEvaluationExpressions());
+ }
+
+
+ /*
+ * Registers a TesterBean as the variable "bean" using
ExpressionFactory.createValueExpression(Object, Class) and
+ * adds a listener.
+ */
+ private static class VariableFixture {
+ final ExpressionFactory factory = ELManager.getExpressionFactory();
+ final ELContext context = new ELManager().getELContext();
+ final TesterBean bean = new TesterBean("test");
+ final TesterEvaluationListener listener = new
TesterEvaluationListener();
+
+ VariableFixture() {
+ context.getVariableMapper().setVariable("bean",
factory.createValueExpression(bean, TesterBean.class));
+ context.addEvaluationListener(listener);
+ }
+
+ void assertEvaluatedOnce(String expression) {
+ Assert.assertEquals(List.of(expression),
listener.getBeforeEvaluationExpressions());
+ Assert.assertEquals(List.of(expression),
listener.getAfterEvaluationExpressions());
+ }
+ }
}
diff --git a/test/org/apache/jasper/el/TestJspExpressionEvaluationListener.java
b/test/org/apache/jasper/el/TestJspExpressionEvaluationListener.java
new file mode 100644
index 0000000000..854c37d3b6
--- /dev/null
+++ b/test/org/apache/jasper/el/TestJspExpressionEvaluationListener.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jasper.el;
+
+import java.util.List;
+
+import jakarta.el.ELContext;
+import jakarta.el.ELManager;
+import jakarta.el.ExpressionFactory;
+import jakarta.el.MethodExpression;
+import jakarta.el.TesterBean;
+import jakarta.el.TesterEvaluationListener;
+import jakarta.el.ValueExpression;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/*
+ * The JSP wrappers add the location of the expression to any exception. The
wrapped expression notifies the
+ * EvaluationListener so the wrappers must not.
+ */
+public class TestJspExpressionEvaluationListener {
+
+ private final ExpressionFactory factory = ELManager.getExpressionFactory();
+ private final ELContext context = new ELManager().getELContext();
+ private final TesterBean bean = new TesterBean("test");
+ private final TesterEvaluationListener listener = new
TesterEvaluationListener();
+
+ private void setup() {
+ context.getVariableMapper().setVariable("bean",
factory.createValueExpression(bean, TesterBean.class));
+ context.addEvaluationListener(listener);
+ }
+
+
+ @Test
+ public void testValueExpressionGetValue() {
+ setup();
+ String expression = "${bean.name}";
+ ValueExpression ve = new JspValueExpression("mark",
factory.createValueExpression(context, expression,
+ String.class));
+
+ Assert.assertEquals("test", ve.getValue(context));
+
+ assertEvaluatedOnce(expression);
+ }
+
+
+ @Test
+ public void testValueExpressionSetValue() {
+ setup();
+ String expression = "${bean.name}";
+ ValueExpression ve = new JspValueExpression("mark",
factory.createValueExpression(context, expression,
+ String.class));
+
+ ve.setValue(context, "updated");
+
+ Assert.assertEquals("updated", bean.getName());
+ assertEvaluatedOnce(expression);
+ }
+
+
+ @Test
+ public void testValueExpressionOtherMethods() {
+ setup();
+ ValueExpression ve = new JspValueExpression("mark",
factory.createValueExpression(context, "${bean.name}",
+ String.class));
+
+ Assert.assertFalse(ve.isReadOnly(context));
+ Assert.assertEquals(String.class, ve.getType(context));
+ ve.getValueReference(context);
+
+ assertNotEvaluated();
+ }
+
+
+ @Test
+ public void testMethodExpressionInvoke() {
+ setup();
+ String expression = "${bean.setName}";
+ MethodExpression me = new JspMethodExpression("mark",
factory.createMethodExpression(context, expression,
+ null, new Class<?>[] { String.class }));
+
+ me.invoke(context, new Object[] { "invoked" });
+
+ Assert.assertEquals("invoked", bean.getName());
+ assertEvaluatedOnce(expression);
+ }
+
+
+ @Test
+ public void testMethodExpressionOtherMethods() {
+ setup();
+ MethodExpression me = new JspMethodExpression("mark",
factory.createMethodExpression(context,
+ "${bean.getName()}", String.class, new Class<?>[0]));
+
+ Assert.assertNotNull(me.getMethodInfo(context));
+ Assert.assertNotNull(me.getMethodReference(context));
+
+ assertNotEvaluated();
+ }
+
+
+ private void assertEvaluatedOnce(String expression) {
+ Assert.assertEquals(List.of(expression),
listener.getBeforeEvaluationExpressions());
+ Assert.assertEquals(List.of(expression),
listener.getAfterEvaluationExpressions());
+ }
+
+
+ private void assertNotEvaluated() {
+ Assert.assertEquals(0,
listener.getBeforeEvaluationExpressions().size());
+ Assert.assertEquals(0,
listener.getAfterEvaluationExpressions().size());
+ }
+}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index f6c7d45782..875c5fe7cb 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -503,6 +503,19 @@
language specification when <code>expr-a</code> is a literal
<code>null</code>. (markt)
</fix>
+ <fix>
+ Ensure that the <code>EvaluationListener</code> is only notified when
+ <code>ValueExpression.getValue()</code>,
+ <code>ValueExpression.setValue()</code> or
+ <code>MethodExpression.invoke()</code> is called and that it is
+ notified once only for each evaluation. Previously, other methods such
+ as <code>ValueExpression.getType()</code> also triggered notifications,
+ expressions created with
+ <code>ExpressionFactory.createValueExpression(Object, Class)</code>
+ triggered additional notifications when used as a variable in another
+ expression and expressions evaluated in JSPs triggered duplicate
+ notifications. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]