GROOVY-8422: Incorrect properties copy in Sql.newInstance (closes #671) The provided Properties should be passed to the DriverManager as-is. A copy is only needed when changes are made to the provided Properties in order to mask sensitive information for logging purposes.
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/ba5c614e Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ba5c614e Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ba5c614e Branch: refs/heads/GROOVY_2_5_X Commit: ba5c614eab6624ebc6b99d229a4f9e6119f50c52 Parents: e07fea6 Author: John Wagenleitner <[email protected]> Authored: Mon Mar 5 18:58:52 2018 -0800 Committer: John Wagenleitner <[email protected]> Committed: Mon Mar 5 19:07:19 2018 -0800 ---------------------------------------------------------------------- .../groovy-sql/src/main/java/groovy/sql/Sql.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/ba5c614e/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java ---------------------------------------------------------------------- diff --git a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java index 9d92043..4c86798 100644 --- a/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java +++ b/subprojects/groovy-sql/src/main/java/groovy/sql/Sql.java @@ -589,14 +589,16 @@ public class Sql { Connection connection; LOG.fine("url = " + url); if (props != null) { - Properties propsCopy = new Properties(props); - connection = DriverManager.getConnection(url.toString(), propsCopy); - if (propsCopy.containsKey("password")) { + connection = DriverManager.getConnection(url.toString(), props); + if (!props.containsKey("password")) { + LOG.fine("props = " + props); + } else { // don't log the password - propsCopy = new Properties(propsCopy); + Properties propsCopy = new Properties(); + propsCopy.putAll(props); propsCopy.setProperty("password", "***"); + LOG.fine("props = " + propsCopy); } - LOG.fine("props = " + propsCopy); } else if (sqlArgs.containsKey("user")) { Object user = sqlArgs.remove("user"); LOG.fine("user = " + user);
