diff --git a/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java b/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java
index b520183528..3d3262a336 100644
--- a/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java
+++ b/extras/src/test/java/com/google/gson/typeadapters/UtcDateTypeAdapterTest.java
@@ -29,6 +29,7 @@
import java.util.TimeZone;
import org.junit.Test;
+@SuppressWarnings("JavaUtilDate")
public final class UtcDateTypeAdapterTest {
private final Gson gson = new GsonBuilder()
.registerTypeAdapter(Date.class, new UtcDateTypeAdapter())
diff --git a/gson/pom.xml b/gson/pom.xml
index deed98dddf..d80226c0a4 100644
--- a/gson/pom.xml
+++ b/gson/pom.xml
@@ -55,6 +55,12 @@
31.1-jre
test
+
+ com.google.errorprone
+ error_prone_annotations
+ 2.18.0
+ true
+
diff --git a/gson/src/main/java/com/google/gson/Gson.java b/gson/src/main/java/com/google/gson/Gson.java
index 054b1f92ed..45336a87e9 100644
--- a/gson/src/main/java/com/google/gson/Gson.java
+++ b/gson/src/main/java/com/google/gson/Gson.java
@@ -1011,7 +1011,7 @@ public T fromJson(String json, Class classOfT) throws JsonSyntaxException
* @see #fromJson(String, Class)
* @see #fromJson(String, TypeToken)
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public T fromJson(String json, Type typeOfT) throws JsonSyntaxException {
return (T) fromJson(json, TypeToken.get(typeOfT));
}
@@ -1104,7 +1104,7 @@ public T fromJson(Reader json, Class classOfT) throws JsonSyntaxException
* @see #fromJson(Reader, Class)
* @see #fromJson(Reader, TypeToken)
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public T fromJson(Reader json, Type typeOfT) throws JsonIOException, JsonSyntaxException {
return (T) fromJson(json, TypeToken.get(typeOfT));
}
@@ -1183,7 +1183,7 @@ private static void assertFullConsumption(Object obj, JsonReader reader) {
* @see #fromJson(Reader, Type)
* @see #fromJson(JsonReader, TypeToken)
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public T fromJson(JsonReader reader, Type typeOfT) throws JsonIOException, JsonSyntaxException {
return (T) fromJson(reader, TypeToken.get(typeOfT));
}
@@ -1297,7 +1297,7 @@ public T fromJson(JsonElement json, Class classOfT) throws JsonSyntaxExce
* @see #fromJson(JsonElement, Class)
* @see #fromJson(JsonElement, TypeToken)
*/
- @SuppressWarnings("unchecked")
+ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
public T fromJson(JsonElement json, Type typeOfT) throws JsonSyntaxException {
return (T) fromJson(json, TypeToken.get(typeOfT));
}
diff --git a/gson/src/main/java/com/google/gson/JsonDeserializationContext.java b/gson/src/main/java/com/google/gson/JsonDeserializationContext.java
index 00c7505432..093653d90f 100644
--- a/gson/src/main/java/com/google/gson/JsonDeserializationContext.java
+++ b/gson/src/main/java/com/google/gson/JsonDeserializationContext.java
@@ -40,5 +40,6 @@ public interface JsonDeserializationContext {
* @return An object of type typeOfT.
* @throws JsonParseException if the parse tree does not contain expected data.
*/
+ @SuppressWarnings("TypeParameterUnusedInFormals")
public T deserialize(JsonElement json, Type typeOfT) throws JsonParseException;
}
\ No newline at end of file
diff --git a/gson/src/main/java/com/google/gson/JsonParser.java b/gson/src/main/java/com/google/gson/JsonParser.java
index 5b80042039..20d3750cea 100644
--- a/gson/src/main/java/com/google/gson/JsonParser.java
+++ b/gson/src/main/java/com/google/gson/JsonParser.java
@@ -15,6 +15,7 @@
*/
package com.google.gson;
+import com.google.errorprone.annotations.InlineMe;
import com.google.gson.internal.Streams;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonToken;
@@ -111,18 +112,21 @@ public static JsonElement parseReader(JsonReader reader)
/** @deprecated Use {@link JsonParser#parseString} */
@Deprecated
+ @InlineMe(replacement = "JsonParser.parseString(json)", imports = "com.google.gson.JsonParser")
public JsonElement parse(String json) throws JsonSyntaxException {
return parseString(json);
}
/** @deprecated Use {@link JsonParser#parseReader(Reader)} */
@Deprecated
+ @InlineMe(replacement = "JsonParser.parseReader(json)", imports = "com.google.gson.JsonParser")
public JsonElement parse(Reader json) throws JsonIOException, JsonSyntaxException {
return parseReader(json);
}
/** @deprecated Use {@link JsonParser#parseReader(JsonReader)} */
@Deprecated
+ @InlineMe(replacement = "JsonParser.parseReader(json)", imports = "com.google.gson.JsonParser")
public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException {
return parseReader(json);
}
diff --git a/gson/src/main/java/com/google/gson/internal/JavaVersion.java b/gson/src/main/java/com/google/gson/internal/JavaVersion.java
index df8e9a49e1..21130ff9d0 100644
--- a/gson/src/main/java/com/google/gson/internal/JavaVersion.java
+++ b/gson/src/main/java/com/google/gson/internal/JavaVersion.java
@@ -45,7 +45,7 @@ static int getMajorJavaVersion(String javaVersion) {
// Parses both legacy 1.8 style and newer 9.0.4 style
private static int parseDotted(String javaVersion) {
try {
- String[] parts = javaVersion.split("[._]");
+ String[] parts = javaVersion.split("[._]", 3);
int firstVer = Integer.parseInt(parts[0]);
if (firstVer == 1 && parts.length > 1) {
return Integer.parseInt(parts[1]);
diff --git a/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java b/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
index 07fee7dff2..9194fc33bf 100644
--- a/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
+++ b/gson/src/main/java/com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java
@@ -81,6 +81,7 @@ private boolean includeField(Field f, boolean serialize) {
}
/** first element holds the default name */
+ @SuppressWarnings("MixedMutabilityReturnType")
private List getFieldNames(Field f) {
SerializedName annotation = f.getAnnotation(SerializedName.class);
if (annotation == null) {
diff --git a/gson/src/main/java/com/google/gson/internal/bind/TreeTypeAdapter.java b/gson/src/main/java/com/google/gson/internal/bind/TreeTypeAdapter.java
index 47ca8fc03a..a1a5f760d4 100644
--- a/gson/src/main/java/com/google/gson/internal/bind/TreeTypeAdapter.java
+++ b/gson/src/main/java/com/google/gson/internal/bind/TreeTypeAdapter.java
@@ -174,8 +174,9 @@ private final class GsonContextImpl implements JsonSerializationContext, JsonDes
@Override public JsonElement serialize(Object src, Type typeOfSrc) {
return gson.toJsonTree(src, typeOfSrc);
}
- @SuppressWarnings("unchecked")
- @Override public R deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
+ @Override
+ @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
+ public R deserialize(JsonElement json, Type typeOfT) throws JsonParseException {
return gson.fromJson(json, typeOfT);
}
}
diff --git a/gson/src/main/java/com/google/gson/internal/sql/SqlDateTypeAdapter.java b/gson/src/main/java/com/google/gson/internal/sql/SqlDateTypeAdapter.java
index 6ae4c3ef50..271f23c21c 100644
--- a/gson/src/main/java/com/google/gson/internal/sql/SqlDateTypeAdapter.java
+++ b/gson/src/main/java/com/google/gson/internal/sql/SqlDateTypeAdapter.java
@@ -36,6 +36,7 @@
* this class state. DateFormat isn't thread safe either, so this class has
* to synchronize its read and write methods.
*/
+@SuppressWarnings("JavaUtilDate")
final class SqlDateTypeAdapter extends TypeAdapter {
static final TypeAdapterFactory FACTORY = new TypeAdapterFactory() {
@SuppressWarnings("unchecked") // we use a runtime check to make sure the 'T's equal
diff --git a/gson/src/main/java/com/google/gson/internal/sql/SqlTimeTypeAdapter.java b/gson/src/main/java/com/google/gson/internal/sql/SqlTimeTypeAdapter.java
index c2a37073f0..ac327ff16f 100644
--- a/gson/src/main/java/com/google/gson/internal/sql/SqlTimeTypeAdapter.java
+++ b/gson/src/main/java/com/google/gson/internal/sql/SqlTimeTypeAdapter.java
@@ -37,6 +37,7 @@
* this class state. DateFormat isn't thread safe either, so this class has
* to synchronize its read and write methods.
*/
+@SuppressWarnings("JavaUtilDate")
final class SqlTimeTypeAdapter extends TypeAdapter