aboutsummaryrefslogtreecommitdiff
path: root/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/guava-testlib/src/com/google/common/testing/NullPointerTester.java')
-rw-r--r--android/guava-testlib/src/com/google/common/testing/NullPointerTester.java43
1 files changed, 8 insertions, 35 deletions
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 73c5705ba..d0202b471 100644
--- a/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java
+++ b/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java
@@ -35,7 +35,6 @@ import com.google.common.reflect.Reflection;
import com.google.common.reflect.TypeToken;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.lang.annotation.Annotation;
-import java.lang.reflect.AnnotatedType;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
@@ -43,7 +42,6 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
@@ -353,9 +351,9 @@ public final class NullPointerTester {
@Nullable 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.
+ * Android VMs and in open-source guava-android. So we skip testing there.
*/
- if (isAndroid() && Reflection.getPackageName(testedClass).startsWith("com.google.common")) {
+ if (Reflection.getPackageName(testedClass).startsWith("com.google.common")) {
return;
}
if (isPrimitiveOrNullable(invokable.getParameters().get(paramIndex))) {
@@ -604,47 +602,27 @@ public final class NullPointerTester {
* Looks for declaration nullness annotations and, if supported, type-use nullness annotations.
*
* <p>Under Android VMs, the methods for retrieving type-use annotations don't exist. This means
- * that {@link NullPointerException} may misbehave under Android when used on classes that rely on
+ * that {@link NullPointerTester} may misbehave under Android when used on classes that rely on
* type-use annotations.
*
* <p>Under j2objc, the necessary APIs exist, but some (perhaps all) return stub values, like
- * empty arrays. Presumably {@link NullPointerException} could likewise misbehave under j2objc,
- * but I don't know that anyone uses it there, anyway.
+ * empty arrays. Presumably {@link NullPointerTester} could likewise misbehave under j2objc, but I
+ * don't know that anyone uses it there, anyway.
*/
private enum NullnessAnnotationReader {
- // Usages (which are unsafe only for Android) are guarded by the annotatedTypeExists() check.
- @SuppressWarnings({"Java7ApiChecker", "AndroidApiChecker", "DoNotCall", "deprecation"})
+ @SuppressWarnings("Java7ApiChecker")
FROM_DECLARATION_AND_TYPE_USE_ANNOTATIONS {
@Override
- @IgnoreJRERequirement
boolean isNullable(Invokable<?, ?> invokable) {
return FROM_DECLARATION_ANNOTATIONS_ONLY.isNullable(invokable)
- || containsNullable(invokable.getAnnotatedReturnType().getAnnotations());
+ ;
// TODO(cpovirk): Should we also check isNullableTypeVariable?
}
@Override
- @IgnoreJRERequirement
boolean isNullable(Parameter param) {
return FROM_DECLARATION_ANNOTATIONS_ONLY.isNullable(param)
- || containsNullable(param.getAnnotatedType().getAnnotations())
- || isNullableTypeVariable(param.getAnnotatedType().getType());
- }
-
- @IgnoreJRERequirement
- boolean isNullableTypeVariable(Type type) {
- if (!(type instanceof TypeVariable)) {
- return false;
- }
- TypeVariable<?> typeVar = (TypeVariable<?>) type;
- for (AnnotatedType bound : typeVar.getAnnotatedBounds()) {
- // Until Java 15, the isNullableTypeVariable case here won't help:
- // https://bugs.openjdk.java.net/browse/JDK-8202469
- if (containsNullable(bound.getAnnotations()) || isNullableTypeVariable(bound.getType())) {
- return true;
- }
- }
- return false;
+ ;
}
},
FROM_DECLARATION_ANNOTATIONS_ONLY {
@@ -663,9 +641,4 @@ public final class NullPointerTester {
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 checkNotNull(System.getProperty("java.runtime.name", "")).contains("Android");
- }
}