Rework AugmentRuntimeType and Choice/Case linkage
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / impl / UnionValueOptionContext.java
index 07085f6568d2d3ffd65bf08f457ec8efd660b710..beb59c96bbc12b605e302553e1e079b264f62714 100644 (file)
@@ -7,13 +7,14 @@
  */
 package org.opendaylight.mdsal.binding.dom.codec.impl;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.Throwables;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
 import java.lang.invoke.MethodType;
 import java.lang.reflect.Method;
-import org.opendaylight.yangtools.concepts.Codec;
+import org.opendaylight.yangtools.concepts.IllegalArgumentCodec;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -22,13 +23,14 @@ final class UnionValueOptionContext {
     private static final Logger LOG = LoggerFactory.getLogger(UnionValueOptionContext.class);
 
     private final Class<?> bindingType;
-    private final Codec<Object,Object> codec;
+    private final IllegalArgumentCodec<Object,Object> codec;
     private final MethodHandle getter;
     private final MethodHandle unionCtor;
 
-    UnionValueOptionContext(final Class<?> unionType, final Class<?> valueType, final Method getter, final Codec<Object, Object> codec) {
-        this.bindingType = Preconditions.checkNotNull(valueType);
-        this.codec = Preconditions.checkNotNull(codec);
+    UnionValueOptionContext(final Class<?> unionType, final Class<?> valueType, final Method getter,
+            final IllegalArgumentCodec<Object, Object> codec) {
+        this.bindingType = requireNonNull(valueType);
+        this.codec = requireNonNull(codec);
 
         try {
             this.getter = MethodHandles.publicLookup().unreflect(getter).asType(OBJECT_TYPE);
@@ -50,6 +52,7 @@ final class UnionValueOptionContext {
         return baValue == null ? null : codec.serialize(baValue);
     }
 
+    @SuppressWarnings("checkstyle:illegalCatch")
     Object deserializeUnion(final Object input) {
         // Side-step potential exceptions by checking the type if it is available
         if (codec instanceof EncapsulatedValueCodec && !((EncapsulatedValueCodec) codec).canAcceptObject(input)) {
@@ -75,12 +78,13 @@ final class UnionValueOptionContext {
         }
     }
 
+    @SuppressWarnings("checkstyle:illegalCatch")
     Object getValueFrom(final Object input) {
         try {
             return getter.invokeExact(input);
         } catch (Throwable e) {
             Throwables.throwIfUnchecked(e);
-            throw new RuntimeException(e);
+            throw new IllegalStateException(e);
         }
     }