changeset 49189:decc1bb41107

8194669: jaotc truncates the invalid filename provided to --output Summary: Do not skip the first character of the linker output Reviewed-by: kvn
author iveresov
date Tue, 23 Jan 2018 08:18:36 -0800
parents 8f451978683c
children 51fc22e5fb00
files src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Linker.java
diffstat 1 files changed, 13 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Linker.java	Tue Jan 23 08:55:47 2018 +0100
+++ b/src/jdk.aot/share/classes/jdk.tools.jaotc/src/jdk/tools/jaotc/Linker.java	Tue Jan 23 08:18:36 2018 -0800
@@ -44,6 +44,14 @@
         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 {
         this.options = main.options;
         String name = options.outputName;
@@ -106,12 +114,7 @@
             Process p = Runtime.getRuntime().exec(linkerCheck);
             final int exitCode = p.waitFor();
             if (exitCode != 0) {
-                InputStream stderr = 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());
+                throw new InternalError(getString(p.getErrorStream()));
             }
         }
     }
@@ -120,15 +123,11 @@
         Process p = Runtime.getRuntime().exec(linkerCmd);
         final int exitCode = p.waitFor();
         if (exitCode != 0) {
-            InputStream stderr = p.getErrorStream();
-            if (stderr.read() == -1) {
-                stderr = p.getInputStream();
+            String errorMessage = getString(p.getErrorStream());
+            if (errorMessage.isEmpty()) {
+                errorMessage = getString(p.getInputStream());
             }
-            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());
+            throw new InternalError(errorMessage);
         }
         File objFile = new File(objectFileName);
         if (objFile.exists()) {