Repository: commons-dbcp Updated Branches: refs/heads/master cf032314f -> f675cbc93
[DBCP-486] DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments throw NullPointerExceptions when connection properties are set Project: http://git-wip-us.apache.org/repos/asf/commons-dbcp/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-dbcp/commit/f675cbc9 Tree: http://git-wip-us.apache.org/repos/asf/commons-dbcp/tree/f675cbc9 Diff: http://git-wip-us.apache.org/repos/asf/commons-dbcp/diff/f675cbc9 Branch: refs/heads/master Commit: f675cbc93ee4bf7395befd90303cfdc79265cee2 Parents: cf03231 Author: Gary Gregory <garydgreg...@gmail.com> Authored: Wed Apr 18 16:36:37 2018 -0600 Committer: Gary Gregory <garydgreg...@gmail.com> Committed: Wed Apr 18 16:36:37 2018 -0600 ---------------------------------------------------------------------- src/changes/changes.xml | 2 +- .../dbcp2/cpdsadapter/DriverAdapterCPDS.java | 30 +++++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/f675cbc9/src/changes/changes.xml ---------------------------------------------------------------------- diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 8f69ffb..7abec82 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(null) and setPassword(null) throw NullPointerExceptions when connection properties are set. + DriverAdapterCPDS.setUser(), setPassword(), and getPooledConnection() with null arguments 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/f675cbc9/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 bf7d960..748dec7 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) { - connectionProperties.put(KEY_USER, username); - connectionProperties.put(KEY_PASSWORD, pass); + update(connectionProperties, KEY_USER, username); + update(connectionProperties, KEY_PASSWORD, pass); pci = new PooledConnectionImpl(DriverManager.getConnection( getUrl(), connectionProperties)); } else { @@ -442,13 +442,7 @@ public class DriverAdapterCPDS public void setPassword(final String v) { assertInitializationAllowed(); this.password = v; - if (connectionProperties != null) { - if (v == null) { - connectionProperties.remove(KEY_PASSWORD); - } else { - connectionProperties.setProperty(KEY_PASSWORD, v); - } - } + update(connectionProperties, KEY_PASSWORD, v); } /** @@ -485,13 +479,7 @@ public class DriverAdapterCPDS public void setUser(final String v) { assertInitializationAllowed(); this.user = v; - if (connectionProperties != null) { - if (v == null) { - connectionProperties.remove(KEY_USER); - } else { - connectionProperties.setProperty(KEY_USER, v); - } - } + update(connectionProperties, KEY_USER, v); } /** @@ -716,4 +704,14 @@ 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); + } + } + } }