diff options
author | Carsten Hammer | 2020-11-01 10:37:14 +0000 |
---|---|---|
committer | Carsten Hammer | 2020-11-01 10:37:14 +0000 |
commit | fc9791018f8ae9cda5078ee148fb76365c827494 (patch) | |
tree | 7a22ee0b3063c2ff89416c25545ee26cd90f63de | |
parent | 6feccb15bc1a8c782a58d810d586190e0d031eb4 (diff) | |
download | rt.equinox.bundles-fc9791018f8ae9cda5078ee148fb76365c827494.tar.gz rt.equinox.bundles-fc9791018f8ae9cda5078ee148fb76365c827494.tar.xz rt.equinox.bundles-fc9791018f8ae9cda5078ee148fb76365c827494.zip |
This equals method is checking wrong operands
Bug: org.eclipse.core.internal.runtime.ReferenceHashSet$HashableSoftReference.equals(Object)
checks for operand being a ReferenceHashSet$HashableWeakReference
This equals method is checking to see if the argument is some
incompatible type (i.e., a class that is neither a supertype nor subtype
of the class that defines the equals method). For example, the Foo class
might have an equals method that looks like:
public boolean equals(Object o) {
if (o instanceof Foo)
return name.equals(((Foo)o).name);
else if (o instanceof String)
return name.equals(o);
else return false;
}
This is considered bad practice, as it makes it very hard to implement
an equals method that is symmetric and transitive. Without those
properties, very unexpected behaviors are possible.
Rank: Troubling (14), confidence: High
Pattern: EQ_CHECK_FOR_OPERAND_NOT_COMPATIBLE_WITH_THIS
Type: Eq, Category: BAD_PRACTICE (Bad practice)
Change-Id: I4c9097e9a582c6c936bf3f0b3f8208acaf4f25a8
Signed-off-by: Carsten Hammer <carsten.hammer@t-online.de>
-rw-r--r-- | bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/ReferenceHashSet.java | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/ReferenceHashSet.java b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/ReferenceHashSet.java index 8a17df038..d8b9e77cd 100644 --- a/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/ReferenceHashSet.java +++ b/bundles/org.eclipse.equinox.common/src/org/eclipse/core/internal/runtime/ReferenceHashSet.java @@ -74,11 +74,11 @@ public class ReferenceHashSet<T> { @Override public boolean equals(Object obj) { - if (!(obj instanceof HashableWeakReference)) + if (!(obj instanceof HashableSoftReference)) return false; Object referent = super.get(); @SuppressWarnings("unchecked") - Object other = ((HashableWeakReference<?>) obj).get(); + Object other = ((HashableSoftReference<?>) obj).get(); if (referent == null) return other == null; return referent.equals(other); |