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 20b0c930 org.apache.commons.dbcp2.datasources.UserPassKey should be
Serializable (SpotBugs)
20b0c930 is described below
commit 20b0c930e2e329dfb9e318499a7b39dc931cdb9e
Author: Gary Gregory <[email protected]>
AuthorDate: Sat Jul 2 09:39:30 2022 -0400
org.apache.commons.dbcp2.datasources.UserPassKey should be Serializable
(SpotBugs)
---
src/changes/changes.xml | 3 +
.../commons/dbcp2/datasources/CharArray.java | 5 +-
.../commons/dbcp2/datasources/TestUserPassKey.java | 150 +++++++++++----------
3 files changed, 85 insertions(+), 73 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 858bc0d7..d3971a98 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -83,6 +83,9 @@ The <action> type attribute can be add,update,fix,remove.
<action dev="ggregory" type="fix" due-to="Kurtcebe Eroglu, Gary Gregory,
Phil Steitz" issue="DBCP-585">
Connection level JMX queries result in concurrent access to connection
objects, causing errors #179
</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">
+ UserPassKey should be Serializable.
+ </action>
<!-- ADD -->
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add and use AbandonedTrace#setLastUsed(Instant).
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 f1d9c2aa..6581232e 100644
--- a/src/main/java/org/apache/commons/dbcp2/datasources/CharArray.java
+++ b/src/main/java/org/apache/commons/dbcp2/datasources/CharArray.java
@@ -17,6 +17,7 @@
package org.apache.commons.dbcp2.datasources;
+import java.io.Serializable;
import java.util.Arrays;
import org.apache.commons.dbcp2.Utils;
@@ -29,7 +30,9 @@ import org.apache.commons.dbcp2.Utils;
*
* @since 2.9.0
*/
-final class CharArray {
+final class CharArray implements Serializable {
+
+ private static final long serialVersionUID = 1L;
static final CharArray NULL = new CharArray((char[]) null);
diff --git
a/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java
b/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java
index 899510f2..c8b8555e 100644
--- a/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java
+++ b/src/test/java/org/apache/commons/dbcp2/datasources/TestUserPassKey.java
@@ -1,72 +1,78 @@
-/*
- * 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.datasources;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotEquals;
-
-import org.apache.commons.dbcp2.Utils;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * Tests for UserPassKey.
- * @since 2.5.0
- */
-public class TestUserPassKey {
-
- private UserPassKey userPassKey;
- private UserPassKey anotherUserPassKey;
-
- @BeforeEach
- public void setUp() {
- userPassKey = new UserPassKey("user", "pass");
- anotherUserPassKey = new UserPassKey((String) null, "");
- }
-
- @Test
- public void testEquals() {
- assertEquals(new UserPassKey("user"), new UserPassKey("user", (char[])
null));
- assertEquals(userPassKey, userPassKey);
- assertNotEquals(userPassKey, null);
- assertNotEquals(userPassKey, new Object());
- assertNotEquals(new UserPassKey(null), userPassKey);
- assertEquals(new UserPassKey(null), new UserPassKey(null));
- assertNotEquals(new UserPassKey("user", "pass"), new
UserPassKey("foo", "pass"));
- }
-
- @Test
- public void testGettersAndSetters() {
- assertEquals("user", userPassKey.getUserName());
- assertEquals("pass", userPassKey.getPassword());
- assertArrayEquals(Utils.toCharArray("pass"),
userPassKey.getPasswordCharArray());
- }
-
- @Test
- public void testHashcode() {
- assertEquals(userPassKey.hashCode(), new UserPassKey("user",
"pass").hashCode());
- assertNotEquals(userPassKey.hashCode(), anotherUserPassKey.hashCode());
- }
-
- @Test
- public void testToString() {
- assertEquals(userPassKey.toString(), new UserPassKey("user",
"pass").toString());
- assertNotEquals(userPassKey.toString(), anotherUserPassKey.toString());
- }
-}
+/*
+ * 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.datasources;
+
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.apache.commons.dbcp2.Utils;
+import org.apache.commons.lang3.SerializationUtils;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests for UserPassKey.
+ */
+public class TestUserPassKey {
+
+ private UserPassKey userPassKey;
+ private UserPassKey anotherUserPassKey;
+
+ @BeforeEach
+ public void setUp() {
+ userPassKey = new UserPassKey("user", "pass");
+ anotherUserPassKey = new UserPassKey((String) null, "");
+ }
+
+ @Test
+ public void testEquals() {
+ assertEquals(new UserPassKey("user"), new UserPassKey("user", (char[])
null));
+ assertEquals(userPassKey, userPassKey);
+ assertNotEquals(userPassKey, null);
+ assertNotEquals(userPassKey, new Object());
+ assertNotEquals(new UserPassKey(null), userPassKey);
+ assertEquals(new UserPassKey(null), new UserPassKey(null));
+ assertNotEquals(new UserPassKey("user", "pass"), new
UserPassKey("foo", "pass"));
+ }
+
+ @Test
+ public void testGettersAndSetters() {
+ assertEquals("user", userPassKey.getUserName());
+ assertEquals("pass", userPassKey.getPassword());
+ assertArrayEquals(Utils.toCharArray("pass"),
userPassKey.getPasswordCharArray());
+ }
+
+ @Test
+ public void testHashcode() {
+ assertEquals(userPassKey.hashCode(), new UserPassKey("user",
"pass").hashCode());
+ assertNotEquals(userPassKey.hashCode(), anotherUserPassKey.hashCode());
+ }
+
+ @Test
+ public void testSerialization() {
+ assertEquals(userPassKey, SerializationUtils.roundtrip(userPassKey));
+ assertEquals(anotherUserPassKey,
SerializationUtils.roundtrip(anotherUserPassKey));
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals(userPassKey.toString(), new UserPassKey("user",
"pass").toString());
+ assertNotEquals(userPassKey.toString(), anotherUserPassKey.toString());
+ }
+}