From c46d2c276ae96f06d30739a430cda98f6f2435c3 Mon Sep 17 00:00:00 2001 From: Sergii Tkachenko Date: Fri, 4 Feb 2022 09:56:26 -0800 Subject: [PATCH] core: test JsonUtil.getObject with a map containing a null value (#8881) Verifies the behavior of JsonUtil.getObject when the map contains a null value for a given key. Note: this may be incorrect behavior. Issue to track the investigation: #8883. --- .../test/java/io/grpc/internal/JsonUtilTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/test/java/io/grpc/internal/JsonUtilTest.java b/core/src/test/java/io/grpc/internal/JsonUtilTest.java index 960800c97c..a01f886822 100644 --- a/core/src/test/java/io/grpc/internal/JsonUtilTest.java +++ b/core/src/test/java/io/grpc/internal/JsonUtilTest.java @@ -19,6 +19,7 @@ package io.grpc.internal; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.junit.Test; @@ -130,4 +131,16 @@ public class JsonUtilTest { assertThat(JsonUtil.getNumberAsInteger(map, "key_nonexistent")).isNull(); assertThat(JsonUtil.getNumberAsLong(map, "key_nonexistent")).isNull(); } + + @Test + public void getObject_mapExplicitNullValue() { + Map mapWithNullValue = Collections.singletonMap("key", null); + try { + JsonUtil.getObject(mapWithNullValue, "key"); + fail("ClassCastException expected"); + } catch (ClassCastException e) { + assertThat(e).hasMessageThat() + .isEqualTo("value 'null' for key 'key' in '{key=null}' is not object"); + } + } }