From 4c3f03cb2a1de461cada3e6a067a2b61af3aa99c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 11 Mar 2017 21:15:55 +0100 Subject: [PATCH] BUG-7954: identify source of the offending statement When we have a conflicting key we should also identify where it was populated, as that may not be immediately obvious by looking at the module source. Change-Id: If48cb1af73b86bd7cbf6926dfc8fe696f796a20e Signed-off-by: Robert Varga --- .../parser/stmt/rfc6020/ChildSchemaNodes.java | 9 +++-- .../yangtools/yang/stmt/Bug7424Test.java | 36 +++++++------------ .../yang/stmt/YangParserNegativeTest.java | 8 ++--- 3 files changed, 22 insertions(+), 31 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ChildSchemaNodes.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ChildSchemaNodes.java index f898e310a5..53d2032697 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ChildSchemaNodes.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ChildSchemaNodes.java @@ -54,9 +54,12 @@ public class ChildSchemaNodes, E extends Effe final StmtContext 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); + if (prev != null) { + throw new SourceException(value.getStatementSourceReference(), + "Error in module '%s': cannot add '%s'. Node name collision: '%s' already declared at %s", + value.getRoot().getStatementArgument(), key, prev.getStatementArgument(), + prev.getStatementSourceReference()); + } } private static NamespaceStorageNode globalOrStatementSpecific(final NamespaceStorageNode storage) { diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7424Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7424Test.java index a0f4b83ebd..6aef3cbc31 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7424Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug7424Test.java @@ -20,12 +20,9 @@ public class Bug7424Test { 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.")); + 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")); } } @@ -35,12 +32,9 @@ public class Bug7424Test { 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.")); + 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")); } } @@ -50,12 +44,9 @@ public class Bug7424Test { 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.")); + 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")); } } @@ -65,12 +56,9 @@ public class Bug7424Test { 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.")); + 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")); } } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java index 2b1143a0b7..45c74ba6b8 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangParserNegativeTest.java @@ -151,7 +151,7 @@ public class YangParserNegativeTest { } catch (final ReactorException e) { final String expected = "Error in module 'container': cannot add '(urn:simple.container" + ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" + - ".demo?revision=1970-01-01)foo' already declared."; + ".demo?revision=1970-01-01)foo' already declared"; assertTrue(e.getCause().getMessage().contains(expected)); } } @@ -167,7 +167,7 @@ public class YangParserNegativeTest { } catch (final ReactorException e) { final String expected = "Error in module 'container-list': cannot add '(urn:simple.container" + ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" + - ".demo?revision=1970-01-01)foo' already declared."; + ".demo?revision=1970-01-01)foo' already declared"; assertTrue(e.getCause().getMessage().contains(expected)); } } @@ -183,7 +183,7 @@ public class YangParserNegativeTest { } catch (final ReactorException e) { final String expected = "Error in module 'container-leaf': cannot add '(urn:simple.container" + ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" + - ".demo?revision=1970-01-01)foo' already declared."; + ".demo?revision=1970-01-01)foo' already declared"; assertTrue(e.getCause().getMessage().contains(expected)); } } @@ -254,4 +254,4 @@ public class YangParserNegativeTest { } } -} \ No newline at end of file +} -- 2.36.6