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-compress.git
The following commit(s) were added to refs/heads/master by this push:
new 5780f045e [COMPRESS-719] CPConstant subclasses are missing optional
hashCode() and equals()
5780f045e is described below
commit 5780f045e3af5ad9bc48ca188b81917617589c31
Author: Gary Gregory <[email protected]>
AuthorDate: Thu Mar 5 22:44:10 2026 -0500
[COMPRESS-719] CPConstant subclasses are missing optional hashCode() and
equals()
---
src/changes/changes.xml | 1 +
.../commons/compress/harmony/pack200/CPClass.java | 20 ++++++-
.../commons/compress/harmony/pack200/CPDouble.java | 17 ++++++
.../commons/compress/harmony/pack200/CPFloat.java | 17 ++++++
.../commons/compress/harmony/pack200/CPInt.java | 16 +++++
.../commons/compress/harmony/pack200/CPLong.java | 16 +++++
.../commons/compress/harmony/pack200/CPString.java | 20 ++++++-
.../compress/harmony/pack200/CPClassTest.java | 70 ++++++++++++++++++++++
.../compress/harmony/pack200/CPDoubleTest.java | 70 ++++++++++++++++++++++
.../compress/harmony/pack200/CPFloatTest.java | 70 ++++++++++++++++++++++
.../compress/harmony/pack200/CPIntTest.java | 70 ++++++++++++++++++++++
.../compress/harmony/pack200/CPLongTest.java | 70 ++++++++++++++++++++++
.../compress/harmony/pack200/CPStringTest.java | 70 ++++++++++++++++++++++
13 files changed, 525 insertions(+), 2 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9d0b57fc9..342a10d64 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -133,6 +133,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate
org.apache.commons.compress.harmony.pack200.PackingUtils.PackingUtils().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate
org.apache.commons.compress.harmony.unpack200.SegmentUtils.SegmentUtils().</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">Fix all Javadoc
warnings.</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory, Shan Jiang"
issue="COMPRESS-719">CPConstant subclasses are missing optional hashCode() and
equals().</action>
<!-- ADD -->
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
MemoryLimitException.MemoryLimitException(long, long).</action>
<action type="add" dev="ggregory" due-to="Gary Gregory">Add
CompressException.CompressException(String, Object...).</action>
diff --git
a/src/main/java/org/apache/commons/compress/harmony/pack200/CPClass.java
b/src/main/java/org/apache/commons/compress/harmony/pack200/CPClass.java
index 40c22249c..3acf13da1 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CPClass.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CPClass.java
@@ -18,6 +18,8 @@
*/
package org.apache.commons.compress.harmony.pack200;
+import java.util.Objects;
+
/**
* Constant pool entry for a class.
*
@@ -35,7 +37,7 @@ public class CPClass extends CPConstant<CPClass> {
* @param value The value.
*/
public CPClass(final CPUTF8 value) {
- this.value = value;
+ this.value = Objects.requireNonNull(value);
this.className = value.getUnderlyingString();
final char[] chars = className.toCharArray();
for (final char element : chars) {
@@ -52,6 +54,17 @@ public int compareTo(final CPClass arg0) {
return className.compareTo(arg0.className);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CPClass)) {
+ return false;
+ }
+ return compareTo((CPClass) obj) == 0;
+ }
+
/**
* Gets the index in the CP UTF8 pool.
*
@@ -61,6 +74,11 @@ public int getIndexInCpUtf8() {
return value.getIndex();
}
+ @Override
+ public int hashCode() {
+ return className.hashCode();
+ }
+
/**
* Tests whether this is an inner class.
*
diff --git
a/src/main/java/org/apache/commons/compress/harmony/pack200/CPDouble.java
b/src/main/java/org/apache/commons/compress/harmony/pack200/CPDouble.java
index 4ff764245..b81767fcc 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CPDouble.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CPDouble.java
@@ -41,6 +41,17 @@ public int compareTo(final CPDouble obj) {
return Double.compare(value, obj.value);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CPDouble)) {
+ return false;
+ }
+ return compareTo((CPDouble) obj) == 0;
+ }
+
/**
* Gets the double value.
*
@@ -49,4 +60,10 @@ public int compareTo(final CPDouble obj) {
public double getDouble() {
return value;
}
+
+ @Override
+ public int hashCode() {
+ return Double.hashCode(value);
+ }
+
}
diff --git
a/src/main/java/org/apache/commons/compress/harmony/pack200/CPFloat.java
b/src/main/java/org/apache/commons/compress/harmony/pack200/CPFloat.java
index 5b622aad9..599ea2cc5 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CPFloat.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CPFloat.java
@@ -41,6 +41,17 @@ public int compareTo(final CPFloat obj) {
return Float.compare(value, obj.value);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CPFloat)) {
+ return false;
+ }
+ return compareTo((CPFloat) obj) == 0;
+ }
+
/**
* Gets the float value.
*
@@ -49,4 +60,10 @@ public int compareTo(final CPFloat obj) {
public float getFloat() {
return value;
}
+
+ @Override
+ public int hashCode() {
+ return Float.hashCode(value);
+ }
+
}
diff --git
a/src/main/java/org/apache/commons/compress/harmony/pack200/CPInt.java
b/src/main/java/org/apache/commons/compress/harmony/pack200/CPInt.java
index e20324c55..826f1198a 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CPInt.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CPInt.java
@@ -41,6 +41,17 @@ public int compareTo(final CPInt obj) {
return Integer.compare(value, obj.value);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CPInt)) {
+ return false;
+ }
+ return compareTo((CPInt) obj) == 0;
+ }
+
/**
* Gets the int value.
*
@@ -49,4 +60,9 @@ public int compareTo(final CPInt obj) {
public int getInt() {
return value;
}
+
+ @Override
+ public int hashCode() {
+ return Integer.hashCode(value);
+ }
}
diff --git
a/src/main/java/org/apache/commons/compress/harmony/pack200/CPLong.java
b/src/main/java/org/apache/commons/compress/harmony/pack200/CPLong.java
index 71575ae2b..1de3d361f 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CPLong.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CPLong.java
@@ -41,6 +41,17 @@ public int compareTo(final CPLong obj) {
return Long.compare(value, obj.value);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CPLong)) {
+ return false;
+ }
+ return compareTo((CPLong) obj) == 0;
+ }
+
/**
* Gets the long value.
*
@@ -50,6 +61,11 @@ public long getLong() {
return value;
}
+ @Override
+ public int hashCode() {
+ return Long.hashCode(value);
+ }
+
@Override
public String toString() {
return "" + value;
diff --git
a/src/main/java/org/apache/commons/compress/harmony/pack200/CPString.java
b/src/main/java/org/apache/commons/compress/harmony/pack200/CPString.java
index 9daff1741..7ff2a47ef 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/CPString.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/CPString.java
@@ -18,6 +18,8 @@
*/
package org.apache.commons.compress.harmony.pack200;
+import java.util.Objects;
+
/**
* Constant pool entry for a String.
*
@@ -34,7 +36,7 @@ public class CPString extends CPConstant<CPString> {
* @param value The value.
*/
public CPString(final CPUTF8 value) {
- this.value = value;
+ this.value = Objects.requireNonNull(value);
this.string = value.getUnderlyingString();
}
@@ -43,6 +45,17 @@ public int compareTo(final CPString arg0) {
return string.compareTo(arg0.string);
}
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (!(obj instanceof CPString)) {
+ return false;
+ }
+ return compareTo((CPString) obj) == 0;
+ }
+
/**
* Gets the index in the CP UTF8 pool.
*
@@ -52,6 +65,11 @@ public int getIndexInCpUtf8() {
return value.getIndex();
}
+ @Override
+ public int hashCode() {
+ return string.hashCode();
+ }
+
@Override
public String toString() {
return string;
diff --git
a/src/test/java/org/apache/commons/compress/harmony/pack200/CPClassTest.java
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPClassTest.java
new file mode 100644
index 000000000..f5cbee722
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/CPClassTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.compress.harmony.pack200;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+class CPClassTest {
+
+ @Test
+ void testEquals() {
+ final CPClass a = new CPClass(new CPUTF8("42"));
+ final CPClass b = new CPClass(new CPUTF8("42"));
+ final CPClass c = new CPClass(new CPUTF8("98"));
+ // Reflexivity
+ assertEquals(a, a);
+ // Symmetry
+ assertEquals(a, b);
+ assertEquals(b, a);
+ // Inequality
+ assertNotEquals(a, c);
+ assertNotEquals(c, a);
+ // Null and different type
+ assertNotEquals(null, a);
+ assertNotEquals(a, "42");
+ }
+
+ @Test
+ void testEqualsEdgeCases() {
+ final CPClass zero = new CPClass(new CPUTF8("0"));
+ final CPClass minValue = new CPClass(new CPUTF8(""));
+ final CPClass maxValue = new CPClass(new
CPUTF8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+ assertEquals(zero, new CPClass(new CPUTF8("0")));
+ assertEquals(minValue, new CPClass(new CPUTF8("")));
+ assertEquals(maxValue, new CPClass(new
CPUTF8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")));
+ assertNotEquals(zero, minValue);
+ assertNotEquals(zero, maxValue);
+ assertNotEquals(minValue, maxValue);
+ }
+
+ @Test
+ void testHashCode() {
+ final CPClass a = new CPClass(new CPUTF8("42"));
+ final CPClass b = new CPClass(new CPUTF8("42"));
+ final CPClass c = new CPClass(new CPUTF8("99"));
+ // Equal objects must have equal hash codes
+ assertEquals(a.hashCode(), b.hashCode());
+ // Unequal objects should (typically) have different hash codes
+ assertNotEquals(a.hashCode(), c.hashCode());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/compress/harmony/pack200/CPDoubleTest.java
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPDoubleTest.java
new file mode 100644
index 000000000..6e3b8ec4c
--- /dev/null
+++
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPDoubleTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.compress.harmony.pack200;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+class CPDoubleTest {
+
+ @Test
+ void testEquals() {
+ final CPDouble a = new CPDouble(42);
+ final CPDouble b = new CPDouble(42);
+ final CPDouble c = new CPDouble(99);
+ // Reflexivity
+ assertEquals(a, a);
+ // Symmetry
+ assertEquals(a, b);
+ assertEquals(b, a);
+ // Inequality
+ assertNotEquals(a, c);
+ assertNotEquals(c, a);
+ // Null and different type
+ assertNotEquals(null, a);
+ assertNotEquals(a, "42");
+ }
+
+ @Test
+ void testEqualsEdgeCases() {
+ final CPDouble zero = new CPDouble(0);
+ final CPDouble minValue = new CPDouble(Double.MIN_VALUE);
+ final CPDouble maxValue = new CPDouble(Double.MAX_VALUE);
+ assertEquals(zero, new CPDouble(0));
+ assertEquals(minValue, new CPDouble(Double.MIN_VALUE));
+ assertEquals(maxValue, new CPDouble(Double.MAX_VALUE));
+ assertNotEquals(zero, minValue);
+ assertNotEquals(zero, maxValue);
+ assertNotEquals(minValue, maxValue);
+ }
+
+ @Test
+ void testHashCode() {
+ final CPDouble a = new CPDouble(42);
+ final CPDouble b = new CPDouble(42);
+ final CPDouble c = new CPDouble(99);
+ // Equal objects must have equal hash codes
+ assertEquals(a.hashCode(), b.hashCode());
+ // Unequal objects should (typically) have different hash codes
+ assertNotEquals(a.hashCode(), c.hashCode());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/compress/harmony/pack200/CPFloatTest.java
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPFloatTest.java
new file mode 100644
index 000000000..c6307ee56
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/CPFloatTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.compress.harmony.pack200;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+class CPFloatTest {
+
+ @Test
+ void testEquals() {
+ final CPFloat a = new CPFloat(42);
+ final CPFloat b = new CPFloat(42);
+ final CPFloat c = new CPFloat(99);
+ // Reflexivity
+ assertEquals(a, a);
+ // Symmetry
+ assertEquals(a, b);
+ assertEquals(b, a);
+ // Inequality
+ assertNotEquals(a, c);
+ assertNotEquals(c, a);
+ // Null and different type
+ assertNotEquals(null, a);
+ assertNotEquals(a, "42");
+ }
+
+ @Test
+ void testEqualsEdgeCases() {
+ final CPFloat zero = new CPFloat(0);
+ final CPFloat minValue = new CPFloat(Float.MIN_VALUE);
+ final CPFloat maxValue = new CPFloat(Float.MAX_VALUE);
+ assertEquals(zero, new CPFloat(0));
+ assertEquals(minValue, new CPFloat(Float.MIN_VALUE));
+ assertEquals(maxValue, new CPFloat(Float.MAX_VALUE));
+ assertNotEquals(zero, minValue);
+ assertNotEquals(zero, maxValue);
+ assertNotEquals(minValue, maxValue);
+ }
+
+ @Test
+ void testHashCode() {
+ final CPFloat a = new CPFloat(42);
+ final CPFloat b = new CPFloat(42);
+ final CPFloat c = new CPFloat(99);
+ // Equal objects must have equal hash codes
+ assertEquals(a.hashCode(), b.hashCode());
+ // Unequal objects should (typically) have different hash codes
+ assertNotEquals(a.hashCode(), c.hashCode());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/compress/harmony/pack200/CPIntTest.java
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPIntTest.java
new file mode 100644
index 000000000..58799b711
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/CPIntTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.compress.harmony.pack200;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+class CPIntTest {
+
+ @Test
+ void testEquals() {
+ final CPInt a = new CPInt(42);
+ final CPInt b = new CPInt(42);
+ final CPInt c = new CPInt(99);
+ // Reflexivity
+ assertEquals(a, a);
+ // Symmetry
+ assertEquals(a, b);
+ assertEquals(b, a);
+ // Inequality
+ assertNotEquals(a, c);
+ assertNotEquals(c, a);
+ // Null and different type
+ assertNotEquals(null, a);
+ assertNotEquals(a, "42");
+ }
+
+ @Test
+ void testEqualsEdgeCases() {
+ final CPInt zero = new CPInt(0);
+ final CPInt minValue = new CPInt(Integer.MIN_VALUE);
+ final CPInt maxValue = new CPInt(Integer.MAX_VALUE);
+ assertEquals(zero, new CPInt(0));
+ assertEquals(minValue, new CPInt(Integer.MIN_VALUE));
+ assertEquals(maxValue, new CPInt(Integer.MAX_VALUE));
+ assertNotEquals(zero, minValue);
+ assertNotEquals(zero, maxValue);
+ assertNotEquals(minValue, maxValue);
+ }
+
+ @Test
+ void testHashCode() {
+ final CPInt a = new CPInt(42);
+ final CPInt b = new CPInt(42);
+ final CPInt c = new CPInt(99);
+ // Equal objects must have equal hash codes
+ assertEquals(a.hashCode(), b.hashCode());
+ // Unequal objects should (typically) have different hash codes
+ assertNotEquals(a.hashCode(), c.hashCode());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/compress/harmony/pack200/CPLongTest.java
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPLongTest.java
new file mode 100644
index 000000000..decab4e81
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/CPLongTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.compress.harmony.pack200;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+class CPLongTest {
+
+ @Test
+ void testEquals() {
+ final CPLong a = new CPLong(42);
+ final CPLong b = new CPLong(42);
+ final CPLong c = new CPLong(99);
+ // Reflexivity
+ assertEquals(a, a);
+ // Symmetry
+ assertEquals(a, b);
+ assertEquals(b, a);
+ // Inequality
+ assertNotEquals(a, c);
+ assertNotEquals(c, a);
+ // Null and different type
+ assertNotEquals(null, a);
+ assertNotEquals(a, "42");
+ }
+
+ @Test
+ void testEqualsEdgeCases() {
+ final CPLong zero = new CPLong(0);
+ final CPLong minValue = new CPLong(Long.MIN_VALUE);
+ final CPLong maxValue = new CPLong(Long.MAX_VALUE);
+ assertEquals(zero, new CPLong(0));
+ assertEquals(minValue, new CPLong(Long.MIN_VALUE));
+ assertEquals(maxValue, new CPLong(Long.MAX_VALUE));
+ assertNotEquals(zero, minValue);
+ assertNotEquals(zero, maxValue);
+ assertNotEquals(minValue, maxValue);
+ }
+
+ @Test
+ void testHashCode() {
+ final CPLong a = new CPLong(42);
+ final CPLong b = new CPLong(42);
+ final CPLong c = new CPLong(99);
+ // Equal objects must have equal hash codes
+ assertEquals(a.hashCode(), b.hashCode());
+ // Unequal objects should (typically) have different hash codes
+ assertNotEquals(a.hashCode(), c.hashCode());
+ }
+}
diff --git
a/src/test/java/org/apache/commons/compress/harmony/pack200/CPStringTest.java
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPStringTest.java
new file mode 100644
index 000000000..1715924a4
--- /dev/null
+++
b/src/test/java/org/apache/commons/compress/harmony/pack200/CPStringTest.java
@@ -0,0 +1,70 @@
+/*
+ * 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.compress.harmony.pack200;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+
+import org.junit.jupiter.api.Test;
+
+class CPStringTest {
+
+ @Test
+ void testEquals() {
+ final CPString a = new CPString(new CPUTF8("42"));
+ final CPString b = new CPString(new CPUTF8("42"));
+ final CPString c = new CPString(new CPUTF8("98"));
+ // Reflexivity
+ assertEquals(a, a);
+ // Symmetry
+ assertEquals(a, b);
+ assertEquals(b, a);
+ // Inequality
+ assertNotEquals(a, c);
+ assertNotEquals(c, a);
+ // Null and different type
+ assertNotEquals(null, a);
+ assertNotEquals(a, "42");
+ }
+
+ @Test
+ void testEqualsEdgeCases() {
+ final CPString zero = new CPString(new CPUTF8("0"));
+ final CPString minValue = new CPString(new CPUTF8(""));
+ final CPString maxValue = new CPString(new
CPUTF8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
+ assertEquals(zero, new CPString(new CPUTF8("0")));
+ assertEquals(minValue, new CPString(new CPUTF8("")));
+ assertEquals(maxValue, new CPString(new
CPUTF8("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")));
+ assertNotEquals(zero, minValue);
+ assertNotEquals(zero, maxValue);
+ assertNotEquals(minValue, maxValue);
+ }
+
+ @Test
+ void testHashCode() {
+ final CPString a = new CPString(new CPUTF8("42"));
+ final CPString b = new CPString(new CPUTF8("42"));
+ final CPString c = new CPString(new CPUTF8("99"));
+ // Equal objects must have equal hash codes
+ assertEquals(a.hashCode(), b.hashCode());
+ // Unequal objects should (typically) have different hash codes
+ assertNotEquals(a.hashCode(), c.hashCode());
+ }
+}