From 24958f66519350f165b6d3e2e1928d619f5fd090 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Fri, 22 Oct 2021 17:59:43 +0200 Subject: [PATCH] Improve StreamingContext diagnostics When we encounter a wrong nested child we end up throwing an opaque ClassCastException. Add an explicit check to improve diagnostics. JIRA: NETCONF-820 Change-Id: I3c5a24c1ff4d12a56dfd5fd6d8cd3f940af330a0 Signed-off-by: Robert Varga (cherry picked from commit 5ca9d3ee04aa5464f81be533f8b4d9b675e7da96) --- .../opendaylight/netconf/util/StreamingContext.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/StreamingContext.java b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/StreamingContext.java index 023ce4d0ae..17535322c5 100644 --- a/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/StreamingContext.java +++ b/netconf/netconf-util/src/main/java/org/opendaylight/netconf/util/StreamingContext.java @@ -248,8 +248,8 @@ abstract class StreamingContext implements Identifiable< AbstractMapMixin(final ListSchemaNode list) { super(NodeIdentifier.create(list.getQName())); - this.innerNode = new ListEntry(NodeIdentifierWithPredicates.of(list.getQName()), list); - this.keyLeaves = list.getKeyDefinition(); + innerNode = new ListEntry(NodeIdentifierWithPredicates.of(list.getQName()), list); + keyLeaves = list.getKeyDefinition(); } @Override @@ -264,7 +264,12 @@ abstract class StreamingContext implements Identifiable< @Override final void emitChildTreeNode(final NormalizedNodeStreamWriter writer, final PathNode node) throws IOException { - final NodeIdentifierWithPredicates childPath = (NodeIdentifierWithPredicates) node.element(); + final PathArgument element = node.element(); + if (!(element instanceof NodeIdentifierWithPredicates)) { + throw new IOException("Child identifier " + element + " is invalid in parent " + getIdentifier()); + } + + final NodeIdentifierWithPredicates childPath = (NodeIdentifierWithPredicates) element; final StreamingContext childOp = getChildOperation(childPath); if (childPath.size() == 0 && node.isEmpty() || childPath.keySet().containsAll(keyLeaves)) { // This is a query for the entire list, or the query specifies everything we need @@ -528,7 +533,7 @@ abstract class StreamingContext implements Identifiable< UnkeyedListMixin(final ListSchemaNode list) { super(NodeIdentifier.create(list.getQName())); - this.innerNode = new UnkeyedListItem(list); + innerNode = new UnkeyedListItem(list); } @Override -- 2.36.6