Merge remote-tracking branch 'origin/jetty-9.2.x'

This commit is contained in:
Greg Wilkins 2015-07-23 22:51:57 +10:00
commit 32e63eb0fd
3 changed files with 40 additions and 53 deletions

View File

@ -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;
}
@ -173,47 +172,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);
}
}
}
}

View File

@ -714,7 +714,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)
{
@ -722,20 +727,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);
}
}
}

View File

@ -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;
@ -694,6 +695,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)
{