Assert route change identifier being IdentifiableItem 61/77861/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Nov 2018 18:17:00 +0000 (19:17 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 15 Nov 2018 18:17:00 +0000 (19:17 +0100)
Rather than doing a straight cast, verify the object beforehand,
giving us a proper data instead of a ClassCastException.

Change-Id: Ia9dafc9d62028fbe66fc11036d6873821c5ef8a7
JIRA: BGPCEP-848
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
bgp/rib-impl/src/main/java/org/opendaylight/protocol/bgp/rib/impl/EffectiveRibInWriter.java

index 28ffffcb8e229bc2155f62b682be6fe7b6fde44f..f990fc7802fabf9ae9225287dd60cdc334f7c678 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.protocol.bgp.rib.impl;
 
+import static com.google.common.base.Verify.verify;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ImmutableMap;
@@ -66,6 +67,8 @@ import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.Identifiable;
 import org.opendaylight.yangtools.yang.binding.Identifier;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.IdentifiableItem;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.slf4j.Logger;
@@ -238,8 +241,11 @@ final class EffectiveRibInWriter implements PrefixesReceivedCounters, PrefixesIn
             final KeyedInstanceIdentifier<Tables, TablesKey> tablePath,
             final Collection<DataObjectModification<R>> routeChanges) {
         for (final DataObjectModification<R> routeChanged : routeChanges) {
-            final I routeKey
-                    = ((InstanceIdentifier.IdentifiableItem<R, I>) routeChanged.getIdentifier()).getKey();
+            final PathArgument routeChangeId = routeChanged.getIdentifier();
+            verify(routeChangeId instanceof IdentifiableItem, "Route change %s has invalid identifier %s",
+                routeChanged, routeChangeId);
+            final I routeKey = ((IdentifiableItem<R, I>) routeChangeId).getKey();
+
             switch (routeChanged.getModificationType()) {
                 case SUBTREE_MODIFIED:
                 case WRITE: