From fe28f8689e3aabb08074ba048896d80077bb09c5 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 6 Nov 2022 11:41:40 -0500 Subject: [PATCH] PMD: AbstractReferenceMap.WeakRef implements hashCode() but not equals() --- src/changes/changes.xml | 3 +++ .../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 @@ AbstractReferenceMap.SoftRef implements hashCode() but not equals(). + + AbstractReferenceMap.WeakRef implements hashCode() but not equals(). + 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 extends AbstractHashedMap 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 extends AbstractHashedMap 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; + } } /**