diff options
author | chibash <chiba@javassist.org> | 2015-08-07 00:48:03 +0900 |
---|---|---|
committer | chibash <chiba@javassist.org> | 2015-08-07 00:48:03 +0900 |
commit | f7543857669ad5fff98d61a75a4f04d848ef4820 (patch) | |
tree | 55d6a962f0fc7045e1a1054567981641a11878ed | |
parent | af8aba0dd41ff5c72b63ba3770a829bffecdb7b4 (diff) | |
download | javassist-f7543857669ad5fff98d61a75a4f04d848ef4820.tar.gz javassist-f7543857669ad5fff98d61a75a4f04d848ef4820.zip |
fixed JASSIST-244
-rw-r--r-- | Readme.html | 6 | ||||
-rw-r--r-- | src/main/javassist/util/proxy/ProxyFactory.java | 23 | ||||
-rw-r--r-- | src/test/test/javassist/proxy/ProxySimpleTest.java | 41 | ||||
-rw-r--r-- | src/test/testproxy/ProxyTester.java | 4 |
4 files changed, 69 insertions, 5 deletions
diff --git a/Readme.html b/Readme.html index 22e5480d..c646c9a6 100644 --- a/Readme.html +++ b/Readme.html @@ -281,6 +281,12 @@ see javassist.Dump. <h2>Changes</h2> +<p>-version 3.21 +<ul> +<li>JIRA JASSIST-244 +</ul> +</p> + <p>-version 3.20 on June 25, 2015 <ul> <li>JIRA JASSIST-241, 242, 246. diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index 8c43fa65..57c280af 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -1146,17 +1146,24 @@ public class ProxyFactory { for (int i = 0; i < methods.length; i++) if (!Modifier.isPrivate(methods[i].getModifiers())) { Method m = methods[i]; - String key = m.getName() + ':' + RuntimeSupport.makeDescriptor(m); // see keyToDesc(). + String key = m.getName() + ':' + RuntimeSupport.makeDescriptor(m); // see keyToDesc(). if (key.startsWith(HANDLER_GETTER_KEY)) hasGetHandler = true; // JIRA JASSIST-85 // put the method to the cache, retrieve previous definition (if any) - Method oldMethod = (Method)hash.put(key, methods[i]); + Method oldMethod = (Method)hash.put(key, m); + + // JIRA JASSIST-244 + // 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)) + hash.put(key, oldMethod); // check if visibility has been reduced if (null != oldMethod && Modifier.isPublic(oldMethod.getModifiers()) - && !Modifier.isPublic(methods[i].getModifiers()) ) { + && !Modifier.isPublic(m.getModifiers()) ) { // we tried to overwrite a public definition with a non-public definition, // use the old definition instead. hash.put(key, oldMethod); @@ -1164,6 +1171,16 @@ public class ProxyFactory { } } + private static boolean isOverloaded(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())) + 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 cab62397..f37e7b8c 100644 --- a/src/test/test/javassist/proxy/ProxySimpleTest.java +++ b/src/test/test/javassist/proxy/ProxySimpleTest.java @@ -99,4 +99,45 @@ public class ProxySimpleTest extends TestCase { public static class WriteReplace2 implements Serializable { public Object writeReplace(int i) { return new Integer(i); } } + + String value244; + + public void testJIRA244() throws Exception { + ProxyFactory factory = new ProxyFactory(); + factory.setSuperclass(Extended244.class); + Extended244 e = (Extended244)factory.create(null, null, new MethodHandler() { + @Override + public Object invoke(Object self, Method thisMethod, + Method proceed, Object[] args) throws Throwable { + value244 += thisMethod.getDeclaringClass().getName(); + return proceed.invoke(self); + } + }); + + value244 = ""; + assertEquals("base", e.base()); + System.out.println(value244); + assertEquals(Extended244.class.getName(), value244); + + value244 = ""; + assertEquals("ext", e.extended()); + System.out.println(value244); + assertEquals(Extended244.class.getName(), value244); + + value244 = ""; + assertEquals("base2ext2", e.base2()); + System.out.println(value244); + assertEquals(Extended244.class.getName(), value244); + } + + // if Base244 is private, then Extended244 has a bridge method for base(). + private static abstract class Base244 { + public String base() { return "base"; } + public String base2() { return "base2"; } + } + + public static class Extended244 extends Base244 { + public String extended() { return "ext"; } + public String base2() { return super.base2() + "ext2"; } + } } diff --git a/src/test/testproxy/ProxyTester.java b/src/test/testproxy/ProxyTester.java index 6d5559b6..e06848f8 100644 --- a/src/test/testproxy/ProxyTester.java +++ b/src/test/testproxy/ProxyTester.java @@ -399,7 +399,7 @@ public class ProxyTester extends TestCase { public static void testJIRA189() throws Exception {
Class persistentClass = Target189.PublishedArticle.class;
ProxyFactory factory = new ProxyFactory();
- factory.writeDirectory = ".";
+ // factory.writeDirectory = ".";
factory.setUseCache(false);
factory.setSuperclass(persistentClass);
factory.setInterfaces(new Class[] { Target189.TestProxy.class });
@@ -417,7 +417,7 @@ public class ProxyTester extends TestCase { public void testJIRA127() throws Exception {
ProxyFactory proxyFactory = new ProxyFactory();
- proxyFactory.writeDirectory = ".";
+ // proxyFactory.writeDirectory = ".";
proxyFactory.setInterfaces(new Class[]{ Target127.Sub.class });
Target127.Sub proxy = (Target127.Sub)proxyFactory.create(new Class[0], new Object[0], new MethodHandler() {
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
|