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

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


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 26ba1fcccf Pull up duplicate check codes
26ba1fcccf is described below

commit 26ba1fcccf5c29e771845e27cba0d47cbe563c6b
Author: lihan <li...@apache.org>
AuthorDate: Fri Sep 2 16:41:28 2022 +0800

    Pull up duplicate check codes
---
 .../apache/catalina/valves/ErrorReportValve.java   | 35 +++++++++++-----------
 .../catalina/valves/JsonErrorReportValve.java      | 18 -----------
 2 files changed, 17 insertions(+), 36 deletions(-)

diff --git a/java/org/apache/catalina/valves/ErrorReportValve.java 
b/java/org/apache/catalina/valves/ErrorReportValve.java
index 43e0e111df..f98a0d6a07 100644
--- a/java/org/apache/catalina/valves/ErrorReportValve.java
+++ b/java/org/apache/catalina/valves/ErrorReportValve.java
@@ -141,6 +141,23 @@ 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);
@@ -160,25 +177,7 @@ 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 8ba4acbc3f..9da5c33550 100644
--- a/java/org/apache/catalina/valves/JsonErrorReportValve.java
+++ b/java/org/apache/catalina/valves/JsonErrorReportValve.java
@@ -41,25 +41,7 @@ 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;


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to