Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Wilkins2015-07-23 12:50:20 +0000
committerGreg Wilkins2015-07-23 12:50:20 +0000
commitc9c2ebc5325e3c11fa9f6ca2193fad5a7095f3cc (patch)
treec8f41350e5f5f5b2a3c6678ae7c00ea4210eae35
parentac8316756c53e7c2be8b81fa1ecb4f35dabd576e (diff)
downloadorg.eclipse.jetty.project-c9c2ebc5325e3c11fa9f6ca2193fad5a7095f3cc.tar.gz
org.eclipse.jetty.project-c9c2ebc5325e3c11fa9f6ca2193fad5a7095f3cc.tar.xz
org.eclipse.jetty.project-c9c2ebc5325e3c11fa9f6ca2193fad5a7095f3cc.zip
473266 - Better handling of MultiException
Add extra exceptions as suppressed exceptions
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java52
-rw-r--r--jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java21
-rw-r--r--jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java20
3 files changed, 40 insertions, 53 deletions
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java
index 5dd913feb2..f3e7d39d21 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/MultiException.java
@@ -18,8 +18,6 @@
package org.eclipse.jetty.util;
-import java.io.PrintStream;
-import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -45,12 +43,14 @@ public class MultiException extends Exception
{
if (e==null)
throw new IllegalArgumentException();
-
+
if(nested == null)
{
initCause(e);
nested = new ArrayList<>();
}
+ else
+ addSuppressed(e);
if (e instanceof MultiException)
{
@@ -70,9 +70,8 @@ public class MultiException extends Exception
/* ------------------------------------------------------------ */
public List<Throwable> getThrowables()
{
- if(nested == null) {
+ if(nested == null)
return Collections.emptyList();
- }
return nested;
}
@@ -172,47 +171,4 @@ public class MultiException extends Exception
return str.toString();
}
- /* ------------------------------------------------------------ */
- @Override
- public void printStackTrace()
- {
- super.printStackTrace();
- if(nested != null) {
- for(Throwable t: nested) {
- t.printStackTrace();
- }
- }
- }
-
-
- /* ------------------------------------------------------------------------------- */
- /**
- * @see java.lang.Throwable#printStackTrace(java.io.PrintStream)
- */
- @Override
- public void printStackTrace(PrintStream out)
- {
- super.printStackTrace(out);
- if(nested != null) {
- for(Throwable t: nested) {
- t.printStackTrace(out);
- }
- }
- }
-
- /* ------------------------------------------------------------------------------- */
- /**
- * @see java.lang.Throwable#printStackTrace(java.io.PrintWriter)
- */
- @Override
- public void printStackTrace(PrintWriter out)
- {
- super.printStackTrace(out);
- if(nested != null) {
- for(Throwable t: nested) {
- t.printStackTrace(out);
- }
- }
- }
-
}
diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
index 66e6371c0a..dfc9168475 100644
--- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
+++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StdErrLog.java
@@ -694,7 +694,12 @@ public class StdErrLog extends AbstractLogger
builder.append(string);
}
- private void format(StringBuilder buffer, Throwable thrown)
+ protected void format(StringBuilder buffer, Throwable thrown)
+ {
+ format(buffer,thrown,"");
+ }
+
+ protected void format(StringBuilder buffer, Throwable thrown, String indent)
{
if (thrown == null)
{
@@ -702,20 +707,26 @@ public class StdErrLog extends AbstractLogger
}
else
{
- buffer.append(EOL);
+ buffer.append(EOL).append(indent);
format(buffer,thrown.toString());
StackTraceElement[] elements = thrown.getStackTrace();
for (int i = 0; elements != null && i < elements.length; i++)
{
- buffer.append(EOL).append("\tat ");
+ buffer.append(EOL).append(indent).append("\tat ");
format(buffer,elements[i].toString());
}
+ for (Throwable suppressed:thrown.getSuppressed())
+ {
+ buffer.append(EOL).append(indent).append("Suppressed: ");
+ format(buffer,suppressed,"\t|"+indent);
+ }
+
Throwable cause = thrown.getCause();
if (cause != null && cause != thrown)
{
- buffer.append(EOL).append("Caused by: ");
- format(buffer,cause);
+ buffer.append(EOL).append(indent).append("Caused by: ");
+ format(buffer,cause,indent);
}
}
}
diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java
index 73633da1b8..38fd37e517 100644
--- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java
+++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java
@@ -22,6 +22,7 @@ import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
@@ -683,6 +684,25 @@ public class StdErrLogTest
assertLevel(log,StdErrLog.LEVEL_WARN); // as configured
}
+ @Test
+ public void testSuppressed()
+ {
+ StdErrLog log = new StdErrLog("xxx",new Properties());
+ StdErrCapture output = new StdErrCapture(log);
+
+ Exception inner = new Exception("inner");
+ inner.addSuppressed( new IllegalStateException(){{addSuppressed(new Exception("branch0"));}});
+ IOException outer = new IOException("outer",inner);
+
+ outer.addSuppressed( new IllegalStateException(){{addSuppressed(new Exception("branch1"));}});
+ outer.addSuppressed( new IllegalArgumentException(){{addSuppressed(new Exception("branch2"));}});
+
+ log.warn("problem",outer);
+
+ output.assertContains("\t|\t|java.lang.Exception: branch2");
+ output.assertContains("\t|\t|java.lang.Exception: branch1");
+ output.assertContains("\t|\t|java.lang.Exception: branch0");
+ }
private void assertLevel(StdErrLog log, int expectedLevel)
{

Back to the top