commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1037572 - in /commons/proper/lang/trunk/src: main/java/org/apache/commons/lang3/reflect/MemberUtils.java test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
Date Sun, 21 Nov 2010 22:09:05 GMT
Author: niallp
Date: Sun Nov 21 22:09:04 2010
New Revision: 1037572

URL: http://svn.apache.org/viewvc?rev=1037572&view=rev
Log:
BEANUTILS-381 getMatchingAccessibleMethod does not correctly handle inheritance and method
overloading - thanks to Todd Nine for the patch

Modified:
    commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java

Modified: commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java?rev=1037572&r1=1037571&r2=1037572&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
(original)
+++ commons/proper/lang/trunk/src/main/java/org/apache/commons/lang3/reflect/MemberUtils.java
Sun Nov 21 22:09:04 2010
@@ -136,7 +136,7 @@ abstract class MemberUtils {
             return getPrimitivePromotionCost(srcClass, destClass);
         }
         float cost = 0.0f;
-        while (destClass != null && !destClass.equals(srcClass)) {
+        while (srcClass != null && !destClass.equals(srcClass)) {
             if (destClass.isInterface() && ClassUtils.isAssignable(srcClass, destClass))
{
                 // slight penalty for interface match.
                 // we still want an exact match to override an interface match,
@@ -147,13 +147,13 @@ abstract class MemberUtils {
                 break;
             }
             cost++;
-            destClass = destClass.getSuperclass();
+            srcClass = srcClass.getSuperclass();
         }
         /*
          * If the destination class is null, we've travelled all the way up to
          * an Object match. We'll penalize this by adding 1.5 to the cost.
          */
-        if (destClass == null) {
+        if (srcClass == null) {
             cost += 1.5f;
         }
         return cost;

Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java?rev=1037572&r1=1037571&r2=1037572&view=diff
==============================================================================
--- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
(original)
+++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/reflect/MethodUtilsTest.java
Sun Nov 21 22:09:04 2010
@@ -296,6 +296,16 @@ public class MethodUtilsTest extends Tes
                 singletonArray(Double.class), singletonArray(Double.TYPE));
         expectMatchingAccessibleMethodParameterTypes(TestBean.class, "foo",
                 singletonArray(Double.TYPE), singletonArray(Double.TYPE));
+        expectMatchingAccessibleMethodParameterTypes(TestBean.class, "foo",
+                singletonArray(Double.TYPE), singletonArray(Double.TYPE));
+        expectMatchingAccessibleMethodParameterTypes(InheritanceBean.class, "testOne",
+                singletonArray(ParentObject.class), singletonArray(ParentObject.class));
+        expectMatchingAccessibleMethodParameterTypes(InheritanceBean.class, "testOne",
+                singletonArray(ChildObject.class), singletonArray(ParentObject.class));
+        expectMatchingAccessibleMethodParameterTypes(InheritanceBean.class, "testTwo",
+                singletonArray(ParentObject.class), singletonArray(GrandParentObject.class));
+        expectMatchingAccessibleMethodParameterTypes(InheritanceBean.class, "testTwo",
+                singletonArray(ChildObject.class), singletonArray(ChildInterface.class));
     }
 
     private void expectMatchingAccessibleMethodParameterTypes(Class<?> cls,
@@ -320,4 +330,17 @@ public class MethodUtilsTest extends Tes
         return result;
     }
 
+    public static class InheritanceBean {
+        public void testOne(Object obj) {}
+        public void testOne(GrandParentObject obj) {}
+        public void testOne(ParentObject obj) {}
+        public void testTwo(Object obj) {}
+        public void testTwo(GrandParentObject obj) {}
+        public void testTwo(ChildInterface obj) {}
+    }
+    interface ChildInterface {}
+    public static class GrandParentObject {}
+    public static class ParentObject extends GrandParentObject {}
+    public static class ChildObject extends ParentObject implements ChildInterface {}
+    
 }



Mime
View raw message