diff --git a/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java b/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java index 82b761bdcd11..413ba66cedeb 100644 --- a/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java +++ b/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java @@ -349,6 +349,13 @@ public int hashCode() { */ private void testParameter( Object instance, Invokable invokable, int paramIndex, Class testedClass) { + /* + * com.google.common is starting to rely on type-use annotations, which aren't visible under + * Android VMs. So we skip testing there. + */ + if (isAndroid() && Reflection.getPackageName(testedClass).startsWith("com.google.common")) { + return; + } if (isPrimitiveOrNullable(invokable.getParameters().get(paramIndex))) { return; // there's nothing to test } @@ -654,4 +661,9 @@ boolean isNullable(Parameter param) { abstract boolean isNullable(Parameter param); } + + private static boolean isAndroid() { + // Arguably it would make more sense to test "can we see type-use annotations" directly.... + return System.getProperty("java.runtime.name").contains("Android"); + } } diff --git a/android/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java b/android/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java index 3c8730516533..fee11890b7db 100644 --- a/android/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java +++ b/android/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java @@ -43,7 +43,7 @@ * * @author Ben Yu */ -@AndroidIncompatible // Android doesn't support the type-use annotations it needs +@AndroidIncompatible // NullPointerTester refuses to run for c.g.c under Android public class ClassSanityTesterTest extends TestCase { private final ClassSanityTester tester = new ClassSanityTester(); diff --git a/android/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java b/android/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java index 4db9310d2a50..d7344abf66dd 100644 --- a/android/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java +++ b/android/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java @@ -56,7 +56,7 @@ * @author Mick Killianey */ @SuppressWarnings("CheckReturnValue") -@AndroidIncompatible // Android doesn't support the type-use annotations it needs +@AndroidIncompatible // NullPointerTester refuses to run for c.g.c under Android public class NullPointerTesterTest extends TestCase { /** Non-NPE RuntimeException. */ diff --git a/guava-testlib/src/com/google/common/testing/NullPointerTester.java b/guava-testlib/src/com/google/common/testing/NullPointerTester.java index 5780dd721d1c..87349a8d882d 100644 --- a/guava-testlib/src/com/google/common/testing/NullPointerTester.java +++ b/guava-testlib/src/com/google/common/testing/NullPointerTester.java @@ -349,6 +349,13 @@ public int hashCode() { */ private void testParameter( Object instance, Invokable invokable, int paramIndex, Class testedClass) { + /* + * com.google.common is starting to rely on type-use annotations, which aren't visible under + * Android VMs. So we skip testing there. + */ + if (isAndroid() && Reflection.getPackageName(testedClass).startsWith("com.google.common")) { + return; + } if (isPrimitiveOrNullable(invokable.getParameters().get(paramIndex))) { return; // there's nothing to test } @@ -654,4 +661,9 @@ boolean isNullable(Parameter param) { abstract boolean isNullable(Parameter param); } + + private static boolean isAndroid() { + // Arguably it would make more sense to test "can we see type-use annotations" directly.... + return System.getProperty("java.runtime.name").contains("Android"); + } } diff --git a/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java b/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java index be7fbe08fcc8..ac4e05fba983 100644 --- a/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/ClassSanityTesterTest.java @@ -45,7 +45,7 @@ * * @author Ben Yu */ -@AndroidIncompatible // Android doesn't support the type-use annotations it needs +@AndroidIncompatible // NullPointerTester refuses to run for c.g.c under Android public class ClassSanityTesterTest extends TestCase { private final ClassSanityTester tester = new ClassSanityTester(); diff --git a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java index 9c3d18d96712..050f05f6d97e 100644 --- a/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java +++ b/guava-testlib/test/com/google/common/testing/NullPointerTesterTest.java @@ -56,7 +56,7 @@ * @author Mick Killianey */ @SuppressWarnings("CheckReturnValue") -@AndroidIncompatible // Android doesn't support the type-use annotations it needs +@AndroidIncompatible // NullPointerTester refuses to run for c.g.c under Android public class NullPointerTesterTest extends TestCase { /** Non-NPE RuntimeException. */