harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a...@apache.org
Subject svn commit: r487594 - in /harmony/enhanced/classlib/trunk/modules/rmi/src: main/java/org/apache/harmony/rmi/remoteref/ main/java/org/apache/harmony/rmi/transport/ test/api/java/org/apache/harmony/rmi/
Date Fri, 15 Dec 2006 16:45:13 GMT
Author: ayza
Date: Fri Dec 15 08:45:12 2006
New Revision: 487594

URL: http://svn.apache.org/viewvc?view=rev&rev=487594
Log:
Patches from HARMONY-1967 ( [classlib][rmi] RMI runtime could not load class with null thread
context classloader) were applied.

Modified:
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastRef.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastServerRef.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/transport/RMIObjectInputStream.java
    harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastRef.java?view=diff&rev=487594&r1=487593&r2=487594
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastRef.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastRef.java
Fri Dec 15 08:45:12 2006
@@ -158,7 +158,7 @@
                         (RMIObjectInputStream) call.getInputStream();
 
                 try {
-                    toReturn = oin.readRMIObject(m.getReturnType(), null);
+                    toReturn = oin.readRMIObject(m.getReturnType());
                 } catch (IOException ioe) {
                     // rmi.70=IOException occured while unmarshalling return value
                     throw new UnmarshalException(Messages.getString("rmi.70"), ioe); //$NON-NLS-1$

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastServerRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastServerRef.java?view=diff&rev=487594&r1=487593&r2=487594
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastServerRef.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/remoteref/UnicastServerRef.java
Fri Dec 15 08:45:12 2006
@@ -543,8 +543,7 @@
 
         try {
             for (int i = 0; i < paramTypes.length; ++i) {
-                params[i] = oin.readRMIObject(paramTypes[i],
-                        paramTypes[i].getClassLoader());
+                params[i] = oin.readRMIObject(paramTypes[i]);
             }
         } catch (RemoteException re) {
             // rmi.69=RemoteException occured while unmarshalling arguments

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/transport/RMIObjectInputStream.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/transport/RMIObjectInputStream.java?view=diff&rev=487594&r1=487593&r2=487594
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/transport/RMIObjectInputStream.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/main/java/org/apache/harmony/rmi/transport/RMIObjectInputStream.java
Fri Dec 15 08:45:12 2006
@@ -34,6 +34,8 @@
 import org.apache.harmony.rmi.common.RMIProperties;
 import org.apache.harmony.rmi.internal.nls.Messages;
 
+import org.apache.harmony.kernel.vm.VM;
+
 
 /**
  * The RMIObjectInputStream is a subclass of ObjectInputStream performing
@@ -47,9 +49,6 @@
     // Annotations for serialized objects.
     private ObjectInputStream locStream;
 
-    // ClassLoader which will be used for classes resolving
-    private ClassLoader defaultLoader = null;
-
     // True if this stream was created for handling a RemoteCall
     private boolean isRCallStream = false;
 
@@ -120,7 +119,7 @@
             annot = null;
         }
         Class cl = RMIClassLoader.loadClass(annot, streamCl.getName(),
-                defaultLoader);
+                VM.getNonBootstrapClassLoader());
         return cl;
     }
 
@@ -141,7 +140,8 @@
         if (useCodebaseOnly) {
             annot = null;
         }
-        Class cl = RMIClassLoader.loadProxyClass(annot, interf, defaultLoader);
+        Class cl = RMIClassLoader.loadProxyClass(annot, interf,
+                VM.getNonBootstrapClassLoader());
         return cl;
     }
 
@@ -169,39 +169,33 @@
      * @throws ClassNotFoundException if class of a serialized object
      *         could not be found
      */
-    public synchronized Object readRMIObject(Class cl, ClassLoader loader)
+    public synchronized Object readRMIObject(Class cl)
             throws IOException, ClassNotFoundException {
-        defaultLoader = loader;
-
-        try {
-            if (cl.isPrimitive()) {
-                if (cl == Boolean.TYPE) {
-                    return new Boolean(readBoolean());
-                } else if (cl == Byte.TYPE) {
-                    return new Byte(readByte());
-                } else if (cl == Short.TYPE) {
-                    return new Short(readShort());
-                } else if (cl == Integer.TYPE) {
-                    return new Integer(readInt());
-                } else if (cl == Long.TYPE) {
-                    return new Long(readLong());
-                } else if (cl == Float.TYPE) {
-                    return new Float(readFloat());
-                } else if (cl == Double.TYPE) {
-                    return new Double(readDouble());
-                } else if (cl == Character.TYPE) {
-                    return new Character(readChar());
-                } else if (cl == Void.TYPE) {
-                    return null;
-                } else {
-                    // rmi.7F=Unknown primitive class: {0}
-                    throw new IOException(Messages.getString("rmi.7F", cl)); //$NON-NLS-1$
-                }
+        if (cl.isPrimitive()) {
+            if (cl == Boolean.TYPE) {
+                return new Boolean(readBoolean());
+            } else if (cl == Byte.TYPE) {
+                return new Byte(readByte());
+            } else if (cl == Short.TYPE) {
+                return new Short(readShort());
+            } else if (cl == Integer.TYPE) {
+                return new Integer(readInt());
+            } else if (cl == Long.TYPE) {
+                return new Long(readLong());
+            } else if (cl == Float.TYPE) {
+                return new Float(readFloat());
+            } else if (cl == Double.TYPE) {
+                return new Double(readDouble());
+            } else if (cl == Character.TYPE) {
+                return new Character(readChar());
+            } else if (cl == Void.TYPE) {
+                return null;
             } else {
-                return readObject();
+                // rmi.7F=Unknown primitive class: {0}
+                throw new IOException(Messages.getString("rmi.7F", cl)); //$NON-NLS-1$
             }
-        } finally {
-            defaultLoader = null;
+        } else {
+            return readObject();
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java?view=diff&rev=487594&r1=487593&r2=487594
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/rmi/src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java
Fri Dec 15 08:45:12 2006
@@ -24,6 +24,7 @@
 
 import java.rmi.MarshalledObject;
 
+import java.io.Serializable;
 import java.util.Hashtable;
 
 import junit.framework.Test;
@@ -80,10 +81,11 @@
      *          If some error occurs.
      */
     public void testGet() throws Exception {
-        assertNull(new MarshalledObject(null).get());
+        Hashtable ht = new Hashtable();
         String str = new String("TEST");
+
+        assertNull(new MarshalledObject(null).get());
         assertEquals(str, new MarshalledObject(str).get());
-        Hashtable ht = new Hashtable();
         ht.put(new Integer(1), str);
         ht.put(new Integer(2), "TEST1");
         MarshalledObject mo = new MarshalledObject(ht);
@@ -93,6 +95,52 @@
     }
 
     /**
+     * Tests if RMI runtime is able to load classes if thread context classloader
+     * is null (regression test for HARMONY-1967)
+     */
+    public void testNullLoader() throws Exception {
+        ClassLoader old_cl = Thread.currentThread().getContextClassLoader();
+
+        try {
+            MarshalledObject mo = new MarshalledObject(new TestClass());
+            Object obj = null;
+
+            // 1-st get: thread context classloader is equal to system classloader
+            try {
+                obj = mo.get();
+
+                if (obj.getClass().getClassLoader() != old_cl) {
+                    fail("1-st get failed: loaded through: "
+                            + obj.getClass().getClassLoader() + ", expected: " + old_cl);
+            } else {
+                System.out.println("1-st get passed.");
+            }
+            } catch (Exception ex) {
+                fail("1-st get failed: " + ex);
+            }
+
+            // 2-nd get: thread context classloader is equal to null
+            Thread.currentThread().setContextClassLoader(null);
+
+            try {
+                obj = mo.get();
+
+                if (obj.getClass().getClassLoader() != old_cl) {
+                    fail("2-nd get failed: loaded through: "
+                            + obj.getClass().getClassLoader() + ", expected: " + old_cl);
+                } else {
+                    System.out.println("2-nd get passed.");
+                }
+            } catch (Exception ex) {
+                fail("2-nd get failed: " + ex);
+            }
+        } finally {
+            // restore thread context classloader
+            Thread.currentThread().setContextClassLoader(old_cl);
+        }
+    }
+
+    /**
      * Returns test suite for this class.
      *
      * @return  Test suite for this class.
@@ -109,5 +157,12 @@
      */
     public static void main(String args[]) {
         junit.textui.TestRunner.run(suite());
+    }
+
+
+    /**
+     * Auxilary empty class.
+     */
+    static class TestClass implements Serializable {
     }
 }



Mime
View raw message