Merge "Bug 981: Fixed accidental shaddowing of data in Data Change Event."
authorGiovanni Meo <gmeo@cisco.com>
Mon, 12 May 2014 13:53:28 +0000 (13:53 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Mon, 12 May 2014 13:53:28 +0000 (13:53 +0000)
1  2 
opendaylight/md-sal/sal-binding-broker/src/main/java/org/opendaylight/controller/md/sal/binding/impl/AbstractForwardedDataBroker.java

@@@ -96,8 -96,12 +96,12 @@@ public abstract class AbstractForwarded
          for (Map.Entry<org.opendaylight.yangtools.yang.data.api.InstanceIdentifier, ? extends NormalizedNode<?, ?>> entry : normalized
                  .entrySet()) {
              try {
-                 Entry<InstanceIdentifier<? extends DataObject>, DataObject> binding = getCodec().toBinding(entry);
-                 newMap.put(binding.getKey(), binding.getValue());
+                 Optional<Entry<InstanceIdentifier<? extends DataObject>, DataObject>> potential = getCodec().toBinding(
+                         entry);
+                 if (potential.isPresent()) {
+                     Entry<InstanceIdentifier<? extends DataObject>, DataObject> binding = potential.get();
+                     newMap.put(binding.getKey(), binding.getValue());
+                 }
              } catch (DeserializationException e) {
                  LOG.warn("Failed to transform {}, omitting it", entry, e);
              }
          Set<InstanceIdentifier<?>> hashSet = new HashSet<>();
          for (org.opendaylight.yangtools.yang.data.api.InstanceIdentifier normalizedPath : normalized) {
              try {
-                 InstanceIdentifier<? extends DataObject> binding = getCodec().toBinding(normalizedPath);
-                 hashSet.add(binding);
+                 Optional<InstanceIdentifier<? extends DataObject>> potential = getCodec().toBinding(normalizedPath);
+                 if (potential.isPresent()) {
+                     InstanceIdentifier<? extends DataObject> binding = potential.get();
+                     hashSet.add(binding);
+                 }
              } catch (DeserializationException e) {
                  LOG.warn("Failed to transform {}, omitting it", normalizedPath, e);
              }
      }
  
      protected Optional<DataObject> toBindingData(final InstanceIdentifier<?> path, final NormalizedNode<?, ?> data) {
-         if(path.isWildcarded()) {
+         if (path.isWildcarded()) {
              return Optional.absent();
          }
  
          @Override
          public DataObject getOriginalSubtree() {
              if (originalDataCache == null) {
 -                originalDataCache = toBindingData(path, domEvent.getOriginalSubtree());
 +                if(domEvent.getOriginalSubtree() != null) {
 +                    originalDataCache = toBindingData(path, domEvent.getOriginalSubtree());
 +                } else {
 +                    originalDataCache = Optional.absent();
 +                }
              }
              return originalDataCache.orNull();
          }
          @Override
          public DataObject getUpdatedSubtree() {
              if (updatedDataCache == null) {
 -                updatedDataCache = toBindingData(path, domEvent.getUpdatedSubtree());
 +                if(domEvent.getUpdatedSubtree() != null) {
 +                    updatedDataCache = toBindingData(path, domEvent.getUpdatedSubtree());
 +                } else {
 +                    updatedDataCache = Optional.absent();
 +                }
              }
 -
              return updatedDataCache.orNull();
          }
  
          @Override
          public String toString() {
              return Objects.toStringHelper(TranslatedDataChangeEvent.class) //
-                 .add("created", getCreatedData()) //
-                 .add("updated", getUpdatedData()) //
-                 .add("removed", getRemovedPaths()) //
-                 .add("dom", domEvent) //
-                 .toString();
+                     .add("created", getCreatedData()) //
+                     .add("updated", getUpdatedData()) //
+                     .add("removed", getRemovedPaths()) //
+                     .add("dom", domEvent) //
+                     .toString();
          }
      }