diff --git a/google-http-client/src/main/java/com/google/api/client/util/Data.java b/google-http-client/src/main/java/com/google/api/client/util/Data.java index 10e3fe5bd..5b2a91e4b 100644 --- a/google-http-client/src/main/java/com/google/api/client/util/Data.java +++ b/google-http-client/src/main/java/com/google/api/client/util/Data.java @@ -108,7 +108,7 @@ public class Data { * @return magic object instance that represents the "null" value (not Java {@code null}) * @throws IllegalArgumentException if unable to create a new instance */ - public static T nullOf(Class objClass) { + public static T nullOf(Class objClass) { // ConcurrentMap.computeIfAbsent is explicitly NOT used in the following logic. The // ConcurrentHashMap implementation of that method BLOCKS if the mappingFunction triggers // modification of the map which createNullInstance can do depending on the state of class diff --git a/google-http-client/src/test/java/com/google/api/client/util/DataTest.java b/google-http-client/src/test/java/com/google/api/client/util/DataTest.java index de428c60c..00f1dd5d2 100644 --- a/google-http-client/src/test/java/com/google/api/client/util/DataTest.java +++ b/google-http-client/src/test/java/com/google/api/client/util/DataTest.java @@ -14,6 +14,7 @@ package com.google.api.client.util; +import com.google.common.collect.ImmutableMap; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; @@ -68,6 +69,12 @@ public void testNullOf() { } } + public void testNullOfTemplateTypes() { + String nullValue = Data.nullOf(String.class); + Map nullField = ImmutableMap.of("v", nullValue); + assertEquals(nullValue, nullField.get("v")); + } + public void testIsNull() { assertTrue(Data.isNull(Data.NULL_BOOLEAN)); assertTrue(Data.isNull(Data.NULL_STRING));