BUG-4145: check if entire YangInstanceIdentifier is present in SchemaContext 95/26895/1
authorRobert Varga <rovarga@cisco.com>
Sun, 13 Sep 2015 18:47:09 +0000 (20:47 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 13 Sep 2015 18:47:09 +0000 (20:47 +0200)
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 <rovarga@cisco.com>
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/AbstractStringInstanceIdentifierCodec.java

index d0abc8a74c7077822e6e22e7c6cb936eba6e0db0..6e1c0a72e5ec73099ac24c78d617ea53ff9259de 100644 (file)
@@ -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;
     }