Skip to content

Commit 1a206d2

Browse files
committed
8364545: tools/javac/launcher/SourceLauncherTest.java fails frequently
Reviewed-by: cstein, jpai
1 parent a5e0c9d commit 1a206d2

File tree

2 files changed

+85
-38
lines changed

2 files changed

+85
-38
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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+
}

test/langtools/tools/javac/launcher/SourceLauncherTest.java

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
/*
2525
* @test
2626
* @bug 8192920 8204588 8246774 8248843 8268869 8235876 8328339 8335896 8344706
27-
* 8362237
2827
* @summary Test source launcher
2928
* @library /tools/lib
3029
* @modules jdk.compiler/com.sun.tools.javac.api
@@ -77,7 +76,7 @@ public static void main(String... args) throws Exception {
7776
System.err.println("version: " + thisVersion);
7877
}
7978

80-
private final ToolBox tb;
79+
final ToolBox tb;
8180
private static final String thisVersion = System.getProperty("java.specification.version");
8281

8382
/*
@@ -715,42 +714,6 @@ public void testTargetException1(Path base) throws IOException {
715714
"at Thrower.main(Thrower.java:4)");
716715
}
717716

718-
/*
719-
* Tests in which main throws an exception without a stacktrace.
720-
*/
721-
@Test
722-
public void testTargetException2(Path base) throws IOException {
723-
tb.writeJavaFiles(base, """
724-
public class TestLauncher {
725-
public static TestLauncher testCheckcast(Object arg) {
726-
return (TestLauncher)arg;
727-
}
728-
729-
public static void main(String[] args) {
730-
// Warmup to trigger C2 compilation
731-
TestLauncher t = new TestLauncher();
732-
for (int i = 0; i < 10_000; ++i) {
733-
testCheckcast(t);
734-
try {
735-
testCheckcast(42);
736-
} catch (Exception e) {
737-
// Expected
738-
}
739-
}
740-
// This will throw a ClassCastException without
741-
// a stack trace if OmitStackTraceInFastThrow
742-
// is enabled (default)
743-
testCheckcast(42);
744-
}
745-
}
746-
""");
747-
Path file = base.resolve("TestLauncher.java");
748-
Result r = run(file, Collections.emptyList(), List.of("3"));
749-
checkEmpty("stdout", r.stdOut);
750-
checkEmpty("stderr", r.stdErr);
751-
checkTrace("exception", r.exception, "java.lang.ClassCastException");
752-
}
753-
754717
@Test
755718
public void testNoDuplicateIncubatorWarning(Path base) throws Exception {
756719
Path module = base.resolve("lib");

0 commit comments

Comments
 (0)