1 /*
2 * Copyright (c) 2017, 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 */
57 }
58 }
59
60 static class MissingNestHost {
61 // jcod version will change NestHost to a non-existent class
62 private void priv_invoke() {
63 System.out.println("MissingNestHost::priv_invoke");
64 }
65 }
66
67 // Helper class adds a level of indirection to avoid the main class
68 // failing verification if these tests are written directly in main.
69 // That can only happen if using invokespecial for nestmate invocation.
70 static class Helper {
71 static void doTest() {
72 try {
73 MissingNestHost m = new MissingNestHost();
74 m.priv_invoke();
75 throw new Error("Unexpected success invoking MissingNestHost.priv_invoke");
76 }
77 catch (NoClassDefFoundError ncdfe) {
78 System.out.println("Got expected exception:" + ncdfe);
79 }
80 }
81 }
82
83 public static void main(String[] args) throws Throwable {
84 // some errors change depending on whether they are caught by the
85 // verifier first
86 boolean verifying = Boolean.parseBoolean(args[0]);
87 System.out.println("Verification is " +
88 (verifying ? "enabled" : "disabled"));
89
90 try {
91 MissingMethod m = new MissingMethod();
92 m.priv_invoke();
93 throw new Error("Unexpected success invoking MissingMethod.priv_invoke");
94 }
95 catch (NoSuchMethodError nsme) {
96 System.out.println("Got expected exception:" + nsme);
97 }
98
99 // This test was revised to expect successful invocation of the
100 // super class method - see JDK-8211065
101 MissingMethodWithSuper m = new MissingMethodWithSuper();
102 m.priv_invoke();
103
104 // Verification of Helper will trigger the nestmate access check failure
105 try {
106 Helper.doTest();
107 }
108 catch (NoClassDefFoundError ncdfe) {
109 if (verifying)
110 System.out.println("Got expected exception:" + ncdfe);
111 else
112 throw new Error("Unexpected error loading Helper class with verification disabled");
113 }
114 }
115 }
|
1 /*
2 * Copyright (c) 2017, 2020, 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 */
57 }
58 }
59
60 static class MissingNestHost {
61 // jcod version will change NestHost to a non-existent class
62 private void priv_invoke() {
63 System.out.println("MissingNestHost::priv_invoke");
64 }
65 }
66
67 // Helper class adds a level of indirection to avoid the main class
68 // failing verification if these tests are written directly in main.
69 // That can only happen if using invokespecial for nestmate invocation.
70 static class Helper {
71 static void doTest() {
72 try {
73 MissingNestHost m = new MissingNestHost();
74 m.priv_invoke();
75 throw new Error("Unexpected success invoking MissingNestHost.priv_invoke");
76 }
77 catch (IllegalAccessError iae) {
78 if (iae.getMessage().contains("java.lang.NoClassDefFoundError: NoSuchClass")) {
79 System.out.println("Got expected exception:" + iae);
80 } else {
81 throw new Error("Unexpected exception", iae);
82 }
83 }
84 }
85 }
86
87 public static void main(String[] args) throws Throwable {
88 // some errors change depending on whether they are caught by the
89 // verifier first
90 boolean verifying = Boolean.parseBoolean(args[0]);
91 System.out.println("Verification is " +
92 (verifying ? "enabled" : "disabled"));
93
94 try {
95 MissingMethod m = new MissingMethod();
96 m.priv_invoke();
97 throw new Error("Unexpected success invoking MissingMethod.priv_invoke");
98 }
99 catch (NoSuchMethodError nsme) {
100 System.out.println("Got expected exception:" + nsme);
101 }
102
103 // This test was revised to expect successful invocation of the
104 // super class method - see JDK-8211065
105 MissingMethodWithSuper m = new MissingMethodWithSuper();
106 m.priv_invoke();
107
108 // Verification of Helper will trigger the nestmate access check failure
109 try {
110 Helper.doTest();
111 }
112 catch (IllegalAccessError iae) {
113 if (verifying)
114 System.out.println("Got expected exception:" + iae);
115 else
116 throw new Error("Unexpected error loading Helper class with verification disabled", iae);
117 }
118 }
119 }
|