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

commit 53462102b51eb3b6589924150b4ab0a8dcaeae35
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Mon May 26 11:10:46 2025 -0400

    Add internal org.apache.commons.dbcp2.datasources.UserPassKey.clear()
---
 .../commons/dbcp2/datasources/UserPassKey.java     | 11 ++++++
 .../commons/dbcp2/datasources/UserPassKeyTest.java | 46 ++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git 
a/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java 
b/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java
index f0d1f857..8f948312 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/UserPassKey.java
@@ -59,6 +59,17 @@ final class UserPassKey implements Serializable {
         this(new CharArray(userName), new CharArray(userPassword));
     }
 
+    /**
+     * Clears the content of the name and password.
+     *
+     * @return {@code this} instance.
+     */
+    UserPassKey clear() {
+        name.clear();
+        password.clear();
+        return this;
+    }
+
     /**
      * Only takes the user name into account.
      */
diff --git 
a/src/test/java/org/apache/commons/dbcp2/datasources/UserPassKeyTest.java 
b/src/test/java/org/apache/commons/dbcp2/datasources/UserPassKeyTest.java
new file mode 100644
index 00000000..2d26fd23
--- /dev/null
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/UserPassKeyTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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
+ *
+ *      https://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.datasources;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link UserPassKey}
+ */
+public class UserPassKeyTest {
+
+    @Test
+    public void testClear() {
+        // user name
+        assertNull(new UserPassKey((String) null).clear().getUserName());
+        assertEquals("", new UserPassKey("").clear().getUserName());
+        assertEquals("\0\0\0", new UserPassKey("foo").clear().getUserName());
+        // password String
+        assertNull(new UserPassKey((String) null, (String) 
null).clear().getPassword());
+        assertEquals("", new UserPassKey("", "").clear().getPassword());
+        assertEquals("\0\0\0", new UserPassKey("foo", 
"bar").clear().getPassword());
+        // password char[]
+        assertNull(new UserPassKey((String) null, (char[]) 
null).clear().getPasswordCharArray());
+        assertArrayEquals("".toCharArray(), new UserPassKey("", 
"").clear().getPasswordCharArray());
+        assertArrayEquals("\0\0\0".toCharArray(), new UserPassKey("foo", 
"bar").clear().getPasswordCharArray());
+    }
+}

Reply via email to