Index: src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java =================================================================== --- src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java (revision 452881) +++ src/test/api/java/org/apache/harmony/rmi/MarshalledObjectTest.java (working copy) @@ -24,6 +24,7 @@ import java.rmi.MarshalledObject; +import java.io.Serializable; import java.util.Hashtable; import junit.framework.Test; @@ -93,6 +94,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. @@ -110,4 +157,11 @@ public static void main(String args[]) { junit.textui.TestRunner.run(suite()); } + + + /** + * Auxilary empty class. + */ + static class TestClass implements Serializable { + } }