Fixed NPE in BindingCodecTree#getSubtreeCodec(YangInstanceIdentifier) 35/17635/1
authorTony Tkacik <ttkacik@cisco.com>
Thu, 2 Apr 2015 13:35:03 +0000 (15:35 +0200)
committerTony Tkacik <ttkacik@cisco.com>
Thu, 2 Apr 2015 13:35:03 +0000 (15:35 +0200)
Change-Id: If77807004779ce6ade106f1bacc9918f98f996ee
Signed-off-by: Tony Tkacik <ttkacik@cisco.com>
code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java

index e0e0c97777e2dfab31450eefb1480c7f954fabee..4fb5e6811dbb147b8acdc34f844cec6bc64c3bfa 100644 (file)
@@ -71,7 +71,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
     private final BindingRuntimeContext context;
     private final SchemaRootCodecContext<?> root;
 
-    BindingCodecContext(final BindingRuntimeContext context, BindingNormalizedNodeCodecRegistry registry) {
+    BindingCodecContext(final BindingRuntimeContext context, final BindingNormalizedNodeCodecRegistry registry) {
         this.context = Preconditions.checkNotNull(context, "Binding Runtime Context is required.");
         this.root = SchemaRootCodecContext.create(this);
         this.identityCodec = new IdentityCodec(context);
@@ -94,7 +94,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
 
     @SuppressWarnings({"rawtypes", "unchecked"})
     @Override
-    public DataObjectSerializer getEventStreamSerializer(Class<?> type) {
+    public DataObjectSerializer getEventStreamSerializer(final Class<?> type) {
         return registry.getSerializer((Class) type);
     }
 
@@ -143,7 +143,7 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
      *
      */
     @Nullable NodeCodecContext<?> getCodecContextNode(final @Nonnull YangInstanceIdentifier dom,
-            final @Nonnull Collection<InstanceIdentifier.PathArgument> bindingArguments) {
+            final @Nullable Collection<InstanceIdentifier.PathArgument> bindingArguments) {
         NodeCodecContext<?> currentNode = root;
         ListNodeCodecContext<?> currentList = null;
 
@@ -165,7 +165,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
 
                 // We entered list, so now we have all information to emit
                 // list path using second list argument.
-                bindingArguments.add(currentList.getBindingPathArgument(domArg));
+                if (bindingArguments != null) {
+                    bindingArguments.add(currentList.getBindingPathArgument(domArg));
+                }
                 currentList = null;
                 currentNode = nextNode;
             } else if (nextNode instanceof ListNodeCodecContext) {
@@ -177,7 +179,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
                 // it is not supported by binding instance identifier.
                 currentNode = nextNode;
             } else if (nextNode instanceof DataContainerCodecContext<?,?>) {
-                bindingArguments.add(((DataContainerCodecContext<?,?>) nextNode).getBindingPathArgument(domArg));
+                if (bindingArguments != null) {
+                    bindingArguments.add(((DataContainerCodecContext<?,?>) nextNode).getBindingPathArgument(domArg));
+                }
                 currentNode = nextNode;
             } else if (nextNode instanceof LeafNodeCodecContext) {
                 LOG.debug("Instance identifier referencing a leaf is not representable (%s)", dom);
@@ -197,7 +201,9 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
         }
 
         if (currentList != null) {
-            bindingArguments.add(currentList.getBindingPathArgument(null));
+            if(bindingArguments != null) {
+                bindingArguments.add(currentList.getBindingPathArgument(null));
+            }
             return currentList;
         }
         return currentNode;
@@ -341,18 +347,18 @@ final class BindingCodecContext implements CodecContextFactory, BindingCodecTree
 
     @SuppressWarnings("unchecked")
     @Override
-    public <T extends DataObject> BindingCodecTreeNode<T> getSubtreeCodec(InstanceIdentifier<T> path) {
+    public <T extends DataObject> BindingCodecTreeNode<T> getSubtreeCodec(final InstanceIdentifier<T> path) {
         // TODO Do we need defensive check here?
         return (BindingCodecTreeNode<T>) getCodecContextNode(path, null);
     }
 
     @Override
-    public BindingCodecTreeNode<?> getSubtreeCodec(YangInstanceIdentifier path) {
+    public BindingCodecTreeNode<?> getSubtreeCodec(final YangInstanceIdentifier path) {
         return getCodecContextNode(path, null);
     }
 
     @Override
-    public BindingCodecTreeNode<?> getSubtreeCodec(SchemaPath path) {
+    public BindingCodecTreeNode<?> getSubtreeCodec(final SchemaPath path) {
         throw new UnsupportedOperationException("Not implemented yet.");
     }
 }