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 c1e11fdadcc2da83df141ee309e86f77cf58415e
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Sun May 25 17:49:11 2025 -0400

    Fix SpotBugs [ERROR] Medium: Shared primitive variable
    "isSharedConnection" in one thread may not yield the value of the most
    recent write from another thread
    [org.apache.commons.dbcp2.managed.ManagedConnection]
    AT_STALE_THREAD_WRITE_OF_PRIMITIVE
---
 pom.xml                                                      |  2 +-
 src/changes/changes.xml                                      |  1 +
 .../org/apache/commons/dbcp2/managed/ManagedConnection.java  | 12 ++++++------
 3 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/pom.xml b/pom.xml
index 186e89ec..b4566e01 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,7 +22,7 @@
   <parent>
     <groupId>org.apache.commons</groupId>
     <artifactId>commons-parent</artifactId>
-    <version>81</version>
+    <version>84</version>
   </parent>
   <modelVersion>4.0.0</modelVersion>
   <artifactId>commons-dbcp2</artifactId>
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 074a113a..568a0f01 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -75,6 +75,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix Javadoc 
warnings on Java 21.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Remove -nouses 
directive from maven-bundle-plugin. OSGi package imports now state 'uses' 
definitions for package imports, this doesn't affect JPMS (from 
org.apache.commons:commons-parent:80).</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">XAException 
thrown by LocalXAResource now all include a message.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Fix SpotBugs 
[ERROR] Medium: Shared primitive variable "isSharedConnection" in one thread 
may not yield the value of the most recent write from another thread 
[org.apache.commons.dbcp2.managed.ManagedConnection] 
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>
diff --git 
a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java 
b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
index b28db71d..ec1e72a5 100644
--- a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
@@ -215,15 +215,15 @@ public class ManagedConnection<C extends Connection> 
extends DelegatingConnectio
         lock.lock();
         try {
             transactionContext.completeTransaction();
+            // If we were using a shared connection, clear the reference now 
that
+            // the transaction has completed
+            if (isSharedConnection) {
+                setDelegate(null);
+                isSharedConnection = false;
+            }
         } finally {
             lock.unlock();
         }
-        // If we were using a shared connection, clear the reference now that
-        // the transaction has completed
-        if (isSharedConnection) {
-            setDelegate(null);
-            isSharedConnection = false;
-        }
         // autoCommit may have been changed directly on the underlying 
connection
         clearCachedState();
         // If this connection was closed during the transaction and there is

Reply via email to