jdk

Форк
0
/
AccessCheckSuper.java 
70 строк · 3.0 Кб
1
/*
2
 * Copyright (c) 2016, 2022, 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
 * @test
26
 * @modules java.base/jdk.internal.misc
27
 * @library /test/lib ..
28
 * @compile p2/c2.java
29
 * @compile p3/c3.java
30
 * @build jdk.test.whitebox.WhiteBox
31
 * @compile/module=java.base java/lang/ModuleHelper.java
32
 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
33
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI AccessCheckSuper
34
 */
35

36
import static jdk.test.lib.Asserts.*;
37

38
public class AccessCheckSuper {
39

40
    // Test that when a class cannot access its super class the message
41
    // contains  both "superclass" text and module text.
42
    public static void main(String args[]) throws Throwable {
43

44
        // Get the class loader for AccessCheckSuper and assume it's also used to
45
        // load class p2.c2 and class p3.c3.
46
        ClassLoader this_cldr = AccessCheckSuper.class.getClassLoader();
47

48
        // Define a module for p2.
49
        Object m2x = ModuleHelper.ModuleObject("module_two", this_cldr, new String[] { "p2" });
50
        assertNotNull(m2x, "Module should not be null");
51
        ModuleHelper.DefineModule(m2x, false, "9.0", "m2x/there", new String[] { "p2" });
52

53
        // Define a module for p3.
54
        Object m3x = ModuleHelper.ModuleObject("module_three", this_cldr, new String[] { "p3" });
55
        assertNotNull(m3x, "Module should not be null");
56
        ModuleHelper.DefineModule(m3x, false, "9.0", "m3x/there", new String[] { "p3" });
57

58
        // Since a readability edge has not been established between module_two
59
        // and module_three, p3.c3 cannot read its superclass p2.c2.
60
        try {
61
            Class p3_c3_class = Class.forName("p3.c3");
62
            throw new RuntimeException("Failed to get IAE (can't read superclass)");
63
        } catch (IllegalAccessError e) {
64
            if (!e.getMessage().contains("superclass access check failed") ||
65
                !e.getMessage().contains("does not read")) {
66
                throw new RuntimeException("Wrong message: " + e.getMessage());
67
            }
68
        }
69
    }
70
}
71

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.