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

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-dbcp.git

commit 86eafdd9f1c1e795b01cc29b431c35c1ecd3fbb7
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Mon May 26 14:21:50 2025 -0400

    [ERROR] Medium: Shared primitive variables in one thread may not yield
    the value of the most recent write from another thread
    [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    
    - [ERROR] Medium: Shared primitive variable "autoCommitOnReturn" in one
    thread may not yield the value of the most recent write from another
    thread [org.apache.commons.dbc-p2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "cacheState" in one thread
    may not yield the value of the most recent write from another thread
    [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "clearStatementPoolOnReturn"
    in one thread may not yield the value of the most recent write from
    another thread [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "autoCommitOnReturn" in one
    thread may not yield the value of the most recent write from another
    thread [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "fastFailValidation" in one
    thread may not yield the value of the most recent write from another
    thread [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "logExpiredConnections" in
    one thread may not yield the value of the most recent write from another
    thread [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "registerConnectionMBean" in
    one thread may not yield the value of the most recent write from another
    thread [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
    - [ERROR] Medium: Shared primitive variable "rollbackOnReturn" in one
    thread may not yield the value of the most recent write from another
    thread [org.apache.commons.dbcp2.BasicDataSource]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
---
 src/changes/changes.xml                                  |  8 ++++++++
 .../java/org/apache/commons/dbcp2/BasicDataSource.java   | 16 ++++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 85a9cdf5..d9ae3bb9 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -108,6 +108,14 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "maxOpenPreparedStatements" in one 
thread may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.PoolableConnectionFactory] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "poolStatements" in one thread may 
not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.PoolableConnectionFactory] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "rollbackOnReturn" in one thread may 
not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.PoolableConnectionFactory] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "autoCommitOnReturn" in one thread 
may not yield the value of the most recent write from another thread 
[org.apache.commons.dbc-p2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "cacheState" in one thread may not 
yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "clearStatementPoolOnReturn" in one 
thread may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "autoCommitOnReturn" in one thread 
may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "fastFailValidation" in one thread 
may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "logExpiredConnections" in one thread 
may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "registerConnectionMBean" in one 
thread may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "rollbackOnReturn" in one thread may 
not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.BasicDataSource] 
AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
org.apache.commons.dbcp2.datasources.PooledConnectionManager.setPassword(char[]).</action>
       <!-- UPDATE -->
diff --git a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java 
b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
index 4df72aea..c13f45df 100644
--- a/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/BasicDataSource.java
@@ -154,7 +154,7 @@ public class BasicDataSource implements DataSource, 
BasicDataSourceMXBean, MBean
      * The property that controls if the pooled connections cache some state 
rather than query the database for current
      * state to improve performance.
      */
-    private boolean cacheState = true;
+    private volatile boolean cacheState = true;
 
     /**
      * The instance of the JDBC Driver to use.
@@ -220,7 +220,7 @@ public class BasicDataSource implements DataSource, 
BasicDataSourceMXBean, MBean
      */
     private boolean poolPreparedStatements;
 
-    private boolean clearStatementPoolOnReturn;
+    private volatile boolean clearStatementPoolOnReturn;
 
     /**
      * <p>
@@ -331,19 +331,19 @@ public class BasicDataSource implements DataSource, 
BasicDataSourceMXBean, MBean
     /**
      * Controls access to the underlying connection.
      */
-    private boolean accessToUnderlyingConnectionAllowed;
+    private volatile boolean accessToUnderlyingConnectionAllowed;
 
     private Duration maxConnDuration = Duration.ofMillis(-1);
 
-    private boolean logExpiredConnections = true;
+    private volatile boolean logExpiredConnections = true;
 
     private String jmxName;
 
-    private boolean registerConnectionMBean = true;
+    private volatile boolean registerConnectionMBean = true;
 
-    private boolean autoCommitOnReturn = true;
+    private volatile boolean autoCommitOnReturn = true;
 
-    private boolean rollbackOnReturn = true;
+    private volatile boolean rollbackOnReturn = true;
 
     private volatile Set<String> disconnectionSqlCodes;
 
@@ -354,7 +354,7 @@ public class BasicDataSource implements DataSource, 
BasicDataSourceMXBean, MBean
      */
     private volatile Set<String> disconnectionIgnoreSqlCodes;
 
-    private boolean fastFailValidation;
+    private volatile boolean fastFailValidation;
 
     /**
      * The object pool that internally manages our connections.

Reply via email to