BUG-9265: Switch empty type mapping from Void to Empty 41/64241/7
authorRobert Varga <robert.varga@pantheon.tech>
Fri, 13 Oct 2017 10:42:03 +0000 (12:42 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 19 Oct 2017 08:39:20 +0000 (10:39 +0200)
Using Void means NormalizedNode.getValue() has to be nullable,
which wreaks havoc to a lot of places. Switch mapping to Empty, which
is a singleton dedicated to representing this type.

This flushes out quite a few of null violations, which are also fixed
up.

Change-Id: I4de3afed3d641eda292fdd4116497f3f22a0d770
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
25 files changed:
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/codec/EmptyCodec.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/codec/StringCodec.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/AnyXmlNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/AugmentationNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/DataContainerChild.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/DataContainerNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/LeafNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/LeafSetEntryNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/LeafSetNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/NormalizedNode.java
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/schema/ValueNode.java
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/EmptyJSONCodec.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/JsonStreamToNormalizedNodeTest.java
yang/yang-data-codec-gson/src/test/java/org/opendaylight/yangtools/yang/data/codec/gson/NormalizedNodeToJsonStreamTest.java
yang/yang-data-codec-xml/src/main/java/org/opendaylight/yangtools/yang/data/codec/xml/EmptyXmlCodec.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/EmptyStringCodec.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/StringStringCodec.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/AbstractImmutableNormalizedNodeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueNode.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/EmptyCodecStringTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/StringCodecStringTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codecs/UnionCodecStringTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/InstanceIdToNodesTest.java
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNodeTest.java
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/SimpleNodeDataWithSchema.java

index cedd7797138c0906d73c81417ac29c2036ca2871..1ca2a882e8298428c954ac5333de8ff2c97299d3 100644 (file)
@@ -8,11 +8,12 @@
 package org.opendaylight.yangtools.yang.data.api.codec;
 
 import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.yangtools.yang.common.Empty;
 
-public interface EmptyCodec<T>  extends Codec<T,Void> {
+public interface EmptyCodec<T> extends Codec<T, Empty> {
     @Override
-    T serialize(Void data);
+    T serialize(Empty data);
 
     @Override
-    Void deserialize(T data);
+    Empty deserialize(T data);
 }
index 365a5069f2f1862d38677eb271bd063ad83502db..2c4db71299f67436fe66f364adbc80c0f1c75fbe 100644 (file)
@@ -7,12 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.data.api.codec;
 
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.Codec;
 
 public interface StringCodec<T> extends Codec<T,String> {
     @Override
-    T serialize(String data);
+    T serialize(@Nonnull String data);
 
     @Override
-    String deserialize(T data);
+    String deserialize(@Nonnull T data);
 }
index a7e4bdcd29ec5e9668f971c76757910de87422db..593d6aeec2d8bd17958a561898e31773d2a9d3db 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import javax.annotation.Nonnull;
 import javax.xml.transform.dom.DOMSource;
 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -15,10 +16,6 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdent
  * AN normalizedNode.
  */
 public interface AnyXmlNode extends AttributesContainer, DataContainerChild<NodeIdentifier, DOMSource> {
-
-    @Override
-    NodeIdentifier getIdentifier();
-
     /**
      * Return value represented as a DOMSource. Returned source contains top level element
      * that duplicates the anyxml node.
@@ -26,5 +23,5 @@ public interface AnyXmlNode extends AttributesContainer, DataContainerChild<Node
      * @return anyxml node value represented as DOMSource.
      */
     @Override
-    DOMSource getValue();
+    @Nonnull DOMSource getValue();
 }
index 5a6d338e132757a87e682fb7c60c9c297dda7b04..540a40fb51c67132f174d28ac9cbf92686657625 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema;
 
 import java.util.Collection;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
@@ -34,8 +35,8 @@ public interface AugmentationNode extends MixinNode, DataContainerNode<Augmentat
      * This is sufficient to identify instance of augmentation, since RFC6020 states that <code>augment</code>
      * that augment statement must not add multiple nodes from same namespace / module to the target node.
      *
-     * @return Identifier which uniquelly identifies augmentation in particular subtree.
+     * @return Identifier which uniquely identifies augmentation in particular subtree.
      */
     @Override
-    AugmentationIdentifier getIdentifier();
+    @Nonnull AugmentationIdentifier getIdentifier();
 }
index 993949296a5892b39ab3de2f764c82f69a337bac..5d2a788a28eb07055542ff5e8a95c0b20031b93c 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 /**
@@ -29,5 +30,5 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgum
  */
 public interface DataContainerChild<K extends PathArgument,V> extends NormalizedNode<K, V> {
     @Override
-    K getIdentifier();
+    @Nonnull K getIdentifier();
 }
index 341c41a5da38828657a6e68cc7afd23baed67462..df43be8819447361f66d9c9c50acddccf9259003 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.api.schema;
 
 import java.util.Collection;
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 /**
@@ -41,5 +42,5 @@ public interface DataContainerNode<K extends PathArgument> extends //
      * @return Iteration of all child nodes
      */
     @Override
-    Collection<DataContainerChild<? extends PathArgument, ?>> getValue();
+    @Nonnull Collection<DataContainerChild<? extends PathArgument, ?>> getValue();
 }
