Check for null pointer when parsing identities.
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / codec / xml / InstanceIdentifierForXmlCodec.java
index 6051b2681388aeb09fbf3213cba99d5ec33c259d..7f8167e451559e0643d310a2967272c8c0a043fd 100644 (file)
@@ -22,8 +22,8 @@ import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.w3c.dom.Element;
@@ -37,7 +37,7 @@ public final class InstanceIdentifierForXmlCodec {
         throw new UnsupportedOperationException("Utility class");
     }
 
-    public static InstanceIdentifier deserialize(final Element element, final SchemaContext schemaContext) {
+    public static YangInstanceIdentifier deserialize(final Element element, final SchemaContext schemaContext) {
         Preconditions.checkNotNull(element, "Value of element for deserialization can't be null");
         Preconditions.checkNotNull(schemaContext,
                 "Schema context for deserialization of instance identifier type can't be null");
@@ -59,10 +59,10 @@ public final class InstanceIdentifierForXmlCodec {
                 result.add(pathArgument);
             }
         }
-        return InstanceIdentifier.create(result);
+        return YangInstanceIdentifier.create(result);
     }
 
-    public static Element serialize(final InstanceIdentifier id, final Element element) {
+    public static Element serialize(final YangInstanceIdentifier id, final Element element) {
         Preconditions.checkNotNull(id, "Variable should contain instance of instance identifier and can't be null");
         Preconditions.checkNotNull(element, "DOM element can't be null");
 
@@ -110,9 +110,9 @@ public final class InstanceIdentifierForXmlCodec {
         }
 
         if (predicates.isEmpty()) {
-            return new InstanceIdentifier.NodeIdentifier(mainQName);
+            return new YangInstanceIdentifier.NodeIdentifier(mainQName);
         } else {
-            return new InstanceIdentifier.NodeIdentifierWithPredicates(mainQName, predicates);
+            return new YangInstanceIdentifier.NodeIdentifierWithPredicates(mainQName, predicates);
         }
 
     }
@@ -149,10 +149,11 @@ public final class InstanceIdentifierForXmlCodec {
         } catch (URISyntaxException e) {
             throw new IllegalArgumentException("It wasn't possible to convert " + namespaceStr + " to URI object.");
         } catch (NullPointerException e) {
-            throw new IllegalArgumentException("I wasn't possible to get namespace for prefix " + prefix);
+            throw new IllegalArgumentException("It wasn't possible to get namespace for prefix " + prefix);
         }
 
-        Module module = schemaContext.findModuleByNamespaceAndRevision(namespace, null);
+        final Module module = schemaContext.findModuleByNamespaceAndRevision(namespace, null);
+        Preconditions.checkNotNull(module, "Unknown module: %s, cannot parse identity %s", namespace, xPathArgument);
         return QName.create(module.getQNameModule(), identifier);
     }