Browse Source

fixed JASSIST-267

tags/rel_3_24_0_rc
NingZhang-Ericsson 5 years ago
parent
commit
fd1d535bb3

+ 23
- 4
src/main/javassist/util/proxy/ProxyFactory.java View File

@@ -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 + ":()";


+ 47
- 2
src/test/test/javassist/proxy/ProxySimpleTest.java View File

@@ -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; }
}
}

Loading…
Cancel
Save