Do not compare NormalizedNodes in CodecDataObject 30/81930/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 7 May 2019 08:58:24 +0000 (10:58 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 7 May 2019 10:08:04 +0000 (12:08 +0200)
Binding DTOs can be shared across instantiations -- for example
groupings. If we are comparing different instantiations, they
can have different namespaces and thus NormalizedNodes do not
compare as equal -- but Binding considers them equal.

JIRA: MDSAL-442
Change-Id: I9838692a046045b3a7e520bd363bfe54b94a6e66
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/CodecDataObject.java

index 5830587a8e7540751c1470baedcdaed07e49f164..505386d8b1b9bce53d085b5806acd3dd66b3944d 100644 (file)
@@ -12,6 +12,7 @@ import static java.util.Objects.requireNonNull;
 
 import com.google.common.base.MoreObjects;
 import com.google.common.base.MoreObjects.ToStringHelper;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.util.Optional;
 import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
 import org.eclipse.jdt.annotation.NonNull;
@@ -57,6 +58,7 @@ public abstract class CodecDataObject<T extends DataObject> implements DataObjec
     }
 
     @Override
+    @SuppressFBWarnings(value = "EQ_UNUSUAL", justification = "State is examined indirectly enough to confuse SpotBugs")
     public final boolean equals(final Object obj) {
         if (obj == this) {
             return true;
@@ -67,9 +69,8 @@ public abstract class CodecDataObject<T extends DataObject> implements DataObjec
         }
         @SuppressWarnings("unchecked")
         final T other = (T) iface.cast(obj);
-        if (other instanceof CodecDataObject) {
-            return data.equals(((CodecDataObject<?>) obj).data);
-        }
+        // Note: we do not want to compare NormalizedNode data here, as we may be looking at different instantiations
+        //       of the same grouping -- in which case normalized node will not compare as equal.
         return codecAugmentedEquals(other);
     }