8194669: jaotc truncates the invalid filename provided to --output

Do not skip the first character of the linker output

Reviewed-by: kvn
This commit is contained in:
Igor Veresov 2018-01-23 08:18:36 -08:00
parent 8ccf366ee6
commit c139d774ba

View File

@ -44,6 +44,14 @@ final class Linker {
return libraryFileName; return libraryFileName;
} }
private static String getString(InputStream stream) {
BufferedReader br = new BufferedReader(new InputStreamReader(stream));
Stream<String> lines = br.lines();
StringBuilder sb = new StringBuilder();
lines.iterator().forEachRemaining(e -> sb.append(e));
return sb.toString();
}
Linker(Main main) throws Exception { Linker(Main main) throws Exception {
this.options = main.options; this.options = main.options;
String name = options.outputName; String name = options.outputName;
@ -106,12 +114,7 @@ final class Linker {
Process p = Runtime.getRuntime().exec(linkerCheck); Process p = Runtime.getRuntime().exec(linkerCheck);
final int exitCode = p.waitFor(); final int exitCode = p.waitFor();
if (exitCode != 0) { if (exitCode != 0) {
InputStream stderr = p.getErrorStream(); throw new InternalError(getString(p.getErrorStream()));
BufferedReader br = new BufferedReader(new InputStreamReader(stderr));
Stream<String> lines = br.lines();
StringBuilder sb = new StringBuilder();
lines.iterator().forEachRemaining(e -> sb.append(e));
throw new InternalError(sb.toString());
} }
} }
} }
@ -120,15 +123,11 @@ final class Linker {
Process p = Runtime.getRuntime().exec(linkerCmd); Process p = Runtime.getRuntime().exec(linkerCmd);
final int exitCode = p.waitFor(); final int exitCode = p.waitFor();
if (exitCode != 0) { if (exitCode != 0) {
InputStream stderr = p.getErrorStream(); String errorMessage = getString(p.getErrorStream());
if (stderr.read() == -1) { if (errorMessage.isEmpty()) {
stderr = p.getInputStream(); errorMessage = getString(p.getInputStream());
} }
BufferedReader br = new BufferedReader(new InputStreamReader(stderr)); throw new InternalError(errorMessage);
Stream<String> lines = br.lines();
StringBuilder sb = new StringBuilder();
lines.iterator().forEachRemaining(e -> sb.append(e));
throw new InternalError(sb.toString());
} }
File objFile = new File(objectFileName); File objFile = new File(objectFileName);
if (objFile.exists()) { if (objFile.exists()) {