From 9f53a6788e20bbded1b5937a5e8fe19ace31beaa Mon Sep 17 00:00:00 2001 From: Elliotte Rusty Harold Date: Tue, 12 Jan 2021 23:02:20 +0000 Subject: [PATCH] fix: address some deprecation warnings in Java 9+ (#1215) --- .../src/main/java/com/google/api/client/xml/Xml.java | 4 ++-- .../main/java/com/google/api/client/util/Data.java | 11 +++++++++++ .../java/com/google/api/client/util/ObjectsTest.java | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java b/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java index 1aa5a343b..a5132839c 100644 --- a/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java +++ b/google-http-client-xml/src/main/java/com/google/api/client/xml/Xml.java @@ -575,10 +575,10 @@ private static Object parseValue(Type valueType, List context, String valu valueType = Data.resolveWildcardTypeOrTypeVariable(context, valueType); if (valueType == Double.class || valueType == double.class) { if (value.equals("INF")) { - return new Double(Double.POSITIVE_INFINITY); + return Double.valueOf(Double.POSITIVE_INFINITY); } if (value.equals("-INF")) { - return new Double(Double.NEGATIVE_INFINITY); + return Double.valueOf(Double.NEGATIVE_INFINITY); } } if (valueType == Float.class || valueType == float.class) { 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 5b2a91e4b..f50b45206 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 @@ -45,36 +45,47 @@ public class Data { // NOTE: create new instances to avoid cache, e.g. new String() /** The single instance of the magic null object for a {@link Boolean}. */ + @SuppressWarnings("deprecation") public static final Boolean NULL_BOOLEAN = new Boolean(true); /** The single instance of the magic null object for a {@link String}. */ + @SuppressWarnings("deprecation") public static final String NULL_STRING = new String(); /** The single instance of the magic null object for a {@link Character}. */ + @SuppressWarnings("deprecation") public static final Character NULL_CHARACTER = new Character((char) 0); /** The single instance of the magic null object for a {@link Byte}. */ + @SuppressWarnings("deprecation") public static final Byte NULL_BYTE = new Byte((byte) 0); /** The single instance of the magic null object for a {@link Short}. */ + @SuppressWarnings("deprecation") public static final Short NULL_SHORT = new Short((short) 0); /** The single instance of the magic null object for a {@link Integer}. */ + @SuppressWarnings("deprecation") public static final Integer NULL_INTEGER = new Integer(0); /** The single instance of the magic null object for a {@link Float}. */ + @SuppressWarnings("deprecation") public static final Float NULL_FLOAT = new Float(0); /** The single instance of the magic null object for a {@link Long}. */ + @SuppressWarnings("deprecation") public static final Long NULL_LONG = new Long(0); /** The single instance of the magic null object for a {@link Double}. */ + @SuppressWarnings("deprecation") public static final Double NULL_DOUBLE = new Double(0); /** The single instance of the magic null object for a {@link BigInteger}. */ + @SuppressWarnings("deprecation") public static final BigInteger NULL_BIG_INTEGER = new BigInteger("0"); /** The single instance of the magic null object for a {@link BigDecimal}. */ + @SuppressWarnings("deprecation") public static final BigDecimal NULL_BIG_DECIMAL = new BigDecimal("0"); /** The single instance of the magic null object for a {@link DateTime}. */ diff --git a/google-http-client/src/test/java/com/google/api/client/util/ObjectsTest.java b/google-http-client/src/test/java/com/google/api/client/util/ObjectsTest.java index 570ede362..5327e9267 100644 --- a/google-http-client/src/test/java/com/google/api/client/util/ObjectsTest.java +++ b/google-http-client/src/test/java/com/google/api/client/util/ObjectsTest.java @@ -34,7 +34,7 @@ public void testConstructor_innerClass() { public void testToString_oneIntegerField() { String toTest = - Objects.toStringHelper(new TestClass()).add("field1", new Integer(42)).toString(); + Objects.toStringHelper(new TestClass()).add("field1", Integer.valueOf(42)).toString(); assertEquals("TestClass{field1=42}", toTest); }