}
final QNameModule qNameModule = QNameModule.create(moduleNs.get(), revisionDate.orElse(null)).intern();
+
+ final StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>> possibleDuplicateModule =
+ stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
+ if (possibleDuplicateModule != null && possibleDuplicateModule != stmt) {
+ throw new SourceException(stmt.getStatementSourceReference(), "Module namespace collision: %s. At %s",
+ qNameModule.getNamespace(), possibleDuplicateModule.getStatementSourceReference());
+ }
+
final ModuleIdentifier moduleIdentifier = ModuleIdentifierImpl.create(stmt.getStatementArgument(),
Optional.empty(), revisionDate);
public void onLinkageDeclared(
final Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt) {
final ModuleIdentifier submoduleIdentifier = getSubmoduleIdentifier(stmt);
+
+ final StmtContext<?, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> possibleDuplicateSubmodule =
+ stmt.getFromNamespace(SubmoduleNamespace.class, submoduleIdentifier);
+ if (possibleDuplicateSubmodule != null && possibleDuplicateSubmodule != stmt) {
+ throw new SourceException(stmt.getStatementSourceReference(), "Submodule name collision: %s. At %s",
+ stmt.getStatementArgument(), possibleDuplicateSubmodule.getStatementSourceReference());
+ }
+
stmt.addContext(SubmoduleNamespace.class, submoduleIdentifier, stmt);
final String belongsToModuleName = firstAttributeOf(stmt.declaredSubstatements(), BelongsToStatement.class);
--- /dev/null
+/*
+ * Copyright (c) 2017 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.yangtools.yang.stmt;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
+
+public class Bug7954Test {
+
+ @Test
+ public void testParsingTheSameModuleTwice() throws Exception {
+ final File yang = new File(getClass().getResource("/bugs/bug7954/foo.yang").toURI());
+
+ try {
+ StmtTestUtils.parseYangSources(yang, yang);
+ fail("An exception should have been thrown because of adding the same YANG module twice.");
+ } catch (final ReactorException ex) {
+ final Throwable cause = ex.getCause();
+ assertTrue(cause instanceof SourceException);
+ assertTrue(cause.getMessage().startsWith("Module namespace collision: foo-ns."));
+ }
+ }
+
+ @Test
+ public void testParsingTheSameSubmoduleTwice() throws Exception {
+ final File yang = new File(getClass().getResource("/bugs/bug7954/bar.yang").toURI());
+ final File childYang = new File(getClass().getResource("/bugs/bug7954/subbar.yang").toURI());
+
+ try {
+ StmtTestUtils.parseYangSources(yang, childYang, childYang);
+ fail("An exception should have been thrown because of adding the same YANG submodule twice.");
+ } catch (final ReactorException ex) {
+ final Throwable cause = ex.getCause();
+ assertTrue(cause instanceof SourceException);
+ assertTrue(cause.getMessage().startsWith("Submodule name collision: subbar."));
+ }
+ }
+}