|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, 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 | + * @bug 8362237 |
| 27 | + * @summary Test source launcher with specific VM behaviors |
| 28 | + * @library /tools/lib |
| 29 | + * @modules jdk.compiler/com.sun.tools.javac.api |
| 30 | + * jdk.compiler/com.sun.tools.javac.launcher |
| 31 | + * jdk.compiler/com.sun.tools.javac.main |
| 32 | + * java.base/jdk.internal.module |
| 33 | + * @build toolbox.JavaTask toolbox.JavacTask toolbox.TestRunner toolbox.ToolBox |
| 34 | + * @run main/othervm -XX:-StackTraceInThrowable SourceLauncherStackTraceTest |
| 35 | + */ |
| 36 | + |
| 37 | +import java.io.IOException; |
| 38 | +import java.nio.file.Path; |
| 39 | +import java.nio.file.Paths; |
| 40 | +import java.util.List; |
| 41 | + |
| 42 | +import toolbox.TestRunner; |
| 43 | + |
| 44 | +/// SourceLauncherTest runs the source launcher in the same VM, so we must |
| 45 | +/// use another test to run specific tests with specific VM flags |
| 46 | +public class SourceLauncherStackTraceTest extends TestRunner { |
| 47 | + |
| 48 | + // Inheritance will shadow all parent tests |
| 49 | + SourceLauncherTest parent = new SourceLauncherTest(); |
| 50 | + |
| 51 | + SourceLauncherStackTraceTest() { |
| 52 | + super(System.err); |
| 53 | + } |
| 54 | + |
| 55 | + public static void main(String... args) throws Exception { |
| 56 | + SourceLauncherStackTraceTest t = new SourceLauncherStackTraceTest(); |
| 57 | + t.runTests(m -> new Object[] { Paths.get(m.getName()) }); |
| 58 | + } |
| 59 | + |
| 60 | + /* |
| 61 | + * Tests in which main throws an exception without a stacktrace. |
| 62 | + */ |
| 63 | + @Test |
| 64 | + public void testTargetException2(Path base) throws IOException { |
| 65 | + parent.tb.writeJavaFiles(base, """ |
| 66 | + public class TestLauncher { |
| 67 | + public static TestLauncher test() { |
| 68 | + throw new RuntimeException("No trace"); |
| 69 | + } |
| 70 | +
|
| 71 | + public static void main(String[] args) { |
| 72 | + // This will throw a RuntimeException without |
| 73 | + // a stack trace due to VM options |
| 74 | + test(); |
| 75 | + } |
| 76 | + } |
| 77 | + """); |
| 78 | + Path file = base.resolve("TestLauncher.java"); |
| 79 | + SourceLauncherTest.Result r = parent.run(file, List.of(), List.of("3")); |
| 80 | + parent.checkEmpty("stdout", r.stdOut()); |
| 81 | + parent.checkEmpty("stderr", r.stdErr()); |
| 82 | + parent.checkTrace("exception", r.exception(), "java.lang.RuntimeException: No trace"); |
| 83 | + } |
| 84 | +} |
0 commit comments