BUG-1578: fixed NPE caused by invalid import statement. 87/10087/1
authorMartin Vitez <mvitez@cisco.com>
Wed, 20 Aug 2014 07:48:26 +0000 (09:48 +0200)
committerMartin Vitez <mvitez@cisco.com>
Wed, 20 Aug 2014 07:48:26 +0000 (09:48 +0200)
If parser can't found imported module it throws YangParseException with error info about root cause.

Change-Id: I3ca81fc46ca57d36b770b3846c10d422d415ac37
Signed-off-by: Martin Vitez <mvitez@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserListenerImpl.java

index 5b5fbbfb1c4b21c5d5a43925fbd2d9a082cbb0e8..ece9226253cb04bb012a19c0fa67b7fae1745619 100644 (file)
@@ -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}
      * <br>
-     * If ModuleImport is present but the value of namespace in ModuleImport is <code>null</code> the method wil throw {@link YangParseException}
+     * If ModuleImport is present but the value of namespace in ModuleImport is <code>null</code> 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<Date, URI> 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 {