Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 65941 invoked from network); 21 Nov 2010 22:09:49 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Nov 2010 22:09:49 -0000 Received: (qmail 22458 invoked by uid 500); 21 Nov 2010 22:10:20 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 22403 invoked by uid 500); 21 Nov 2010 22:10:19 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 22396 invoked by uid 99); 21 Nov 2010 22:10:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Nov 2010 22:10:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 21 Nov 2010 22:10:19 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3C20323889DA; Sun, 21 Nov 2010 22:09:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@commons.apache.org From: niallp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101121220905.3C20323889DA@eris.apache.org> 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 {} + }