// ignore a bridge method with the same signature that the overridden one has.
if (null != oldMethod && isBridge(m)
&& !Modifier.isPublic(oldMethod.getDeclaringClass().getModifiers())
- && !Modifier.isAbstract(oldMethod.getModifiers()) && !isOverloaded(i, methods))
+ && !Modifier.isAbstract(oldMethod.getModifiers()) && !isDuplicated(i, methods))
hash.put(key, oldMethod);
// check if visibility has been reduced
}
}
- private static boolean isOverloaded(int index, Method[] methods) {
+ private static boolean isDuplicated(int index, Method[] methods) {
String name = methods[index].getName();
for (int i = 0; i < methods.length; i++)
if (i != index)
- if (name.equals(methods[i].getName()))
+ if (name.equals(methods[i].getName()) && areParametersSame(methods[index], methods[i]))
return true;
return false;
}
-
+
+ private static boolean areParametersSame(Method method, Method targetMethod) {
+ Class<?>[] methodTypes = method.getParameterTypes();
+ Class<?>[] targetMethodTypes = targetMethod.getParameterTypes();
+ int i = -1;
+ if (methodTypes.length == targetMethodTypes.length) {
+ for (Class<?> clz : methodTypes) {
+ i++;
+
+ if (clz.equals(targetMethodTypes[i].getClass())) {
+ continue;
+ } else {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
private static final String HANDLER_GETTER_KEY
= HANDLER_GETTER + ":()";
package test.javassist.proxy;
-import junit.framework.TestCase;
-
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import javassist.util.proxy.MethodHandler;
import javassist.util.proxy.Proxy;
import javassist.util.proxy.ProxyFactory;
+import junit.framework.TestCase;
@SuppressWarnings({"rawtypes","unchecked"})
public class ProxySimpleTest extends TestCase {
protected void bar(int i) { result += "q"; }
public void baz(int i) { result += "r"; }
}
+
+
+ String value267;
+
+ public void testJIRA267() throws Exception {
+ Extended267 extended267 = new Extended267();
+ for (Method method: extended267.getClass().getMethods()) {
+ System.out.println(method.getName() + "::" + method.getModifiers() + ":" + method.getParameterCount() + ":" + method.isSynthetic() + ":" + method.isBridge());
+ }
+ ProxyFactory factory = new ProxyFactory();
+ factory.setSuperclass(Extended267.class);
+ Extended267 e = (Extended267)factory.create(null, null, new MethodHandler() {
+ @Override
+ public Object invoke(Object self, Method thisMethod,
+ Method proceed, Object[] args) throws Throwable {
+ value267 += thisMethod.getDeclaringClass().getName();
+ return proceed.invoke(self, args);
+ }
+ });
+
+ value267 = "";
+ assertEquals("base", e.base());
+ System.out.println(value267);
+ assertEquals(Extended267.class.getName(), value267);
+
+ value267 = "";
+ assertEquals("base2", e.base("2"));
+ System.out.println(value267);
+ assertEquals(Extended267.class.getName(), value267);
+
+ value267 = "";
+ assertEquals("extended22", e.base(2));
+ System.out.println(value267);
+ assertEquals(Extended267.class.getName(), value267);
+ }
+
+ private static abstract class Base267 {
+ public String base() { return "base"; }
+ public String base(String s) { return "base" + s; }
+ public String base(Integer i) { return "base" + i; }
+ }
+
+ public static class Extended267 extends Base267 {
+ public String base(Integer i) { return "extended" + i + i; }
+ }
+
}