From bd453654173fdb8109cb86413daa245d9d109081 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 11 Feb 2019 17:25:47 +0100 Subject: [PATCH] Account for reported UNMODIFIED nodes DataObjectModification has no way of expressing UNMODIFIED nodes, but they can (and are) reported from DataTreeCandidateNode, hence we end up reporting IllegalStateException when the user tries to look at those nodes. Make sure we take the node under consideration and do not report unmodified children, hence preventing the ISE from happening. JIRA: MDSAL-422 Change-Id: I34d36ae083c5ce3ad793eb584236f175f7a3a906 Signed-off-by: Robert Varga --- .../adapter/LazyDataObjectModification.java | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataObjectModification.java b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataObjectModification.java index 27785f55a9..42311591ca 100644 --- a/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataObjectModification.java +++ b/binding/mdsal-binding-dom-adapter/src/main/java/org/opendaylight/mdsal/binding/dom/adapter/LazyDataObjectModification.java @@ -7,8 +7,10 @@ */ package org.opendaylight.mdsal.binding.dom.adapter; +import static java.util.Objects.requireNonNull; +import static org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType.UNMODIFIED; + import com.google.common.base.MoreObjects; -import com.google.common.base.Preconditions; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -55,14 +57,14 @@ final class LazyDataObjectModification implements DataObje private volatile ModificationType modificationType; private LazyDataObjectModification(final BindingCodecTreeNode codec, final DataTreeCandidateNode domData) { - this.codec = Preconditions.checkNotNull(codec); - this.domData = Preconditions.checkNotNull(domData); + this.codec = requireNonNull(codec); + this.domData = requireNonNull(domData); this.identifier = codec.deserializePathArgument(domData.getIdentifier()); } static LazyDataObjectModification create(final BindingCodecTreeNode codec, final DataTreeCandidateNode domData) { - return new LazyDataObjectModification<>(codec,domData); + return new LazyDataObjectModification<>(codec, domData); } private static Collection> from(final BindingCodecTreeNode @@ -75,22 +77,24 @@ final class LazyDataObjectModification implements DataObje private static void populateList(final List> result, final BindingCodecTreeNode parentCodec, final Collection domChildNodes) { for (final DataTreeCandidateNode domChildNode : domChildNodes) { - final BindingStructuralType type = BindingStructuralType.from(domChildNode); - if (type != BindingStructuralType.NOT_ADDRESSABLE) { - /* - * Even if type is UNKNOWN, from perspective of BindingStructuralType - * we try to load codec for it. We will use that type to further specify - * debug log. - */ - try { - final BindingCodecTreeNode childCodec = - parentCodec.yangPathArgumentChild(domChildNode.getIdentifier()); - populateList(result,type, childCodec, domChildNode); - } catch (final IllegalArgumentException e) { - if (type == BindingStructuralType.UNKNOWN) { - LOG.debug("Unable to deserialize unknown DOM node {}",domChildNode,e); - } else { - LOG.debug("Binding representation for DOM node {} was not found",domChildNode,e); + if (domChildNode.getModificationType() != UNMODIFIED) { + final BindingStructuralType type = BindingStructuralType.from(domChildNode); + if (type != BindingStructuralType.NOT_ADDRESSABLE) { + /* + * Even if type is UNKNOWN, from perspective of BindingStructuralType + * we try to load codec for it. We will use that type to further specify + * debug log. + */ + try { + final BindingCodecTreeNode childCodec = + parentCodec.yangPathArgumentChild(domChildNode.getIdentifier()); + populateList(result, type, childCodec, domChildNode); + } catch (final IllegalArgumentException e) { + if (type == BindingStructuralType.UNKNOWN) { + LOG.debug("Unable to deserialize unknown DOM node {}", domChildNode, e); + } else { + LOG.debug("Binding representation for DOM node {} was not found", domChildNode, e); + } } } } @@ -119,7 +123,9 @@ final class LazyDataObjectModification implements DataObje private static void populateListWithSingleCodec(final List> result, final BindingCodecTreeNode codec, final Collection childNodes) { for (final DataTreeCandidateNode child : childNodes) { - result.add(create(codec, child)); + if (child.getModificationType() != UNMODIFIED) { + result.add(create(codec, child)); + } } } @@ -240,10 +246,7 @@ final class LazyDataObjectModification implements DataObje while (toEnter.hasNext() && current != null) { current = current.getModifiedChild(toEnter.next()); } - if (current != null) { - return create(childCodec, current); - } - return null; + return current != null && current.getModificationType() != UNMODIFIED ? create(childCodec, current) : null; } @Override -- 2.36.6