aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2011-08-21 15:46:37 +0000
committerchiba <chiba@30ef5769-5b8d-40dd-aea6-55b5d6557bb3>2011-08-21 15:46:37 +0000
commit76a1cba9c433e8242bb6648e72b3ed43c7a4995a (patch)
treefe389e08b5e5af9355be800e10d01a1d9dd976b5 /src
parentdfc5f7b442d82bd527dac6506c9811cd417849a0 (diff)
downloadjavassist-76a1cba9c433e8242bb6648e72b3ed43c7a4995a.tar.gz
javassist-76a1cba9c433e8242bb6648e72b3ed43c7a4995a.zip
fixed JASSIST-127
git-svn-id: http://anonsvn.jboss.org/repos/javassist/trunk@588 30ef5769-5b8d-40dd-aea6-55b5d6557bb3
Diffstat (limited to 'src')
-rw-r--r--src/main/javassist/util/proxy/ProxyFactory.java26
-rw-r--r--src/main/javassist/util/proxy/RuntimeSupport.java14
2 files changed, 31 insertions, 9 deletions
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();
}