import org.opendaylight.yangtools.yang.parser.spi.meta.NamespaceBehaviour;
import org.opendaylight.yangtools.yang.parser.spi.meta.StatementNamespace;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
/**
* Statement local namespace, which holds direct schema node descendants.
@SuppressWarnings("unchecked")
@Override
public void addTo(final NamespaceStorageNode storage, final QName key, final StmtContext<?, D, E> value) {
- // FIXME: BUG-7424: usee putToLocalStorageIfAbsent()
- globalOrStatementSpecific(storage).putToLocalStorage(ChildSchemaNodes.class, key, value);
+ final StmtContext<?, D, E> prev = globalOrStatementSpecific(storage).putToLocalStorageIfAbsent(
+ ChildSchemaNodes.class, key, value);
+
+ SourceException.throwIf(prev != null, value.getStatementSourceReference(),
+ "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared.", value.getRoot()
+ .getStatementArgument(), key, prev != null ? prev.getStatementArgument() : null);
}
private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) {
--- /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 org.junit.Test;
+import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
+
+public class Bug7424Test {
+ @Test
+ public void testRpc() throws Exception {
+ try {
+ StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc.yang");
+ fail("Test should fail due to invalid yang model.");
+ } catch (final SomeModifiersUnresolvedException e) {
+ assertTrue(e
+ .getCause()
+ .getMessage()
+ .startsWith(
+ "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+ + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+ }
+ }
+
+ @Test
+ public void testNotification() throws Exception {
+ try {
+ StmtTestUtils.parseYangSource("/bugs/bug7424/foo-notification.yang");
+ fail("Test should fail due to invalid yang model.");
+ } catch (final SomeModifiersUnresolvedException e) {
+ assertTrue(e
+ .getCause()
+ .getMessage()
+ .startsWith(
+ "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+ + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+ }
+ }
+
+ @Test
+ public void testData() throws Exception {
+ try {
+ StmtTestUtils.parseYangSource("/bugs/bug7424/foo-data.yang");
+ fail("Test should fail due to invalid yang model.");
+ } catch (final SomeModifiersUnresolvedException e) {
+ assertTrue(e
+ .getCause()
+ .getMessage()
+ .startsWith(
+ "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+ + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+ }
+ }
+
+ @Test
+ public void testRpcUses() throws Exception {
+ try {
+ StmtTestUtils.parseYangSource("/bugs/bug7424/foo-rpc-uses.yang");
+ fail("Test should fail due to invalid yang model.");
+ } catch (final SomeModifiersUnresolvedException e) {
+ assertTrue(e
+ .getCause()
+ .getMessage()
+ .startsWith(
+ "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
+ + "Node name collision: '(foo?revision=1970-01-01)name' already declared."));
+ }
+ }
+}