diff options
author | cpovirk <cpovirk@google.com> | 2021-04-05 13:52:13 -0700 |
---|---|---|
committer | Google Java Core Libraries <java-core-libraries-team+copybara@google.com> | 2021-04-05 13:54:57 -0700 |
commit | a6489b698173d00ce4d3106642705e2c460eb00a (patch) | |
tree | 9fced7ea6abd69925040d4d59510c74ae776ae5d | |
parent | 77351571c97870a3f4caadb9ee689724b46e4c91 (diff) | |
download | guava-a6489b698173d00ce4d3106642705e2c460eb00a.tar.gz |
Recognize `@ParametricNullness` in `NullPointerTester`.
In short: Take a method parameter whose type is a type-variable usage `T`. `NullPointerTester` assumed that the method should throw an exception when passed `null` unless the parameter type is annotated `@Nullable T`. But for a type like `Predicate<T>`, we don't want a `Predicate<@Nullable String>` to throw an exception if passed `null`. The only case in which a class should _definitely_ throw for such a parameter is if it doesn't permit nullable type arguments at all (like `ImmutableList`). Yet, in our new world, we don't want to annotate the argument of `Predicate.apply` as `@Nullable`.
The annotation `@ParametricNullness` is our new way of distinguishing `Predicate` (where we'll use it) from `ImmutableList` (where we won't).
Eventually, we will remove the annotation, at which point we'll either update `NullPointerTester` to distinguish `Predicate` from `ImmutableList` based on their type parameters' bounds or else we'll disable `NullPointerTester` at least temporarily.
RELNOTES=n/a
PiperOrigin-RevId: 366867268
-rw-r--r-- | android/guava-testlib/src/com/google/common/testing/NullPointerTester.java | 3 | ||||
-rw-r--r-- | guava-testlib/src/com/google/common/testing/NullPointerTester.java | 3 |
2 files changed, 4 insertions, 2 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 a32a53b7b..1099854d1 100644 --- a/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java +++ b/android/guava-testlib/src/com/google/common/testing/NullPointerTester.java @@ -474,7 +474,8 @@ public final class NullPointerTester { } private static final ImmutableSet<String> NULLABLE_ANNOTATION_SIMPLE_NAMES = - ImmutableSet.of("CheckForNull", "Nullable", "NullableDecl", "NullableType"); + ImmutableSet.of( + "CheckForNull", "Nullable", "NullableDecl", "NullableType", "ParametricNullness"); static boolean isNullable(AnnotatedElement e) { for (Annotation annotation : e.getAnnotations()) { diff --git a/guava-testlib/src/com/google/common/testing/NullPointerTester.java b/guava-testlib/src/com/google/common/testing/NullPointerTester.java index cd0dd15a6..785870cdd 100644 --- a/guava-testlib/src/com/google/common/testing/NullPointerTester.java +++ b/guava-testlib/src/com/google/common/testing/NullPointerTester.java @@ -473,7 +473,8 @@ public final class NullPointerTester { } private static final ImmutableSet<String> NULLABLE_ANNOTATION_SIMPLE_NAMES = - ImmutableSet.of("CheckForNull", "Nullable", "NullableDecl", "NullableType"); + ImmutableSet.of( + "CheckForNull", "Nullable", "NullableDecl", "NullableType", "ParametricNullness"); static boolean isNullable(Invokable<?, ?> invokable) { return isNullable(invokable.getAnnotatedReturnType().getAnnotations()) |