diff --git a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java index 0f414e81e9..152f0482af 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java +++ b/gson/src/main/java/com/google/gson/internal/bind/TypeAdapters.java @@ -570,7 +570,11 @@ public InetAddress read(JsonReader in) throws IOException { return null; } // regrettably, this should have included both the host name and the host address - return InetAddress.getByName(in.nextString()); + // For compatibility, we use InetAddress.getByName rather than the possibly-better + // .getAllByName + @SuppressWarnings("AddressSelection") + InetAddress addr = InetAddress.getByName(in.nextString()); + return addr; } @Override public void write(JsonWriter out, InetAddress value) throws IOException { diff --git a/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java b/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java index 3edee56a22..c57719af72 100644 --- a/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java +++ b/gson/src/test/java/com/google/gson/DefaultInetAddressTypeAdapterTest.java @@ -37,6 +37,7 @@ public void setUp() throws Exception { @Test public void testInetAddressSerializationAndDeserialization() throws Exception { + @SuppressWarnings("AddressSelection") // we really do want this method InetAddress address = InetAddress.getByName("8.8.8.8"); String jsonAddress = gson.toJson(address); assertThat(jsonAddress).isEqualTo("\"8.8.8.8\""); diff --git a/pom.xml b/pom.xml index 9ba8f03989..7e792a5992 100644 --- a/pom.xml +++ b/pom.xml @@ -150,7 +150,7 @@ com.google.errorprone error_prone_core - 2.20.0 + 2.21.1