1 /* 2 * Copyright (c) 2019, Red Hat, Inc. 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 pe/c.java 29 * @build sun.hotspot.WhiteBox 30 * @compile/module=java.base java/lang/ModuleHelper.java 31 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 32 * sun.hotspot.WhiteBox$WhiteBoxPermission 33 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ExceptionModuleName 34 */ 35 36 import static jdk.test.lib.Asserts.*; 37 38 public class ExceptionModuleName { 39 40 public static void main(String args[]) throws Throwable { 41 Object javaBaseModule = Class.forName("java.lang.Object").getModule(); 42 assertNotNull(javaBaseModule, "java.base Module should not be null"); 43 44 ClassLoader cl = ExceptionModuleName.class.getClassLoader(); 45 46 Object mod = ModuleHelper.ModuleObject("my_module", cl, new String[] { "pe" }); 47 assertNotNull(mod, "Module should not be null"); 48 ModuleHelper.DefineModule(mod, false, "9.0", "my_module/here", new String[] { "pe" }); 49 ModuleHelper.AddReadsModule(mod, javaBaseModule); 50 51 ModuleHelper.AddModuleExportsToAll(mod, "pe"); 52 53 Class c = Class.forName("pe.c"); 54 try { 55 c.newInstance(); 56 throw new RuntimeException("Failed to get ISE"); 57 } catch (IllegalStateException e) { 58 if (e.getMessage() == null || !e.getMessage().contains("Expected message")) { 59 throw new RuntimeException("Wrong message", e); 60 } 61 62 StackTraceElement[] fs = e.getStackTrace(); 63 if (fs.length < 1) { 64 throw new RuntimeException("Wrong number of stack trace elements", e); 65 } 66 67 StackTraceElement top = fs[0]; 68 if (!"pe.c.c(c.java:43)".equals(top.toString())) { 69 throw new RuntimeException("Wrong top frame", e); 70 } 71 } 72 } 73 } 74