From: Robert Varga Date: Wed, 1 May 2019 17:18:57 +0000 (+0200) Subject: Defend against nulls in ValueContext X-Git-Tag: v4.0.1~14 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=5a9f47ef322c88911ab859ac5418e168b7fb9096;p=mdsal.git Defend against nulls in ValueContext We should never attempt to deserialize null values for keys, defend against them. Change-Id: I6439bb6ce22da11476cd4f8bd89e3ec04c05ba96 Signed-off-by: Robert Varga --- diff --git a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueContext.java b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueContext.java index 1ee46c73d3..6d003bf20a 100644 --- a/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueContext.java +++ b/binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/ValueContext.java @@ -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 +}