Defend against nulls in ValueContext 61/81861/2
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 1 May 2019 17:18:57 +0000 (19:18 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 1 May 2019 17:33:07 +0000 (19:33 +0200)
We should never attempt to deserialize null values for keys,
defend against them.

Change-Id: I6439bb6ce22da11476cd4f8bd89e3ec04c05ba96
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueContext.java

index 1ee46c73d340864dea6a589e0487f7f439ee5871..6d003bf20a59251ff2c38ef09d10aee97fabd22e 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.mdsal.binding.dom.codec.impl;
 
-import com.google.common.base.Preconditions;
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Verify.verifyNotNull;
+
 import com.google.common.base.Throwables;
 import java.lang.invoke.MethodHandle;
 import java.lang.invoke.MethodHandles;
@@ -43,14 +45,14 @@ final class ValueContext {
             throw new IllegalStateException(e);
         }
 
-        Preconditions.checkArgument(value != null,
-                "All keys must be specified for %s. Missing key is %s. Supplied key is %s",
+        checkArgument(value != null, "All keys must be specified for %s. Missing key is %s. Supplied key is %s",
                 identifier, getterName, obj);
         return codec.serialize(value);
     }
 
     Object deserialize(final Object obj) {
-        return codec.deserialize(obj);
+        checkArgument(obj != null, "Attempted to serialize null for %s component of %s", getterName, identifier);
+        return verifyNotNull(codec.deserialize(obj), "Codec for %s of %s returned null for %s", getterName, identifier,
+            obj);
     }
-
-}
\ No newline at end of file
+}