Skip to content

Enclose runMain in try-catch #5615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 4, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions compiler/test/dotty/tools/vulpix/ChildJVMMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@ public class ChildJVMMain {
static final String MessageEnd = "##THIS IS THE END FOR ME, GOODBYE##";

private static void runMain(String dir) throws Exception {
String jcp = System.getProperty("java.class.path");
String sep = File.pathSeparator;
System.setProperty("java.class.path", jcp == null ? dir : dir + sep + jcp);

ArrayList<URL> cp = new ArrayList<>();
for (String path : dir.split(sep))
cp.add(new File(path).toURI().toURL());

URLClassLoader ucl = new URLClassLoader(cp.toArray(new URL[cp.size()]));
Class<?> cls = ucl.loadClass("Test");
Method meth = cls.getMethod("main", String[].class);
Method meth = null;
Object[] args = new Object[]{ new String[]{ "jvm" } };

try {
String jcp = System.getProperty("java.class.path");
String sep = File.pathSeparator;
System.setProperty("java.class.path", jcp == null ? dir : dir + sep + jcp);

ArrayList<URL> cp = new ArrayList<>();
for (String path : dir.split(sep))
cp.add(new File(path).toURI().toURL());

URLClassLoader ucl = new URLClassLoader(cp.toArray(new URL[cp.size()]));

Class<?> cls = ucl.loadClass("Test");
meth = cls.getMethod("main", String[].class);
}
catch(Throwable e) {
System.out.println(MessageStart);
e.printStackTrace();
throw e;
}
System.out.println(MessageStart);

meth.invoke(null, args);
Expand Down