You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2021/06/23 16:07:17 UTC

[tomcat] branch 10.0.x updated: Fix concurrency issues reported by SpotBugs

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

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


The following commit(s) were added to refs/heads/10.0.x by this push:
     new ef57a96  Fix concurrency issues reported by SpotBugs
ef57a96 is described below

commit ef57a96e0fc772f9cb6dba7095b1882a2a97e129
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Wed Jun 23 17:06:25 2021 +0100

    Fix concurrency issues reported by SpotBugs
    
    Tests not affected as they don't generate concurrent requests to this
    servlet but fix the concurrency issues anyway.
---
 test/jakarta/servlet/http/TestHttpServletDoHead.java | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/test/jakarta/servlet/http/TestHttpServletDoHead.java b/test/jakarta/servlet/http/TestHttpServletDoHead.java
index 006c560..31f4b91 100644
--- a/test/jakarta/servlet/http/TestHttpServletDoHead.java
+++ b/test/jakarta/servlet/http/TestHttpServletDoHead.java
@@ -144,9 +144,6 @@ public class TestHttpServletDoHead extends TomcatBaseTest {
         private final int validWriteCount;
         private final boolean explicitFlush;
 
-        private PrintWriter pw = null;
-        private OutputStream os = null;
-
         public HeadTestServlet(int bufferSize, boolean useWriter, int invalidWriteCount, ResetType resetType,
                 int validWriteCount, boolean explicitFlush) {
             this.bufferSize = bufferSize;
@@ -164,6 +161,8 @@ public class TestHttpServletDoHead extends TomcatBaseTest {
             resp.setContentType("text/plain");
             resp.setCharacterEncoding("UTF-8");
 
+            PrintWriter pw = null;
+            OutputStream os = null;
             // Do this rather than repeated calls to getWriter() /
             // getOutputStream() to ensure that HEAD handling doesn't rely on
             // replacing the OutputStream / PrintWriter (an earlier
@@ -175,7 +174,7 @@ public class TestHttpServletDoHead extends TomcatBaseTest {
             }
 
             for (int i = 0; i < invalidWriteCount; i++) {
-                write(INVALID);
+                write(INVALID, pw, os);
             }
 
             try {
@@ -193,11 +192,11 @@ public class TestHttpServletDoHead extends TomcatBaseTest {
                     }
                 }
             } catch (IllegalStateException ise) {
-                write("\nIllegalStateException\n");
+                write("\nIllegalStateException\n", pw, os);
             }
 
             for (int i = 0; i < validWriteCount; i++) {
-                write(VALID);
+                write(VALID, pw, os);
             }
 
             if (explicitFlush) {
@@ -205,7 +204,7 @@ public class TestHttpServletDoHead extends TomcatBaseTest {
             }
         }
 
-        private void write(String msg) throws IOException {
+        private void write(String msg, PrintWriter pw, OutputStream os) throws IOException {
             if (useWriter) {
                 pw.print(msg);
             } else {

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