Skip to content

Commit 2b31453

Browse files
author
Aggelos Biboudis
authored
Merge pull request #5615 from dotty-staging/try-child-jvm-main
Enclose runMain in try-catch
2 parents bcccb2f + b98a1ab commit 2b31453

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

compiler/test/dotty/tools/vulpix/ChildJVMMain.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,28 @@ public class ChildJVMMain {
1313
static final String MessageEnd = "##THIS IS THE END FOR ME, GOODBYE##";
1414

1515
private static void runMain(String dir) throws Exception {
16-
String jcp = System.getProperty("java.class.path");
17-
String sep = File.pathSeparator;
18-
System.setProperty("java.class.path", jcp == null ? dir : dir + sep + jcp);
19-
20-
ArrayList<URL> cp = new ArrayList<>();
21-
for (String path : dir.split(sep))
22-
cp.add(new File(path).toURI().toURL());
23-
24-
URLClassLoader ucl = new URLClassLoader(cp.toArray(new URL[cp.size()]));
25-
Class<?> cls = ucl.loadClass("Test");
26-
Method meth = cls.getMethod("main", String[].class);
16+
Method meth = null;
2717
Object[] args = new Object[]{ new String[]{ "jvm" } };
28-
18+
try {
19+
String jcp = System.getProperty("java.class.path");
20+
String sep = File.pathSeparator;
21+
System.setProperty("java.class.path", jcp == null ? dir : dir + sep + jcp);
22+
23+
ArrayList<URL> cp = new ArrayList<>();
24+
for (String path : dir.split(sep))
25+
cp.add(new File(path).toURI().toURL());
26+
27+
URLClassLoader ucl = new URLClassLoader(cp.toArray(new URL[cp.size()]));
28+
29+
Class<?> cls = ucl.loadClass("Test");
30+
meth = cls.getMethod("main", String[].class);
31+
}
32+
catch (Throwable e) {
33+
// Include the failure stack trace to the test output
34+
System.out.println(MessageStart);
35+
e.printStackTrace();
36+
throw e;
37+
}
2938
System.out.println(MessageStart);
3039

3140
meth.invoke(null, args);

0 commit comments

Comments
 (0)