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/06 16:42:07 UTC
[commons-collections] 01/02: PMD: AbstractReferenceMap.WeakRef implements hashCode() but not equals()
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-collections.git
commit fe28f8689e3aabb08074ba048896d80077bb09c5
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 11:41:40 2022 -0500
PMD: AbstractReferenceMap.WeakRef implements hashCode() but not equals()
---
src/changes/changes.xml | 3 +++
.../commons/collections4/map/AbstractReferenceMap.java | 17 ++++++++++++++++-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 25856d352..49e5b6cc4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -109,6 +109,9 @@
<action type="fix" dev="ggregory" due-to="Gary Gregory">
AbstractReferenceMap.SoftRef implements hashCode() but not equals().
</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">
+ AbstractReferenceMap.WeakRef implements hashCode() but not equals().
+ </action>
<!-- ADD -->
<action issue="COLLECTIONS-760" dev="kinow" type="add" due-to="Isira Seneviratne">
Add tests for MapUtils.
diff --git a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
index 3aab462d1..346427171 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
@@ -978,7 +978,7 @@ public abstract class AbstractReferenceMap<K, V> extends AbstractHashedMap<K, V>
if (getClass() != obj.getClass()) {
return false;
}
- SoftRef<?> other = (SoftRef<?>) obj;
+ final SoftRef<?> other = (SoftRef<?>) obj;
return hash == other.hash;
}
}
@@ -999,6 +999,21 @@ public abstract class AbstractReferenceMap<K, V> extends AbstractHashedMap<K, V>
public int hashCode() {
return hash;
}
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final WeakRef<?> other = (WeakRef<?>) obj;
+ return hash == other.hash;
+ }
}
/**