tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject [tomcat] 01/04: Fix SpotBugs warnings in JDBC pool module
Date Wed, 20 Nov 2019 13:24:50 GMT
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

View the commit online:
https://github.com/apache/tomcat/commit/52c6412892def19fdd9a0f341f8c3f772839610d

commit 52c6412892def19fdd9a0f341f8c3f772839610d
Author: Mark Thomas <markt@apache.org>
AuthorDate: Wed Nov 20 12:23:21 2019 +0000

    Fix SpotBugs warnings in JDBC pool module
---
 .../org/apache/tomcat/jdbc/pool/ConnectionPool.java   |  5 ++++-
 .../org/apache/tomcat/jdbc/pool/PoolProperties.java   |  2 +-
 .../org/apache/tomcat/jdbc/pool/PooledConnection.java |  4 ++--
 .../tomcat/jdbc/pool/interceptor/StatementCache.java  |  3 ++-
 .../interceptor/StatementDecoratorInterceptor.java    |  2 +-
 res/findbugs/filter-false-positives.xml               | 19 +++++++++++++++++++
 6 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
index 7763a98..cbb1615 100644
--- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
+++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
@@ -622,7 +622,10 @@ public class ConnectionPool {
         // we could have threads stuck in idle.poll(timeout) that will never be
         // notified
         if (waitcount.get() > 0) {
-            idle.offer(create(true));
+            if (!idle.offer(create(true))) {
+                log.warn("Failed to add a new connection to the pool after releasing a connection
" +
+                        "when at least one thread was waiting for a connection.");
+            }
         }
     }
 
diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
index 3b09eb0..2d995d9 100644
--- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
+++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PoolProperties.java
@@ -54,7 +54,7 @@ public class PoolProperties implements PoolConfiguration, Cloneable, Serializabl
     private volatile String validationQuery;
     private volatile int validationQueryTimeout = -1;
     private volatile String validatorClassName;
-    private volatile Validator validator;
+    private transient volatile Validator validator;
     private volatile boolean testOnBorrow = false;
     private volatile boolean testOnReturn = false;
     private volatile boolean testWhileIdle = false;
diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
index 69cf1f0..8978810 100644
--- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
+++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/PooledConnection.java
@@ -202,9 +202,9 @@ public class PooledConnection implements PooledConnectionMBean {
                 log.debug("Unable to disconnect previous connection.", x);
             } //catch
         } //end if
-        if (poolProperties.getDataSource()==null && poolProperties.getDataSourceJNDI()!=null)
{
+        //if (poolProperties.getDataSource()==null && poolProperties.getDataSourceJNDI()!=null)
{
             //TODO lookup JNDI name
-        }
+        //}
 
         if (poolProperties.getDataSource()!=null) {
             connectUsingDataSource();
diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java
index 03b7f84..a5b4d36 100644
--- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java
+++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementCache.java
@@ -20,6 +20,7 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.Arrays;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -305,7 +306,7 @@ public class StatementCache extends StatementDecoratorInterceptor implements
Sta
                         proxy.cached = true;
                         shouldClose = false;
                     }
-                } catch (Exception x) {
+                } catch (RuntimeException | ReflectiveOperationException | SQLException x)
{
                     removeStatement(proxy);
                 }
             }
diff --git a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java
b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java
index 51ae9df..3066ef2 100644
--- a/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java
+++ b/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/StatementDecoratorInterceptor.java
@@ -49,7 +49,7 @@ public class StatementDecoratorInterceptor extends AbstractCreateStatementInterc
     /**
      * the constructor to create the resultSet proxies
      */
-    protected static Constructor<?> resultSetConstructor = null;
+    protected static volatile Constructor<?> resultSetConstructor = null;
 
     @Override
     public void closeInvoked() {
diff --git a/res/findbugs/filter-false-positives.xml b/res/findbugs/filter-false-positives.xml
index 4578e0b..5d63303 100644
--- a/res/findbugs/filter-false-positives.xml
+++ b/res/findbugs/filter-false-positives.xml
@@ -1104,6 +1104,14 @@
     <Bug code="RV" />
   </Match>
   <Match>
+    <!-- Name shadowing is deliberate -->
+    <Or>
+      <Class name="org.apache.tomcat.jdbc.pool.DataSource" />
+      <Class name="org.apache.tomcat.jdbc.pool.XADataSource" />
+    </Or>
+    <Bug pattern="NM_SAME_SIMPLE_NAME_AS_INTERFACE" />
+  </Match>
+  <Match>
     <!-- Lock is released -->
     <Class name="org.apache.tomcat.jdbc.pool.FairBlockingQueue" />
     <Method name="poll" />
@@ -1128,6 +1136,17 @@
     <Bug pattern="SQL_NONCONSTANT_STRING_PASSED_TO_EXECUTE" />
   </Match>
   <Match>
+    <!-- Array elements are not mutated -->
+    <Class name="org.apache.tomcat.jdbc.pool.PoolProperties" />
+    <Field name="interceptors" />
+    <Bug pattern="VO_VOLATILE_REFERENCE_TO_ARRAY" />
+  </Match>
+  <Match>
+    <!-- The name isn't great but it is part of the public API now -->
+    <Class name="org.apache.tomcat.jdbc.pool.TrapException" />
+    <Bug pattern="NM_CLASS_NOT_EXCEPTION" />
+  </Match>
+  <Match>
     <!-- Lack of thread-safety is accepted in return for better performance. -->
     <Class name="org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport$QueryStats" />
     <Or>


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


Mime
View raw message