Index: src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java =================================================================== --- src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java (revision 488679) +++ src/test/api/java/org/apache/harmony/security/tests/java/security/SecureClassLoader2Test.java (working copy) @@ -20,6 +20,8 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; +import java.net.URL; +import java.security.CodeSigner; import java.security.CodeSource; import java.security.PermissionCollection; import java.security.ProtectionDomain; @@ -75,4 +77,28 @@ assertNotNull("Expected dynamic policy", pd.getClassLoader()); assertNull("Expected null permissions", pd.getPermissions()); } + + /** + * @tests java.security.SecureClassLoader#defineClass(String, byte[], int, int, java.security.CodeSource) + * Tests if defineClass throws IndexOutOfBoundsException if len is greater then byte array length. + */ + public static void test_defineClass_WrongLen() { + // Regression test for HARMONY-1147 + class TestSecureClassLoader extends SecureClassLoader { + public void defineClass1 (String name, byte[] array, int off, int len, CodeSource cs) { + defineClass(name, array, off, len, cs); + } + } + + try { + CodeSource lcs = new CodeSource(new URL(new URL("http://www.foo.com"), "0"), + new CodeSigner[192]); + new TestSecureClassLoader().defineClass1((String) null, new byte[]{2,2}, 0, 127, lcs); + fail("No exceptions thrown, while IndexOutOfBoundException was expected"); + } catch (IndexOutOfBoundsException ioobe) { + // passed + } catch (Exception ex) { + fail("Wrong exception thrown: " + ex + " instead of expected IndexOutOfBoundException"); + } + } } \ No newline at end of file