Bug 4540: Yang parser exceptions should follow consistent path
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / ModuleStatementSupport.java
index 1f68421d2cf0e33583b76245074b87bb024a34a0..ea6d565b895288b891582df87ec952ac5d7e319f 100644 (file)
@@ -97,8 +97,8 @@ public class ModuleStatementSupport extends
         Optional<URI> moduleNs = Optional.fromNullable(firstAttributeOf(stmt.declaredSubstatements(),
                 NamespaceStatement.class));
         if (!moduleNs.isPresent()) {
-            throw new IllegalArgumentException("Namespace of the module [" + stmt.getStatementArgument()
-                    + "] is missing.");
+            throw new SourceException(String.format("Namespace of the module [%s] is missing",
+                    stmt.getStatementArgument()), stmt.getStatementSourceReference());
         }
 
         Optional<Date> revisionDate = Optional.fromNullable(Utils.getLatestRevision(stmt.declaredSubstatements()));
@@ -106,7 +106,7 @@ public class ModuleStatementSupport extends
             revisionDate = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_REV);
         }
 
-        QNameModule qNameModule = QNameModule.cachedReference(QNameModule.create(moduleNs.get(), revisionDate.orNull()));
+        QNameModule qNameModule = QNameModule.create(moduleNs.get(), revisionDate.orNull()).intern();
         ModuleIdentifier moduleIdentifier = new ModuleIdentifierImpl(stmt.getStatementArgument(),
                 Optional.<URI> absent(), revisionDate);
 
@@ -116,7 +116,8 @@ public class ModuleStatementSupport extends
 
         String modulePrefix = firstAttributeOf(stmt.declaredSubstatements(), PrefixStatement.class);
         if (modulePrefix == null) {
-            throw new IllegalArgumentException("Prefix of the module [" + stmt.getStatementArgument() + "] is missing.");
+            throw new SourceException(String.format("Prefix of the module [%s] is missing",
+                    stmt.getStatementArgument()), stmt.getStatementSourceReference());
         }
 
         stmt.addToNs(PrefixToModule.class, modulePrefix, qNameModule);
@@ -134,4 +135,4 @@ public class ModuleStatementSupport extends
         super.onFullDefinitionDeclared(stmt);
         SUBSTATEMENT_VALIDATOR.validate(stmt);
     }
-}
\ No newline at end of file
+}