[jboss-cvs] javassist SVN: r588 - in trunk: src/main/javassist/util/proxy and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Aug 21 11:46:38 EDT 2011


Author: chiba
Date: 2011-08-21 11:46:37 -0400 (Sun, 21 Aug 2011)
New Revision: 588

Modified:
   trunk/Readme.html
   trunk/src/main/javassist/util/proxy/ProxyFactory.java
   trunk/src/main/javassist/util/proxy/RuntimeSupport.java
Log:
fixed JASSIST-127

Modified: trunk/Readme.html
===================================================================
--- trunk/Readme.html	2011-07-08 09:37:05 UTC (rev 587)
+++ trunk/Readme.html	2011-08-21 15:46:37 UTC (rev 588)
@@ -281,10 +281,15 @@
 
 <h2>Changes</h2>
 
+<p>-version 3.16
+<ul>
+	<li>JIRA JASSIST-127
+</ul>
+
 <p>-version 3.15 on July 8, 2011
 <ul>
    	<li>The license was changed to MPL/LGPL/Apache triple.
-   	<li>JIRA JASSIST-138 was fixed.
+   	<li>JIRA JASSIST-138 and 142 were fixed.
 </ul>
 
 <p>-version 3.14 on October 5, 2010

Modified: trunk/src/main/javassist/util/proxy/ProxyFactory.java
===================================================================
--- trunk/src/main/javassist/util/proxy/ProxyFactory.java	2011-07-08 09:37:05 UTC (rev 587)
+++ trunk/src/main/javassist/util/proxy/ProxyFactory.java	2011-08-21 15:46:37 UTC (rev 588)
@@ -912,7 +912,7 @@
             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 @@
 
     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 @@
             }
     }
 
-    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,

Modified: trunk/src/main/javassist/util/proxy/RuntimeSupport.java
===================================================================
--- trunk/src/main/javassist/util/proxy/RuntimeSupport.java	2011-07-08 09:37:05 UTC (rev 587)
+++ trunk/src/main/javassist/util/proxy/RuntimeSupport.java	2011-08-21 15:46:37 UTC (rev 588)
@@ -155,6 +155,20 @@
             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();
     }



More information about the jboss-cvs-commits mailing list