Author: ggregory
Date: Mon May 12 16:39:03 2014
New Revision: 1594027

URL: http://svn.apache.org/r1594027
Log:
Add ivars to track the throwable's message and localized message since the real 
Throwable class may not exist in the JVM (or ClassLoader) where the proxy is 
derserialized. Working toward new XML and JSON Serialization and 
Deserialization.

Modified:
    
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java

Modified: 
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
URL: 
http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java?rev=1594027&r1=1594026&r2=1594027&view=diff
==============================================================================
--- 
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
 (original)
+++ 
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
 Mon May 12 16:39:03 2014
@@ -31,6 +31,11 @@ import org.apache.logging.log4j.status.S
 
 /**
  * Wraps a Throwable to add packaging information about each stack trace 
element.
+ * <p>
+ * A proxy is used to represent a throwable that may not exist in a different 
class loader or JVM. When an application
+ * deserializes a ThrowableProxy, the throwable will not be set, but the 
throwable's information is preserved in other
+ * fields of the proxy.
+ * </p>
  */
 public class ThrowableProxy implements Serializable {
 
@@ -50,6 +55,10 @@ public class ThrowableProxy implements S
 
     private final transient Throwable throwable;
 
+    private final String message;
+    
+    private final String localizedMessage;
+
     private final String name;
 
     private final StackTracePackageElement[] callerPackageData;
@@ -95,6 +104,8 @@ public class ThrowableProxy implements S
     public ThrowableProxy(final Throwable throwable) {
         this.throwable = throwable;
         this.name = throwable.getClass().getName();
+        this.message = throwable.getMessage();
+        this.localizedMessage = throwable.getLocalizedMessage();
         final Map<String, CacheEntry> map = new HashMap<String, CacheEntry>();
         final Stack<Class<?>> stack = getCurrentStack();
         callerPackageData = resolvePackageData(stack, map, null, 
throwable.getStackTrace());
@@ -115,6 +126,8 @@ public class ThrowableProxy implements S
                            final Throwable cause) {
         this.throwable = cause;
         this.name = cause.getClass().getName();
+        this.message = throwable.getMessage();
+        this.localizedMessage = throwable.getLocalizedMessage();
         callerPackageData = resolvePackageData(stack, map, 
parent.getStackTrace(), cause.getStackTrace());
         this.causeProxy = cause.getCause() == null ? null :
             new ThrowableProxy(parent, stack, map, cause.getCause());
@@ -129,6 +142,14 @@ public class ThrowableProxy implements S
         return causeProxy;
     }
 
+    public String getMessage() {
+        return message;
+    }
+
+    public String getLocalizedMessage() {
+        return localizedMessage;
+    }
+
     /**
      * Return the FQCN of the Throwable.
      * @return The FQCN of the Throwable.
@@ -156,7 +177,7 @@ public class ThrowableProxy implements S
 
     @Override
     public String toString() {
-        final String msg = throwable.getMessage();
+        final String msg = this.message;
         return msg != null ? name + ": " + msg : name;
     }
 


Reply via email to