BUG-7464: do not throw ISE/RTE in "impossible" cases
[yangtools.git] / third-party / triemap / src / main / java / org / opendaylight / yangtools / triemap / CNode.java
index 2b3885443032b74da154a6d999785d1d1cc79945..593a66d3c21e995c92e13f93b75fd360a9738836 100644 (file)
@@ -19,6 +19,7 @@ import static org.opendaylight.yangtools.triemap.Constants.HASH_BITS;
 import static org.opendaylight.yangtools.triemap.Constants.LEVEL_BITS;
 
 import com.google.common.base.Verify;
+import com.google.common.base.VerifyException;
 import java.util.concurrent.ThreadLocalRandom;
 
 final class CNode<K, V> extends MainNode<K, V> {
@@ -74,6 +75,10 @@ final class CNode<K, V> extends MainNode<K, V> {
         return (sz = csize) != NO_SIZE ? sz : (csize = computeSize(ct));
     }
 
+    static VerifyException invalidElement(final BasicNode elem) {
+        throw new VerifyException("A CNode can contain only CNodes and SNodes, not " + elem);
+    }
+
     // lends itself towards being parallelizable by choosing
     // a random starting offset in the array
     // => if there are concurrent size computations, they start
@@ -105,7 +110,7 @@ final class CNode<K, V> extends MainNode<K, V> {
         } else if (elem instanceof INode) {
             return ((INode<?, ?>) elem).size(ct);
         } else {
-            throw new IllegalStateException("Unhandled element " + elem);
+            throw invalidElement(elem);
         }
     }