From: Robert Varga Date: Sun, 13 Sep 2015 18:47:09 +0000 (+0200) Subject: BUG-4145: check if entire YangInstanceIdentifier is present in SchemaContext X-Git-Tag: release/beryllium~327 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=13bb06fa8a386783fa4796a8527b033b6d0f0271;p=yangtools.git BUG-4145: check if entire YangInstanceIdentifier is present in SchemaContext A failure to find the SchemaNode for a path argument results in a NullPointerException. We need the SchemaNode to understand whether it targets an augmentation, as those need to be pruned from string output. This patch improves the behaviour by throwing an IllegalArgumentException with a description of which component we failed to find. Change-Id: I128eb63cf05b278b1af7516d426a6f0bafa87b90 Signed-off-by: Robert Varga --- diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractStringInstanceIdentifierCodec.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractStringInstanceIdentifierCodec.java index d0abc8a74c..6e1c0a72e5 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractStringInstanceIdentifierCodec.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractStringInstanceIdentifierCodec.java @@ -32,15 +32,16 @@ public abstract class AbstractStringInstanceIdentifierCodec extends AbstractName DataSchemaContextNode current = getDataContextTree().getRoot(); for (PathArgument arg : data.getPathArguments()) { current = current.getChild(arg); + Preconditions.checkArgument(current != null, + "Invalid input %s: schema for argument %s (after %s) not found", data, arg, sb); - if(current.isMixin()) { + if (current.isMixin()) { /* * XML/YANG instance identifier does not have concept * of augmentation identifier, or list as whole which - * identifies mixin (same as paretn element), + * identifies a mixin (same as the parent element), * so we can safely ignore it if it is part of path * (since child node) is identified in same fashion. - * */ continue; } @@ -84,7 +85,7 @@ public abstract class AbstractStringInstanceIdentifierCodec extends AbstractName */ protected abstract @Nonnull DataSchemaContextTree getDataContextTree(); - protected Object deserializeKeyValue(DataSchemaNode schemaNode, String value) { + protected Object deserializeKeyValue(final DataSchemaNode schemaNode, final String value) { return value; }