Index: test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java =================================================================== --- test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java (revision 446563) +++ test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java (working copy) @@ -22,6 +22,7 @@ import java.io.BufferedInputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.util.Vector; import junit.framework.Test; import junit.framework.TestCase; @@ -55,6 +56,45 @@ xml123bytes = byteout.toByteArray(); } + static class MockClassLoader extends ClassLoader { + public Class loadClass(String name) throws ClassNotFoundException { + throw new ClassNotFoundException(); + } + + protected Class findClass(String name) + throws ClassNotFoundException { + throw new ClassNotFoundException(); + } + + } + + public void testConstructor_ClassLoader() { + XMLDecoder dec; + final Vector exceptions = new Vector(); + + ExceptionListener el = new ExceptionListener() { + public void exceptionThrown(Exception e) { + exceptions.addElement(e); + } + }; + + dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this, + el, Thread.currentThread().getContextClassLoader()); + assertEquals(Integer.valueOf("1"), dec.readObject()); + assertEquals(0, exceptions.size()); + dec.close(); + + dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this, + el, new MockClassLoader()); + try { + dec.readObject(); + assertTrue(exceptions.size() > 0); + } catch (ArrayIndexOutOfBoundsException e) { + // also valid + } + dec.close(); + } + public void testClose() { XMLDecoder dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes)); assertEquals(Integer.valueOf("1"), dec.readObject());