commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject commons-dbcp git commit: [DBCP-494] org.apache.commons.dbcp2.PStmtKey should make copies of given arrays in constructors.
Date Fri, 08 Jun 2018 22:05:25 GMT
Repository: commons-dbcp
Updated Branches:
  refs/heads/master f61244c48 -> 89d2eb8fa


[DBCP-494] org.apache.commons.dbcp2.PStmtKey should make copies of given
arrays in constructors.

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

Branch: refs/heads/master
Commit: 89d2eb8fab09847c42ca1eb32c62e0d4ef7699e6
Parents: f61244c
Author: Gary Gregory <garydgregory@gmail.com>
Authored: Fri Jun 8 16:05:22 2018 -0600
Committer: Gary Gregory <garydgregory@gmail.com>
Committed: Fri Jun 8 16:05:22 2018 -0600

----------------------------------------------------------------------
 src/changes/changes.xml                         |  3 +
 .../java/org/apache/commons/dbcp2/PStmtKey.java |  4 +-
 .../org/apache/commons/dbcp2/TestPStmtKey.java  | 84 ++++++++++++++++++++
 3 files changed, 89 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/89d2eb8f/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index cea3bab..f5eae35 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -70,6 +70,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action dev="ggregory" type="update" issue="DBCP-491" due-to="Zheng Feng, Gary Gregory">
         Ensure DBCP ConnectionListener can deal with transaction managers which invoke rollback
in a separate thread.
       </action>
+      <action dev="ggregory" type="update" issue="DBCP-494" due-to="Gary Gregory">
+        org.apache.commons.dbcp2.PStmtKey should make copies of given arrays in constructors.
+      </action>
     </release>
     <release version="2.3.0" date="2018-05-12" description="This is a minor release, including
bug fixes and enhancements.">
       <action dev="pschumacher" type="fix" issue="DBCP-476" due-to="Gary Evesson, Richard
Cordova">

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/89d2eb8f/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/dbcp2/PStmtKey.java b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
index 4ceb7d1..3de19b8 100644
--- a/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
+++ b/src/main/java/org/apache/commons/dbcp2/PStmtKey.java
@@ -113,7 +113,7 @@ public class PStmtKey {
         _catalog = catalog;
         _stmtType = StatementType.PREPARED_STATEMENT;
         _autoGeneratedKeys = null;
-        _columnIndexes = columnIndexes;
+        _columnIndexes = columnIndexes == null ? null : Arrays.copyOf(columnIndexes, columnIndexes.length);
         _columnNames = null;
         _resultSetType = null;
         _resultSetConcurrency = null;
@@ -128,7 +128,7 @@ public class PStmtKey {
         _stmtType = StatementType.PREPARED_STATEMENT;
         _autoGeneratedKeys = null;
         _columnIndexes = null;
-        _columnNames = columnNames;
+        _columnNames = columnNames == null ? null : Arrays.copyOf(columnNames, columnNames.length);
         _resultSetType = null;
         _resultSetConcurrency = null;
         _resultSetHoldability = null;

http://git-wip-us.apache.org/repos/asf/commons-dbcp/blob/89d2eb8f/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java b/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java
new file mode 100644
index 0000000..ab88ee0
--- /dev/null
+++ b/src/test/java/org/apache/commons/dbcp2/TestPStmtKey.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.dbcp2;
+
+import java.util.Arrays;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Tests {@link PStmtKey}.
+ *
+ * @since 2.3.1
+ */
+public class TestPStmtKey {
+
+    /**
+     * Tests {@link org.apache.commons.dbcp2.PStmtKey#PStmtKey(String, String, int[])}.
+     *
+     * See https://issues.apache.org/jira/browse/DBCP-494
+     */
+    @Test
+    public void testCtorStringStringArrayOfInts() {
+        final int[] input = {0, 0 };
+        final PStmtKey pStmtKey = new PStmtKey("", "", input);
+        Assert.assertArrayEquals(input, pStmtKey.getColumnIndexes());
+        input[0] = 1;
+        input[1] = 1;
+        Assert.assertFalse(Arrays.equals(input, pStmtKey.getColumnIndexes()));
+    }
+
+    /**
+     * Tests {@link org.apache.commons.dbcp2.PStmtKey#PStmtKey(String, String, int[])}.
+     *
+     * See https://issues.apache.org/jira/browse/DBCP-494
+     */
+    @Test
+    public void testCtorStringStringArrayOfNullInts() {
+        final int[] input = null;
+        final PStmtKey pStmtKey = new PStmtKey("", "", input);
+        Assert.assertArrayEquals(input, pStmtKey.getColumnIndexes());
+    }
+
+    /**
+     * Tests {@link org.apache.commons.dbcp2.PStmtKey#PStmtKey(String, String, String[])}.
+     *
+     * See https://issues.apache.org/jira/browse/DBCP-494
+     */
+    @Test
+    public void testCtorStringStringArrayOfNullStrings() {
+        final String[] input = null;
+        final PStmtKey pStmtKey = new PStmtKey("", "", input);
+        Assert.assertArrayEquals(input, pStmtKey.getColumnNames());
+    }
+
+    /**
+     * Tests {@link org.apache.commons.dbcp2.PStmtKey#PStmtKey(String, String, String[])}.
+     *
+     * See https://issues.apache.org/jira/browse/DBCP-494
+     */
+    @Test
+    public void testCtorStringStringArrayOfStrings() {
+        final String[] input = {"A", "B" };
+        final PStmtKey pStmtKey = new PStmtKey("", "", input);
+        Assert.assertArrayEquals(input, pStmtKey.getColumnNames());
+        input[0] = "C";
+        input[1] = "D";
+        Assert.assertFalse(Arrays.equals(input, pStmtKey.getColumnNames()));
+    }
+}


Mime
View raw message