This patch fixes the RMI bug 25520 (the user class is not found by the RMI server). The user class is not found because there is no user class loader on the stack of that thread. It can only be loaded by the loader, returned from the Thread.currentClassLoader().

I think, there is no harm to return the thread current class loader rather than null from the VMObjectInputStream.currentClassLoader. The system class loader will be the parent class of this class loader anyway.

2006-01-27  Audrius Meskauskas  <[EMAIL PROTECTED]>

   * java/io/VMObjectInputStream.java (loaderAction.run):
   If no user class loaders found on the stack, return the thread
   context class loader. (currentClassLoader): Explained.



Index: VMObjectInputStream.java
===================================================================
RCS file: /sources/classpath/classpath/vm/reference/java/io/VMObjectInputStream.java,v
retrieving revision 1.4
diff -u -r1.4 VMObjectInputStream.java
--- VMObjectInputStream.java	9 Sep 2005 12:12:03 -0000	1.4
+++ VMObjectInputStream.java	27 Jan 2006 16:17:13 -0000
@@ -55,25 +55,36 @@
       }
   }
 
-  // PrivilegedAction needed for Class.getClassLoader()
+  /**
+   * PrivilegedAction needed for Class.getClassLoader()
+   */ 
   private static PrivilegedAction loaderAction = new PrivilegedAction()
+  {
+   /**
+     * Returns the first user defined class loader on the call stack, or the
+     * context class loader of the current thread, when no non-null class loader
+     * was found.
+     */
+    public Object run()
     {
-      public Object run()
-      {
-	Class[] ctx = VMStackWalker.getClassContext();
-	for (int i = 0; i < ctx.length; i++)
-	  {
-	    ClassLoader cl = ctx[i].getClassLoader();
-	    if (cl != null)
-	      return cl;
-	  }
-	return null;
-      }
+      Class[] ctx = VMStackWalker.getClassContext();
+
+      for (int i = 0; i < ctx.length; i++)
+        {
+          ClassLoader cl = ctx[i].getClassLoader();
+          if (cl != null)
+            return cl;
+        }
+      return Thread.currentThread().getContextClassLoader();
+    }
     };
 
   /**
-   * Returns the first user defined class loader on the call stack, or
-   * null when no non-null class loader was found.
+   * Returns the first user defined class loader on the call stack, or the
+   * context class loader of the current thread, when no non-null class loader
+   * was found.
+   * 
+   * @return the class loader
    */
   static ClassLoader currentClassLoader()
   {

Reply via email to