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 2019/11/14 22:00:01 UTC

[tomcat] branch 8.5.x updated: Fix remaining SpotBugs warnings in main code tree

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

markt 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 065f64c  Fix remaining SpotBugs warnings in main code tree
065f64c is described below

commit 065f64c7ee3762b5df191ababc72c3d50e523ab3
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Nov 14 21:58:43 2019 +0000

    Fix remaining SpotBugs warnings in main code tree
---
 .../tomcat/util/net/NioBlockingSelector.java       |  4 +-
 java/org/apache/tomcat/util/threads/TaskQueue.java |  6 +-
 res/findbugs/filter-false-positives.xml            | 83 ++++++++++++++++++++++
 3 files changed, 88 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/tomcat/util/net/NioBlockingSelector.java b/java/org/apache/tomcat/util/net/NioBlockingSelector.java
index fe193bc..286c06f 100644
--- a/java/org/apache/tomcat/util/net/NioBlockingSelector.java
+++ b/java/org/apache/tomcat/util/net/NioBlockingSelector.java
@@ -41,7 +41,7 @@ public class NioBlockingSelector {
 
     private static final Log log = LogFactory.getLog(NioBlockingSelector.class);
 
-    private static int threadCounter = 0;
+    private static AtomicInteger threadCounter = new AtomicInteger(0);
 
     private final SynchronizedStack<KeyReference> keyReferenceStack =
             new SynchronizedStack<>();
@@ -58,7 +58,7 @@ public class NioBlockingSelector {
         poller = new BlockPoller();
         poller.selector = sharedSelector;
         poller.setDaemon(true);
-        poller.setName("NioBlockingSelector.BlockPoller-"+(++threadCounter));
+        poller.setName("NioBlockingSelector.BlockPoller-"+(threadCounter.getAndIncrement()));
         poller.start();
     }
 
diff --git a/java/org/apache/tomcat/util/threads/TaskQueue.java b/java/org/apache/tomcat/util/threads/TaskQueue.java
index 03e738c..600fe5b 100644
--- a/java/org/apache/tomcat/util/threads/TaskQueue.java
+++ b/java/org/apache/tomcat/util/threads/TaskQueue.java
@@ -32,7 +32,7 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> {
 
     private static final long serialVersionUID = 1L;
 
-    private volatile ThreadPoolExecutor parent = null;
+    private transient volatile ThreadPoolExecutor parent = null;
 
     // No need to be volatile. This is written and read in a single thread
     // (when stopping a context and firing the  listeners)
@@ -55,12 +55,12 @@ public class TaskQueue extends LinkedBlockingQueue<Runnable> {
     }
 
     public boolean force(Runnable o) {
-        if ( parent==null || parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue");
+        if (parent == null || parent.isShutdown()) throw new RejectedExecutionException("Executor not running, can't force a command into the queue");
         return super.offer(o); //forces the item onto the queue, to be used if the task is rejected
     }
 
     public boolean force(Runnable o, long timeout, TimeUnit unit) throws InterruptedException {
-        if ( parent==null || parent.isShutdown() ) throw new RejectedExecutionException("Executor not running, can't force a command into the queue");
+        if (parent == null || parent.isShutdown()) throw new RejectedExecutionException("Executor not running, can't force a command into the queue");
         return super.offer(o,timeout,unit); //forces the item onto the queue, to be used if the task is rejected
     }
 
diff --git a/res/findbugs/filter-false-positives.xml b/res/findbugs/filter-false-positives.xml
index dff3613..4578e0b 100644
--- a/res/findbugs/filter-false-positives.xml
+++ b/res/findbugs/filter-false-positives.xml
@@ -1147,6 +1147,11 @@
     <Bug pattern="UUF_UNUSED_PUBLIC_OR_PROTECTED_FIELD" />
   </Match>
   <Match>
+    <!-- Field is populated by JNI code -->
+    <Class name="org.apache.tomcat.jni.Sockaddr" />
+    <Bug pattern="UWF_UNWRITTEN_PUBLIC_OR_PROTECTED_FIELD"/>
+  </Match>
+  <Match>
     <Class name="org.apache.tomcat.util.IntrospectionUtils" />
     <Method name="findMethod"/>
     <Bug code="NP" />
@@ -1312,6 +1317,25 @@
     <Bug code="NN" />
   </Match>
   <Match>
+    <!-- There is only a single wait in run() when the poller is idle -->
+    <Class name="org.apache.tomcat.util.net.AprEndpoint$Poller"/>
+    <Or>
+      <Method name="add"/>
+      <Method name="close"/>
+      <Method name="destroy"/>
+    </Or>
+    <Bug pattern="NO_NOTIFY_NOT_NOTIFYALL" />
+  </Match>
+  <Match>
+    <!-- Single condition. No interupts. -->
+    <Or>
+      <Class name="org.apache.tomcat.util.net.AprEndpoint$Poller"/>
+      <Class name="org.apache.tomcat.util.net.AprEndpoint$Sendfile"/>
+    </Or>
+    <Method name="destroy"/>
+    <Bug pattern="WA_NOT_IN_LOOP" />
+  </Match>
+  <Match>
     <Class name="org.apache.tomcat.util.net.AprEndpoint$Sendfile"/>
     <Method name="run"/>
     <Or>
@@ -1322,6 +1346,21 @@
     </Or>
   </Match>
   <Match>
+    <!-- There is only a single wait in run() when the poller is idle -->
+    <Class name="org.apache.tomcat.util.net.AprEndpoint$Sendfile"/>
+    <Or>
+      <Method name="add"/>
+      <Method name="destroy"/>
+    </Or>
+    <Bug pattern="NO_NOTIFY_NOT_NOTIFYALL" />
+  </Match>
+  <Match>
+    <!-- Simpler to wait a pollTime than test each Poller thread -->
+    <Class name="org.apache.tomcat.util.net.AprEndpoint$Sendfile"/>
+    <Method name="destroy"/>
+    <Bug pattern="UW_UNCOND_WAIT" />
+  </Match>
+  <Match>
     <!-- Sync is there to protect referenced object not field -->
     <Class name="org.apache.tomcat.util.net.AprEndpoint$SocketEventProcessor"/>
     <Method name="run"/>
@@ -1365,6 +1404,24 @@
     <Bug code="ML"/>
   </Match>
   <Match>
+    <!-- Single condition so no need for wait to be in loop -->
+    <Class name="org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper"/>
+    <Or>
+      <Method name="read"/>
+      <Method name="write"/>
+    </Or>
+    <Bug pattern="WA_NOT_IN_LOOP" />
+  </Match>
+  <Match>
+    <!-- Single wait so no need for notifyAll() -->
+    <Class name="org.apache.tomcat.util.net.Nio2Endpoint$Nio2SocketWrapper$VectoredIOCompletionHandler"/>
+    <Or>
+      <Method name="completed"/>
+      <Method name="failed"/>
+    </Or>
+    <Bug pattern="NO_NOTIFY_NOT_NOTIFYALL " />
+  </Match>
+  <Match>
     <Class name="org.apache.tomcat.util.net.SecureNioChannel"/>
     <Method name="rehandshake"/>
     <Bug code="DE" />
@@ -1382,6 +1439,26 @@
     <Bug code="SF" />
   </Match>
   <Match>
+    <!-- Stream will be closed -->
+    <Class name="org.apache.tomcat.util.net.jsse.PEMFile" />
+    <Method name="&lt;init&gt;" />
+    <Pattern name="OS_OPEN_STREAM" />
+  </Match>
+  <Match>
+    <!-- Array elements are not modified after assignment -->
+    <Class name="org.apache.tomcat.util.net.openssl.OpenSSLEngine" />
+    <Or>
+      <Field name="peerCerts"/>
+      <Field name="x509PeerCerts"/>
+    </Or>
+    <Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY" />
+  </Match>
+  <Match>
+    <!-- No performance issue as there is no DNS resolution -->
+    <Class name="org.apache.tomcat.util.scan.StandardJarScanner" />
+    <Bug pattern="DMI_COLLECTION_OF_URLS" />
+  </Match>
+  <Match>
     <!-- Yes the simple name is the same as the super class. Accept it. -->
     <Class name="org.apache.tomcat.util.threads.ThreadPoolExecutor" />
     <Bug code="Nm" />
@@ -1398,6 +1475,12 @@
     <Method name="upgradeDispatch"/>
     <Bug code="SF" />
   </Match>
+  <Match>
+    <!-- The array contents is never mutated. -->
+    <Class name="org.apache.tomcat.websocket.server.WsRemoteEndpointImplServer" />
+    <Field name="buffers" />
+    <Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY" />
+  </Match>
 
   <!-- Example code -->
   <Match>


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