You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/11/19 21:25:20 UTC
[commons-bcel] 02/02: org.apache.bcel.util.ClassPath hashCode() and equals() don't match.
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-bcel.git
commit 8b3e1751c6dcdf5cf82f312692df27fb9d714fbd
Author: Gary David Gregory (Code signing key) <gg...@apache.org>
AuthorDate: Sat Nov 19 16:25:14 2022 -0500
org.apache.bcel.util.ClassPath hashCode() and equals() don't match.
---
src/changes/changes.xml | 1 +
src/main/java/org/apache/bcel/util/ClassPath.java | 21 ++++++++++++---------
2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 9fab3684..4adb3858 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -91,6 +91,7 @@ The <action> type attribute can be add,update,fix,remove.
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.StackMapEntry.StackMapEntry(DataInput, ConstantPool) reads signed instead of unsigned shorts from its DataInput.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.StackMapType.StackMapType(DataInput, ConstantPool) reads signed instead of unsigned shorts from its DataInput.</action>
<action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.classfile.ConstantInvokeDynamic.ConstantInvokeDynamic(DataInput).</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">org.apache.bcel.util.ClassPath hashCode() and equals() don't match.</action>
<!-- UPDATE -->
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump spotbugs-maven-plugin from 4.7.2.2 to 4.7.3.0 #167.</action>
<action type="update" dev="ggregory" due-to="Dependabot">Bump jmh.version from 1.35 to 1.36 #170.</action>
diff --git a/src/main/java/org/apache/bcel/util/ClassPath.java b/src/main/java/org/apache/bcel/util/ClassPath.java
index de8aa568..c6e36c6d 100644
--- a/src/main/java/org/apache/bcel/util/ClassPath.java
+++ b/src/main/java/org/apache/bcel/util/ClassPath.java
@@ -536,7 +536,7 @@ public class ClassPath implements Closeable {
@SuppressWarnings("resource")
public ClassPath(final ClassPath parent, final String classPathString) {
this.parent = parent;
- this.classPathString = classPathString;
+ this.classPathString = Objects.requireNonNull(classPathString, "classPathString");
this.paths = new ArrayList<>();
for (final StringTokenizer tokenizer = new StringTokenizer(classPathString, File.pathSeparator); tokenizer.hasMoreTokens();) {
final String path = tokenizer.nextToken();
@@ -580,12 +580,18 @@ public class ClassPath implements Closeable {
}
@Override
- public boolean equals(final Object o) {
- if (o instanceof ClassPath) {
- final ClassPath cp = (ClassPath) o;
- return classPathString.equals(cp.toString());
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
}
- return false;
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ ClassPath other = (ClassPath) obj;
+ return Objects.equals(classPathString, other.classPathString);
}
/**
@@ -767,9 +773,6 @@ public class ClassPath implements Closeable {
@Override
public int hashCode() {
- if (parent != null) {
- return classPathString.hashCode() + parent.hashCode();
- }
return classPathString.hashCode();
}