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

markt 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 7690caf7dc Address CI failures for potentially ambiguous bean methods.
7690caf7dc is described below

commit 7690caf7dcc5a4c4e9306f38c3d181aa0880f416
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Mar 31 00:36:06 2023 +0100

    Address CI failures for potentially ambiguous bean methods.
---
 java/jakarta/el/BeanSupportStandalone.java | 22 ++++++++++++++++++++++
 test/jakarta/el/TestBeanSupport.java       | 23 +++++++++++++++++------
 2 files changed, 39 insertions(+), 6 deletions(-)

diff --git a/java/jakarta/el/BeanSupportStandalone.java 
b/java/jakarta/el/BeanSupportStandalone.java
index a2531451d2..0414261359 100644
--- a/java/jakarta/el/BeanSupportStandalone.java
+++ b/java/jakarta/el/BeanSupportStandalone.java
@@ -19,6 +19,7 @@ package jakarta.el;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -32,6 +33,15 @@ import jakarta.el.BeanELResolver.BeanProperty;
  */
 class BeanSupportStandalone extends BeanSupport {
 
+    /*
+     * The full JavaBeans implementation has a much more detailed definition 
of method order that applies to an entire
+     * class. When ordering write methods for a single property, a much 
simpler comparator can be used because it is
+     * known that the method names are the same, the return parameters are 
both void and the methods only have a single
+     * parameter.
+     */
+    private static final Comparator<Method> WRITE_METHOD_COMPARATOR =
+            Comparator.comparing(m -> m.getParameterTypes()[0].getName());
+
     @Override
     BeanProperties getBeanProperties(Class<?> type) {
         return new BeanPropertiesStandalone(type);
@@ -133,6 +143,9 @@ class BeanSupportStandalone extends BeanSupport {
                 if (readMethod != null) {
                     type = readMethod.getReturnType();
                 } else {
+                    if (writeMethods.size() > 1) {
+                        writeMethods.sort(WRITE_METHOD_COMPARATOR);
+                    }
                     type = writeMethods.get(0).getParameterTypes()[0];
                 }
                 for (Method candidate : writeMethods) {
@@ -214,4 +227,13 @@ class BeanSupportStandalone extends BeanSupport {
             return writeMethod;
         }
     }
+
+
+    static final class WriteMethodComparator implements Comparator<Method> {
+
+        @Override
+        public int compare(Method m1, Method m2) {
+            return 0;
+        }
+    }
 }
diff --git a/test/jakarta/el/TestBeanSupport.java 
b/test/jakarta/el/TestBeanSupport.java
index 0807a90dce..e5185a530f 100644
--- a/test/jakarta/el/TestBeanSupport.java
+++ b/test/jakarta/el/TestBeanSupport.java
@@ -74,12 +74,14 @@ public class TestBeanSupport extends ELBaseTest {
         doTest(MismatchBean.class, "value", TypeA.class, TypeA.class, null);
     }
 
-    /*
-     * The first setter found "wins".
-     */
     @Test
-    public void testAmbiguousBean() {
-        doTest(AmbiguousBean.class, "value", TypeA.class, null, TypeA.class);
+    public void testAmbiguousBean01() {
+        doTest(AmbiguousBean01.class, "value", TypeA.class, null, TypeA.class);
+    }
+
+    @Test
+    public void testAmbiguousBean02() {
+        doTest(AmbiguousBean02.class, "value", TypeA.class, null, TypeA.class);
     }
 
 
@@ -222,7 +224,7 @@ public class TestBeanSupport extends ELBaseTest {
     }
 
 
-    public static class AmbiguousBean {
+    public static class AmbiguousBean01 {
         public void setValue(@SuppressWarnings("unused") TypeA value) {
         }
 
@@ -231,6 +233,15 @@ public class TestBeanSupport extends ELBaseTest {
     }
 
 
+    public static class AmbiguousBean02 {
+        public void setValue(@SuppressWarnings("unused") String value) {
+        }
+
+        public void setValue(@SuppressWarnings("unused") TypeA value) {
+        }
+    }
+
+
     public static class TypeA {
     }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to