commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1057013 - in /commons/proper/lang/branches/LANG_2_X/src: main/java/org/apache/commons/lang/reflect/MemberUtils.java test/java/org/apache/commons/lang/reflect/MethodUtilsTest.java
Date Sun, 09 Jan 2011 20:04:16 GMT
Author: niallp
Date: Sun Jan  9 20:04:16 2011
New Revision: 1057013

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

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

Modified: commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/reflect/MemberUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/reflect/MemberUtils.java?rev=1057013&r1=1057012&r2=1057013&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/reflect/MemberUtils.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/main/java/org/apache/commons/lang/reflect/MemberUtils.java
Sun Jan  9 20:04:16 2011
@@ -168,7 +168,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,
@@ -179,13 +179,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/branches/LANG_2_X/src/test/java/org/apache/commons/lang/reflect/MethodUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/reflect/MethodUtilsTest.java?rev=1057013&r1=1057012&r2=1057013&view=diff
==============================================================================
--- commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/reflect/MethodUtilsTest.java
(original)
+++ commons/proper/lang/branches/LANG_2_X/src/test/java/org/apache/commons/lang/reflect/MethodUtilsTest.java
Sun Jan  9 20:04:16 2011
@@ -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