From 76a1cba9c433e8242bb6648e72b3ed43c7a4995a Mon Sep 17 00:00:00 2001 From: chiba Date: Sun, 21 Aug 2011 15:46:37 +0000 Subject: [PATCH] fixed JASSIST-127 git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@588 30ef5769-5b8d-40dd-aea6-55b5d6557bb3 --- Readme.html | 7 ++++- .../javassist/util/proxy/ProxyFactory.java | 26 ++++++++++++------- .../javassist/util/proxy/RuntimeSupport.java | 14 ++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/Readme.html b/Readme.html index 2e875a21..07908f5b 100644 --- a/Readme.html +++ b/Readme.html @@ -281,10 +281,15 @@ see javassist.Dump.

Changes

+

-version 3.16 +

+

-version 3.15 on July 8, 2011

-version 3.14 on October 5, 2010 diff --git a/src/main/javassist/util/proxy/ProxyFactory.java b/src/main/javassist/util/proxy/ProxyFactory.java index 2f0f07e0..721f58c8 100644 --- a/src/main/javassist/util/proxy/ProxyFactory.java +++ b/src/main/javassist/util/proxy/ProxyFactory.java @@ -912,7 +912,7 @@ public class ProxyFactory { int mod = meth.getModifiers(); if (testBit(signature, index)) { override(className, meth, prefix, index, - keyToDesc(key), cf, cp); + keyToDesc(key, meth), cf, cp); } index++; } @@ -1013,27 +1013,34 @@ public class ProxyFactory { private static HashMap getMethods(Class superClass, Class[] interfaceTypes) { HashMap hash = new HashMap(); + HashSet set = new HashSet(); for (int i = 0; i < interfaceTypes.length; i++) - getMethods(hash, interfaceTypes[i]); + getMethods(hash, interfaceTypes[i], set); - getMethods(hash, superClass); + getMethods(hash, superClass, set); return hash; } - private static void getMethods(HashMap hash, Class clazz) { + private static void getMethods(HashMap hash, Class clazz, Set visitedClasses) { + // This both speeds up scanning by avoiding duplicate interfaces and is needed to + // ensure that superinterfaces are always scanned before subinterfaces. + if (!visitedClasses.add(clazz)) + return; + Class[] ifs = clazz.getInterfaces(); for (int i = 0; i < ifs.length; i++) - getMethods(hash, ifs[i]); + getMethods(hash, ifs[i], visitedClasses); Class parent = clazz.getSuperclass(); if (parent != null) - getMethods(hash, parent); + getMethods(hash, parent, visitedClasses); Method[] methods = SecurityActions.getDeclaredMethods(clazz); 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); + // JIRA JASSIST-127 (covariant return types). + String key = m.getName() + ':' + RuntimeSupport.makeDescriptor(m.getParameterTypes(), null); // JIRA JASSIST-85 // put the method to the cache, retrieve previous definition (if any) Method oldMethod = (Method)hash.put(key, methods[i]); @@ -1048,8 +1055,9 @@ public class ProxyFactory { } } - private static String keyToDesc(String key) { - return key.substring(key.indexOf(':') + 1); + private static String keyToDesc(String key, Method m) { + String params = key.substring(key.indexOf(':') + 1); + return RuntimeSupport.makeDescriptor(params, m.getReturnType()); } private static MethodInfo makeConstructor(String thisClassName, Constructor cons, diff --git a/src/main/javassist/util/proxy/RuntimeSupport.java b/src/main/javassist/util/proxy/RuntimeSupport.java index 3d8d5b72..c11c72d8 100644 --- a/src/main/javassist/util/proxy/RuntimeSupport.java +++ b/src/main/javassist/util/proxy/RuntimeSupport.java @@ -155,6 +155,20 @@ public class RuntimeSupport { makeDesc(sbuf, params[i]); sbuf.append(')'); + if (retType != null) + makeDesc(sbuf, retType); + + return sbuf.toString(); + } + + /** + * Makes a descriptor for a given method. + * + * @param params the descriptor of parameter types. + * @param retType return type. + */ + public static String makeDescriptor(String params, Class retType) { + StringBuffer sbuf = new StringBuffer(params); makeDesc(sbuf, retType); return sbuf.toString(); } -- 2.39.5