8216529: in case of a crash, javac should print out the parameters passed to it
Reviewed-by: jjg, cushon
This commit is contained in:
parent
5f2fe089e3
commit
5bb0835887
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. 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
|
||||
@ -29,12 +29,18 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.NoSuchFileException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.security.CodeSource;
|
||||
import java.security.DigestInputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -307,6 +313,7 @@ public class Main {
|
||||
comp.closeables = comp.closeables.prepend(log.getWriter(WriterKind.NOTICE));
|
||||
}
|
||||
|
||||
boolean printArgsToFile = options.isSet("printArgsToFile");
|
||||
try {
|
||||
comp.compile(args.getFileObjects(), args.getClassNames(), null, List.nil());
|
||||
|
||||
@ -338,6 +345,7 @@ public class Main {
|
||||
if (twoClassLoadersInUse(iae)) {
|
||||
bugMessage(iae);
|
||||
}
|
||||
printArgsToFile = true;
|
||||
return Result.ABNORMAL;
|
||||
} catch (Throwable ex) {
|
||||
// Nasty. If we've already reported an error, compensate
|
||||
@ -345,8 +353,12 @@ public class Main {
|
||||
// exceptions.
|
||||
if (comp == null || comp.errorCount() == 0 || options.isSet("dev"))
|
||||
bugMessage(ex);
|
||||
printArgsToFile = true;
|
||||
return Result.ABNORMAL;
|
||||
} finally {
|
||||
if (printArgsToFile) {
|
||||
printArgumentsToFile(argv);
|
||||
}
|
||||
if (comp != null) {
|
||||
try {
|
||||
comp.close();
|
||||
@ -357,6 +369,29 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
void printArgumentsToFile(String... params) {
|
||||
Path out = Paths.get(String.format("javac.%s.args",
|
||||
new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime())));
|
||||
String strOut = "";
|
||||
try {
|
||||
try (Writer w = Files.newBufferedWriter(out)) {
|
||||
for (String param : params) {
|
||||
param = param.replaceAll("\\\\", "\\\\\\\\");
|
||||
if (param.matches(".*\\s+.*")) {
|
||||
param = "\"" + param + "\"";
|
||||
}
|
||||
strOut += param + '\n';
|
||||
}
|
||||
w.write(strOut);
|
||||
}
|
||||
log.printLines(PrefixKind.JAVAC, "msg.parameters.output", out.toAbsolutePath());
|
||||
} catch (IOException ioe) {
|
||||
log.printLines(PrefixKind.JAVAC, "msg.parameters.output.error", out.toAbsolutePath());
|
||||
System.err.println(strOut);
|
||||
System.err.println();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean twoClassLoadersInUse(IllegalAccessError iae) {
|
||||
String msg = iae.getMessage();
|
||||
Pattern pattern = Pattern.compile("(?i)(?<=tried to access class )([a-z_$][a-z\\d_$]*\\.)*[a-z_$][a-z\\d_$]*");
|
||||
|
@ -352,7 +352,7 @@ javac.msg.bug=\
|
||||
An exception has occurred in the compiler ({0}). \
|
||||
Please file a bug against the Java compiler via the Java bug reporting page (http://bugreport.java.com) \
|
||||
after checking the Bug Database (http://bugs.java.com) for duplicates. \
|
||||
Include your program and the following diagnostic in your report. Thank you.
|
||||
Include your program, the following diagnostic, and the parameters passed to the Java compiler in your report. Thank you.
|
||||
|
||||
javac.msg.io=\
|
||||
\n\nAn input/output error occurred.\n\
|
||||
@ -372,3 +372,9 @@ Consult the following stack trace for details.\n
|
||||
|
||||
javac.version={0} {1}
|
||||
javac.fullVersion={0} full version "{1}"
|
||||
|
||||
javac.msg.parameters.output=\
|
||||
printing javac parameters to: {0}
|
||||
|
||||
javac.msg.parameters.output.error=\
|
||||
error while trying to print javac parameters to: {0}, parameters will follow:
|
||||
|
Loading…
x
Reference in New Issue
Block a user