From 4c2a7a9e04a185999a2d5411215bbca5b65884b9 Mon Sep 17 00:00:00 2001 From: Martin Vitez Date: Wed, 20 Aug 2014 09:48:26 +0200 Subject: [PATCH] BUG-1578: fixed NPE caused by invalid import statement. If parser can't found imported module it throws YangParseException with error info about root cause. Change-Id: I3ca81fc46ca57d36b770b3846c10d422d415ac37 Signed-off-by: Martin Vitez --- .../yang/parser/impl/YangParserListenerImpl.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java index 5b5fbbfb1c..ece9226253 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java @@ -546,7 +546,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener { * contains ":" the string is evaluated as prefix:name of element. In this case method will look into import map * and extract correct ModuleImport. If such import is not present in import map the method will throw {@link YangParseException} *
- * If ModuleImport is present but the value of namespace in ModuleImport is null the method wil throw {@link YangParseException} + * If ModuleImport is present but the value of namespace in ModuleImport is null the method will throw {@link YangParseException} * * @param qnameString QName value as String * @param line line in Yang model document where QName occur. @@ -573,12 +573,12 @@ public final class YangParserListenerImpl extends YangParserBaseListener { } Date revision = imp.getRevision(); TreeMap namespaces = namespaceContext.get(imp.getModuleName()); + if (namespaces == null) { + throw new YangParseException(moduleName, line, String.format("Imported module %s not found", + imp.getModuleName())); + } URI namespace; if (revision == null) { - if (namespaces == null) { - throw new YangParseException(moduleName, line, "imported module " + imp.getModuleName() - + " with prefix " + imp.getPrefix() + " not found."); - } revision = namespaces.lastEntry().getKey(); namespace = namespaces.lastEntry().getValue(); } else { -- 2.36.6