Fix formatting

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/7c2fc7c5
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/7c2fc7c5
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/7c2fc7c5

Branch: refs/heads/LOG4J2-1349-gcfree-threadcontext
Commit: 7c2fc7c54f25a399ca84ed08b7d664ca73887398
Parents: 5cbf04f
Author: Matt Sicker <boa...@gmail.com>
Authored: Thu Sep 8 10:11:02 2016 -0500
Committer: Matt Sicker <boa...@gmail.com>
Committed: Thu Sep 8 10:11:02 2016 -0500

----------------------------------------------------------------------
 .../logging/log4j/core/impl/ThrowableProxy.java | 273 +++++++++----------
 1 file changed, 124 insertions(+), 149 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/7c2fc7c5/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
----------------------------------------------------------------------
diff --git 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
index 5cd73bc..a052e4d 100644
--- 
a/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
+++ 
b/log4j-core/src/main/java/org/apache/logging/log4j/core/impl/ThrowableProxy.java
@@ -38,13 +38,13 @@ import org.apache.logging.log4j.util.Strings;
 
 /**
  * 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 may not be set, but the 
throwable's information is preserved in other
  * fields of the proxy like the message and stack trace.
  * </p>
- * 
+ *
  * <p>
  * TODO: Move this class to org.apache.logging.log4j.core because it is used 
from LogEvent.
  * </p>
@@ -54,12 +54,12 @@ import org.apache.logging.log4j.util.Strings;
  */
 public class ThrowableProxy implements Serializable {
 
-       private static final String TAB = "\t";
+    private static final String TAB = "\t";
     private static final String CAUSED_BY_LABEL = "Caused by: ";
-       private static final String SUPPRESSED_LABEL = "Suppressed: ";
+    private static final String SUPPRESSED_LABEL = "Suppressed: ";
     private static final String WRAPPED_BY_LABEL = "Wrapped by: ";
 
-       /**
+    /**
      * Cached StackTracePackageElement and ClassLoader.
      * <p>
      * Consider this class private.
@@ -115,9 +115,8 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Constructs the wrapper for the Throwable that includes packaging data.
-     * 
-     * @param throwable
-     *        The Throwable to wrap, must not be null.
+     *
+     * @param throwable The Throwable to wrap, must not be null.
      */
     public ThrowableProxy(final Throwable throwable) {
         this(throwable, null);
@@ -125,11 +124,9 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Constructs the wrapper for the Throwable that includes packaging data.
-     * 
-     * @param throwable
-     *        The Throwable to wrap, must not be null.
-     * @param visited
-     *        The set of visited suppressed exceptions.
+     *
+     * @param throwable The Throwable to wrap, must not be null.
+     * @param visited   The set of visited suppressed exceptions.
      */
     private ThrowableProxy(final Throwable throwable, final Set<Throwable> 
visited) {
         this.throwable = throwable;
@@ -141,26 +138,24 @@ public class ThrowableProxy implements Serializable {
         this.extendedStackTrace = this.toExtendedStackTrace(stack, map, null, 
throwable.getStackTrace());
         final Throwable throwableCause = throwable.getCause();
         final Set<Throwable> causeVisited = new HashSet<>(1);
-        this.causeProxy = throwableCause == null ? null : new 
ThrowableProxy(throwable, stack, map, throwableCause, visited, causeVisited);
+        this.causeProxy = throwableCause == null ? null : new 
ThrowableProxy(throwable, stack, map, throwableCause,
+            visited, causeVisited);
         this.suppressedProxies = this.toSuppressedProxies(throwable, visited);
     }
 
     /**
      * Constructs the wrapper for a Throwable that is referenced as the cause 
by another Throwable.
-     * 
-     * @param parent
-     *        The Throwable referencing this Throwable.
-     * @param stack
-     *        The Class stack.
-     * @param map
-     *        The cache containing the packaging data.
-     * @param cause
-     *        The Throwable to wrap.
+     *
+     * @param parent            The Throwable referencing this Throwable.
+     * @param stack             The Class stack.
+     * @param map               The cache containing the packaging data.
+     * @param cause             The Throwable to wrap.
      * @param suppressedVisited TODO
-     * @param causeVisited TODO
+     * @param causeVisited      TODO
      */
     private ThrowableProxy(final Throwable parent, final Stack<Class<?>> 
stack, final Map<String, CacheEntry> map,
-            final Throwable cause, final Set<Throwable> suppressedVisited, 
final Set<Throwable> causeVisited) {
+                           final Throwable cause, final Set<Throwable> 
suppressedVisited,
+                           final Set<Throwable> causeVisited) {
         causeVisited.add(cause);
         this.throwable = cause;
         this.name = cause.getClass().getName();
@@ -169,7 +164,7 @@ public class ThrowableProxy implements Serializable {
         this.extendedStackTrace = this.toExtendedStackTrace(stack, map, 
parent.getStackTrace(), cause.getStackTrace());
         final Throwable causeCause = cause.getCause();
         this.causeProxy = causeCause == null || 
causeVisited.contains(causeCause) ? null : new ThrowableProxy(parent,
-                stack, map, causeCause, suppressedVisited, causeVisited);
+            stack, map, causeCause, suppressedVisited, causeVisited);
         this.suppressedProxies = this.toSuppressedProxies(cause, 
suppressedVisited);
     }
 
@@ -212,26 +207,27 @@ public class ThrowableProxy implements Serializable {
     }
 
     private void formatCause(final StringBuilder sb, final String prefix, 
final ThrowableProxy cause,
-            final List<String> ignorePackages, final TextRenderer 
textRenderer) {
+                             final List<String> ignorePackages, final 
TextRenderer textRenderer) {
         formatThrowableProxy(sb, prefix, CAUSED_BY_LABEL, cause, 
ignorePackages, textRenderer);
     }
 
-       private void formatThrowableProxy(final StringBuilder sb, final String 
prefix, final String causeLabel,
-                       final ThrowableProxy throwableProxy, final List<String> 
ignorePackages, final TextRenderer textRenderer) {
-               if (throwableProxy == null) {
-                       return;
-               }
+    private void formatThrowableProxy(final StringBuilder sb, final String 
prefix, final String causeLabel,
+                                      final ThrowableProxy throwableProxy, 
final List<String> ignorePackages,
+                                      final TextRenderer textRenderer) {
+        if (throwableProxy == null) {
+            return;
+        }
         textRenderer.render(prefix, sb, "Prefix");
         textRenderer.render(causeLabel, sb, "CauseLabel");
         throwableProxy.renderOn(sb, textRenderer);
         textRenderer.render(EOL_STR, sb, "Text");
-               this.formatElements(sb, prefix, 
throwableProxy.commonElementCount,
-                               throwableProxy.getStackTrace(), 
throwableProxy.extendedStackTrace, ignorePackages, textRenderer);
-               this.formatSuppressed(sb, prefix + TAB, 
throwableProxy.suppressedProxies, ignorePackages, textRenderer);
-               this.formatCause(sb, prefix, throwableProxy.causeProxy, 
ignorePackages, textRenderer);
-       }
+        this.formatElements(sb, prefix, throwableProxy.commonElementCount,
+            throwableProxy.getStackTrace(), throwableProxy.extendedStackTrace, 
ignorePackages, textRenderer);
+        this.formatSuppressed(sb, prefix + TAB, 
throwableProxy.suppressedProxies, ignorePackages, textRenderer);
+        this.formatCause(sb, prefix, throwableProxy.causeProxy, 
ignorePackages, textRenderer);
+    }
 
-       void renderOn(final StringBuilder output, final TextRenderer 
textRenderer) {
+    void renderOn(final StringBuilder output, final TextRenderer textRenderer) 
{
         final String msg = this.message;
         textRenderer.render(this.name, output, "Name");
         if (msg != null) {
@@ -241,49 +237,50 @@ public class ThrowableProxy implements Serializable {
     }
 
     private void formatSuppressed(final StringBuilder sb, final String prefix, 
final ThrowableProxy[] suppressedProxies,
-                       final List<String> ignorePackages, final TextRenderer 
textRenderer) {
-               if (suppressedProxies == null) {
-                       return;
-               }
-               for (final ThrowableProxy suppressedProxy : suppressedProxies) {
-                       formatThrowableProxy(sb, prefix, SUPPRESSED_LABEL, 
suppressedProxy, ignorePackages, textRenderer);
-               }
-       }
-
-       private void formatElements(final StringBuilder sb, final String 
prefix, final int commonCount,
-                       final StackTraceElement[] causedTrace, final 
ExtendedStackTraceElement[] extStackTrace,
-                       final List<String> ignorePackages, final TextRenderer 
textRenderer) {
-               if (ignorePackages == null || ignorePackages.isEmpty()) {
-                       for (final ExtendedStackTraceElement element : 
extStackTrace) {
-                               this.formatEntry(element, sb, prefix, 
textRenderer);
-                       }
-               } else {
-                       int count = 0;
-                       for (int i = 0; i < extStackTrace.length; ++i) {
-                               if (!this.ignoreElement(causedTrace[i], 
ignorePackages)) {
-                                       if (count > 0) {
-                                               appendSuppressedCount(sb, 
prefix, count, textRenderer);
-                                               count = 0;
-                                       }
-                                       this.formatEntry(extStackTrace[i], sb, 
prefix, textRenderer);
-                               } else {
-                                       ++count;
-                               }
-                       }
-                       if (count > 0) {
-                               appendSuppressedCount(sb, prefix, count, 
textRenderer);
-                       }
-               }
-               if (commonCount != 0) {
+                                  final List<String> ignorePackages, final 
TextRenderer textRenderer) {
+        if (suppressedProxies == null) {
+            return;
+        }
+        for (final ThrowableProxy suppressedProxy : suppressedProxies) {
+            formatThrowableProxy(sb, prefix, SUPPRESSED_LABEL, 
suppressedProxy, ignorePackages, textRenderer);
+        }
+    }
+
+    private void formatElements(final StringBuilder sb, final String prefix, 
final int commonCount,
+                                final StackTraceElement[] causedTrace, final 
ExtendedStackTraceElement[] extStackTrace,
+                                final List<String> ignorePackages, final 
TextRenderer textRenderer) {
+        if (ignorePackages == null || ignorePackages.isEmpty()) {
+            for (final ExtendedStackTraceElement element : extStackTrace) {
+                this.formatEntry(element, sb, prefix, textRenderer);
+            }
+        } else {
+            int count = 0;
+            for (int i = 0; i < extStackTrace.length; ++i) {
+                if (!this.ignoreElement(causedTrace[i], ignorePackages)) {
+                    if (count > 0) {
+                        appendSuppressedCount(sb, prefix, count, textRenderer);
+                        count = 0;
+                    }
+                    this.formatEntry(extStackTrace[i], sb, prefix, 
textRenderer);
+                } else {
+                    ++count;
+                }
+            }
+            if (count > 0) {
+                appendSuppressedCount(sb, prefix, count, textRenderer);
+            }
+        }
+        if (commonCount != 0) {
             textRenderer.render(prefix, sb, "Prefix");
             textRenderer.render("\t... ", sb, "More");
             textRenderer.render(Integer.toString(commonCount), sb, "More");
             textRenderer.render(" more", sb, "More");
             textRenderer.render(EOL_STR, sb, "Text");
-               }
-       }
+        }
+    }
 
-    private void appendSuppressedCount(final StringBuilder sb, final String 
prefix, final int count, final TextRenderer textRenderer) {
+    private void appendSuppressedCount(final StringBuilder sb, final String 
prefix, final int count,
+                                       final TextRenderer textRenderer) {
         textRenderer.render(prefix, sb, "Prefix");
         if (count == 1) {
             textRenderer.render("\t... ", sb, "Suppressed");
@@ -295,7 +292,8 @@ public class ThrowableProxy implements Serializable {
         textRenderer.render(EOL_STR, sb, "Text");
     }
 
-    private void formatEntry(final ExtendedStackTraceElement 
extStackTraceElement, final StringBuilder sb, final String prefix, final 
TextRenderer textRenderer) {
+    private void formatEntry(final ExtendedStackTraceElement 
extStackTraceElement, final StringBuilder sb,
+                             final String prefix, final TextRenderer 
textRenderer) {
         textRenderer.render(prefix, sb, "Prefix");
         textRenderer.render("\tat ", sb, "At");
         extStackTraceElement.renderOn(sb, textRenderer);
@@ -304,11 +302,9 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Formats the specified Throwable.
-     * 
-     * @param sb
-     *        StringBuilder to contain the formatted Throwable.
-     * @param cause
-     *        The Throwable to format.
+     *
+     * @param sb    StringBuilder to contain the formatted Throwable.
+     * @param cause The Throwable to format.
      */
     public void formatWrapper(final StringBuilder sb, final ThrowableProxy 
cause) {
         this.formatWrapper(sb, cause, null, PlainTextRenderer.getInstance());
@@ -316,13 +312,10 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Formats the specified Throwable.
-     * 
-     * @param sb
-     *        StringBuilder to contain the formatted Throwable.
-     * @param cause
-     *        The Throwable to format.
-     * @param ignorePackages
-     *        The List of packages to be suppressed from the trace.
+     *
+     * @param sb             StringBuilder to contain the formatted Throwable.
+     * @param cause          The Throwable to format.
+     * @param ignorePackages The List of packages to be suppressed from the 
trace.
      */
     @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
     public void formatWrapper(final StringBuilder sb, final ThrowableProxy 
cause, final List<String> ignorePackages) {
@@ -331,18 +324,15 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Formats the specified Throwable.
-     * 
-     * @param sb
-     *            StringBuilder to contain the formatted Throwable.
-     * @param cause
-     *            The Throwable to format.
-     * @param ignorePackages
-     *            The List of packages to be suppressed from the trace.
-     * @param textRenderer
-     *            The text render
+     *
+     * @param sb             StringBuilder to contain the formatted Throwable.
+     * @param cause          The Throwable to format.
+     * @param ignorePackages The List of packages to be suppressed from the 
trace.
+     * @param textRenderer   The text render
      */
     @SuppressWarnings("ThrowableResultOfMethodCallIgnored")
-    public void formatWrapper(final StringBuilder sb, final ThrowableProxy 
cause, final List<String> ignorePackages, final TextRenderer textRenderer) {
+    public void formatWrapper(final StringBuilder sb, final ThrowableProxy 
cause, final List<String> ignorePackages,
+                              final TextRenderer textRenderer) {
         final Throwable caused = cause.getCauseProxy() != null ? 
cause.getCauseProxy().getThrowable() : null;
         if (caused != null) {
             this.formatWrapper(sb, cause.causeProxy, ignorePackages, 
textRenderer);
@@ -351,7 +341,7 @@ public class ThrowableProxy implements Serializable {
         cause.renderOn(sb, textRenderer);
         textRenderer.render(EOL_STR, sb, "Text");
         this.formatElements(sb, Strings.EMPTY, cause.commonElementCount,
-                cause.getThrowable().getStackTrace(), 
cause.extendedStackTrace, ignorePackages, textRenderer);
+            cause.getThrowable().getStackTrace(), cause.extendedStackTrace, 
ignorePackages, textRenderer);
     }
 
     public ThrowableProxy getCauseProxy() {
@@ -360,7 +350,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Formats the Throwable that is the cause of this Throwable.
-     * 
+     *
      * @return The formatted Throwable that caused this Throwable.
      */
     public String getCauseStackTraceAsString() {
@@ -369,9 +359,8 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Formats the Throwable that is the cause of this Throwable.
-     * 
-     * @param packages
-     *        The List of packages to be suppressed from the trace.
+     *
+     * @param packages The List of packages to be suppressed from the trace.
      * @return The formatted Throwable that caused this Throwable.
      */
     public String getCauseStackTraceAsString(final List<String> packages) {
@@ -380,11 +369,9 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Formats the Throwable that is the cause of this Throwable.
-     * 
-     * @param ignorePackages
-     *            The List of packages to be suppressed from the trace.
-     * @param textRenderer
-     *            the text renderer
+     *
+     * @param ignorePackages The List of packages to be suppressed from the 
trace.
+     * @param textRenderer   the text renderer
      * @return The formatted Throwable that caused this Throwable.
      */
     public String getCauseStackTraceAsString(final List<String> 
ignorePackages, final TextRenderer textRenderer) {
@@ -396,14 +383,14 @@ public class ThrowableProxy implements Serializable {
         this.renderOn(sb, textRenderer);
         textRenderer.render(EOL_STR, sb, "Text");
         this.formatElements(sb, Strings.EMPTY, 0, 
this.throwable.getStackTrace(), this.extendedStackTrace,
-                ignorePackages, textRenderer);
+            ignorePackages, textRenderer);
         return sb.toString();
     }
 
     /**
      * Returns the number of elements that are being omitted because they are 
common with the parent Throwable's stack
      * trace.
-     * 
+     *
      * @return The number of elements omitted from the stack trace.
      */
     public int getCommonElementCount() {
@@ -412,7 +399,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Gets the stack trace including packaging information.
-     * 
+     *
      * @return The stack trace including packaging information.
      */
     public ExtendedStackTraceElement[] getExtendedStackTrace() {
@@ -421,7 +408,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Format the stack trace including packaging information.
-     * 
+     *
      * @return The formatted stack trace including packaging information.
      */
     public String getExtendedStackTraceAsString() {
@@ -430,9 +417,8 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Format the stack trace including packaging information.
-     * 
-     * @param ignorePackages
-     *        List of packages to be ignored in the trace.
+     *
+     * @param ignorePackages List of packages to be ignored in the trace.
      * @return The formatted stack trace including packaging information.
      */
     public String getExtendedStackTraceAsString(final List<String> 
ignorePackages) {
@@ -441,11 +427,9 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Format the stack trace including packaging information.
-     * 
-     * @param ignorePackages
-     *            List of packages to be ignored in the trace.
-     * @param textRenderer
-     *            The message renderer
+     *
+     * @param ignorePackages List of packages to be ignored in the trace.
+     * @param textRenderer   The message renderer
      * @return The formatted stack trace including packaging information.
      */
     public String getExtendedStackTraceAsString(final List<String> 
ignorePackages, final TextRenderer textRenderer) {
@@ -471,7 +455,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Return the FQCN of the Throwable.
-     * 
+     *
      * @return The FQCN of the Throwable.
      */
     public String getName() {
@@ -484,7 +468,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Gets proxies for suppressed exceptions.
-     * 
+     *
      * @return proxies for suppressed exceptions.
      */
     public ThrowableProxy[] getSuppressedProxies() {
@@ -493,7 +477,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Format the suppressed Throwables.
-     * 
+     *
      * @return The formatted suppressed Throwables.
      */
     public String getSuppressedStackTrace() {
@@ -510,7 +494,7 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * The throwable or null if this object is deserialized from XML or JSON.
-     * 
+     *
      * @return The throwable or null if this object is deserialized from XML 
or JSON.
      */
     public Throwable getThrowable() {
@@ -543,11 +527,9 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Loads classes not located via Reflection.getCallerClass.
-     * 
-     * @param lastLoader
-     *        The ClassLoader that loaded the Class that called this Class.
-     * @param className
-     *        The name of the Class.
+     *
+     * @param lastLoader The ClassLoader that loaded the Class that called 
this Class.
+     * @param className  The name of the Class.
      * @return The Class object for the Class or null if it could not be 
located.
      */
     private Class<?> loadClass(final ClassLoader lastLoader, final String 
className) {
@@ -583,18 +565,14 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Construct the CacheEntry from the Class's information.
-     * 
-     * @param stackTraceElement
-     *        The stack trace element
-     * @param callerClass
-     *        The Class.
-     * @param exact
-     *        True if the class was obtained via Reflection.getCallerClass.
-     * 
+     *
+     * @param stackTraceElement The stack trace element
+     * @param callerClass       The Class.
+     * @param exact             True if the class was obtained via 
Reflection.getCallerClass.
      * @return The CacheEntry.
      */
     private CacheEntry toCacheEntry(final StackTraceElement stackTraceElement, 
final Class<?> callerClass,
-            final boolean exact) {
+                                    final boolean exact) {
         String location = "?";
         String version = "?";
         ClassLoader lastLoader = null;
@@ -631,19 +609,16 @@ public class ThrowableProxy implements Serializable {
 
     /**
      * Resolve all the stack entries in this stack trace that are not common 
with the parent.
-     * 
-     * @param stack
-     *        The callers Class stack.
-     * @param map
-     *        The cache of CacheEntry objects.
-     * @param rootTrace
-     *        The first stack trace resolve or null.
-     * @param stackTrace
-     *        The stack trace being resolved.
+     *
+     * @param stack      The callers Class stack.
+     * @param map        The cache of CacheEntry objects.
+     * @param rootTrace  The first stack trace resolve or null.
+     * @param stackTrace The stack trace being resolved.
      * @return The StackTracePackageElement array.
      */
     ExtendedStackTraceElement[] toExtendedStackTrace(final Stack<Class<?>> 
stack, final Map<String, CacheEntry> map,
-            final StackTraceElement[] rootTrace, final StackTraceElement[] 
stackTrace) {
+                                                     final StackTraceElement[] 
rootTrace,
+                                                     final StackTraceElement[] 
stackTrace) {
         int stackLength;
         if (rootTrace != null) {
             int rootIndex = rootTrace.length - 1;
@@ -684,7 +659,7 @@ public class ThrowableProxy implements Serializable {
                     }
                 } else {
                     final CacheEntry entry = 
this.toCacheEntry(stackTraceElement,
-                            this.loadClass(lastLoader, className), false);
+                        this.loadClass(lastLoader, className), false);
                     extClassInfo = entry.element;
                     map.put(stackTraceElement.toString(), entry);
                     if (entry.loader != null) {

Reply via email to