re PR libgcj/21785 (ClassNotFound during deserialization)
authorTom Tromey <tromey@redhat.com>
Wed, 1 Jun 2005 19:58:25 +0000 (19:58 +0000)
committerTom Tromey <tromey@gcc.gnu.org>
Wed, 1 Jun 2005 19:58:25 +0000 (19:58 +0000)
PR libgcj/21785:
* java/io/natObjectInputStream.cc (currentClassLoader): Removed.
(currentLoader): New method.
* java/io/ObjectInputStream.java (resolveProxyClass): Use
currentLoader.
(currentLoader): Now native.
(currentClassLoader): Removed.
* testsuite/libjava.lang/pr21785.java: New file.
* testsuite/libjava.lang/pr21785.out: New file.

From-SVN: r100462

libjava/ChangeLog
libjava/java/io/ObjectInputStream.java
libjava/java/io/natObjectInputStream.cc
libjava/testsuite/libjava.lang/pr21785.java [new file with mode: 0644]
libjava/testsuite/libjava.lang/pr21785.out [new file with mode: 0644]

index cddaecbd1d984042d365497f954c5d8b30c84a46..a22d52061c097c659f0bd60348f39e44edff9b69 100644 (file)
@@ -1,3 +1,15 @@
+2005-06-01  Tom Tromey  <tromey@redhat.com>
+
+       PR libgcj/21785:
+       * java/io/natObjectInputStream.cc (currentClassLoader): Removed.
+       (currentLoader): New method.
+       * java/io/ObjectInputStream.java (resolveProxyClass): Use
+       currentLoader.
+       (currentLoader): Now native.
+       (currentClassLoader): Removed.
+       * testsuite/libjava.lang/pr21785.java: New file.
+       * testsuite/libjava.lang/pr21785.out: New file.
+
 2005-06-01  Tom Tromey  <tromey@redhat.com>
 
        PR libgcj/21753:
index 2cfe4c99419bdfee8d00a9243de70cece540305c..0a97486d1bbdbd8ddfd3d8bdda4240ad6ea6e049 100644 (file)
@@ -783,21 +783,11 @@ public class ObjectInputStream extends InputStream
   }
 
   /**
-   * This method invokes the method currentClassLoader for the
-   * current security manager (or build an empty one if it is not
-   * present).
-   *
-   * @return The most recent non-system ClassLoader on the execution stack.
-   * @see java.lang.SecurityManager#currentClassLoader()
+   * Returns he most recent user defined ClassLoader on the execution stack
+   * or null of none is found.
    */
-  private ClassLoader currentLoader()
-  {
-    SecurityManager sm = System.getSecurityManager();
-    if (sm == null)
-      sm = new SecurityManager () {};
-    
-    return currentClassLoader(sm);
-  }
+  // GCJ LOCAL: native method.
+  private native ClassLoader currentLoader();
 
   /**
    * Lookup a class stored in the local hashtable. If it is not
@@ -883,12 +873,7 @@ public class ObjectInputStream extends InputStream
   protected Class resolveProxyClass(String[] intfs)
     throws IOException, ClassNotFoundException
   {
-    SecurityManager sm = System.getSecurityManager();
-    
-    if (sm == null)
-      sm = new SecurityManager() {};
-    
-    ClassLoader cl = currentClassLoader(sm);
+    ClassLoader cl = currentLoader();
     
     Class[] clss = new Class[intfs.length];
     if(cl == null)
@@ -1866,15 +1851,6 @@ public class ObjectInputStream extends InputStream
       }
   }
 
-  /**
-   * This native method is used to get access to the protected method
-   * of the same name in SecurityManger.
-   *
-   * @param sm SecurityManager instance which should be called.
-   * @return The current class loader in the calling stack.
-   */
-  private static native ClassLoader currentClassLoader (SecurityManager sm);
-
   private void callReadMethod (Method readObject, Class klass, Object obj)
     throws ClassNotFoundException, IOException
   {
index 0e0d5a719cc7d4409b90cf18163bb2cfc94d9c86..2d1a55665d1e1b6098a9bd61d68f844a40e95bb1 100644 (file)
@@ -1,6 +1,6 @@
 // natObjectInputStream.cc - Native part of ObjectInputStream class.
 
-/* Copyright (C) 1998, 1999, 2000, 2001  Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2005  Free Software Foundation
 
    This ObjectInputStream is part of libgcj.
 
@@ -24,6 +24,7 @@ details.  */
 #include <java/lang/SecurityManager.h>
 #include <java/lang/reflect/Constructor.h>
 #include <java/lang/reflect/Method.h>
+#include <java-stack.h>
 
 #ifdef DEBUG
 #include <java/lang/System.h>
@@ -69,9 +70,11 @@ java::io::ObjectInputStream::allocateObject (jclass klass, jclass,
   return obj;
 }
 
-java::lang::ClassLoader*
-java::io::ObjectInputStream::currentClassLoader (::java::lang::SecurityManager *sm)
+java::lang::ClassLoader *
+java::io::ObjectInputStream::currentLoader ()
 {
-  return sm->currentClassLoader ();
+  jclass caller = _Jv_StackTrace::GetCallingClass (&ObjectInputStream::class$);
+  if (caller)
+    return caller->getClassLoaderInternal();
+  return NULL;
 }
-
diff --git a/libjava/testsuite/libjava.lang/pr21785.java b/libjava/testsuite/libjava.lang/pr21785.java
new file mode 100644 (file)
index 0000000..7869754
--- /dev/null
@@ -0,0 +1,21 @@
+import java.io.*;
+
+public class pr21785 implements Serializable
+{
+  public static void main(String[] args)
+  {
+    try {
+      ByteArrayOutputStream outb = new ByteArrayOutputStream();
+      ObjectOutputStream outs = new ObjectOutputStream(outb);
+      outs.writeObject(new pr21785());
+      byte[] store = outb.toByteArray();
+
+      ByteArrayInputStream inb = new ByteArrayInputStream(store);
+      ObjectInputStream ins = new ObjectInputStream(inb);
+      ins.readObject();
+    }
+    catch (Throwable e) {
+      throw new Error(e);
+    }
+  }
+}
diff --git a/libjava/testsuite/libjava.lang/pr21785.out b/libjava/testsuite/libjava.lang/pr21785.out
new file mode 100644 (file)
index 0000000..e69de29