JUnit exceptions cause chains need to be serializable, too.

http://gwt-code-reviews.appspot.com/1160801

Review by: conroy@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9310 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/junit/client/impl/JUnitResult.java b/user/src/com/google/gwt/junit/client/impl/JUnitResult.java
index e79e1ed..8d777d9 100644
--- a/user/src/com/google/gwt/junit/client/impl/JUnitResult.java
+++ b/user/src/com/google/gwt/junit/client/impl/JUnitResult.java
@@ -30,13 +30,13 @@
  */
 public class JUnitResult implements Serializable {
 
-  // Computed at the server, via HTTP header.
-  private transient String agent;
-
   /**
    * If non-null, an exception that occurred during the run.
    */
-  private ExceptionWrapper exceptionWrapper;
+  ExceptionWrapper exceptionWrapper;
+
+  // Computed at the server, via HTTP header.
+  private transient String agent;
 
   // Computed at the server, via HTTP header.
   private transient String host;
diff --git a/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java b/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java
index 1b17421..bf2a6bf 100644
--- a/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java
+++ b/user/super/com/google/gwt/junit/translatable/com/google/gwt/junit/client/impl/GWTRunner.java
@@ -156,6 +156,23 @@
   }
 
   /**
+   * Convert unserializable exceptions (usually from dev mode) into generic
+   * serializable ones.
+   */
+  private static void ensureSerializable(ExceptionWrapper wrapper,
+      SerializationStreamWriter writer) {
+    if (wrapper == null) {
+      return;
+    }
+    ensureSerializable(wrapper.causeWrapper, writer);
+    try {
+      writer.writeObject(wrapper.exception);
+    } catch (SerializationException e) {
+      wrapper.exception = new Exception(wrapper.exception.toString());
+    }
+  }
+
+  /**
    * This client's info.
    */
   private ClientInfo clientInfo;
@@ -248,22 +265,10 @@
     if (result != null && failureMessage != null) {
       RuntimeException ex = new RuntimeException(failureMessage);
       result.setException(ex);
-    } else if (!GWT.isProdMode() && result.getException() != null) {
+    } else if (!GWT.isProdMode() && result.exceptionWrapper != null) {
       SerializationStreamFactory fac = (SerializationStreamFactory) junitHost;
       SerializationStreamWriter writer = fac.createStreamWriter();
-      Throwable ex = result.getException();
-      try {
-        writer.writeObject(ex);
-      } catch (SerializationException e) {
-        /*
-         * Probably a dev mode exception that isn't client-side serializable.
-         * Send it as a plain old Exception instead.
-         */
-        StackTraceElement[] st = ex.getStackTrace();
-        ex = new Exception(ex.toString());
-        ex.setStackTrace(st);
-        result.setException(ex);
-      }
+      ensureSerializable(result.exceptionWrapper, writer);
     }
     TestInfo currentTest = getCurrentTest();
     currentResults.put(currentTest, result);