Throw InvalidNormalizedNodeStreamException on bad entry 77/104477/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Feb 2023 14:41:47 +0000 (15:41 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 22 Feb 2023 14:49:08 +0000 (15:49 +0100)
Remove a source of nulls in Lithium-based inputs, allowing us to
properly annotate returns.

Change-Id: Ifc84ce42f9f35ce4c050f87076b0d346b8dbf79d
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
codec/yang-data-codec-binfmt/src/main/java/org/opendaylight/yangtools/yang/data/codec/binfmt/AbstractLithiumDataInput.java

index a23137d6bdd37e79dffa01ed4269d84456a99927..eec7c9beeff83431cb474bb6c2fcf8ed8848bc93 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Set;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.dom.DOMSource;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
 import org.opendaylight.yangtools.yang.common.Decimal64;
 import org.opendaylight.yangtools.yang.common.Empty;
@@ -281,15 +282,15 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
         return children;
     }
 
-    abstract AugmentationIdentifier readAugmentationIdentifier() throws IOException;
+    abstract @NonNull AugmentationIdentifier readAugmentationIdentifier() throws IOException;
 
-    abstract NodeIdentifier readNodeIdentifier() throws IOException;
+    abstract @NonNull NodeIdentifier readNodeIdentifier() throws IOException;
 
-    final AugmentationIdentifier defaultReadAugmentationIdentifier() throws IOException {
+    final @NonNull AugmentationIdentifier defaultReadAugmentationIdentifier() throws IOException {
         return AugmentationIdentifier.create(readQNameSet());
     }
 
-    private NodeIdentifierWithPredicates readNormalizedNodeWithPredicates() throws IOException {
+    private @NonNull NodeIdentifierWithPredicates readNormalizedNodeWithPredicates() throws IOException {
         final QName qname = readQName();
         final int count = input.readInt();
         switch (count) {
@@ -353,7 +354,7 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
         return readYangInstanceIdentifierInternal();
     }
 
-    private YangInstanceIdentifier readYangInstanceIdentifierInternal() throws IOException {
+    private @NonNull YangInstanceIdentifier readYangInstanceIdentifierInternal() throws IOException {
         int size = input.readInt();
         final Builder<PathArgument> pathArguments = ImmutableList.builderWithExpectedSize(size);
         for (int i = 0; i < size; i++) {
@@ -375,14 +376,12 @@ abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput
     public final PathArgument readPathArgument() throws IOException {
         // read Type
         int type = input.readByte();
-        return  switch (type) {
+        return switch (type) {
             case LithiumPathArgument.AUGMENTATION_IDENTIFIER -> readAugmentationIdentifier();
             case LithiumPathArgument.NODE_IDENTIFIER -> readNodeIdentifier();
             case LithiumPathArgument.NODE_IDENTIFIER_WITH_PREDICATES -> readNormalizedNodeWithPredicates();
             case LithiumPathArgument.NODE_IDENTIFIER_WITH_VALUE -> new NodeWithValue<>(readQName(), readObject());
-            default ->
-                // FIXME: throw hard error
-                null;
+            default -> throw new InvalidNormalizedNodeStreamException("Unexpected PathArgument type " + type);
         };
     }
 }