BUG-4688: Rework SchemaContext module lookups
[yangtools.git] / yang / yang-data-util / src / main / java / org / opendaylight / yangtools / yang / data / util / ModuleStringIdentityrefCodec.java
index 385943908b21f385a5fbbed475349b579287d288..a7b3f23c543a8d357cdf63dfe5f6426e1b82ec79 100644 (file)
@@ -11,6 +11,7 @@ package org.opendaylight.yangtools.yang.data.util;
 import static java.util.Objects.requireNonNull;
 
 import java.net.URI;
+import java.util.Iterator;
 import javax.annotation.Nonnull;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.codec.IdentityrefCodec;
@@ -30,7 +31,7 @@ public abstract class ModuleStringIdentityrefCodec
 
     @Override
     protected String prefixForNamespace(@Nonnull final URI namespace) {
-        final Module module = context.findModuleByNamespaceAndRevision(namespace, null);
-        return module == null ? null : module.getName();
+        final Iterator<Module> modules = context.findModules(namespace).iterator();
+        return modules.hasNext() ? modules.next().getName() : null;
     }
 }