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


The following commit(s) were added to refs/heads/master by this push:
     new 31dd9577 Reuse Utils.clone(char[])
31dd9577 is described below

commit 31dd957714e19889aafb16c2418a1bc07a5d6315
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Jul 10 15:34:19 2022 -0400

    Reuse Utils.clone(char[])
---
 .../commons/dbcp2/DataSourceConnectionFactory.java | 222 ++++++++++-----------
 .../dbcp2/cpdsadapter/DriverAdapterCPDS.java       |   2 +-
 .../commons/dbcp2/datasources/CharArray.java       |   2 +-
 .../managed/DataSourceXAConnectionFactory.java     |   6 +-
 4 files changed, 116 insertions(+), 116 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/dbcp2/DataSourceConnectionFactory.java 
b/src/main/java/org/apache/commons/dbcp2/DataSourceConnectionFactory.java
index a5b83bd6..e7dbac3a 100644
--- a/src/main/java/org/apache/commons/dbcp2/DataSourceConnectionFactory.java
+++ b/src/main/java/org/apache/commons/dbcp2/DataSourceConnectionFactory.java
@@ -1,111 +1,111 @@
-/*
- * 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.sql.Connection;
-import java.sql.SQLException;
-
-import javax.sql.DataSource;
-
-/**
- * A {@link DataSource}-based implementation of {@link ConnectionFactory}.
- *
- * @since 2.0
- */
-public class DataSourceConnectionFactory implements ConnectionFactory {
-
-    private final DataSource dataSource;
-
-    private final String userName;
-
-    private final char[] userPassword;
-
-    /**
-     * Constructs an instance for the given DataSource.
-     *
-     * @param dataSource
-     *            The DataSource for this factory.
-     */
-    public DataSourceConnectionFactory(final DataSource dataSource) {
-        this(dataSource, null, (char[]) null);
-    }
-
-    /**
-     * Constructs an instance for the given DataSource.
-     *
-     * @param dataSource
-     *            The DataSource for this factory.
-     * @param userName
-     *            The user name.
-     * @param userPassword
-     *            The user password.
-     * @since 2.4.0
-     */
-    public DataSourceConnectionFactory(final DataSource dataSource, final 
String userName, final char[] userPassword) {
-        this.dataSource = dataSource;
-        this.userName = userName;
-        this.userPassword = Utils.clone(userPassword);
-    }
-
-    /**
-     * Constructs an instance for the given DataSource.
-     *
-     * @param dataSource
-     *            The DataSource for this factory.
-     * @param userName
-     *            The user name.
-     * @param password
-     *            The user password.
-     */
-    public DataSourceConnectionFactory(final DataSource dataSource, final 
String userName, final String password) {
-        this.dataSource = dataSource;
-        this.userName = userName;
-        this.userPassword = Utils.toCharArray(password);
-    }
-
-    @Override
-    public Connection createConnection() throws SQLException {
-        if (null == userName && null == userPassword) {
-            return dataSource.getConnection();
-        }
-        return dataSource.getConnection(userName, 
Utils.toString(userPassword));
-    }
-
-    /**
-     * @return The data source.
-     * @since 2.6.0
-     */
-    public DataSource getDataSource() {
-        return dataSource;
-    }
-
-    /**
-     * @return The user name.
-     * @since 2.6.0
-     */
-    public String getUserName() {
-        return userName;
-    }
-
-    /**
-     * @return The user password.
-     * @since 2.6.0
-     */
-    public char[] getUserPassword() {
-        return userPassword == null ? null : userPassword.clone();
-    }
-}
+/*
+ * 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.sql.Connection;
+import java.sql.SQLException;
+
+import javax.sql.DataSource;
+
+/**
+ * A {@link DataSource}-based implementation of {@link ConnectionFactory}.
+ *
+ * @since 2.0
+ */
+public class DataSourceConnectionFactory implements ConnectionFactory {
+
+    private final DataSource dataSource;
+
+    private final String userName;
+
+    private final char[] userPassword;
+
+    /**
+     * Constructs an instance for the given DataSource.
+     *
+     * @param dataSource
+     *            The DataSource for this factory.
+     */
+    public DataSourceConnectionFactory(final DataSource dataSource) {
+        this(dataSource, null, (char[]) null);
+    }
+
+    /**
+     * Constructs an instance for the given DataSource.
+     *
+     * @param dataSource
+     *            The DataSource for this factory.
+     * @param userName
+     *            The user name.
+     * @param userPassword
+     *            The user password.
+     * @since 2.4.0
+     */
+    public DataSourceConnectionFactory(final DataSource dataSource, final 
String userName, final char[] userPassword) {
+        this.dataSource = dataSource;
+        this.userName = userName;
+        this.userPassword = Utils.clone(userPassword);
+    }
+
+    /**
+     * Constructs an instance for the given DataSource.
+     *
+     * @param dataSource
+     *            The DataSource for this factory.
+     * @param userName
+     *            The user name.
+     * @param password
+     *            The user password.
+     */
+    public DataSourceConnectionFactory(final DataSource dataSource, final 
String userName, final String password) {
+        this.dataSource = dataSource;
+        this.userName = userName;
+        this.userPassword = Utils.toCharArray(password);
+    }
+
+    @Override
+    public Connection createConnection() throws SQLException {
+        if (null == userName && null == userPassword) {
+            return dataSource.getConnection();
+        }
+        return dataSource.getConnection(userName, 
Utils.toString(userPassword));
+    }
+
+    /**
+     * @return The data source.
+     * @since 2.6.0
+     */
+    public DataSource getDataSource() {
+        return dataSource;
+    }
+
+    /**
+     * @return The user name.
+     * @since 2.6.0
+     */
+    public String getUserName() {
+        return userName;
+    }
+
+    /**
+     * @return The user password.
+     * @since 2.6.0
+     */
+    public char[] getUserPassword() {
+        return Utils.clone(userPassword);
+    }
+}
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 881181bf..8c0b4f49 100644
--- a/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
+++ b/src/main/java/org/apache/commons/dbcp2/cpdsadapter/DriverAdapterCPDS.java
@@ -362,7 +362,7 @@ public class DriverAdapterCPDS implements 
ConnectionPoolDataSource, Referenceabl
      * @since 2.4.0
      */
     public char[] getPasswordCharArray() {
-        return userPassword == null ? null : userPassword.clone();
+        return Utils.clone(userPassword);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/dbcp2/datasources/CharArray.java 
b/src/main/java/org/apache/commons/dbcp2/datasources/CharArray.java
index 6581232e..0d9b3292 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CharArray.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CharArray.java
@@ -73,7 +73,7 @@ final class CharArray implements Serializable {
      * @return value, may be null.
      */
     char[] get() {
-        return chars == null ? null : chars.clone();
+        return Utils.clone(chars);
     }
 
     @Override
diff --git 
a/src/main/java/org/apache/commons/dbcp2/managed/DataSourceXAConnectionFactory.java
 
b/src/main/java/org/apache/commons/dbcp2/managed/DataSourceXAConnectionFactory.java
index 20530477..c3d293a3 100644
--- 
a/src/main/java/org/apache/commons/dbcp2/managed/DataSourceXAConnectionFactory.java
+++ 
b/src/main/java/org/apache/commons/dbcp2/managed/DataSourceXAConnectionFactory.java
@@ -120,7 +120,7 @@ public class DataSourceXAConnectionFactory implements 
XAConnectionFactory {
         this.transactionRegistry = new TransactionRegistry(transactionManager, 
transactionSynchronizationRegistry);
         this.xaDataSource = xaDataSource;
         this.userName = userName;
-        this.userPassword = userPassword == null ? null : userPassword.clone();
+        this.userPassword = Utils.clone(userPassword);
     }
 
     /**
@@ -213,7 +213,7 @@ public class DataSourceXAConnectionFactory implements 
XAConnectionFactory {
      * @return the user password.
      */
     public char[] getUserPassword() {
-        return userPassword == null ? null : userPassword.clone();
+        return Utils.clone(userPassword);
     }
 
     /**
@@ -233,7 +233,7 @@ public class DataSourceXAConnectionFactory implements 
XAConnectionFactory {
      * @since 2.4.0
      */
     public void setPassword(final char[] userPassword) {
-        this.userPassword = userPassword == null ? null : userPassword.clone();
+        this.userPassword = Utils.clone(userPassword);
     }
 
     /**

Reply via email to