This is an automated email from the ASF dual-hosted git repository.

lihan pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/main by this push:
     new 58d6656362 Fix a regression that caused a  nuance in refactoring for 
ErrorReportValve
58d6656362 is described below

commit 58d66563624026cc96cbc03045a649fedf440a9f
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 1048985d32..365109ebf9 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 319be06fe2..870cbc8c91 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -136,6 +136,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

Reply via email to