diff --git a/core/src/main/java/hudson/init/impl/InstallUncaughtExceptionHandler.java b/core/src/main/java/hudson/init/impl/InstallUncaughtExceptionHandler.java index be55c08ff4eb094724468d15ac4e0f69d4ed45d5..d8412f6ad45c3c0a8fda8c3c1fd3e00da87cc1f4 100644 --- a/core/src/main/java/hudson/init/impl/InstallUncaughtExceptionHandler.java +++ b/core/src/main/java/hudson/init/impl/InstallUncaughtExceptionHandler.java @@ -20,11 +20,18 @@ import org.kohsuke.stapler.Stapler; * @author Kohsuke Kawaguchi */ public class InstallUncaughtExceptionHandler { + + private static final Logger LOGGER = Logger.getLogger(InstallUncaughtExceptionHandler.class.getName()); + @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 { + if (rsp.isCommitted()) { + LOGGER.log(Level.WARNING, null, e); + return; + } req.setAttribute("javax.servlet.error.exception",e); try { WebApp.get(j.servletContext).getSomeStapler() @@ -38,10 +45,10 @@ public class InstallUncaughtExceptionHandler { }); try { Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler()); - DefaultUncaughtExceptionHandler.LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler."); + LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler."); } catch (SecurityException ex) { - DefaultUncaughtExceptionHandler.LOGGER.log(Level.SEVERE, + LOGGER.log(Level.SEVERE, "Failed to set the default UncaughtExceptionHandler. " + "If any threads die due to unhandled coding errors then there will be no logging of this information. " + "The lack of this diagnostic information will make it harder to track down issues which will reduce the supportability of Jenkins. " + @@ -53,8 +60,6 @@ public class InstallUncaughtExceptionHandler { /** An UncaughtExceptionHandler that just logs the exception */ private static class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler { - private static final Logger LOGGER = Logger.getLogger(InstallUncaughtExceptionHandler.class.getName()); - @Override public void uncaughtException(Thread t, Throwable ex) { // if this was an OutOfMemoryError then all bets about logging are off - but in the absence of anything else... @@ -65,4 +70,7 @@ public class InstallUncaughtExceptionHandler { } } + + private InstallUncaughtExceptionHandler() {} + }