From 312699f71746b2d2d039cc03a8f727b4240cbf25 Mon Sep 17 00:00:00 2001 From: Tony Tkacik Date: Thu, 2 Apr 2015 15:35:03 +0200 Subject: [PATCH] Fixed NPE in BindingCodecTree#getSubtreeCodec(YangInstanceIdentifier) Change-Id: If77807004779ce6ade106f1bacc9918f98f996ee Signed-off-by: Tony Tkacik --- .../data/codec/impl/BindingCodecContext.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java index e0e0c97777..4fb5e6811d 100644 --- a/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java +++ b/code-generator/binding-data-codec/src/main/java/org/opendaylight/yangtools/binding/data/codec/impl/BindingCodecContext.java @@ -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 bindingArguments) { + final @Nullable Collection 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 BindingCodecTreeNode getSubtreeCodec(InstanceIdentifier path) { + public BindingCodecTreeNode getSubtreeCodec(final InstanceIdentifier path) { // TODO Do we need defensive check here? return (BindingCodecTreeNode) 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."); } } -- 2.36.6