Do not allow nulls in NodeWithValue 42/84342/8
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 12 Sep 2019 15:11:39 +0000 (17:11 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 14 Apr 2021 08:24:58 +0000 (08:24 +0000)
We do not allow leaves to have a null value, hence the same
restriction should apply to NodeWithValue.

Change-Id: I4df0caf67baacf12d8b81b70dd447dff7e05a992
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToSimpleNodes.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/LeafListEntryContextNode.java

index fb7fabb56eaf3e62282da3fbfa7ad7e140d3abce..a7539e9167f08cb0917ba2b532e12f22e925194e 100644 (file)
@@ -840,14 +840,14 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
     public static final class NodeWithValue<T> extends AbstractPathArgument {
         private static final long serialVersionUID = -3637456085341738431L;
 
-        private final T value;
+        private final @NonNull T value;
 
         public NodeWithValue(final QName node, final T value) {
             super(node);
-            this.value = value;
+            this.value = requireNonNull(value);
         }
 
-        public T getValue() {
+        public @NonNull T getValue() {
             return value;
         }
 
index 0d66db347b1b91a6a576fb65055a27a0f265b2e7..d693372308e1e4b15d960c4758c79bc3391662ef 100644 (file)
@@ -11,6 +11,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 
 import java.util.Iterator;
 import java.util.Optional;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -69,7 +70,8 @@ abstract class InstanceIdToSimpleNodes<T extends PathArgument> extends InstanceI
 
     static final class LeafListEntryNormalization extends InstanceIdToSimpleNodes<NodeWithValue> {
         LeafListEntryNormalization(final LeafListSchemaNode potential) {
-            super(new NodeWithValue<>(potential.getQName(), null));
+            // We are fudging a value here
+            super(new NodeWithValue<>(potential.getQName(), Empty.getInstance()));
         }
 
         @Override
index 2cd1eb8c5a9347d22da14c2ba5372ab9f3ed5b3c..641758c3e73084aab3e57ea781e767f40a9c683d 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.data.util;
 
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
 final class LeafListEntryContextNode extends AbstractLeafNodeContext<NodeWithValue<?>, LeafListSchemaNode> {
     LeafListEntryContextNode(final LeafListSchemaNode potential) {
-        super(new NodeWithValue<>(potential.getQName(), null), potential);
+        super(new NodeWithValue<>(potential.getQName(), Empty.getInstance()), potential);
     }
 
     @Override