This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 54468c9c1c Fix array exception generating error message after 
refactoring
54468c9c1c is described below

commit 54468c9c1c51b27c6a6bde3d4df75364803495ce
Author: remm <[email protected]>
AuthorDate: Fri Feb 6 15:59:57 2026 +0100

    Fix array exception generating error message after refactoring
    
    BZ69948, would throw an ArrayOutOfBoundsException instead of a
    PropertyNotFoundException.
    Based on PR#950 submitted by Jérôme Besnard.
---
 java/org/apache/el/parser/AstValue.java         |  9 +++-----
 test/org/apache/el/TestValueExpressionImpl.java | 29 +++++++++++++++++++++++++
 webapps/docs/changelog.xml                      |  6 +++++
 3 files changed, 38 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/el/parser/AstValue.java 
b/java/org/apache/el/parser/AstValue.java
index 222f16ac86..3de3ef10a9 100644
--- a/java/org/apache/el/parser/AstValue.java
+++ b/java/org/apache/el/parser/AstValue.java
@@ -87,33 +87,30 @@ public final class AstValue extends SimpleNode {
                 // Method call at end of expression
                 ctx.setPropertyResolved(false);
                 property = this.children[i].getValue(ctx);
-                i += 2;
-
                 if (property == null) {
                     throw new PropertyNotFoundException(
                             MessageFactory.get("error.unreachable.property", 
this.children[i].getImage()));
                 }
+                i += 2;
             } else if (i + 1 < propCount) {
                 // Object with property not at end of expression
                 property = this.children[i].getValue(ctx);
                 ctx.setPropertyResolved(false);
                 base = resolver.getValue(ctx, base, property);
                 i++;
-
             } else {
                 // Object with property at end of expression
                 ctx.setPropertyResolved(false);
                 property = this.children[i].getValue(ctx);
-                i++;
-
                 if (property == null) {
                     throw new PropertyNotFoundException(
                             MessageFactory.get("error.unreachable.property", 
this.children[i].getImage()));
                 }
+                i++;
             }
             if (base == null) {
                 throw new PropertyNotFoundException(
-                        MessageFactory.get("error.unreachable.property", 
this.children[i].getImage()));
+                        MessageFactory.get("error.unreachable.property", 
this.children[propCount - 1].getImage()));
             }
         }
 
diff --git a/test/org/apache/el/TestValueExpressionImpl.java 
b/test/org/apache/el/TestValueExpressionImpl.java
index de56634df4..fd3a789564 100644
--- a/test/org/apache/el/TestValueExpressionImpl.java
+++ b/test/org/apache/el/TestValueExpressionImpl.java
@@ -26,6 +26,7 @@ import java.util.Optional;
 import jakarta.el.ELBaseTest;
 import jakarta.el.ELContext;
 import jakarta.el.ExpressionFactory;
+import jakarta.el.PropertyNotFoundException;
 import jakarta.el.ValueExpression;
 import jakarta.el.ValueReference;
 
@@ -384,4 +385,32 @@ public class TestValueExpressionImpl extends ELBaseTest {
         Integer result = (Integer) ve.getValue(context);
         Assert.assertNull(result);
     }
+
+    @Test
+    public void testBug69948() {
+        ExpressionFactory factory = ExpressionFactory.newInstance();
+        ELContext context = new ELContextImpl();
+
+        TesterBeanEmptyMap beanEmptyMap = new TesterBeanEmptyMap();
+        TesterBeanA beanA = new TesterBeanA();
+        beanA.setName(null);
+
+        ValueExpression var = factory.createValueExpression(beanEmptyMap, 
TesterBeanEmptyMap.class);
+        context.getVariableMapper().setVariable("beanEmptyMap", var);
+        var = factory.createValueExpression(beanA, TesterBeanA.class);
+        context.getVariableMapper().setVariable("beanA", var);
+
+
+        ValueExpression ve = factory.createValueExpression(context, 
"${beanEmptyMap[beanA.name][beanA.name]}", Object.class);
+
+        Assert.assertThrows(PropertyNotFoundException.class, () -> 
ve.getValueReference(context));
+    }
+
+    public static class TesterBeanEmptyMap extends HashMap<Object, Map<String, 
Object>> {
+        private static final long serialVersionUID = 1L;
+        @Override
+        public Map<String, Object> get(Object key) {
+            return Collections.emptyMap();
+        }
+    }
 }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 31d3b736b0..b9fa6fcee6 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -266,6 +266,12 @@
         <code>java.util.Date</code>. (markt)
       </add>
       <!-- Entries for backport and removal before 12.0.0-M1 below this line 
-->
+      <fix>
+        <bug>69948</bug>: Avoid ArrayOutOfBoundsException instead of
+        PropertyNotFoundException when generating a properties not found
+        exception in AstValue. Based on <pr>950</pr> submitted by Jérôme
+        Besnard. (remm)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Cluster">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to