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:35:59 UTC
[commons-collections] branch master updated: PMD: AbstractReferenceMap.SoftRef 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
The following commit(s) were added to refs/heads/master by this push:
new d22eb8951 PMD: AbstractReferenceMap.SoftRef implements hashCode() but not equals()
d22eb8951 is described below
commit d22eb8951b761cd6afa03bfed74d42f0462467f8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Nov 6 11:35:53 2022 -0500
PMD: AbstractReferenceMap.SoftRef implements hashCode() but not equals()
---
src/changes/changes.xml | 3 +++
.../commons/collections4/map/AbstractReferenceMap.java | 15 +++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 201151db1..25856d352 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -106,6 +106,9 @@
<action type="fix" dev="ggregory" due-to="Marc Wrobel">
Fix minor typos #323
</action>
+ <action type="fix" dev="ggregory" due-to="Gary Gregory">
+ AbstractReferenceMap.SoftRef 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 295ef67c9..3aab462d1 100644
--- a/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
+++ b/src/main/java/org/apache/commons/collections4/map/AbstractReferenceMap.java
@@ -966,6 +966,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;
+ }
+ SoftRef<?> other = (SoftRef<?>) obj;
+ return hash == other.hash;
+ }
}
/**