diff options
author | Pete Gillin <peteg@google.com> | 2018-05-23 13:32:48 +0100 |
---|---|---|
committer | Pete Gillin <peteg@google.com> | 2018-05-23 16:47:35 +0100 |
commit | 62244591b9a0d651ff1f8473ccf8973a259f9cdb (patch) | |
tree | 6453ca7680ab0cb7246c1692a9120a629009d94e /annotations/generate_annotated_java_files.py | |
parent | 60fe74e5309855153e768bcb6577a1ca9d266d88 (diff) |
Improve some nullability annotations for List.
The effects of this change are:
was: boolean containsAll(@NonNull Collection<@Nullable ?> c)
now: boolean containsAll(@NonNull Collection<?> c)
was: boolean addAll(@NonNull Collection<@NullFromTypeParam ? extends E> c)
now: boolean addAll(@NonNull Collection<? extends @NullFromTypeParam E> c)
was: boolean addAll(int index, @NonNull Collection<@NullFromTypeParam ? extends E> c)
now: boolean addAll(int index, @NonNull Collection<? extends @NullFromTypeParam E> c)
was: default void sort(@Nullable Comparator<? super E> c)
now: default void sort(@Nullable Comparator<? super @NullFromTypeParam E> c)
was: Object @NonNull [] toArray();
now: @Nullable Object @NonNull [] toArray();
was: <T> T @NonNull [] toArray(T @NonNull [] a)
now: <T> @Nullable T @NonNull [] toArray(T @NonNull [] a)
Reasoning:
For addAll: This is the correct change because @NullFromTypeParam
should apply to the type param, which is the bound of the wildcard,
not to the wildcard itself. (See the type-path production in
https://checkerframework.org/annotation-file-utilities/annotation-file-format.html
to understand the actual .jaif change here.)
For containAll: Nullable is the default for ?. We don't annotate it
anywhere else it occurs (removeAll, retainAll)
For sort: This appears to have been an oversight previously.
For toArray: In both cases, we declare that it returns a non-null
array of nullables. The nullability of the array contents was missing
before. In reality, it will have the nullability of the list contents,
but that isn't available. In the no-arg case, we're getting back an
Object array and we can't say that those Objects aren't null. In the
one-arg case, we're getting back an array of whatever type we passed
in, with an unsafe cast. You could hava a List of Nullables, call
toArray with an array of non-nulls, and the array you'd get back could
have nulls in it. So we have to say it's an array of nullables anyway.
(Aside: Automatically detecting these kinds of problem is on the roadmap.)
Bug: 64930165
Test: make doc, and compare the generated annotated sources before + after
Change-Id: I8a2a0394b69a7b8dcaafd6385767779c2667231b
Diffstat (limited to 'annotations/generate_annotated_java_files.py')
0 files changed, 0 insertions, 0 deletions