From f65206e17b180061ef40ab6d9499f711133429e2 Mon Sep 17 00:00:00 2001 From: Maicol <79454487+MaicolAntali@users.noreply.github.com> Date: Mon, 6 Feb 2023 15:13:28 +0100 Subject: [PATCH] Adds Error Prone to the `maven-compiler-plugin` (#2308) * Adds Error Prone to the `pom.xml` * Adds Error Prone annotations to avoid compiling errors * Adds profile to run Error Prone in JDK8 * Revert "Adds profile to run Error Prone in JDK8" This reverts commit 61771d0da55003ea5bc8c6f086d925aec583c9a2. * Fix Error Prone warn * Add comment to `pom.xml` * Fix the `@SuppressWarnings("GetClassOnClass")` * Replace the Error Prone link in the `pom.xml` * Disable Error Prone with jdk-15` * Remove a new-line in `pom.xml` --- .../PostConstructAdapterFactoryTest.java | 6 ++--- .../java/com/google/gson/JsonArrayTest.java | 1 + .../java/com/google/gson/JsonObjectTest.java | 1 + .../com/google/gson/common/TestTypes.java | 3 ++- .../functional/DefaultTypeAdaptersTest.java | 2 +- .../gson/functional/InstanceCreatorTest.java | 4 +-- .../ReflectionAccessFilterTest.java | 2 +- .../gson/functional/TypeVariableTest.java | 5 ++-- .../google/gson/stream/JsonReaderTest.java | 3 ++- pom.xml | 25 ++++++++++++++++++- 10 files changed, 40 insertions(+), 12 deletions(-) diff --git a/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java b/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java index 65053bacbf..a4b9d04e7f 100644 --- a/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java +++ b/extras/src/test/java/com/google/gson/typeadapters/PostConstructAdapterFactoryTest.java @@ -57,8 +57,8 @@ public void testList() { assertEquals(sandwiches, sandwichesFromJson); } - @SuppressWarnings("overrides") // for missing hashCode() override - static class Sandwich { + @SuppressWarnings({"overrides", "EqualsHashCode"}) // for missing hashCode() override + static class Sandwich { public String bread; public String cheese; @@ -92,7 +92,7 @@ public boolean equals(Object o) { } } - @SuppressWarnings("overrides") // for missing hashCode() override + @SuppressWarnings({"overrides", "EqualsHashCode"}) // for missing hashCode() override static class MultipleSandwiches { public List sandwiches; diff --git a/gson/src/test/java/com/google/gson/JsonArrayTest.java b/gson/src/test/java/com/google/gson/JsonArrayTest.java index 12b28e42a2..01e8286aa2 100644 --- a/gson/src/test/java/com/google/gson/JsonArrayTest.java +++ b/gson/src/test/java/com/google/gson/JsonArrayTest.java @@ -38,6 +38,7 @@ public void testEqualsOnEmptyArray() { } @Test + @SuppressWarnings("TruthSelfEquals") public void testEqualsNonEmptyArray() { JsonArray a = new JsonArray(); JsonArray b = new JsonArray(); diff --git a/gson/src/test/java/com/google/gson/JsonObjectTest.java b/gson/src/test/java/com/google/gson/JsonObjectTest.java index d0da6abb78..9b37823dc0 100644 --- a/gson/src/test/java/com/google/gson/JsonObjectTest.java +++ b/gson/src/test/java/com/google/gson/JsonObjectTest.java @@ -163,6 +163,7 @@ public void testEqualsOnEmptyObject() { } @Test + @SuppressWarnings("TruthSelfEquals") public void testEqualsNonEmptyObject() { JsonObject a = new JsonObject(); JsonObject b = new JsonObject(); diff --git a/gson/src/test/java/com/google/gson/common/TestTypes.java b/gson/src/test/java/com/google/gson/common/TestTypes.java index 13807637e8..9df4a73d59 100644 --- a/gson/src/test/java/com/google/gson/common/TestTypes.java +++ b/gson/src/test/java/com/google/gson/common/TestTypes.java @@ -227,7 +227,8 @@ public String getExpectedJson() { } } - @SuppressWarnings("overrides") // for missing hashCode() override + // for missing hashCode() override + @SuppressWarnings({"overrides", "EqualsHashCode"}) public static class ClassWithNoFields { // Nothing here.. @Override diff --git a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java index 33ebc682b4..ee15bfc450 100644 --- a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java @@ -103,7 +103,7 @@ public void testClassSerialization() { @Test public void testClassDeserialization() { try { - gson.fromJson("String.class", String.class.getClass()); + gson.fromJson("String.class", Class.class); fail(); } catch (UnsupportedOperationException expected) { } diff --git a/gson/src/test/java/com/google/gson/functional/InstanceCreatorTest.java b/gson/src/test/java/com/google/gson/functional/InstanceCreatorTest.java index 930a18d572..ea3f979983 100644 --- a/gson/src/test/java/com/google/gson/functional/InstanceCreatorTest.java +++ b/gson/src/test/java/com/google/gson/functional/InstanceCreatorTest.java @@ -122,11 +122,11 @@ class SubTreeSet extends TreeSet {} Type sortedSetType = new TypeToken>() {}.getType(); SortedSet set = gson.fromJson("[\"a\"]", sortedSetType); - assertThat("a").isEqualTo(set.first()); + assertThat(set.first()).isEqualTo("a"); assertThat(set.getClass()).isEqualTo(SubTreeSet.class); set = gson.fromJson("[\"b\"]", SortedSet.class); - assertThat("b").isEqualTo(set.first()); + assertThat(set.first()).isEqualTo("b"); assertThat(set.getClass()).isEqualTo(SubTreeSet.class); } } diff --git a/gson/src/test/java/com/google/gson/functional/ReflectionAccessFilterTest.java b/gson/src/test/java/com/google/gson/functional/ReflectionAccessFilterTest.java index 67b60e2b61..dc58d024ef 100644 --- a/gson/src/test/java/com/google/gson/functional/ReflectionAccessFilterTest.java +++ b/gson/src/test/java/com/google/gson/functional/ReflectionAccessFilterTest.java @@ -18,7 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.fail; -import static org.junit.Assume.assumeNotNull;; +import static org.junit.Assume.assumeNotNull; import com.google.gson.Gson; import com.google.gson.GsonBuilder; diff --git a/gson/src/test/java/com/google/gson/functional/TypeVariableTest.java b/gson/src/test/java/com/google/gson/functional/TypeVariableTest.java index fdde72c892..c788febe36 100644 --- a/gson/src/test/java/com/google/gson/functional/TypeVariableTest.java +++ b/gson/src/test/java/com/google/gson/functional/TypeVariableTest.java @@ -73,7 +73,8 @@ public void testBasicTypeVariables() { assertThat(blue2).isEqualTo(blue1); } - @SuppressWarnings("overrides") // for missing hashCode() override + // for missing hashCode() override + @SuppressWarnings({"overrides", "EqualsHashCode"}) public static class Blue extends Red { public Blue() { super(false); @@ -103,7 +104,7 @@ public Red(S redField) { } } - @SuppressWarnings("overrides") // for missing hashCode() override + @SuppressWarnings({"overrides", "EqualsHashCode"}) // for missing hashCode() override public static class Foo extends Red { private S someSField; private T someTField; diff --git a/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java b/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java index 92af5bd122..09c07470df 100644 --- a/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java +++ b/gson/src/test/java/com/google/gson/stream/JsonReaderTest.java @@ -1698,7 +1698,8 @@ public void testDeeplyNestedObjects() throws IOException { reader.beginObject(); assertThat(reader.nextName()).isEqualTo("a"); } - assertThat(reader.getPath()); + assertThat(reader.getPath()).isEqualTo("$.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a" + + ".a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"); assertThat(reader.nextBoolean()).isTrue(); for (int i = 0; i < 40; i++) { reader.endObject(); diff --git a/pom.xml b/pom.xml index 2ca77f6850..d4f2733ec6 100644 --- a/pom.xml +++ b/pom.xml @@ -1,5 +1,6 @@ 4.0.0 @@ -104,12 +107,32 @@ true true - true + true + + -XDcompilePolicy=simple + -Xplugin:ErrorProne + -J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED + -J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED + -J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED -Xlint:all,-options + + + com.google.errorprone + error_prone_core + 2.18.0 + + [11,)