You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/05/26 15:36:48 UTC
(commons-dbcp) 07/13: Fix SpotBugs [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.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE
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 2f1b9d9ea53f3919239a362902a0180fab50fd6d
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Mon May 26 10:21:00 2025 -0400
Fix SpotBugs [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.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultBlockWhenExhausted" in one thread may not yield the value of the
most recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultLifo"
in one thread may not yield the value of the most recent write from
another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultMaxIdle" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultMaxTotal" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultMinIdle" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultNumTestsPerEvictionRun" in one thread may not yield the value of
the most recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultTestOnBorrow" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultTestOnCreate" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultTestOnReturn" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultTestWhileIdle" in one thread may not yield the value of the most
recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"defaultTransactionIsolation" in one thread may not yield the value of
the most recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
- Fix SpotBugs [ERROR] Medium: Shared primitive variable
"rollbackAfterValidation" in one thread may not yield the value of the
most recent write from another thread
[org.apache.commons.dbcp2.datasources.InstanceKeyDataSource]
AT_STALE_THREAD_WRITE_OF_PRIMITIVE
---
src/changes/changes.xml | 13 +++++++++++-
.../dbcp2/datasources/InstanceKeyDataSource.java | 24 +++++++++++-----------
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index b8fc825d..cb798696 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -82,7 +82,18 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Operation on the "fatalSqlExceptionThrown" shared variable in "PoolableConnection" class is not atomic [org.apache.commons.dbcp2.PoolableConnection] AT_NONATOMIC_OPERATIONS_ON_SHARED_VARIABLE.</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.PoolingConnection] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "maxTotal" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.SharedPoolDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
- <!-- ADD -->
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultBlockWhenExhausted" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultLifo" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultMaxIdle" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultMaxTotal" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultMinIdle" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultNumTestsPerEvictionRun" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultTestOnBorrow" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultTestOnCreate" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultTestOnReturn" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultTestWhileIdle" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "defaultTransactionIsolation" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs [ERROR] Medium: Shared primitive variable "rollbackAfterValidation" in one thread may not yield the value of the most recent write from another thread [org.apache.commons.dbcp2.datasources.InstanceKeyDataSource] AT_STALE_THREAD_WRITE_OF_PRIMITIVE.</action> <!-- ADD -->
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 78 to 81.</action>
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-pool2 from 2.12.0 to 2.12.1 #474.</action>
diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
index d7eb1568..d3bf08eb 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/InstanceKeyDataSource.java
@@ -112,19 +112,19 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
private String instanceKey;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_BLOCK_WHEN_EXHAUSTED}. */
- private boolean defaultBlockWhenExhausted = BaseObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED;
+ private volatile boolean defaultBlockWhenExhausted = BaseObjectPoolConfig.DEFAULT_BLOCK_WHEN_EXHAUSTED;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_EVICTION_POLICY_CLASS_NAME}. */
private String defaultEvictionPolicyClassName = BaseObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_LIFO}. */
- private boolean defaultLifo = BaseObjectPoolConfig.DEFAULT_LIFO;
+ private volatile boolean defaultLifo = BaseObjectPoolConfig.DEFAULT_LIFO;
/** Pool property defaults to {@link GenericKeyedObjectPoolConfig#DEFAULT_MAX_IDLE_PER_KEY}. */
- private int defaultMaxIdle = GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY;
+ private volatile int defaultMaxIdle = GenericKeyedObjectPoolConfig.DEFAULT_MAX_IDLE_PER_KEY;
/** Pool property defaults to {@link GenericKeyedObjectPoolConfig#DEFAULT_MAX_TOTAL}. */
- private int defaultMaxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL;
+ private volatile int defaultMaxTotal = GenericKeyedObjectPoolConfig.DEFAULT_MAX_TOTAL;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_MAX_WAIT}. */
private Duration defaultMaxWaitDuration = BaseObjectPoolConfig.DEFAULT_MAX_WAIT;
@@ -133,25 +133,25 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
private Duration defaultMinEvictableIdleDuration = BaseObjectPoolConfig.DEFAULT_MIN_EVICTABLE_IDLE_DURATION;
/** Pool property defaults to {@link GenericKeyedObjectPoolConfig#DEFAULT_MIN_IDLE_PER_KEY}. */
- private int defaultMinIdle = GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY;
+ private volatile int defaultMinIdle = GenericKeyedObjectPoolConfig.DEFAULT_MIN_IDLE_PER_KEY;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_NUM_TESTS_PER_EVICTION_RUN}. */
- private int defaultNumTestsPerEvictionRun = BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
+ private volatile int defaultNumTestsPerEvictionRun = BaseObjectPoolConfig.DEFAULT_NUM_TESTS_PER_EVICTION_RUN;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION}. */
private Duration defaultSoftMinEvictableIdleDuration = BaseObjectPoolConfig.DEFAULT_SOFT_MIN_EVICTABLE_IDLE_DURATION;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_TEST_ON_CREATE}. */
- private boolean defaultTestOnCreate = BaseObjectPoolConfig.DEFAULT_TEST_ON_CREATE;
+ private volatile boolean defaultTestOnCreate = BaseObjectPoolConfig.DEFAULT_TEST_ON_CREATE;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_TEST_ON_BORROW}. */
- private boolean defaultTestOnBorrow = BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
+ private volatile boolean defaultTestOnBorrow = BaseObjectPoolConfig.DEFAULT_TEST_ON_BORROW;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_TEST_ON_RETURN}. */
- private boolean defaultTestOnReturn = BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
+ private volatile boolean defaultTestOnReturn = BaseObjectPoolConfig.DEFAULT_TEST_ON_RETURN;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_TEST_WHILE_IDLE}. */
- private boolean defaultTestWhileIdle = BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
+ private volatile boolean defaultTestWhileIdle = BaseObjectPoolConfig.DEFAULT_TEST_WHILE_IDLE;
/** Pool property defaults to {@link BaseObjectPoolConfig#DEFAULT_DURATION_BETWEEN_EVICTION_RUNS}. */
private Duration defaultDurationBetweenEvictionRuns = BaseObjectPoolConfig.DEFAULT_DURATION_BETWEEN_EVICTION_RUNS;
@@ -163,7 +163,7 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
private Duration validationQueryTimeoutDuration = Duration.ofSeconds(-1);
/** Connection factory property defaults to false. */
- private boolean rollbackAfterValidation;
+ private volatile boolean rollbackAfterValidation;
/** Connection factory property defaults to -1 milliseconds. */
private Duration maxConnDuration = Duration.ofMillis(-1);
@@ -172,7 +172,7 @@ public abstract class InstanceKeyDataSource implements DataSource, Referenceable
private Boolean defaultAutoCommit;
/** Connection property defaults to {@link #UNKNOWN_TRANSACTIONISOLATION}. */
- private int defaultTransactionIsolation = UNKNOWN_TRANSACTIONISOLATION;
+ private volatile int defaultTransactionIsolation = UNKNOWN_TRANSACTIONISOLATION;
/** Connection property defaults to false. */
private Boolean defaultReadOnly;