Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/runtime/LoaderConstraints/ldrCnstrFldMsg/LdrCnstrFldMsgTest.java
40948 views
1
/*
2
* Copyright (c) 2018, 2019, 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
25
/*
26
* @test
27
* @compile pkg/Grand.java pkg/Parent.java pkg/ClassLoaderForParentFoo.java
28
* @compile pkg/ClassLoaderForChildGrandFoo.java pkg/Child.jasm
29
* @run main/othervm LdrCnstrFldMsgTest
30
*/
31
32
import java.lang.reflect.Method;
33
34
// Check that the LinkageError loader constraint message for fields contains the
35
// correct information.
36
//
37
// The test creates two class loaders. The first class loader loads classes
38
// Child, Foo, and Grand. The second class loader loads Parent and Foo. Class
39
// Parent is a sub-class of Grand and class Child is a sub-class of Parent.
40
// Class Child tries to load Parent._field1. This should fail because type Foo
41
// for Parent._field1 is a different type than Child's Foo.
42
//
43
// Grand (ldr1) has field _field1 of type Foo(ldr1)
44
// |
45
// Parent (ldr2) has field _field1 of type Foo(ldr2)
46
// |
47
// Child (ldr1)
48
//
49
// java.lang.LinkageError: loader constraint violation:
50
// when resolving field "_field1" of type pkg.Foo,
51
// the class loader pkg.ClassLoaderForChildGrandFoo @42b2e259 of the current class, pkg.Child,
52
// and the class loader pkg.ClassLoaderForParentFoo @4b55c90f for the field's defining class, pkg.Parent,
53
// have different Class objects for type pkg.Foo
54
// (pkg.Child is in unnamed module of loader pkg.ClassLoaderForChildGrandFoo @42b2e259, parent loader 'app';
55
// pkg.Parent is in unnamed module of loader pkg.ClassLoaderForParentFoo @4b55c90f, parent loader 'app')
56
//
57
public class LdrCnstrFldMsgTest {
58
public static void main(String... args) throws Exception {
59
ClassLoader l = new pkg.ClassLoaderForChildGrandFoo("pkg.Foo", "pkg.Child", "pkg.Grand");
60
l.loadClass("pkg.Foo");
61
62
// Try to call a public method in Grand.
63
Runnable r = (Runnable) l.loadClass("pkg.Child").newInstance();
64
try {
65
r.run();
66
throw new RuntimeException("Expected LinkageError exception not thrown");
67
} catch (java.lang.LinkageError e) {
68
if (!e.getMessage().contains("for the field's defining class, pkg.Parent,") ||
69
!e.getMessage().contains("have different Class objects for type pkg.Foo")) {
70
throw new RuntimeException("Wrong LinkageError exception thrown: " + e.toString());
71
}
72
}
73
}
74
}
75
76