Check requested schema tree statement namespace
[yangtools.git] / parser / yang-parser-reactor / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / reactor / InferredStatementContext.java
index 2190e66a25e0a350e68c6e73590ddbd70cb8e07b..9cf3f6c9514275d2e1815ecc595bf815218be4a7 100644 (file)
@@ -430,7 +430,22 @@ final class InferredStatementContext<A, D extends DeclaredStatement<A>, E extend
             return null;
         }
 
-        final QName templateQName = qname.bindTo(StmtContextUtils.getRootModuleQName(prototype));
+        // Determine if the requested QName can be satisfied from the prototype: for that to happen it has to match
+        // our transformation implied by targetModule.
+        final var requestedNamespace = qname.getModule();
+        final QName templateQName;
+        if (targetModule != null) {
+            if (!targetModule.equals(requestedNamespace)) {
+                return null;
+            }
+            templateQName = qname.bindTo(StmtContextUtils.getRootModuleQName(prototype));
+        } else {
+            if (!StmtContextUtils.getRootModuleQName(prototype).equals(requestedNamespace)) {
+                return null;
+            }
+            templateQName = qname;
+        }
+
         LOG.debug("Materializing child {} from {}", qname, templateQName);
 
         final StmtContext<?, ?, ?> template;