This is an automated email from the ASF dual-hosted git repository. lihan pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/8.5.x by this push: new 06dcaa332e Fix a regression that caused a nuance in refactoring for ErrorReportValve 06dcaa332e is described below commit 06dcaa332e9276b95a25f9016a98c44c0b995f7d Author: lihan <li...@apache.org> AuthorDate: Mon Nov 7 10:18:24 2022 +0800 Fix a regression that caused a nuance in refactoring for ErrorReportValve revert 64573401. https://bz.apache.org/bugzilla/show_bug.cgi?id=66338 --- .../apache/catalina/valves/ErrorReportValve.java | 35 +++++++++++----------- .../catalina/valves/JsonErrorReportValve.java | 20 +++++++++++++ webapps/docs/changelog.xml | 4 +++ 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/java/org/apache/catalina/valves/ErrorReportValve.java b/java/org/apache/catalina/valves/ErrorReportValve.java index cc204695f8..42ae752c77 100644 --- a/java/org/apache/catalina/valves/ErrorReportValve.java +++ b/java/org/apache/catalina/valves/ErrorReportValve.java @@ -141,23 +141,6 @@ public class ErrorReportValve extends ValveBase { response.setSuspended(false); try { - int statusCode = response.getStatus(); - - // Do nothing on a 1xx, 2xx and 3xx status - // Do nothing if anything has been written already - // Do nothing if the response hasn't been explicitly marked as in error - // and that error has not been reported. - if (statusCode < 400 || response.getContentWritten() > 0 || !response.setErrorReported()) { - return; - } - - // If an error has occurred that prevents further I/O, don't waste time - // producing an error report that will never be read - AtomicBoolean result = new AtomicBoolean(false); - response.getCoyoteResponse().action(ActionCode.IS_IO_ALLOWED, result); - if (!result.get()) { - return; - } report(request, response, throwable); } catch (Throwable tt) { ExceptionUtils.handleThrowable(tt); @@ -177,7 +160,25 @@ public class ErrorReportValve extends ValveBase { * a root cause exception */ protected void report(Request request, Response response, Throwable throwable) { + int statusCode = response.getStatus(); + + // Do nothing on a 1xx, 2xx and 3xx status + // Do nothing if anything has been written already + // Do nothing if the response hasn't been explicitly marked as in error + // and that error has not been reported. + if (statusCode < 400 || response.getContentWritten() > 0 || !response.setErrorReported()) { + return; + } + + // If an error has occurred that prevents further I/O, don't waste time + // producing an error report that will never be read + AtomicBoolean result = new AtomicBoolean(false); + response.getCoyoteResponse().action(ActionCode.IS_IO_ALLOWED, result); + if (!result.get()) { + return; + } + ErrorPage errorPage = null; if (throwable != null) { errorPage = errorPageSupport.find(throwable); diff --git a/java/org/apache/catalina/valves/JsonErrorReportValve.java b/java/org/apache/catalina/valves/JsonErrorReportValve.java index 8af7968d30..a9bb895585 100644 --- a/java/org/apache/catalina/valves/JsonErrorReportValve.java +++ b/java/org/apache/catalina/valves/JsonErrorReportValve.java @@ -18,9 +18,11 @@ package org.apache.catalina.valves; import java.io.IOException; import java.io.Writer; +import java.util.concurrent.atomic.AtomicBoolean; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; +import org.apache.coyote.ActionCode; import org.apache.tomcat.util.ExceptionUtils; import org.apache.tomcat.util.res.StringManager; @@ -39,7 +41,25 @@ public class JsonErrorReportValve extends ErrorReportValve { @Override protected void report(Request request, Response response, Throwable throwable) { + int statusCode = response.getStatus(); + + // Do nothing on a 1xx, 2xx and 3xx status + // Do nothing if anything has been written already + // Do nothing if the response hasn't been explicitly marked as in error + // and that error has not been reported. + if (statusCode < 400 || response.getContentWritten() > 0 || !response.setErrorReported()) { + return; + } + + // If an error has occurred that prevents further I/O, don't waste time + // producing an error report that will never be read + AtomicBoolean result = new AtomicBoolean(false); + response.getCoyoteResponse().action(ActionCode.IS_IO_ALLOWED, result); + if (!result.get()) { + return; + } + StringManager smClient = StringManager.getManager(Constants.Package, request.getLocales()); response.setLocale(smClient.getLocale()); String type = null; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index b778b75c52..3d49ec6b9b 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -119,6 +119,10 @@ on the <code>SystemLogHandler</code> which caught incorrect exception. (lihan) </fix> + <fix> + <bug>66338</bug>: Fix a regression that caused a nuance in refactoring + for <code>ErrorReportValve</code>. (lihan) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org