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 e7c3a5777c Fix literal null handling with [] and . operators
e7c3a5777c is described below
commit e7c3a5777caa24f9915ef2c28d4ff69b54809aae
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Nov 19 13:16:27 2026 +0000
Fix literal null handling with [] and . operators
---
java/org/apache/el/parser/AstValue.java | 9 +++-
test/org/apache/el/parser/TestAstValue.java | 81 +++++++++++++++++++++++++++++
webapps/docs/changelog.xml | 5 ++
3 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/el/parser/AstValue.java
b/java/org/apache/el/parser/AstValue.java
index aa93ab81cd..f620b6b605 100644
--- a/java/org/apache/el/parser/AstValue.java
+++ b/java/org/apache/el/parser/AstValue.java
@@ -127,7 +127,11 @@ public final class AstValue extends SimpleNode {
int i = 1;
Object suffix = null;
ELResolver resolver = ctx.getELResolver();
- while (base != null && i < propCount) {
+ while (i < propCount) {
+ if (base == null) {
+ ctx.setPropertyResolved(true);
+ break;
+ }
suffix = this.children[i].getValue(ctx);
if (i + 1 < propCount && (this.children[i + 1] instanceof
AstMethodParameters mps)) {
if (base instanceof Optional && "orElseGet".equals(suffix) &&
mps.jjtGetNumChildren() == 1) {
@@ -151,6 +155,9 @@ public final class AstValue extends SimpleNode {
base = resolver.getValue(ctx, base, suffix);
i++;
}
+ if (!ctx.isPropertyResolved()) {
+ break;
+ }
}
if (!ctx.isPropertyResolved()) {
throw new
PropertyNotFoundException(MessageFactory.get("error.resolver.unhandled", base,
suffix));
diff --git a/test/org/apache/el/parser/TestAstValue.java
b/test/org/apache/el/parser/TestAstValue.java
index 46858c19c5..62869d9d1b 100644
--- a/test/org/apache/el/parser/TestAstValue.java
+++ b/test/org/apache/el/parser/TestAstValue.java
@@ -16,7 +16,12 @@
*/
package org.apache.el.parser;
+import jakarta.el.CompositeELResolver;
+import jakarta.el.ELContext;
+import jakarta.el.ELManager;
import jakarta.el.ELProcessor;
+import jakarta.el.PropertyNotFoundException;
+import jakarta.el.TesterELContext;
import org.junit.Assert;
import org.junit.Test;
@@ -32,4 +37,80 @@ public class TestAstValue {
Object result = processor.eval("bean.text.toLowerCase()");
Assert.assertNull(result);
}
+
+
+ @Test
+ public void testLiteralNullWithProperty01() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null.a"));
+ }
+
+
+ @Test
+ public void testLiteralNullWithProperty02() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null.a.b"));
+ }
+
+
+ @Test
+ public void testLiteralNullWithProperty03() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null['a']"));
+ }
+
+
+ @Test
+ public void testLiteralNullWithProperty04() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null['a']['b']"));
+ }
+
+
+ @Test(expected = PropertyNotFoundException.class)
+ public void testUnresolvedIntermediateProperty() {
+ // The empty CompositeELResolver means unknown will not be resolved.
+ ELContext context = new TesterELContext(new CompositeELResolver());
+ ELManager.getExpressionFactory()
+ .createValueExpression(context, "${'x'.unknown.next}",
Object.class)
+ .getValue(context);
+ }
+
+
+ @Test(expected = PropertyNotFoundException.class)
+ public void testUnresolvedIntermediateMethod() {
+ // The empty CompositeELResolver means unknown will not be resolved.
+ ELContext context = new TesterELContext(new CompositeELResolver());
+ ELManager.getExpressionFactory()
+ .createValueExpression(context, "${'x'.unknown().next}",
Object.class)
+ .getValue(context);
+ }
+
+
+ @Test
+ public void testLiteralNullWithMethod01() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null.method()"));
+ }
+
+
+ @Test
+ public void testLiteralNullWithMethod02() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null.method().a"));
+ }
+
+
+ @Test
+ public void testLiteralNullWithMethod03() {
+ ELProcessor processor = new ELProcessor();
+ Assert.assertNull(processor.eval("null.a.method()"));
+ }
+
+
+ @Test(expected = PropertyNotFoundException.class)
+ public void testLiteralNullWithPropertyAsLvalue() {
+ ELProcessor processor = new ELProcessor();
+ processor.setValue("null.prop", "a");
+ }
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 4c91ab620f..d910e8464c 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -240,6 +240,11 @@
Remove the loop variable after the ForEach and ForTokens tag plugins.
Pull request <pr>1158</pr> provided by Arturo Bernal. (markt)
</fix>
+ <fix>
+ Align evaluation of expressions with section 1.6 of the expression
+ language specification when <code>expr-a</code> is a literal
+ <code>null</code>. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]