Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/BadObjectClass/TestUnloadClassError.java
40942 views
1
/*
2
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
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
* @test
25
* @bug 6194361
26
* @bug 8202669
27
* @summary Make sure the VM doesn't crash and throws a SecurityException
28
* if defineClass() is called on a byte buffer that parses into a invalid
29
* java.lang.Object class.
30
* Also, make sure the vm doesn't crash on notification for unloading an invalid
31
* java.lang.Object class.
32
* @library /test/lib
33
* @modules java.base/jdk.internal.misc
34
* java.compiler
35
* @run main TestUnloadClassError
36
*/
37
38
import jdk.test.lib.compiler.InMemoryJavaCompiler;
39
import jdk.test.lib.classloader.ClassUnloadCommon;
40
41
public class TestUnloadClassError extends ClassLoader {
42
43
static String source =
44
" package java.lang;" +
45
" public class Object" +
46
" {" +
47
" int field;" +
48
" public boolean equals(Object o) {" +
49
" System.out.println(o.field);" +
50
" return false;" +
51
" }" +
52
" }";
53
54
public static void main(String[] args) throws Exception
55
{
56
try {
57
TestUnloadClassError loader = new TestUnloadClassError();
58
byte[] buf = InMemoryJavaCompiler.compile("java.lang.Object", source,
59
"--patch-module=java.base");
60
Class c = loader.defineClass(buf, 0, buf.length);
61
System.out.println("test FAILS");
62
throw new RuntimeException("Did not get security exception");
63
} catch(SecurityException e) {
64
System.out.println("test expects SecurityException");
65
}
66
67
// Unload bad class
68
ClassUnloadCommon.triggerUnloading();
69
System.out.println("test PASSES if it doesn't crash");
70
}
71
}
72
73