Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Error Prone for Maven builds. #6128

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static <T> T[] clone(T[] array) {

// Class.cast is not supported in GWT. This method is a no-op in GWT.
static void checkCast(Class<?> clazz, Object obj) {
clazz.cast(obj);
Object unused = clazz.cast(obj);
}

static String format(String template, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ public void testResolveNestedClass() {
assertEquals(String.class, new Owner.Nested<String>() {}.getTypeArgument());
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testResolveInnerClass() {
assertEquals(String.class, new Owner<Integer>().new Inner<String>() {}.getTypeArgument());
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testResolveOwnerClass() {
assertEquals(Integer.class, new Owner<Integer>().new Inner<String>() {}.getOwnerType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,35 @@ public void testRecursiveWildcardSubtypeBug() throws Exception {
}
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfInnerClass_nonStaticAnonymousClass() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfInnerClass_nonStaticAnonymousClass_typeParameterOfOwnerTypeNotMatch() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Indoor>().new Shop<Electronics>() {}.getClass();
assertFalse(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfInnerClass_nonStaticAnonymousClass_typeParameterOfInnerTypeNotMatch() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Outdoor>().new Shop<Grocery>() {}.getClass();
assertFalse(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public static void testSubtypeOfInnerClass_staticAnonymousClass() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public static void testSubtypeOfStaticAnonymousClass() {
Class<?> superclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass));
Expand All @@ -79,6 +84,7 @@ public static void testSubtypeOfStaticAnonymousClass() {
.isSubtypeOf(superclass));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfNonStaticAnonymousClass() {
Class<?> superclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,7 @@ Type type() {
}
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public <T> void testRejectTypeVariable_withOwnerType() {
// Neither has subclass
assertHasTypeVariable(new From<Integer>().new To<String>().type());
Expand Down
34 changes: 34 additions & 0 deletions android/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<checker-framework.version>3.12.0</checker-framework.version>
<animal.sniffer.version>1.20</animal.sniffer.version>
<maven-javadoc-plugin.version>3.1.0</maven-javadoc-plugin.version>
<javac.version>9+181-r4173-1</javac.version>
<!-- Empty for all JDKs but 9-12 -->
<maven-javadoc-plugin.additionalJOptions></maven-javadoc-plugin.additionalJOptions>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
Expand Down Expand Up @@ -122,6 +123,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<!--
Make includes/excludes fully work:
Expand All @@ -131,7 +133,18 @@
-->
<arg>-sourcepath</arg>
<arg>doesnotexist</arg>
<!-- https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<!-- https://errorprone.info/docs/installation#jdk-8 -->
<version>2.10.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -427,5 +440,26 @@
</test.add.opens>
</properties>
</profile>
<!-- https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md#jdk-8 -->
<profile>
<id>jdk8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<compilerArgs combine.children="append">
<arg>-J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static <T> T[] clone(T[] array) {

// Class.cast is not supported in GWT. This method is a no-op in GWT.
static void checkCast(Class<?> clazz, Object obj) {
clazz.cast(obj);
Object unused = clazz.cast(obj);
}

static String format(String template, Object... args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,12 @@ public void testResolveNestedClass() {
assertEquals(String.class, new Owner.Nested<String>() {}.getTypeArgument());
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testResolveInnerClass() {
assertEquals(String.class, new Owner<Integer>().new Inner<String>() {}.getTypeArgument());
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testResolveOwnerClass() {
assertEquals(Integer.class, new Owner<Integer>().new Inner<String>() {}.getOwnerType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,30 +47,35 @@ public void testRecursiveWildcardSubtypeBug() throws Exception {
}
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfInnerClass_nonStaticAnonymousClass() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfInnerClass_nonStaticAnonymousClass_typeParameterOfOwnerTypeNotMatch() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Indoor>().new Shop<Electronics>() {}.getClass();
assertFalse(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfInnerClass_nonStaticAnonymousClass_typeParameterOfInnerTypeNotMatch() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Outdoor>().new Shop<Grocery>() {}.getClass();
assertFalse(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public static void testSubtypeOfInnerClass_staticAnonymousClass() {
TypeToken<?> supertype = new TypeToken<Mall<Outdoor>.Shop<Electronics>>() {};
Class<?> subclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(subclass).isSubtypeOf(supertype));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public static void testSubtypeOfStaticAnonymousClass() {
Class<?> superclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass));
Expand All @@ -79,6 +84,7 @@ public static void testSubtypeOfStaticAnonymousClass() {
.isSubtypeOf(superclass));
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public void testSubtypeOfNonStaticAnonymousClass() {
Class<?> superclass = new Mall<Outdoor>().new Shop<Electronics>() {}.getClass();
assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1747,6 +1747,7 @@ Type type() {
}
}

@SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports
public <T> void testRejectTypeVariable_withOwnerType() {
// Neither has subclass
assertHasTypeVariable(new From<Integer>().new To<String>().type());
Expand Down
34 changes: 34 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<checker-framework.version>3.12.0</checker-framework.version>
<animal.sniffer.version>1.20</animal.sniffer.version>
<maven-javadoc-plugin.version>3.1.0</maven-javadoc-plugin.version>
<javac.version>9+181-r4173-1</javac.version>
<!-- Empty for all JDKs but 9-12 -->
<maven-javadoc-plugin.additionalJOptions></maven-javadoc-plugin.additionalJOptions>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
Expand Down Expand Up @@ -123,6 +124,7 @@
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
<compilerArgs>
<!--
Make includes/excludes fully work:
Expand All @@ -132,7 +134,18 @@
-->
<arg>-sourcepath</arg>
<arg>doesnotexist</arg>
<!-- https://errorprone.info/docs/installation#maven -->
<arg>-XDcompilePolicy=simple</arg>
<arg>-Xplugin:ErrorProne</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<!-- https://errorprone.info/docs/installation#jdk-8 -->
<version>2.10.0</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -434,5 +447,26 @@
</test.add.opens>
</properties>
</profile>
<!-- https://github.com/google/error-prone/blob/f8e33bc460be82ab22256a7ef8b979d7a2cacaba/docs/installation.md#jdk-8 -->
<profile>
<id>jdk8</id>
<activation>
<jdk>1.8</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<compilerArgs combine.children="append">
<arg>-J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>