UncaughtExceptionHandler should avoid reporting EOFException.
package hudson.init.impl;
import hudson.init.Initializer;
+import java.io.EOFException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.WebApp;
import org.kohsuke.stapler.compression.CompressionFilter;
@@ -17,7 +18,7 @@ import java.util.logging.Logger;
import org.kohsuke.stapler.Stapler;
/**
- * @author Kohsuke Kawaguchi
+ * Deals with exceptions that get thrown all the way up to the Stapler rendering layer.
*/
public class InstallUncaughtExceptionHandler {
@@ -25,23 +26,19 @@ public class InstallUncaughtExceptionHandler {
@Initializer
public static void init(final Jenkins j) throws IOException {
- CompressionFilter.setUncaughtExceptionHandler(j.servletContext, new UncaughtExceptionHandler() {
- @Override
- public void reportException(Throwable e, ServletContext context, HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
+ CompressionFilter.setUncaughtExceptionHandler(j.servletContext, (e, context, req, rsp) -> {
if (rsp.isCommitted()) {
- LOGGER.log(Level.WARNING, null, e);
+ LOGGER.log(isEOFException(e) ? Level.FINE : Level.WARNING, null, e);
return;
}
req.setAttribute("javax.servlet.error.exception",e);
try {
- WebApp.get(j.servletContext).getSomeStapler()
- .invoke(req,rsp, Jenkins.getInstance(), "/oops");
+ WebApp.get(j.servletContext).getSomeStapler().invoke(req, rsp, Jenkins.get(), "/oops");
} catch (ServletException | IOException x) {
if (!Stapler.isSocketException(x)) {
throw x;
}
}
- }
});
try {
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
@@ -57,6 +54,16 @@ public class InstallUncaughtExceptionHandler {
}
}
+ private static boolean isEOFException(Throwable e) {
+ if (e == null) {
+ return false;
+ } else if (e instanceof EOFException) {
+ return true;
+ } else {
+ return isEOFException(e.getCause());
+ }
+ }
+
/** An UncaughtExceptionHandler that just logs the exception */
private static class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
