Bump upstreams to SNAPSHOTs
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / codecs / RestCodec.java
index 7ede7a042c808582cd5b6a3c9f90a86bb3de14ea..9d585bcbf4b34aabab64def32c4290a12dbb2a3e 100644 (file)
@@ -86,21 +86,22 @@ public final class RestCodec {
         private ObjectCodec(final TypeDefinition<?> typeDefinition, final DOMMountPoint mountPoint,
                 final EffectiveModelContext schemaContext) {
             this.schemaContext = schemaContext;
-            this.type = RestUtil.resolveBaseTypeFrom(typeDefinition);
-            if (this.type instanceof IdentityrefTypeDefinition) {
-                this.identityrefCodec = new IdentityrefCodecImpl(mountPoint, schemaContext);
+            type = RestUtil.resolveBaseTypeFrom(typeDefinition);
+            if (type instanceof IdentityrefTypeDefinition) {
+                identityrefCodec = new IdentityrefCodecImpl(mountPoint, schemaContext);
             } else {
-                this.identityrefCodec = null;
+                identityrefCodec = null;
             }
-            if (this.type instanceof InstanceIdentifierTypeDefinition) {
-                this.instanceIdentifier = new InstanceIdentifierCodecImpl(mountPoint, schemaContext);
+            if (type instanceof InstanceIdentifierTypeDefinition) {
+                instanceIdentifier = new InstanceIdentifierCodecImpl(mountPoint, schemaContext);
             } else {
-                this.instanceIdentifier = null;
+                instanceIdentifier = null;
             }
         }
 
         @SuppressWarnings("unchecked")
         @Override
+        @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "Legacy returns")
         public Object deserialize(final Object input) {
             try {
                 if (type instanceof IdentityrefTypeDefinition) {
@@ -113,6 +114,7 @@ public final class RestCodec {
                                     + "Therefore NULL is used as translation of - {}",
                             input == null ? "null" : input.getClass(), String.valueOf(input));
                     }
+                    // FIXME: this should be a hard error
                     return null;
                 } else if (type instanceof InstanceIdentifierTypeDefinition) {
                     return input instanceof IdentityValuesDTO ? instanceIdentifier.deserialize(input)
@@ -120,18 +122,21 @@ public final class RestCodec {
                         : new StringModuleInstanceIdentifierCodec(schemaContext).deserialize((String) input);
                 } else {
                     final TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> typeAwarecodec =
-                            TypeDefinitionAwareCodec.from(this.type);
+                            TypeDefinitionAwareCodec.from(type);
                     if (typeAwarecodec != null) {
                         if (input instanceof IdentityValuesDTO) {
                             return typeAwarecodec.deserialize(((IdentityValuesDTO) input).getOriginValue());
                         }
                         return typeAwarecodec.deserialize(String.valueOf(input));
                     } else {
+                        // FIXME: this should be a hard error
                         LOG.debug("Codec for type \"{}\" is not implemented yet.", type.getQName().getLocalName());
                         return null;
                     }
                 }
-            } catch (final ClassCastException e) { // TODO remove this catch when everyone use codecs
+            } catch (final ClassCastException e) {
+                // FIXME: remove this catch when everyone use codecs
+                // FIXME: this should be a hard error
                 LOG.error("ClassCastException was thrown when codec is invoked with parameter {}", input, e);
                 return null;
             }
@@ -139,27 +144,31 @@ public final class RestCodec {
 
         @SuppressWarnings("unchecked")
         @Override
+        @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "Legacy returns")
         public Object serialize(final Object input) {
             try {
-                if (this.type instanceof IdentityrefTypeDefinition) {
-                    return this.identityrefCodec.serialize(input);
-                } else if (this.type instanceof LeafrefTypeDefinition) {
+                if (type instanceof IdentityrefTypeDefinition) {
+                    return identityrefCodec.serialize(input);
+                } else if (type instanceof LeafrefTypeDefinition) {
                     return LEAFREF_DEFAULT_CODEC.serialize(input);
-                } else if (this.type instanceof InstanceIdentifierTypeDefinition) {
-                    return this.instanceIdentifier.serialize(input);
+                } else if (type instanceof InstanceIdentifierTypeDefinition) {
+                    return instanceIdentifier.serialize(input);
                 } else {
                     final TypeDefinitionAwareCodec<Object, ? extends TypeDefinition<?>> typeAwarecodec =
-                            TypeDefinitionAwareCodec.from(this.type);
+                            TypeDefinitionAwareCodec.from(type);
                     if (typeAwarecodec != null) {
                         return typeAwarecodec.serialize(input);
                     } else {
+                        // FIXME: this needs to be a hard error
                         if (LOG.isDebugEnabled()) {
                             LOG.debug("Codec for type \"{}\" is not implemented yet.", type.getQName().getLocalName());
                         }
                         return null;
                     }
                 }
-            } catch (final ClassCastException e) { // TODO remove this catch when everyone use codecs
+            } catch (final ClassCastException e) {
+                // FIXME: remove this catch when everyone use codecs
+                // FIXME: this needs to be a hard error
                 LOG.error("ClassCastException was thrown when codec is invoked with parameter {}", input, e);
                 return input;
             }
@@ -185,10 +194,11 @@ public final class RestCodec {
         }
 
         @Override
+        @SuppressFBWarnings(value = "NP_NONNULL_RETURN_VIOLATION", justification = "Legacy return")
         public QName deserialize(final IdentityValuesDTO data) {
             final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
-            final Module module =
-                    getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint, schemaContext);
+            final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint, schemaContext);
+            // FIXME: this needs to be a hard error
             if (module == null) {
                 LOG.info("Module was not found for namespace {}", valueWithNamespace.getNamespace());
                 LOG.info("Idenetityref will be translated as NULL for data - {}", String.valueOf(valueWithNamespace));
@@ -246,14 +256,15 @@ public final class RestCodec {
 
         @SuppressFBWarnings(value = {
             "NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE",
-            "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE"
+            "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
+            "NP_NONNULL_RETURN_VIOLATION"
         }, justification = "Unrecognised NullableDecl")
         @Override
         public YangInstanceIdentifier deserialize(final IdentityValuesDTO data) {
             final List<PathArgument> result = new ArrayList<>();
             final IdentityValue valueWithNamespace = data.getValuesWithNamespaces().get(0);
-            final Module module =
-                    getModuleByNamespace(valueWithNamespace.getNamespace(), this.mountPoint, schemaContext);
+            final Module module = getModuleByNamespace(valueWithNamespace.getNamespace(), mountPoint, schemaContext);
+            // FIXME: this needs to be a hard error
             if (module == null) {
                 LOG.info("Module by namespace '{}' of first node in instance-identifier was not found.",
                         valueWithNamespace.getNamespace());
@@ -267,9 +278,10 @@ public final class RestCodec {
             for (int i = 0; i < identities.size(); i++) {
                 final IdentityValue identityValue = identities.get(i);
                 XMLNamespace validNamespace =
-                        resolveValidNamespace(identityValue.getNamespace(), this.mountPoint, schemaContext);
+                        resolveValidNamespace(identityValue.getNamespace(), mountPoint, schemaContext);
                 final DataSchemaNode node = findInstanceDataChildByNameAndNamespace(
                         parentContainer, identityValue.getValue(), validNamespace);
+                // FIXME: this needs to be a hard error
                 if (node == null) {
                     LOG.info("'{}' node was not found in {}", identityValue, parentContainer.getChildNodes());
                     LOG.info("Instance-identifier will be translated as NULL for data - {}",
@@ -283,6 +295,7 @@ public final class RestCodec {
                 } else {
                     if (node instanceof LeafListSchemaNode) { // predicate is value of leaf-list entry
                         final Predicate leafListPredicate = identityValue.getPredicates().get(0);
+                        // FIXME: this needs to be a hard error
                         if (!leafListPredicate.isLeafList()) {
                             LOG.info("Predicate's data is not type of leaf-list. It should be in format \".='value'\"");
                             LOG.info("Instance-identifier will be translated as NULL for data - {}",
@@ -294,7 +307,7 @@ public final class RestCodec {
                         final DataNodeContainer listNode = (DataNodeContainer) node;
                         final Map<QName, Object> predicatesMap = new HashMap<>();
                         for (final Predicate predicate : identityValue.getPredicates()) {
-                            validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), this.mountPoint,
+                            validNamespace = resolveValidNamespace(predicate.getName().getNamespace(), mountPoint,
                                     schemaContext);
                             final DataSchemaNode listKey = findInstanceDataChildByNameAndNamespace(listNode,
                                     predicate.getName().getValue(), validNamespace);
@@ -302,6 +315,7 @@ public final class RestCodec {
                         }
                         pathArgument = NodeIdentifierWithPredicates.of(qName, predicatesMap);
                     } else {
+                        // FIXME: this needs to be a hard error
                         LOG.info("Node {} is not List or Leaf-list.", node);
                         LOG.info("Instance-identifier will be translated as NULL for data - {}",
                                 String.valueOf(identityValue.getValue()));
@@ -314,6 +328,7 @@ public final class RestCodec {
                     if (node instanceof DataNodeContainer) {
                         parentContainer = (DataNodeContainer) node;
                     } else {
+                        // FIXME: this needs to be a hard error
                         LOG.info("Node {} isn't instance of DataNodeContainer", node);
                         LOG.info("Instance-identifier will be translated as NULL for data - {}",
                                 String.valueOf(identityValue.getValue()));
@@ -343,8 +358,6 @@ public final class RestCodec {
         }
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static Module getModuleByNamespace(final String namespace, final DOMMountPoint mountPoint,
             final SchemaContext schemaContext) {
         final XMLNamespace validNamespace = resolveValidNamespace(namespace, mountPoint, schemaContext);
@@ -385,8 +398,6 @@ public final class RestCodec {
         return null;
     }
 
-    @SuppressFBWarnings(value = "UPM_UNCALLED_PRIVATE_METHOD",
-            justification = "https://github.com/spotbugs/spotbugs/issues/811")
     private static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container,
             final String name, final XMLNamespace namespace) {
         requireNonNull(namespace);