[aspectwerkz-dev] MethodComparator.compareMethodInfo throws exception

Niklas Therning <[email protected]> Wed, 08 Dec 2004 11:39:30 +0100
Newsgroups gmane.comp.java.aspectwerkz.devel
Message-ID <[email protected]>
I just upgraded from RC1 to the latest CVS. Now when I run my app I get 
a java.lang.Error in MethodComparator.compareMethodInfo(). I've found 
that it happens when the methods of net.sf.cglib.proxy.Factory are 
sorted. This interface has two methods of the same name and the same 
number of args but different arg types. The following test code can be 
used to reproduce this:

import org.codehaus.aspectwerkz.reflect.ClassInfoHelper;
import org.codehaus.aspectwerkz.reflect.impl.asm.AsmClassInfo;

public class Test {
    public static interface TestInterface {
        void test(String s);
        void test(String[] s);
    }
   
    public static void main(String[] args) {
        ClassInfoHelper.createSortedMethodList(
                AsmClassInfo.getClassInfo(TestInterface.class.getName(),
                        Test.class.getClassLoader()));
    }
}

I've had a look at MethodComparator.compareMethodInfo() and I think the 
for loop at the end of that method should be changed from

for (int i = 0; i < args1.length; i++) {
    if (args1[i].getName().equals(args2[i].getName())) {
        return 0;
    }
}

to something like

for (int i = 0; i < args1.length; i++) {
    int c = args1[i].getName().compareTo(args2[i].getName());
    if (c != 0) {
        return c;
    }
}

/Niklas