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 2018/04/18 22:34:13 UTC

commons-dbcp git commit: Revert "[DBCP-486] DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments throw NullPointerExceptions when connection properties are set"

Repository: commons-dbcp
Updated Branches:
  refs/heads/master a6feb941e -> cf032314f


Revert "[DBCP-486] DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments throw NullPointerExceptions when connection properties are set"

This reverts commit a6feb941e5ff8fde22865f981d912c6d5f48546e.


Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/cf032314
Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/cf032314
Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/cf032314

Branch: refs/heads/master
Commit: cf032314f935892a8cc5ca7a43bcf1c9011f3242
Parents: a6feb94
Author: Gary Gregory <ga...@gmail.com>
Authored: Wed Apr 18 16:33:54 2018 -0600
Committer: Gary Gregory <ga...@gmail.com>
Committed: Wed Apr 18 16:33:54 2018 -0600

----------------------------------------------------------------------
 src/changes/changes.xml                         |  2 +-
 .../dbcp2/cpdsadapter/DriverAdapterCPDS.java    | 30 +++++++++++---------
 .../dbcp2/managed/ManagedConnection.java        | 20 ++++++-------
 3 files changed, 25 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/cf032314/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 7abec82..8f69ffb 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -68,7 +68,7 @@ The <action> type attribute can be add,update,fix,remove.
         Make constant public: org.apache.commons.dbcp2.PoolingDriver.URL_PREFIX.
       </action>
       <action dev="ggregory" type="update" issue="DBCP-486" due-to="Gary Gregory">
-        DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments throw NullPointerExceptions when connection properties are set.
+        DriverAdapterCPDS.setUser(null) and setPassword(null) throw NullPointerExceptions when connection properties are set.
       </action>
     </release>
     <release version="2.2.0" date="2017-12-DD" description="This is a minor release, including bug fixes and enhancements.">

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/cf032314/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
index 748dec7..bf7d960 100644
--- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
+++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
@@ -177,8 +177,8 @@ public class DriverAdapterCPDS
         // exception upon first invocation.
         try {
             if (connectionProperties != null) {
-                update(connectionProperties, KEY_USER, username);
-                update(connectionProperties, KEY_PASSWORD, pass);
+                connectionProperties.put(KEY_USER, username);
+                connectionProperties.put(KEY_PASSWORD, pass);
                 pci = new PooledConnectionImpl(DriverManager.getConnection(
                         getUrl(), connectionProperties));
             } else {
@@ -442,7 +442,13 @@ public class DriverAdapterCPDS
     public void setPassword(final String v) {
         assertInitializationAllowed();
         this.password = v;
-        update(connectionProperties, KEY_PASSWORD, v);
+        if (connectionProperties != null) {
+            if (v == null) {
+                connectionProperties.remove(KEY_PASSWORD);
+            } else {
+                connectionProperties.setProperty(KEY_PASSWORD, v);
+            }
+        }
     }
 
     /**
@@ -479,7 +485,13 @@ public class DriverAdapterCPDS
     public void setUser(final String v) {
         assertInitializationAllowed();
         this.user = v;
-        update(connectionProperties, KEY_USER, v);
+        if (connectionProperties != null) {
+            if (v == null) {
+                connectionProperties.remove(KEY_USER);
+            } else {
+                connectionProperties.setProperty(KEY_USER, v);
+            }
+        }
     }
 
     /**
@@ -704,14 +716,4 @@ public class DriverAdapterCPDS
     {
         _maxPreparedStatements = maxPreparedStatements;
     }
-    
-    private void update(final Properties properties, final String key, final String value) {
-        if (properties != null) {
-            if (value == null) {
-                properties.remove(key);
-            } else {
-                properties.setProperty(key, value);
-            }
-        }        
-    }
 }

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/cf032314/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
----------------------------------------------------------------------
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 d05144b..a66a7a8 100644
--- a/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
+++ b/src/main/java/org/apache/commons/dbcp2/managed/ManagedConnection.java
@@ -159,16 +159,14 @@ public class ManagedConnection<C extends Connection> extends DelegatingConnectio
     @Override
     public void close() throws SQLException {
         if (!isClosedInternal()) {
-            synchronized (this) {
-                try {
-                    // Don't actually close the connection if in a transaction. The
-                    // connection will be closed by the transactionComplete method.
-                    if (transactionContext == null) {
-                        super.close();
-                    }
-                } finally {
-                    setClosedInternal(true);
+            try {
+                // Don't actually close the connection if in a transaction. The
+                // connection will be closed by the transactionComplete method.
+                if (transactionContext == null) {
+                    super.close();
                 }
+            } finally {
+                setClosedInternal(true);
             }
         }
     }
@@ -188,9 +186,7 @@ public class ManagedConnection<C extends Connection> extends DelegatingConnectio
     }
 
     protected void transactionComplete() {
-        synchronized (this) {
-            transactionContext = null;
-        }
+        transactionContext = null;
 
         // If we were using a shared connection, clear the reference now that
         // the transaction has completed