index 5ec80151ee0c6a9661924c08daf567cf88009822..86bebfee51bc4022c4c0a4e3d2b3bb309efc2de5 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 
@@ -27,5 +28,5 @@ public interface LeafNode<T> extends AttributesContainer, DataContainerChild<Nod
      * @return Returned value of this leaf node. Value SHOULD meet criteria defined by schema.
      */
     @Override
-    T getValue();
+    @Nonnull T getValue();
 }
index 5c5d8603cface33d3208e3bf1734aa400cda9c2f..2cc0396a23a78953456527c77ab9742825cd8f99 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
 
@@ -38,5 +39,5 @@ public interface LeafSetEntryNode<T> extends AttributesContainer, NormalizedNode
      * @return {@link NodeWithValue} which identifies this leaf set entry.
      */
     @Override
-    NodeWithValue getIdentifier();
+    @Nonnull NodeWithValue getIdentifier();
 }
index 3b42c44686deca71dffe0c445f1089a2f10389b7..77d45199e9fbe91387ed520a37a24d0e72872413 100644 (file)
@@ -20,9 +20,7 @@ import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithV
  *
  * @param <T> Type of leaf node values.
  */
-public interface LeafSetNode<T> extends
-    MixinNode, //
-    DataContainerChild<NodeIdentifier, Collection<LeafSetEntryNode<T>>>, //
-    NormalizedNodeContainer<NodeIdentifier, NodeWithValue,LeafSetEntryNode<T>> {
+public interface LeafSetNode<T> extends MixinNode, DataContainerChild<NodeIdentifier, Collection<LeafSetEntryNode<T>>>,
+    NormalizedNodeContainer<NodeIdentifier, NodeWithValue, LeafSetEntryNode<T>> {
 
 }
index 700f0f5bc203a49aa32b61a9e8abac30298691fd..72688525ea028877f3539e592c99602bad7e7568 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.concepts.Identifiable;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -35,12 +36,12 @@ public interface NormalizedNode<K extends PathArgument, V> extends Identifiable<
      * @return Node identifier, non-null.
      */
     @Override
-    K getIdentifier();
+    @Nonnull K getIdentifier();
 
     /**
      * Value of node.
      *
      * @return Value of the node, may be null.
      */
-    V getValue();
+    @Nonnull V getValue();
 }
index eb70bfaa987791827d53bba969a06dda178eeebd..5edbdcff88674c6758feb010f1ebf9f0a3e71fc8 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.api.schema;
 
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 
 /**
@@ -30,5 +31,5 @@ public interface ValueNode<K extends PathArgument, V> extends NormalizedNode<K,
      *
      */
     @Override
-    V getValue();
+    @Nonnull V getValue();
 }
index 2e2e5f9dab0d9d4de74f9690c947296df46894a0..e5f3371843cef247f6d4f7878170a8d6bf7fc773 100644 (file)
@@ -10,8 +10,9 @@ package org.opendaylight.yangtools.yang.data.codec.gson;
 
 import com.google.gson.stream.JsonWriter;
 import java.io.IOException;
+import org.opendaylight.yangtools.yang.common.Empty;
 
