Skip to content

Commit

Permalink
Issue #4334 - Improve testing of ErrorHandler behavior
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Nov 20, 2019
1 parent dc03431 commit 9e40fc9
Show file tree
Hide file tree
Showing 2 changed files with 283 additions and 76 deletions.
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -491,16 +492,18 @@ protected void writeErrorPageStacks(HttpServletRequest request, Writer writer)
throws IOException
{
Throwable th = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION);
if (_showStacks && th != null)
while (th != null)
{
PrintWriter pw = writer instanceof PrintWriter ? (PrintWriter)writer : new PrintWriter(writer);
pw.write("<pre>");
while (th != null)
{
th.printStackTrace(pw);
th = th.getCause();
}
writer.write("<h3>Caused by:</h3><pre>");
// You have to pre-generate and then use #write(writer, String)
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
th.printStackTrace(pw);
pw.flush();
write(writer, sw.getBuffer().toString()); // IMPORTANT STEP
writer.write("</pre>\n");

th = th.getCause();
}
}

Expand Down

0 comments on commit 9e40fc9

Please sign in to comment.