Add exception class name to serialized/deserialized throwable.
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@10777 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/core/client/impl/SerializableThrowable.java b/user/src/com/google/gwt/core/client/impl/SerializableThrowable.java
index e967fbf..f5b993d 100644
--- a/user/src/com/google/gwt/core/client/impl/SerializableThrowable.java
+++ b/user/src/com/google/gwt/core/client/impl/SerializableThrowable.java
@@ -29,7 +29,30 @@
private SerializableThrowable cause = null;
private String message = null;
private StackTraceElement[] stackTrace = null;
-
+ private String typeName = null;
+
+ /**
+ * A subclass of Throwable that contains the serialized exception class type.
+ */
+ public static class ThrowableWithClassName extends Throwable {
+
+ private String typeName;
+
+ public ThrowableWithClassName(String message, Throwable cause, String typeName) {
+ super(message, cause);
+ this.typeName = typeName;
+ }
+
+ public ThrowableWithClassName(String message, String typeName) {
+ super(message);
+ this.typeName = typeName;
+ }
+
+ public String getExceptionClass() {
+ return typeName;
+ }
+ }
+
/**
* Create a new SerializableThrowable from a Throwable.
*/
@@ -39,6 +62,7 @@
cause = new SerializableThrowable(t.getCause());
}
stackTrace = t.getStackTrace();
+ typeName = t.getClass().getName();
}
protected SerializableThrowable() {
@@ -63,9 +87,9 @@
public Throwable getThrowable() {
Throwable t;
if (cause != null) {
- t = new Throwable(message, cause.getThrowable());
+ t = new ThrowableWithClassName(message, cause.getThrowable(), typeName);
} else {
- t = new Throwable(message);
+ t = new ThrowableWithClassName(message, typeName);
}
t.setStackTrace(stackTrace);
return t;
diff --git a/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java b/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java
index 9ae3792..1c9b153 100644
--- a/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java
+++ b/user/src/com/google/gwt/logging/client/JsonLogRecordClientUtil.java
@@ -68,6 +68,7 @@
private static JSONObject throwableAsJsonObject(Throwable t) {
JSONObject obj = new JSONObject();
if (t != null) {
+ obj.put("type", getJsonString(t.getClass().getName()));
obj.put("message", getJsonString(t.getMessage()));
obj.put("cause", throwableAsJsonObject(t.getCause()));
StackTraceElement[] stackTrace = t.getStackTrace();
diff --git a/user/src/com/google/gwt/logging/impl/FormatterImpl.java b/user/src/com/google/gwt/logging/impl/FormatterImpl.java
index df9b153..2af328c 100644
--- a/user/src/com/google/gwt/logging/impl/FormatterImpl.java
+++ b/user/src/com/google/gwt/logging/impl/FormatterImpl.java
@@ -16,6 +16,8 @@
package com.google.gwt.logging.impl;
+import com.google.gwt.core.client.impl.SerializableThrowable;
+
import java.util.Date;
import java.util.HashSet;
import java.util.logging.Formatter;
@@ -63,7 +65,11 @@
seenCauses.add(currentCause);
s.append(causedBy);
causedBy = newline + "Caused by: "; // after 1st, all say "caused by"
- s.append(currentCause.getClass().getName());
+ if (currentCause instanceof SerializableThrowable.ThrowableWithClassName) {
+ s.append(((SerializableThrowable.ThrowableWithClassName) currentCause).getExceptionClass());
+ } else {
+ s.append(currentCause.getClass().getName());
+ }
s.append(": " + currentCause.getMessage());
StackTraceElement[] stackElems = currentCause.getStackTrace();
if (stackElems != null) {
diff --git a/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java b/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java
index adb20bc..f3384a8 100644
--- a/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java
+++ b/user/src/com/google/gwt/logging/server/JsonLogRecordServerUtil.java
@@ -16,6 +16,8 @@
package com.google.gwt.logging.server;
+import com.google.gwt.core.client.impl.SerializableThrowable;
+
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -82,7 +84,9 @@
} else {
stackTrace = new StackTraceElement[0];
}
- Throwable thrown = new Throwable(message, cause);
+ String exceptionClass = t.getString("type");
+ SerializableThrowable.ThrowableWithClassName thrown =
+ new SerializableThrowable.ThrowableWithClassName(message, cause, exceptionClass);
thrown.setStackTrace(stackTrace);
return thrown;
}