BUG-7267: catch RuntimeExceptions when processing sources
[yangtools.git] / yang / yang-parser-impl / src / main / java / org / opendaylight / yangtools / yang / parser / stmt / rfc6020 / KeyStatementImpl.java
index 451e6130b23468df3a28386eb5033fa02262a182..74f968f312482e2864d5475744acccbca11705f1 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 com.google.common.collect.ImmutableSet.Builder;
 import java.util.Collection;
@@ -20,6 +19,7 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement
 import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContextUtils;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.KeyEffectiveStatementImpl;
 
 public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<SchemaNodeIdentifier>> implements
@@ -52,9 +52,8 @@ public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<Schem
 
             // Throws NPE on nulls, retains first inserted value, cannot be modified
             final Collection<SchemaNodeIdentifier> ret = builder.build();
-
-            Preconditions.checkArgument(ret.size() == tokens, "Key argument '%s' contains duplicates. At %s", value,
-                    ctx.getStatementSourceReference());
+            SourceException.throwIf(ret.size() != tokens, ctx.getStatementSourceReference(),
+                    "Key argument '%s' contains duplicates", value);
             return ret;
         }
 
@@ -71,7 +70,7 @@ public class KeyStatementImpl extends AbstractDeclaredStatement<Collection<Schem
         }
 
         @Override
-        public void onFullDefinitionDeclared(StmtContext.Mutable<Collection<SchemaNodeIdentifier>, KeyStatement,
+        public void onFullDefinitionDeclared(final StmtContext.Mutable<Collection<SchemaNodeIdentifier>, KeyStatement,
                 EffectiveStatement<Collection<SchemaNodeIdentifier>, KeyStatement>> stmt) {
             super.onFullDefinitionDeclared(stmt);
             SUBSTATEMENT_VALIDATOR.validate(stmt);