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

michaelo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/velocity-engine.git


The following commit(s) were added to refs/heads/master by this push:
     new 4b56a898 [VELOCITY-986] [BREAKING CHANGE] Map size method is called 
instead of provided size property
4b56a898 is described below

commit 4b56a898ec0f71968a591e5e264d09c81dff13b8
Author: Ravi Mergu <[email protected]>
AuthorDate: Thu Jul 24 00:30:00 2025 +0530

    [VELOCITY-986] [BREAKING CHANGE] Map size method is called instead of 
provided size property
    
    This closes #59
---
 .../runtime/parser/node/PropertyExecutor.java      |  5 ++++-
 .../apache/velocity/test/UberspectorTestCase.java  | 24 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git 
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
 
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
index 83f9c7ae..b81ced75 100644
--- 
a/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
+++ 
b/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/PropertyExecutor.java
@@ -26,6 +26,7 @@
 import org.slf4j.Logger;
 
 import java.lang.reflect.InvocationTargetException;
+import java.util.Map;
 
 /**
  * Returned the value of object property when executed.
@@ -120,7 +121,9 @@ protected void discover(final Class<?> clazz, final String 
property)
                 setMethod(introspector.getMethod(clazz, sb.toString(), 
params));
             }
 
-            if (!isAlive())
+            // Check if no valid method was found and
+            // the class is not a Map before trying record-style property 
access
+            if (!isAlive() && !Map.class.isAssignableFrom(clazz))
             {
                 /*
                  * If no JavaBean property was found, try the convention used 
by Java 16 records.
diff --git 
a/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java
 
b/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java
index a578a97a..24b7c1c2 100644
--- 
a/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java
+++ 
b/velocity-engine-core/src/test/java/org/apache/velocity/test/UberspectorTestCase.java
@@ -28,7 +28,9 @@
 import org.apache.velocity.util.introspection.VelPropertyGet;
 import org.apache.velocity.util.introspection.VelPropertySet;
 
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 
@@ -284,6 +286,28 @@ public void testDisambiguation()
         setter.invoke(uto, new HashMap());
     }
 
+    public void testMapDefaultMethods() throws Exception {
+        Map<String, Object> map = new HashMap<>();
+        List<Integer> list = new ArrayList<>();
+        list.add(1);
+        map.put("values", list);
+        map.put("size", "6Feet");
+
+        Uberspect u = ri.getUberspect();
+
+        VelPropertyGet valuesGetter = u.getPropertyGet(map, "values", null);
+        Object valuesObj = valuesGetter.invoke(map);
+        assertNotNull(valuesGetter);
+        assertTrue(valuesObj instanceof ArrayList);
+        assertEquals(list, valuesObj);
+
+        VelPropertyGet sizeGetter = u.getPropertyGet(map, "size", null);
+        Object sizeObj = sizeGetter.invoke(map);
+        assertNotNull(sizeGetter);
+        assertTrue(sizeObj instanceof String);
+        assertEquals("6Feet", sizeObj);
+    }
+
     /*
      *
      *    public void testMapGetSet()

Reply via email to