-final class EmptyJSONCodec implements JSONCodec<Void> {
+final class EmptyJSONCodec implements JSONCodec<Empty> {
 
     static final EmptyJSONCodec INSTANCE = new EmptyJSONCodec();
 
@@ -20,17 +21,17 @@ final class EmptyJSONCodec implements JSONCodec<Void> {
     }
 
     @Override
-    public Class<Void> getDataType() {
-        return Void.class;
+    public Class<Empty> getDataType() {
+        return Empty.class;
     }
 
     @Override
-    public Void parseValue(final Object ctx, final String input) {
-        return null;
+    public Empty parseValue(final Object ctx, final String input) {
+        return Empty.getInstance();
     }
 
     @Override
-    public void writeValue(final JsonWriter ctx, final Void value) throws IOException {
+    public void writeValue(final JsonWriter ctx, final Empty value) throws IOException {
         ctx.beginArray();
         ctx.value((String) null);
         ctx.endArray();
index 60cc51d43f588298b39421acf3981b2361d6cc42..c0599b7b6b1fbbb6b59a889dc91e271f6484be1e 100644 (file)
@@ -24,6 +24,7 @@ import java.net.URISyntaxException;
 import java.util.Collections;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -164,7 +165,7 @@ public class JsonStreamToNormalizedNodeTest {
         final String inputJson = loadTextFile("/complexjson/type-empty.json");
         final ContainerNode awaitedStructure = containerBuilder()
                 .withNodeIdentifier(new NodeIdentifier(CONT_1))
-                .addChild(leafNode(EMPTY_LEAF, null))
+                .addChild(leafNode(EMPTY_LEAF, Empty.getInstance()))
                 .build();
 
         verifyTransformationToNormalizedNode(inputJson, awaitedStructure);
index 6dfd0aeef8c070f5dfd721f8f52bb86a2de1ce38..2f9fa49d1a54b4d5f7b61d793ae877dd09f6c2f5 100644 (file)
@@ -29,6 +29,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@@ -297,7 +298,7 @@ public class NormalizedNodeToJsonStreamTest {
         final StringWriter writer = new StringWriter();
         final ContainerNode emptyStructure = Builders.containerBuilder()
                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CONT_1))
-                .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, null)).build();
+                .addChild(ImmutableNodes.leafNode(EMPTY_LEAF, Empty.getInstance())).build();
         final String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, emptyStructure);
         final JsonObject cont1 = resolveCont1(jsonOutput);
         final JsonElement emptyObj = cont1.get("empty");
index c55a14f2715ee71d6fd4597c46a679ab2870095d..f6bbdd0bd0ef12ea9bbed3417112938fd0a7fed9 100644 (file)
@@ -5,14 +5,16 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.yangtools.yang.data.codec.xml;
 
+import static java.util.Objects.requireNonNull;
+
 import javax.xml.namespace.NamespaceContext;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
+import org.opendaylight.yangtools.yang.common.Empty;
 
-final class EmptyXmlCodec implements XmlCodec<Void> {
+final class EmptyXmlCodec implements XmlCodec<Empty> {
 
     static final EmptyXmlCodec INSTANCE = new EmptyXmlCodec();
 
@@ -21,17 +23,18 @@ final class EmptyXmlCodec implements XmlCodec<Void> {
     }
 
     @Override
-    public Class<Void> getDataType() {
-        return Void.class;
+    public Class<Empty> getDataType() {
+        return Empty.class;
     }
 
     @Override
-    public Void parseValue(final NamespaceContext ctx, final String str) {
-        return null;
+    public Empty parseValue(final NamespaceContext ctx, final String str) {
+        return Empty.getInstance();
     }
 
     @Override
-    public void writeValue(final XMLStreamWriter ctx, final Void value) throws XMLStreamException {
+    public void writeValue(final XMLStreamWriter ctx, final Empty value) throws XMLStreamException {
+        requireNonNull(value);
         ctx.writeCharacters("");
     }
 }
index 9d49f6a34385da7e9d6dd6f9f68c949784c11fc2..4a62a291feacf27890001826dc0e92fddc77cc91 100644 (file)
@@ -8,28 +8,30 @@
 package org.opendaylight.yangtools.yang.data.impl.codec;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
 
-import com.google.common.base.Strings;
 import java.util.Optional;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 
-final class EmptyStringCodec extends TypeDefinitionAwareCodec<Void, EmptyTypeDefinition> implements
+final class EmptyStringCodec extends TypeDefinitionAwareCodec<Empty, EmptyTypeDefinition> implements
         EmptyCodec<String> {
     static final EmptyStringCodec INSTANCE = new EmptyStringCodec();
 
     private EmptyStringCodec() {
-        super(Optional.empty(), Void.class);
+        super(Optional.empty(), Empty.class);
     }
 
     @Override
-    public String serialize(final Void data) {
+    public String serialize(final Empty data) {
+        requireNonNull(data);
         return "";
     }
 
     @Override
-    public Void deserialize(final String stringRepresentation) {
-        checkArgument(Strings.isNullOrEmpty(stringRepresentation), "The value must be empty");
-        return null;
+    public Empty deserialize(final String stringRepresentation) {
+        checkArgument(stringRepresentation.isEmpty(), "The value must be empty");
+        return Empty.getInstance();
     }
 }
\ No newline at end of file
index 8ee7bb279054300ec48f8635b0f9802b2883aacf..d05f57c5b9c41b6848185293848f0383d5fc1243 100644 (file)
@@ -8,6 +8,7 @@
 package org.opendaylight.yangtools.yang.data.impl.codec;
 
 import static com.google.common.base.Preconditions.checkArgument;
+import static java.util.Objects.requireNonNull;
 
 import com.google.common.annotations.Beta;
 import com.google.common.collect.ImmutableRangeSet;
@@ -15,7 +16,6 @@ import com.google.common.collect.Range;
 import com.google.common.collect.RangeSet;
 import com.google.common.collect.TreeRangeSet;
 import java.util.Collection;
-import java.util.Objects;
 import java.util.Optional;
 import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
@@ -56,17 +56,13 @@ public class StringStringCodec extends TypeDefinitionAwareCodec<String, StringTy
 
     @Override
     public final String deserialize(final String stringRepresentation) {
-        if (stringRepresentation == null) {
-            // FIXME: These seems buggy, but someone may be using this behaviour
-            return "";
-        }
-        validate(stringRepresentation);
+        validate(requireNonNull(stringRepresentation));
         return stringRepresentation;
     }
 
     @Override
     public final String serialize(final String data) {
-        return Objects.toString(data, "");
+        return requireNonNull(data);
     }
 
     void validate(final String str) {
index d33db494217b05a0b5c23d44c8db44292357d546..0f817a52f2f38f3796ae135c99591c8eb54faf3d 100644 (file)
@@ -7,6 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 
+import static com.google.common.base.Preconditions.checkState;
+import static java.util.Objects.requireNonNull;
+
 import java.util.Collections;
 import java.util.Map;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -22,10 +25,12 @@ abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V,
     private V value;
 
     protected final I getNodeIdentifier() {
+        checkState(nodeIdentifier != null, "Identifier has not been set");
         return nodeIdentifier;
     }
 
     protected final V getValue() {
+        checkState(value != null, "Value has not been set");
         return value;
     }
 
@@ -34,20 +39,20 @@ abstract class AbstractImmutableNormalizedNodeBuilder<I extends PathArgument, V,
     }
 
     @Override
-    public NormalizedNodeAttrBuilder<I,V,R> withValue(final V value) {
-        this.value = value;
+    public NormalizedNodeAttrBuilder<I, V, R> withValue(final V value) {
+        this.value = requireNonNull(value);
         return this;
     }
 
     @Override
-    public NormalizedNodeAttrBuilder<I,V,R> withNodeIdentifier(final I nodeIdentifier) {
-        this.nodeIdentifier = nodeIdentifier;
+    public NormalizedNodeAttrBuilder<I, V, R> withNodeIdentifier(final I nodeIdentifier) {
+        this.nodeIdentifier = requireNonNull(nodeIdentifier);
         return this;
     }
 
     @Override
-    public NormalizedNodeAttrBuilder<I,V,R> withAttributes(final Map<QName, String> attributes) {
-        this.attributes = attributes;
+    public NormalizedNodeAttrBuilder<I, V, R> withAttributes(final Map<QName, String> attributes) {
+        this.attributes = requireNonNull(attributes);
         return this;
     }
 }
index a37a44450e5df1b6ff83bfa284d9d7e7361c0387..31f8bab90dcd668012ee1a980e0c114397491ac8 100644 (file)
@@ -7,39 +7,28 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
-import javax.annotation.Nullable;
+import static java.util.Objects.requireNonNull;
+
+import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public abstract class AbstractImmutableNormalizedValueNode<K extends PathArgument, V> extends
         AbstractImmutableNormalizedNode<K, V> {
 
-    private static final Logger LOG = LoggerFactory.getLogger(AbstractImmutableNormalizedValueNode.class);
-    @Nullable
+    @Nonnull
     private final V value;
 
-    protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, @Nullable final V value) {
+    protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, @Nonnull final V value) {
         super(nodeIdentifier);
-
-        /*
-         * Null value is allowed for empty type definition so it should be debug,
-         * but still we are logging it in case we need to debug missing values.
-         */
-        // FIXME: one we do not map YANG 'void' to java.lang.Void we should be enforcing non-null here
-        if (value == null) {
-            LOG.debug("The value of node {} is null", nodeIdentifier.getNodeType());
-        }
-        this.value = value;
+        this.value = requireNonNull(value);
     }
 
-    @Nullable
     @Override
     public final V getValue() {
         return wrapValue(value);
     }
 
-    @Nullable
+    @Nonnull
     protected final V value() {
         return value;
     }
index fc41d6d8c0222cfe44ffef4ae0a82e6d245d9024..c2f778893c10770b8402e8310753c9dc3aabe21f 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yangtools.yang.data.impl.codecs;
 import static org.junit.Assert.assertEquals;
 
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.api.codec.EmptyCodec;
 import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
 
@@ -26,7 +27,7 @@ public class EmptyCodecStringTest {
     public void testSerialize() {
         EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class);
 
-        assertEquals("serialize", "", codec.serialize(null));
+        assertEquals("serialize", "", codec.serialize(Empty.getInstance()));
     }
 
     @SuppressWarnings("unchecked")
@@ -34,8 +35,7 @@ public class EmptyCodecStringTest {
     public void testDeserialize() {
         EmptyCodec<String> codec = TypeDefinitionAwareCodecTestHelper.getCodec(BaseTypes.emptyType(), EmptyCodec.class);
 
-        assertEquals("deserialize", null, codec.deserialize(""));
-        assertEquals("deserialize", null, codec.deserialize(null));
+        assertEquals("deserialize", Empty.getInstance(), codec.deserialize(""));
 
         TypeDefinitionAwareCodecTestHelper.deserializeWithExpectedIllegalArgEx(codec, "foo");
     }
index a78c05dd9453ca15320085d85e900844c3690ce4..115080b10ff9c73eeeed46da6c5f71b8d802750f 100644 (file)
@@ -29,7 +29,6 @@ public class StringCodecStringTest {
 
         assertEquals("serialize", "foo", codec.serialize("foo"));
         assertEquals("serialize", "", codec.serialize(""));
-        assertEquals("serialize", "", codec.serialize(null));
     }
 
     @SuppressWarnings("unchecked")
@@ -40,6 +39,5 @@ public class StringCodecStringTest {
 
         assertEquals("deserialize", "bar", codec.deserialize("bar"));
         assertEquals("deserialize", "", codec.deserialize(""));
-        assertEquals("deserialize", "", codec.deserialize(null));
     }
 }
index 2ec4f164640129439b719ca9a297a29166174465..a7c762cfd716a8948fe0ed742d1ee6024e19a520 100644 (file)
@@ -14,6 +14,7 @@ import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwa
 import static org.opendaylight.yangtools.yang.data.impl.codecs.TypeDefinitionAwareCodecTestHelper.toEnumTypeDefinition;
 
 import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.Empty;
 import org.opendaylight.yangtools.yang.data.api.codec.UnionCodec;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
@@ -62,8 +63,7 @@ public class UnionCodecStringTest {
         assertEquals("deserialize", 123, codec.deserialize("123"));
         assertEquals("deserialize", -123, codec.deserialize("-123"));
         assertEquals("deserialize", 41234567890L, codec.deserialize("41234567890"));
-        assertEquals("deserialize", null, codec.deserialize(""));
-        assertEquals("deserialize", null, codec.deserialize(null));
+        assertEquals("deserialize", Empty.getInstance(), codec.deserialize(""));
 
         deserializeWithExpectedIllegalArgEx(codec, "enum3");
         deserializeWithExpectedIllegalArgEx(codec, "123o");
index 91a143635843baded91d0348a5183ca229bf2a4b..6e91d46a491034349fa0f02b33ad0da9426a4e99 100644 (file)
@@ -67,6 +67,7 @@ public class InstanceIdToNodesTest {
 
     @Test
     public void testInAugment() throws Exception {
+        final LeafNode<?> leaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("").build();
         final ContainerNode expectedFilter = Builders
                 .containerBuilder()
                 .withNodeIdentifier(rootContainer)
@@ -77,11 +78,10 @@ public class InstanceIdToNodesTest {
                                         Builders.augmentationBuilder()
                                                 .withNodeIdentifier(augmentation)
                                                 .withChild(
-                                                        Builders.leafBuilder().withNodeIdentifier(augmentedLeaf)
-                                                                .build()).build()).build()).build();
+                                                        leaf).build()).build()).build();
 
         final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
-                YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf));
+                YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), leaf);
         assertEquals(expectedFilter, filter);
     }
 
@@ -107,6 +107,7 @@ public class InstanceIdToNodesTest {
 
     @Test
     public void testListChoice() throws Exception {
+        final LeafNode<?> leaf = Builders.leafBuilder().withNodeIdentifier(leafFromCase).withValue("").build();
         final ContainerNode expectedFilter = Builders
                 .containerBuilder()
                 .withNodeIdentifier(rootContainer)
@@ -124,14 +125,14 @@ public class InstanceIdToNodesTest {
                                                 .withChild(
                                                         Builders.choiceBuilder()
                                                                 .withNodeIdentifier(choice)
-                                                                .withChild(
-                                                                        Builders.leafBuilder()
-                                                                                .withNodeIdentifier(leafFromCase)
-                                                                                .build()).build()).build()).build())
+                                                                .withChild(leaf)
+                                                                .build())
+                                                .build())
+                                .build())
                 .build();
 
         final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
-                YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase));
+                YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase), leaf);
         assertEquals(expectedFilter, filter);
     }
 
