Fixed wrong exception types
[netconf.git] / restconf / restconf-nb-rfc8040 / src / main / java / org / opendaylight / restconf / nb / rfc8040 / utils / parser / YangInstanceIdentifierSerializer.java
index b20c5c15bd5606c9f5d617313820ea9b1a42d1ae..dcd5abbf28106987a255c398bbe9d9cf039578de 100644 (file)
@@ -7,9 +7,12 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.utils.parser;
 
-import com.google.common.base.Preconditions;
 import java.util.Iterator;
+import java.util.Locale;
 import java.util.Map.Entry;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants;
 import org.opendaylight.restconf.nb.rfc8040.utils.parser.builder.ParserBuilderConstants.Serializer;
@@ -57,10 +60,9 @@ public final class YangInstanceIdentifierSerializer {
 
             final PathArgument arg = data.getPathArguments().get(i);
             variables.setCurrent(variables.getCurrent().getChild(arg));
-
-            Preconditions.checkArgument(variables.getCurrent() != null,
-                    "Invalid input %s: schema for argument %s (after %s) not found", data, arg, path);
-
+            RestconfDocumentedException.throwIf(variables.getCurrent() == null, ErrorType.APPLICATION,
+                    ErrorTag.UNKNOWN_ELEMENT, "Invalid input '%s': schema for argument '%s' (after '%s') not found",
+                    data, arg, path);
             if (variables.getCurrent().isMixin()) {
                 continue;
             }
@@ -105,9 +107,7 @@ public final class YangInstanceIdentifierSerializer {
     private static void prepareNodeWithPredicates(final StringBuilder path, final PathArgument arg) {
         path.append(arg.getNodeType().getLocalName());
 
-        final Iterator<Entry<QName, Object>> iterator = ((NodeIdentifierWithPredicates) arg).getKeyValues()
-                .entrySet().iterator();
-
+        final Iterator<Entry<QName, Object>> iterator = ((NodeIdentifierWithPredicates) arg).entrySet().iterator();
         if (iterator.hasNext()) {
             path.append(ParserBuilderConstants.Deserializer.EQUAL);
         }
@@ -137,7 +137,7 @@ public final class YangInstanceIdentifierSerializer {
         while (start < valueOf.length()) {
             if (Serializer.PERCENT_ENCODE_CHARS.matches(valueOf.charAt(start))) {
                 final String format = String.format("%x", (int) valueOf.charAt(start));
-                final String upperCase = format.toUpperCase();
+                final String upperCase = format.toUpperCase(Locale.ROOT);
                 sb.append(ParserBuilderConstants.Deserializer.PERCENT_ENCODING + upperCase);
             } else {
                 sb.append(valueOf.charAt(start));