Fixed some major sonar issues
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / XpathStringParsingPathArgumentBuilder.java
index d25f0655c0652bdf383e4051dda65059c36e2298..133df37c1cc023f7791123a399c428091e9c8eaf 100644 (file)
@@ -12,6 +12,7 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import java.util.LinkedList;
+import java.util.List;
 import javax.annotation.Nullable;
 import org.opendaylight.yangtools.concepts.Builder;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -70,7 +71,7 @@ class XpathStringParsingPathArgumentBuilder implements Builder<Iterable<PathArgu
     private final AbstractStringInstanceIdentifierCodec codec;
     private final String data;
 
-    private final LinkedList<PathArgument> product = new LinkedList<>();
+    private final List<PathArgument> product = new LinkedList<>();
 
     private DataSchemaContextNode<?> current;
     private int offset;
@@ -92,9 +93,9 @@ class XpathStringParsingPathArgumentBuilder implements Builder<Iterable<PathArgu
     }
 
     private PathArgument computeNextArgument() {
-        checkValid(SLASH  == currentChar(),"Identifier must start with '/'.");
+        checkValid(SLASH == currentChar(), "Identifier must start with '/'.");
         skipCurrentChar();
-
+        checkValid(!allCharactersConsumed(), "Identifier cannot end with '/'.");
         QName name = nextQName();
         if(allCharactersConsumed() || SLASH == currentChar()) {
             return computeIdentifier(name);
@@ -150,15 +151,18 @@ class XpathStringParsingPathArgumentBuilder implements Builder<Iterable<PathArgu
             skipWhitespaces();
             checkCurrentAndSkip(EQUALS, "Precondition must contain '='");
             skipWhitespaces();
-            final Object value = deserializeValue(key,nextQuotedValue());
+            final String keyValue = nextQuotedValue();
             skipWhitespaces();
             checkCurrentAndSkip(PRECONDITION_END, "Precondition must ends with ']'");
 
             // Break-out from method for leaf-list case
             if(key == null && currentNode.isLeaf()) {
                 checkValid(offset == data.length(), "Leaf argument must be last argument of instance identifier.");
-                return new YangInstanceIdentifier.NodeWithValue(name, value);
+                return new YangInstanceIdentifier.NodeWithValue(name, keyValue);
             }
+            final DataSchemaContextNode<?> keyNode = currentNode.getChild(key);
+            checkValid(keyNode != null, "%s is not correct schema node identifier.", key);
+            final Object value = codec.deserializeKeyValue(keyNode.getDataSchemaNode(), keyValue);
             keyValues.put(key, value);
         }
         return new YangInstanceIdentifier.NodeIdentifierWithPredicates(name, keyValues.build());