BUG 5125: Fix NPE on module's with unknown namespace 08/33908/1
authorTomas Cere <tcere@cisco.com>
Tue, 2 Feb 2016 14:11:26 +0000 (15:11 +0100)
committerTomas Cere <tcere@cisco.com>
Tue, 2 Feb 2016 14:30:50 +0000 (14:30 +0000)
Change-Id: I9e7db1f3aa36bf6def6318442bb2559cc698dd2c
Signed-off-by: Tomas Cere <tcere@cisco.com>
opendaylight/netconf/mdsal-netconf-connector/src/main/java/org/opendaylight/netconf/mdsal/connector/ops/EditConfig.java

index fb8bcf18d01624fc6d9da5bbd5227c259677aa96..a33f020f2e2c412e4a0138f8002247e3b9fe1f4b 100644 (file)
@@ -23,6 +23,7 @@ import org.opendaylight.controller.config.util.xml.XmlUtil;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
 import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
+import org.opendaylight.netconf.api.NetconfDocumentedException;
 import org.opendaylight.netconf.api.xml.XmlNetconfConstants;
 import org.opendaylight.netconf.mdsal.connector.CurrentSchemaContext;
 import org.opendaylight.netconf.mdsal.connector.TransactionProvider;
@@ -165,6 +166,11 @@ public class EditConfig extends AbstractSingletonNetconfOperation {
         try {
             //returns module with newest revision since findModuleByNamespace returns a set of modules and we only need the newest one
             final Module module = schemaContext.getCurrentContext().findModuleByNamespaceAndRevision(new URI(namespace), null);
+            if (module == null) {
+                // no module is present with this namespace
+                throw new NetconfDocumentedException("Unable to find module by namespace: " + namespace,
+                        ErrorType.application, ErrorTag.unknown_namespace, ErrorSeverity.error);
+            }
             DataSchemaNode schemaNode = module.getDataChildByName(element.getName());
             if (schemaNode != null) {
                 dataSchemaNode = Optional.of(module.getDataChildByName(element.getName()));