Fix to allow devmode exceptions to be reported back from a client.

When I converted JUnit to use normal serialization to transmit exceptions, I introduced a problem.  In DevMode, exceptions can get into the client space from the hosting environment, such as HostedModeException.  Because these types are not visible to the client, they can't be serialized.  This works around the issue by using a known-good exception type.

http://gwt-code-reviews.appspot.com/1147801/show

Review by: conroy@google.com

git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@9293 8db76d5a-ed1c-0410-87a9-c151d255dfc7
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 882a22a..1b17421 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
@@ -27,6 +27,9 @@
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.Window;
 import com.google.gwt.user.client.rpc.AsyncCallback;
+import com.google.gwt.user.client.rpc.SerializationException;
+import com.google.gwt.user.client.rpc.SerializationStreamFactory;
+import com.google.gwt.user.client.rpc.SerializationStreamWriter;
 import com.google.gwt.user.client.rpc.ServiceDefTarget;
 
 import java.util.HashMap;
@@ -245,7 +248,23 @@
     if (result != null && failureMessage != null) {
       RuntimeException ex = new RuntimeException(failureMessage);
       result.setException(ex);
-    }   
+    } else if (!GWT.isProdMode() && result.getException() != 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);
+      }
+    }
     TestInfo currentTest = getCurrentTest();
     currentResults.put(currentTest, result);
     ++currentTestIndex;