OSDN Git Service

Make the 008-exceptions test print everything to stdout
authorKevin Brodsky <kevin.brodsky@linaro.org>
Mon, 14 Dec 2015 10:15:04 +0000 (10:15 +0000)
committerKevin Brodsky <kevin.brodsky@linaro.org>
Wed, 16 Dec 2015 14:26:19 +0000 (14:26 +0000)
Printing to different streams (stderr and stdout) may cause the
messages to be interleaved, making the test fail. Without this patch,
this kind of outcome has been observed:

--- expected.txt 2015-12-09 08:13:50.583294910 +0000
+++ output.txt 2015-12-09 08:55:35.635185771 +0000
@@ -1,15 +1,15 @@
 Got an NPE: second throw
 java.lang.NullPointerException: second throw
- at Main.catchAndRethrow(Main.java:77)
+Static Init
+BadError: This is bad by convention: BadInit
+java.lang.NoClassDefFoundError: BadInit at Main.catchAndRethrow(Main.java:77)
  at Main.exceptions_007(Main.java:59)
  at Main.main(Main.java:67)
 Caused by: java.lang.NullPointerException: first throw
  at Main.throwNullPointerException(Main.java:84)
  at Main.catchAndRethrow(Main.java:74)
  ... 2 more
-Static Init
-BadError: This is bad by convention: BadInit
-java.lang.NoClassDefFoundError: BadInit
+
 BadError: This is bad by convention: BadInit
 Static BadInitNoStringInit
 BadErrorNoStringInit: This is bad by convention

Change-Id: Iaabf5ed593d100abf157adf46c1761338227d2cf

test/008-exceptions/src/Main.java

index 9e3477a..b8231f1 100644 (file)
@@ -60,7 +60,7 @@ public class Main {
         } catch (NullPointerException npe) {
             System.out.print("Got an NPE: ");
             System.out.println(npe.getMessage());
-            npe.printStackTrace();
+            npe.printStackTrace(System.out);
         }
     }
     public static void main (String args[]) {
@@ -103,7 +103,7 @@ public class Main {
                 System.out.println(e.getCause());
             }
         } catch (Exception error) {
-            error.printStackTrace();
+            error.printStackTrace(System.out);
         }
     }
 
@@ -126,7 +126,7 @@ public class Main {
                 System.out.println(e.getCause());
             }
         } catch (Exception error) {
-            error.printStackTrace();
+            error.printStackTrace(System.out);
         }
     }
 }