aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main/javassist/util/proxy/ProxyFactory.java27
-rw-r--r--src/test/test/javassist/proxy/ProxySimpleTest.java49
2 files changed, 70 insertions, 6 deletions
diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java
index 072fb42c..da9e29c6 100644
--- a/src/main/javassist/util/proxy/ProxyFactory.java
+++ b/src/main/javassist/util/proxy/ProxyFactory.java
@@ -1190,7 +1190,7 @@ public class ProxyFactory {
// 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
@@ -1203,16 +1203,35 @@ public class ProxyFactory {
}
}
- 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 + ":()";
diff --git a/src/test/test/javassist/proxy/ProxySimpleTest.java b/src/test/test/javassist/proxy/ProxySimpleTest.java
index 212c15fa..76178a7e 100644
--- a/src/test/test/javassist/proxy/ProxySimpleTest.java
+++ b/src/test/test/javassist/proxy/ProxySimpleTest.java
@@ -1,7 +1,5 @@
package test.javassist.proxy;
-import junit.framework.TestCase;
-
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
@@ -13,6 +11,7 @@ import javassist.util.proxy.MethodFilter;
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 {
@@ -286,4 +285,50 @@ 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; }
+ }
+
}