17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary Verifies the behaviour of Unsafe.defineClass
27 * @library /test/lib
28 * @modules java.base/jdk.internal.misc
29 * java.compiler
30 * java.management
31 * @run main DefineClass
32 */
33
34 import java.security.ProtectionDomain;
35 import java.io.InputStream;
36 import jdk.test.lib.InMemoryJavaCompiler;
37 import jdk.test.lib.unsafe.UnsafeHelper;
38 import jdk.internal.misc.Unsafe;
39 import static jdk.test.lib.Asserts.*;
40
41 public class DefineClass {
42 public static void main(String args[]) throws Exception {
43 Unsafe unsafe = UnsafeHelper.getUnsafe();
44 TestClassLoader classloader = new TestClassLoader();
45 ProtectionDomain pd = new ProtectionDomain(null, null);
46
47 byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }");
48
49 // Invalid class data
50 try {
51 unsafe.defineClass(null, klassbuf, 4, klassbuf.length - 4, classloader, pd);
52 throw new RuntimeException("defineClass did not throw expected ClassFormatError");
53 } catch (ClassFormatError e) {
54 // Expected
55 }
56
57 // Negative offset
58 try {
59 unsafe.defineClass(null, klassbuf, -1, klassbuf.length, classloader, pd);
60 throw new RuntimeException("defineClass did not throw expected IndexOutOfBoundsException");
61 } catch (IndexOutOfBoundsException e) {
62 // Expected
63 }
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @summary Verifies the behaviour of Unsafe.defineClass
27 * @library /test/lib
28 * @modules java.base/jdk.internal.misc
29 * java.compiler
30 * java.management
31 * @run main DefineClass
32 */
33
34 import java.security.ProtectionDomain;
35 import java.io.InputStream;
36 import jdk.test.lib.InMemoryJavaCompiler;
37 import jdk.internal.misc.Unsafe;
38 import static jdk.test.lib.Asserts.*;
39
40 public class DefineClass {
41 public static void main(String args[]) throws Exception {
42 Unsafe unsafe = Unsafe.getUnsafe();
43 TestClassLoader classloader = new TestClassLoader();
44 ProtectionDomain pd = new ProtectionDomain(null, null);
45
46 byte klassbuf[] = InMemoryJavaCompiler.compile("TestClass", "class TestClass { }");
47
48 // Invalid class data
49 try {
50 unsafe.defineClass(null, klassbuf, 4, klassbuf.length - 4, classloader, pd);
51 throw new RuntimeException("defineClass did not throw expected ClassFormatError");
52 } catch (ClassFormatError e) {
53 // Expected
54 }
55
56 // Negative offset
57 try {
58 unsafe.defineClass(null, klassbuf, -1, klassbuf.length, classloader, pd);
59 throw new RuntimeException("defineClass did not throw expected IndexOutOfBoundsException");
60 } catch (IndexOutOfBoundsException e) {
61 // Expected
62 }
|