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`
This commit is contained in:
Maicol 2023-02-06 15:13:28 +01:00 committed by GitHub
parent 0d22e5d205
commit 9f26679e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 57 additions and 12 deletions

View File

@ -57,8 +57,8 @@ public class PostConstructAdapterFactoryTest {
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 class PostConstructAdapterFactoryTest {
}
}
@SuppressWarnings("overrides") // for missing hashCode() override
@SuppressWarnings({"overrides", "EqualsHashCode"}) // for missing hashCode() override
static class MultipleSandwiches {
public List<Sandwich> sandwiches;

View File

@ -35,6 +35,7 @@ public final class JsonArrayTest {
}
@Test
@SuppressWarnings("TruthSelfEquals")
public void testEqualsNonEmptyArray() {
JsonArray a = new JsonArray();
JsonArray b = new JsonArray();

View File

@ -163,6 +163,7 @@ public class JsonObjectTest {
}
@Test
@SuppressWarnings("TruthSelfEquals")
public void testEqualsNonEmptyObject() {
JsonObject a = new JsonObject();
JsonObject b = new JsonObject();

View File

@ -227,7 +227,8 @@ public class TestTypes {
}
}
@SuppressWarnings("overrides") // for missing hashCode() override
// for missing hashCode() override
@SuppressWarnings({"overrides", "EqualsHashCode"})
public static class ClassWithNoFields {
// Nothing here..
@Override

View File

@ -103,7 +103,7 @@ public class DefaultTypeAdaptersTest {
@Test
public void testClassDeserialization() {
try {
gson.fromJson("String.class", String.class.getClass());
gson.fromJson("String.class", Class.class);
fail();
} catch (UnsupportedOperationException expected) {
}

View File

@ -122,11 +122,11 @@ public class InstanceCreatorTest {
Type sortedSetType = new TypeToken<SortedSet<String>>() {}.getType();
SortedSet<String> 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);
}
}

View File

@ -18,7 +18,7 @@ package com.google.gson.functional;
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;

View File

@ -73,7 +73,8 @@ public class TypeVariableTest {
assertThat(blue2).isEqualTo(blue1);
}
@SuppressWarnings("overrides") // for missing hashCode() override
// for missing hashCode() override
@SuppressWarnings({"overrides", "EqualsHashCode"})
public static class Blue extends Red<Boolean> {
public Blue() {
super(false);
@ -103,7 +104,7 @@ public class TypeVariableTest {
}
}
@SuppressWarnings("overrides") // for missing hashCode() override
@SuppressWarnings({"overrides", "EqualsHashCode"}) // for missing hashCode() override
public static class Foo<S, T> extends Red<Boolean> {
private S someSField;
private T someTField;

View File

@ -1698,7 +1698,8 @@ public final class JsonReaderTest {
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();

42
pom.xml
View File

@ -94,12 +94,32 @@
<configuration>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<failOnWarning>true</failOnWarning>
<fork>true</fork>
<compilerArgs>
<!-- Args related to Error Prone, see: https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED</arg>
<arg>-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED</arg>
<arg>-J--add-opens=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED</arg>
<!-- Enable all warnings, except for ones which cause issues when building with newer JDKs, see also
https://docs.oracle.com/en/java/javase/11/tools/javac.html -->
<compilerArg>-Xlint:all,-options</compilerArg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.18.0</version>
</path>
</annotationProcessorPaths>
<jdkToolchain>
<version>[11,)</version>
</jdkToolchain>
@ -271,6 +291,26 @@
</build>
<profiles>
<!-- Disable Error Prone in Java 15 -->
<profile>
<id>jdk15</id>
<activation>
<jdk>15</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs combine.self="override">
<compilerArg>-Xlint:all,-options</compilerArg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<!-- Profile defining additional plugins to be executed for release -->
<profile>
<id>release</id>