From e06a8cec65815599e510d7f9c1ea9d2a8eaa438a Mon Sep 17 00:00:00 2001 From: cpovirk Date: Wed, 3 Aug 2022 18:36:27 -0700 Subject: [PATCH] Enable Error Prone for Maven builds. Fixes https://github.com/google/guava/issues/2484 RELNOTES=n/a PiperOrigin-RevId: 465199181 --- .../common/collect/testing/Platform.java | 2 +- .../reflect/TypeTokenResolutionTest.java | 2 ++ .../common/reflect/TypeTokenSubtypeTest.java | 6 ++++ .../google/common/reflect/TypeTokenTest.java | 1 + android/pom.xml | 34 +++++++++++++++++++ .../common/collect/testing/Platform.java | 2 +- .../reflect/TypeTokenResolutionTest.java | 2 ++ .../common/reflect/TypeTokenSubtypeTest.java | 6 ++++ .../google/common/reflect/TypeTokenTest.java | 1 + pom.xml | 34 +++++++++++++++++++ 10 files changed, 88 insertions(+), 2 deletions(-) diff --git a/android/guava-testlib/src/com/google/common/collect/testing/Platform.java b/android/guava-testlib/src/com/google/common/collect/testing/Platform.java index a2c020c915d4..cfc7ac3b284e 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/Platform.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/Platform.java @@ -34,7 +34,7 @@ static 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) { diff --git a/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java b/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java index 69e59ff18895..2aa7ae5e8b97 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java @@ -178,10 +178,12 @@ public void testResolveNestedClass() { assertEquals(String.class, new Owner.Nested() {}.getTypeArgument()); } + @SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports public void testResolveInnerClass() { assertEquals(String.class, new Owner().new Inner() {}.getTypeArgument()); } + @SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports public void testResolveOwnerClass() { assertEquals(Integer.class, new Owner().new Inner() {}.getOwnerType()); } diff --git a/android/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java b/android/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java index 0dd2318e9776..4905df74ef18 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java @@ -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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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().new Shop() {}.getClass(); assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass)); @@ -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().new Shop() {}.getClass(); assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass)); diff --git a/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index cb0dc99404fc..daf348662fea 100644 --- a/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/android/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -1747,6 +1747,7 @@ Type type() { } } + @SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports public void testRejectTypeVariable_withOwnerType() { // Neither has subclass assertHasTypeVariable(new From().new To().type()); diff --git a/android/pom.xml b/android/pom.xml index 27450e0573a3..1b4a65c0b2ea 100644 --- a/android/pom.xml +++ b/android/pom.xml @@ -18,6 +18,7 @@ 3.12.0 1.20 3.1.0 + 9+181-r4173-1 3.2.1 @@ -122,6 +123,7 @@ 1.8 1.8 + UTF-8 -sourcepath doesnotexist + + -XDcompilePolicy=simple + -Xplugin:ErrorProne + + + com.google.errorprone + error_prone_core + + 2.10.0 + + @@ -427,5 +440,26 @@ + + + jdk8 + + 1.8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + + -J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar + + + + + + diff --git a/guava-testlib/src/com/google/common/collect/testing/Platform.java b/guava-testlib/src/com/google/common/collect/testing/Platform.java index a2c020c915d4..cfc7ac3b284e 100644 --- a/guava-testlib/src/com/google/common/collect/testing/Platform.java +++ b/guava-testlib/src/com/google/common/collect/testing/Platform.java @@ -34,7 +34,7 @@ static 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) { diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java index 69e59ff18895..2aa7ae5e8b97 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenResolutionTest.java @@ -178,10 +178,12 @@ public void testResolveNestedClass() { assertEquals(String.class, new Owner.Nested() {}.getTypeArgument()); } + @SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports public void testResolveInnerClass() { assertEquals(String.class, new Owner().new Inner() {}.getTypeArgument()); } + @SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports public void testResolveOwnerClass() { assertEquals(Integer.class, new Owner().new Inner() {}.getOwnerType()); } diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java index 0dd2318e9776..4905df74ef18 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenSubtypeTest.java @@ -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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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.Shop>() {}; Class subclass = new Mall().new Shop() {}.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().new Shop() {}.getClass(); assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass)); @@ -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().new Shop() {}.getClass(); assertTrue(TypeToken.of(superclass).isSubtypeOf(superclass)); diff --git a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java index cb0dc99404fc..daf348662fea 100644 --- a/guava-tests/test/com/google/common/reflect/TypeTokenTest.java +++ b/guava-tests/test/com/google/common/reflect/TypeTokenTest.java @@ -1747,6 +1747,7 @@ Type type() { } } + @SuppressWarnings("RestrictedApiChecker") // crashes under JDK8, which EP no longer supports public void testRejectTypeVariable_withOwnerType() { // Neither has subclass assertHasTypeVariable(new From().new To().type()); diff --git a/pom.xml b/pom.xml index 143c649e9bfb..eb4ab9317906 100644 --- a/pom.xml +++ b/pom.xml @@ -18,6 +18,7 @@ 3.12.0 1.20 3.1.0 + 9+181-r4173-1 3.2.1 @@ -123,6 +124,7 @@ 1.8 1.8 + UTF-8 -sourcepath doesnotexist + + -XDcompilePolicy=simple + -Xplugin:ErrorProne + + + com.google.errorprone + error_prone_core + + 2.10.0 + + @@ -434,5 +447,26 @@ + + + jdk8 + + 1.8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + + true + + -J-Xbootclasspath/p:${settings.localRepository}/com/google/errorprone/javac/${javac.version}/javac-${javac.version}.jar + + + + + +