Guard against null data in AbstractLeafCandidateNode 45/20845/2
authorRobert Varga <rovarga@cisco.com>
Wed, 20 May 2015 19:56:22 +0000 (21:56 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 21 May 2015 17:55:06 +0000 (17:55 +0000)
An instance of this class is defunct if data is ever null, as accessors
will throw a NPE from Optional.of(). Make sure data passed down is never
null, catching any possible offenders.

This transitively fixes the transformation functions, as they will throw
NPE when they get a null input, as per Function API contract.

Change-Id: I8851e3c68dc9aa5abab4874f019fd214b20c0415
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/AbstractLeafCandidateNode.java

index 41e6eb4185ab4720ef96cdd24fec5c9434605389..18076396165029ec0aa1d9a6a7a6351dc8705cd5 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.tree;
 
 import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import java.util.Collection;
 import java.util.Collections;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -18,7 +19,7 @@ abstract class AbstractLeafCandidateNode implements DataTreeCandidateNode {
     private final NormalizedNode<?, ?> data;
 
     protected AbstractLeafCandidateNode(final NormalizedNode<?, ?> data) {
-        this.data = data;
+        this.data = Preconditions.checkNotNull(data);
     }
 
     protected final Optional<NormalizedNode<?, ?>> dataOptional() {