@@ -157,6 +158,7 @@ public class InstanceIdToNodesTest {
                                                                 .withChild(
                                                                         Builders.leafBuilder()
                                                                                 .withNodeIdentifier(leafFromCase)
+                                                                                .withValue("")
                                                                                 .build()).build()).build()).build())
                 .build();
 
index d27baf80dc2a7a31f0e71b6552ad604774d50e20..effb1a5448710c8da11b62692cff7e5283d40f4e 100644 (file)
@@ -26,14 +26,6 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
     // This test is based on using different references; we're testing equals()
     @SuppressWarnings({"RedundantStringConstructorCall", "EqualsWithItself"})
     public void equalsByteTest() {
-
-        LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(LEAF_QNAME, null);
-        LeafNode<byte[]> equalLeafNodeNull = ImmutableNodes.leafNode(SAME_LEAF_QNAME, null);
-
-        assertTrue(leafNodeNull.equals(leafNodeNull));
-        assertTrue(leafNodeNull.equals(equalLeafNodeNull));
-        assertTrue(equalLeafNodeNull.equals(leafNodeNull));
-
         byte[] value = "test".getBytes();
         byte[] equalValue = "test".getBytes();
 
@@ -47,8 +39,7 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
         Byte[] value2 = new Byte[] { new Byte("1"), new Byte("2") };
         Byte[] equalValue2 = new Byte[] { new Byte("1"), new Byte("2") };
 
-        LeafNode<Byte[]> leafNode2 = ImmutableNodes
-                .leafNode(LEAF_QNAME, value2);
+        LeafNode<Byte[]> leafNode2 = ImmutableNodes.leafNode(LEAF_QNAME, value2);
         LeafNode<Byte[]> equalLeafNode2 = ImmutableNodes.leafNode(SAME_LEAF_QNAME, equalValue2);
 
         assertTrue(leafNode2.equals(leafNode2));
@@ -192,10 +183,6 @@ public class AbstractImmutableNormalizedValueAttrNodeTest {
         assertFalse(leafNode4.equals(leafNode5));
         assertFalse(leafNode6.equals(leafNode5));
 
-        LeafNode<byte[]> leafNodeNull = ImmutableNodes.leafNode(SAME_LEAF_QNAME, null);
-        assertFalse(leafNodeNull.equals(leafNode));
-        assertFalse(leafNode.equals(leafNodeNull));
-
         byte[] byteValue = new byte[] { 1, 1 };
 
         LeafNode<byte[]> byteLeafNode = ImmutableNodes.leafNode(SAME_LEAF_QNAME, byteValue);
index c7cbfa088d31d78888201dde4c247858a4656564..2fb5f83696eb741de889d626e8d7775c136bc7ed 100644 (file)
@@ -7,6 +7,8 @@
  */
 package org.opendaylight.yangtools.yang.data.util;
 
+import static java.util.Objects.requireNonNull;
+
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
 /**
@@ -25,11 +27,10 @@ public abstract class SimpleNodeDataWithSchema extends AbstractNodeDataWithSchem
     }
 
     public void setValue(final Object value) {
-        this.value = value;
+        this.value = requireNonNull(value);
     }
 
     public Object getValue() {
         return value;
     }
-
 }