PMD: AbstractReferenceMap.WeakRef implements hashCode() but not equals()

This commit is contained in:
Gary Gregory 2022-11-06 11:41:40 -05:00
parent d22eb8951b
commit fe28f8689e
2 changed files with 19 additions and 1 deletions

View File

@ -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.

View File

@ -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;
}
}
/**