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 d7dd91963a Fix literal null handling with [] and . operators
d7dd91963a is described below

commit d7dd91963a7e581f52b4a3a57a6023f48e876b3b
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 52e96b5031..f666c1909b 100644
--- a/java/org/apache/el/parser/AstValue.java
+++ b/java/org/apache/el/parser/AstValue.java
@@ -133,7 +133,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)) {
                 AstMethodParameters mps = (AstMethodParameters) 
this.children[i + 1];
@@ -158,6 +162,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 e474905fc0..24b14b1b63 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]

Reply via email to