This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 353d0d0b1e Align Tomcat with clarifications in Jakarta EL
353d0d0b1e is described below
commit 353d0d0b1e0aaab09301cc26035833fd84a91a32
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 | 4 +-
java/jakarta/el/ValueExpression.java | 4 +-
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, 341 insertions(+), 72 deletions(-)
diff --git a/java/jakarta/el/MethodExpression.java
b/java/jakarta/el/MethodExpression.java
index 876619b07f..cb3312a615 100644
--- a/java/jakarta/el/MethodExpression.java
+++ b/java/jakarta/el/MethodExpression.java
@@ -17,6 +17,7 @@
package jakarta.el;
import java.io.Serial;
+import java.util.Objects;
/**
* Represents a compiled EL method expression. A MethodExpression is the
result of compiling an EL expression
@@ -94,8 +95,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 2db42cdbca..3d02a5b26f 100644
--- a/java/jakarta/el/ValueExpression.java
+++ b/java/jakarta/el/ValueExpression.java
@@ -17,6 +17,7 @@
package jakarta.el;
import java.io.Serial;
+import java.util.Objects;
/**
* Represents a parsed EL expression that can be evaluated to produce a value.
@@ -116,8 +117,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 47be8ee954..91fc6e7464 100644
--- a/java/org/apache/el/MethodExpressionImpl.java
+++ b/java/org/apache/el/MethodExpressionImpl.java
@@ -190,10 +190,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 {
@@ -292,9 +289,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 0302f8d674..26e5163563 100644
--- a/java/org/apache/el/MethodExpressionLiteral.java
+++ b/java/org/apache/el/MethodExpressionLiteral.java
@@ -71,17 +71,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());
@@ -101,11 +94,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 f76414652d..afb7890df5 100644
--- a/java/org/apache/el/ValueExpressionImpl.java
+++ b/java/org/apache/el/ValueExpressionImpl.java
@@ -158,10 +158,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")
@@ -194,10 +191,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
@@ -236,9 +230,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 616fe436db..79a7703d38 100644
--- a/java/org/apache/el/ValueExpressionLiteral.java
+++ b/java/org/apache/el/ValueExpressionLiteral.java
@@ -64,36 +64,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 49226c96c2..ced6edec2c 100644
--- a/java/org/apache/jasper/el/JspMethodExpression.java
+++ b/java/org/apache/jasper/el/JspMethodExpression.java
@@ -65,11 +65,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;
@@ -91,11 +88,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;
@@ -116,11 +110,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 c431c53909..355c251e1f 100644
--- a/java/org/apache/jasper/el/JspValueExpression.java
+++ b/java/org/apache/jasper/el/JspValueExpression.java
@@ -66,11 +66,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;
@@ -86,11 +83,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;
@@ -107,10 +101,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;
@@ -131,11 +123,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 196c55d8a7..21420671a8 100644
--- a/test/jakarta/el/TestEvaluationListener.java
+++ b/test/jakarta/el/TestEvaluationListener.java
@@ -129,4 +129,187 @@ public class TestEvaluationListener extends ELBaseTest {
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 19c365cad2..71983c978d 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -502,6 +502,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]