Do not throw IllegalArgumentException 06/58306/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 6 Jun 2017 08:13:19 +0000 (10:13 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 7 Jun 2017 13:40:52 +0000 (13:40 +0000)
We have enough information to throw a SourceException, so do that
to propagate relevant diagnostics.

Change-Id: I5d7b5db1cba00fc3bea6f63025091086c6d2ed34
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/UsesStatementImpl.java

index 532d70fcbf8643cda3f6b3af6553a342e334dce7..32ace4cbc881450bb89583d29cdf15b332427282 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.yangtools.yang.parser.stmt.rfc6020;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -287,15 +286,17 @@ public class UsesStatementImpl extends AbstractDeclaredStatement<QName> implemen
             final StatementContextBase<?, ?, ?> usesParentCtx) {
 
         final Object refineArgument = refineCtx.getStatementArgument();
-        Preconditions.checkArgument(refineArgument instanceof SchemaNodeIdentifier,
-                "Invalid refine argument %s. It must be instance of SchemaNodeIdentifier. At %s", refineArgument,
-                refineCtx.getStatementSourceReference());
+        InferenceException.throwIf(!(refineArgument instanceof SchemaNodeIdentifier),
+            refineCtx.getStatementSourceReference(),
+            "Invalid refine argument %s. It must be instance of SchemaNodeIdentifier.", refineArgument);
 
         final SchemaNodeIdentifier refineTargetNodeIdentifier = (SchemaNodeIdentifier) refineArgument;
         final StatementContextBase<?, ?, ?> refineTargetNodeCtx = Utils.findNode(usesParentCtx,
                 refineTargetNodeIdentifier);
-        Preconditions.checkArgument(refineTargetNodeCtx != null, "Refine target node %s not found. At %s",
-                refineTargetNodeIdentifier, refineCtx.getStatementSourceReference());
+
+        InferenceException.throwIfNull(refineTargetNodeCtx, refineCtx.getStatementSourceReference(),
+            "Refine target node %s not found.", refineTargetNodeIdentifier);
+
         if (StmtContextUtils.isUnknownStatement(refineTargetNodeCtx)) {
             LOG.debug(
                     "Refine node '{}' in uses '{}' has target node unknown statement '{}'. Refine has been skipped. At line: {}",