From a421c0ab5bbed82414554ce8ac6b9efe7236d2f7 Mon Sep 17 00:00:00 2001 From: James Perkins Date: Tue, 6 Nov 2018 07:04:03 -0800 Subject: [PATCH 1/2] [LOGMGR-210] Use the StackTraceFormatter to format exceptions in structured formatters. --- .../jboss/logmanager/formatters/StructuredFormatter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/jboss/logmanager/formatters/StructuredFormatter.java b/src/main/java/org/jboss/logmanager/formatters/StructuredFormatter.java index d83b5ad8..562ccba2 100644 --- a/src/main/java/org/jboss/logmanager/formatters/StructuredFormatter.java +++ b/src/main/java/org/jboss/logmanager/formatters/StructuredFormatter.java @@ -19,7 +19,6 @@ package org.jboss.logmanager.formatters; -import java.io.PrintWriter; import java.io.Writer; import java.time.Instant; import java.time.ZoneId; @@ -248,9 +247,9 @@ public final synchronized String format(final ExtLogRecord record) { } if (isFormattedExceptionOutputType()) { - final StringBuilderWriter w = new StringBuilderWriter(); - thrown.printStackTrace(new PrintWriter(w)); - generator.add(getKey(Key.STACK_TRACE), w.toString()); + final StringBuilder sb = new StringBuilder(); + StackTraceFormatter.renderStackTrace(sb, thrown, false, -1); + generator.add(getKey(Key.STACK_TRACE), sb.toString()); } } if (details) { From 947376bc31fa045140c2c9f71815d0ed0f5896a5 Mon Sep 17 00:00:00 2001 From: James Perkins Date: Tue, 6 Nov 2018 07:04:50 -0800 Subject: [PATCH 2/2] Ignore checking the stack trace for the IBM JDK as the exceptions are not formatted the same as OpenJDK or how the StackTraceFormatter formats them. --- .../logmanager/formatters/StackTraceFormatterTests.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/test/java/org/jboss/logmanager/formatters/StackTraceFormatterTests.java b/src/test/java/org/jboss/logmanager/formatters/StackTraceFormatterTests.java index d7f2facd..47afab6b 100644 --- a/src/test/java/org/jboss/logmanager/formatters/StackTraceFormatterTests.java +++ b/src/test/java/org/jboss/logmanager/formatters/StackTraceFormatterTests.java @@ -23,6 +23,7 @@ import java.io.StringWriter; import org.junit.Assert; +import org.junit.Assume; import org.junit.Test; /** @@ -30,6 +31,8 @@ */ public class StackTraceFormatterTests { + private static final boolean IS_IBM_JDK = System.getProperty("java.vendor").startsWith("IBM"); + @Test public void compareSimpleStackTrace() { final RuntimeException e = new RuntimeException(); @@ -57,6 +60,7 @@ public void compareCauseStackTrace() { @Test public void compareSuppressedAndCauseStackTrace() { + Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK); final RuntimeException r1 = new RuntimeException("Exception 1"); final RuntimeException r2 = new RuntimeException("Exception 2", r1); final RuntimeException r3 = new RuntimeException("Exception 3", r2); @@ -76,6 +80,7 @@ public void compareSuppressedAndCauseStackTrace() { @Test public void compareNestedSuppressedStackTrace() { + Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK); final RuntimeException r1 = new RuntimeException("Exception 1"); final RuntimeException r2 = new RuntimeException("Exception 2", r1); final RuntimeException r3 = new RuntimeException("Exception 3", r2); @@ -99,6 +104,7 @@ public void compareNestedSuppressedStackTrace() { @Test public void compareMultiNestedSuppressedStackTrace() { + Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK); final Throwable cause = createMultiNestedCause(); final StringWriter writer = new StringWriter(); @@ -112,6 +118,7 @@ public void compareMultiNestedSuppressedStackTrace() { @Test public void compareMultiNestedSuppressedAndNestedCauseStackTrace() { + Assume.assumeFalse("The IBM JDK does not show print circular references.", IS_IBM_JDK); final Throwable rootCause = createMultiNestedCause(); final RuntimeException cause = new RuntimeException("This is the parent", rootCause);