/* * Copyright (c) 2019, Red Hat, Inc. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @modules java.base/jdk.internal.misc * @library /test/lib .. * @compile pe/c.java * @build sun.hotspot.WhiteBox * @compile/module=java.base java/lang/ModuleHelper.java * @run driver ClassFileInstaller sun.hotspot.WhiteBox * sun.hotspot.WhiteBox$WhiteBoxPermission * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI ExceptionModuleName */ import static jdk.test.lib.Asserts.*; public class ExceptionModuleName { public static void main(String args[]) throws Throwable { Object javaBaseModule = Class.forName("java.lang.Object").getModule(); assertNotNull(javaBaseModule, "java.base Module should not be null"); ClassLoader cl = ExceptionModuleName.class.getClassLoader(); Object mod = ModuleHelper.ModuleObject("my_module", cl, new String[] { "pe" }); assertNotNull(mod, "Module should not be null"); ModuleHelper.DefineModule(mod, false, "9.0", "my_module/here", new String[] { "pe" }); ModuleHelper.AddReadsModule(mod, javaBaseModule); ModuleHelper.AddModuleExportsToAll(mod, "pe"); Class c = Class.forName("pe.c"); try { c.newInstance(); throw new RuntimeException("Failed to get ISE"); } catch (IllegalStateException e) { if (e.getMessage() == null || !e.getMessage().contains("Expected message")) { throw new RuntimeException("Wrong message", e); } StackTraceElement[] fs = e.getStackTrace(); if (fs.length < 1) { throw new RuntimeException("Wrong number of stack trace elements", e); } StackTraceElement top = fs[0]; if (!"pe.c.c(c.java:43)".equals(top.toString())) { throw new RuntimeException("Wrong top frame", e); } } } }