Update @SuppressWarnings annotations for go/nullness diagnostics

in preparation for upgrading the version of the Checker Framework in google3.

More information: go/checker-3110-lsc

PiperOrigin-RevId: 377374612
This commit is contained in:
olly 2021-06-03 22:32:37 +01:00 committed by bachinger
parent 80927843cb
commit b56b769faa
5 changed files with 80 additions and 17 deletions

View File

@ -108,7 +108,12 @@ public final class Assertions {
* @return The non-null reference that was validated. * @return The non-null reference that was validated.
* @throws IllegalStateException If {@code reference} is null. * @throws IllegalStateException If {@code reference} is null.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull({"#1"}) @EnsuresNonNull({"#1"})
@Pure @Pure
public static <T> T checkStateNotNull(@Nullable T reference) { public static <T> T checkStateNotNull(@Nullable T reference) {
@ -128,7 +133,12 @@ public final class Assertions {
* @return The non-null reference that was validated. * @return The non-null reference that was validated.
* @throws IllegalStateException If {@code reference} is null. * @throws IllegalStateException If {@code reference} is null.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull({"#1"}) @EnsuresNonNull({"#1"})
@Pure @Pure
public static <T> T checkStateNotNull(@Nullable T reference, Object errorMessage) { public static <T> T checkStateNotNull(@Nullable T reference, Object errorMessage) {
@ -146,7 +156,12 @@ public final class Assertions {
* @return The non-null reference that was validated. * @return The non-null reference that was validated.
* @throws NullPointerException If {@code reference} is null. * @throws NullPointerException If {@code reference} is null.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull({"#1"}) @EnsuresNonNull({"#1"})
@Pure @Pure
public static <T> T checkNotNull(@Nullable T reference) { public static <T> T checkNotNull(@Nullable T reference) {
@ -166,7 +181,12 @@ public final class Assertions {
* @return The non-null reference that was validated. * @return The non-null reference that was validated.
* @throws NullPointerException If {@code reference} is null. * @throws NullPointerException If {@code reference} is null.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull({"#1"}) @EnsuresNonNull({"#1"})
@Pure @Pure
public static <T> T checkNotNull(@Nullable T reference, Object errorMessage) { public static <T> T checkNotNull(@Nullable T reference, Object errorMessage) {
@ -183,7 +203,12 @@ public final class Assertions {
* @return The non-null, non-empty string that was validated. * @return The non-null, non-empty string that was validated.
* @throws IllegalArgumentException If {@code string} is null or 0-length. * @throws IllegalArgumentException If {@code string} is null or 0-length.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull({"#1"}) @EnsuresNonNull({"#1"})
@Pure @Pure
public static String checkNotEmpty(@Nullable String string) { public static String checkNotEmpty(@Nullable String string) {
@ -202,7 +227,12 @@ public final class Assertions {
* @return The non-null, non-empty string that was validated. * @return The non-null, non-empty string that was validated.
* @throws IllegalArgumentException If {@code string} is null or 0-length. * @throws IllegalArgumentException If {@code string} is null or 0-length.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull({"#1"}) @EnsuresNonNull({"#1"})
@Pure @Pure
public static String checkNotEmpty(@Nullable String string, Object errorMessage) { public static String checkNotEmpty(@Nullable String string, Object errorMessage) {

View File

@ -61,7 +61,7 @@ public final class BundleUtil {
} }
// Method.invoke may take null "key". // Method.invoke may take null "key".
@SuppressWarnings("nullness:argument.type.incompatible") @SuppressWarnings({"nullness:argument.type.incompatible", "nullness:argument"})
@Nullable @Nullable
private static IBinder getBinderByReflection(Bundle bundle, @Nullable String key) { private static IBinder getBinderByReflection(Bundle bundle, @Nullable String key) {
@Nullable Method getIBinder = getIBinderMethod; @Nullable Method getIBinder = getIBinderMethod;
@ -85,7 +85,7 @@ public final class BundleUtil {
} }
// Method.invoke may take null "key" and "binder". // Method.invoke may take null "key" and "binder".
@SuppressWarnings("nullness:argument.type.incompatible") @SuppressWarnings({"nullness:argument.type.incompatible", "nullness:argument"})
private static void putBinderByReflection( private static void putBinderByReflection(
Bundle bundle, @Nullable String key, @Nullable IBinder binder) { Bundle bundle, @Nullable String key, @Nullable IBinder binder) {
@Nullable Method putIBinder = putIBinderMethod; @Nullable Method putIBinder = putIBinderMethod;

View File

@ -102,7 +102,7 @@ public final class ListenerSet<T> {
flushingEvents = new ArrayDeque<>(); flushingEvents = new ArrayDeque<>();
queuedEvents = new ArrayDeque<>(); queuedEvents = new ArrayDeque<>();
// It's safe to use "this" because we don't send a message before exiting the constructor. // It's safe to use "this" because we don't send a message before exiting the constructor.
@SuppressWarnings("methodref.receiver.bound.invalid") @SuppressWarnings({"methodref.receiver.bound.invalid", "nullness:methodref.receiver.bound"})
HandlerWrapper handler = clock.createHandler(looper, this::handleMessage); HandlerWrapper handler = clock.createHandler(looper, this::handleMessage);
this.handler = handler; this.handler = handler;
} }

View File

@ -35,7 +35,11 @@ public final class ParsableNalUnitBitArray {
* @param offset The byte offset in {@code data} to start reading from. * @param offset The byte offset in {@code data} to start reading from.
* @param limit The byte offset of the end of the bitstream in {@code data}. * @param limit The byte offset of the end of the bitstream in {@code data}.
*/ */
@SuppressWarnings({"initialization.fields.uninitialized", "method.invocation.invalid"}) @SuppressWarnings({
"initialization.fields.uninitialized",
"method.invocation.invalid",
"nullness:method.invocation"
})
public ParsableNalUnitBitArray(byte[] data, int offset, int limit) { public ParsableNalUnitBitArray(byte[] data, int offset, int limit) {
reset(data, offset, limit); reset(data, offset, limit);
} }

View File

@ -335,14 +335,24 @@ public final class Util {
* *
* <p>Use {@link Assertions#checkNotNull(Object)} to throw if the value is null. * <p>Use {@link Assertions#checkNotNull(Object)} to throw if the value is null.
*/ */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull("#1") @EnsuresNonNull("#1")
public static <T> T castNonNull(@Nullable T value) { public static <T> T castNonNull(@Nullable T value) {
return value; return value;
} }
/** Casts a nullable type array to a non-null type array without runtime null check. */ /** Casts a nullable type array to a non-null type array without runtime null check. */
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"}) @SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull("#1") @EnsuresNonNull("#1")
public static <T> T[] castNonNullTypeArray(@NullableType T[] value) { public static <T> T[] castNonNullTypeArray(@NullableType T[] value) {
return value; return value;
@ -356,7 +366,12 @@ public final class Util {
* @param length The output array length. Must be less or equal to the length of the input array. * @param length The output array length. Must be less or equal to the length of the input array.
* @return The copied array. * @return The copied array.
*/ */
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:return.type.incompatible"}) @SuppressWarnings({
"nullness:argument.type.incompatible",
"nullness:argument",
"nullness:return.type.incompatible",
"nullness:return"
})
public static <T> T[] nullSafeArrayCopy(T[] input, int length) { public static <T> T[] nullSafeArrayCopy(T[] input, int length) {
Assertions.checkArgument(length <= input.length); Assertions.checkArgument(length <= input.length);
return Arrays.copyOf(input, length); return Arrays.copyOf(input, length);
@ -370,7 +385,12 @@ public final class Util {
* @param to The end of the range to be copied, exclusive. * @param to The end of the range to be copied, exclusive.
* @return The copied array. * @return The copied array.
*/ */
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:return.type.incompatible"}) @SuppressWarnings({
"nullness:argument.type.incompatible",
"nullness:argument",
"nullness:return.type.incompatible",
"nullness:return"
})
public static <T> T[] nullSafeArrayCopyOfRange(T[] input, int from, int to) { public static <T> T[] nullSafeArrayCopyOfRange(T[] input, int from, int to) {
Assertions.checkArgument(0 <= from); Assertions.checkArgument(0 <= from);
Assertions.checkArgument(to <= input.length); Assertions.checkArgument(to <= input.length);
@ -397,7 +417,7 @@ public final class Util {
* @param second The second array. * @param second The second array.
* @return The concatenated result. * @return The concatenated result.
*/ */
@SuppressWarnings({"nullness:assignment.type.incompatible"}) @SuppressWarnings({"nullness:assignment.type.incompatible", "nullness:assignment"})
public static <T> T[] nullSafeArrayConcatenation(T[] first, T[] second) { public static <T> T[] nullSafeArrayConcatenation(T[] first, T[] second) {
T[] concatenation = Arrays.copyOf(first, first.length + second.length); T[] concatenation = Arrays.copyOf(first, first.length + second.length);
System.arraycopy( System.arraycopy(
@ -491,7 +511,12 @@ public final class Util {
* callback is required. * callback is required.
* @return A {@link Handler} with the specified callback on the current {@link Looper} thread. * @return A {@link Handler} with the specified callback on the current {@link Looper} thread.
*/ */
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:return.type.incompatible"}) @SuppressWarnings({
"nullness:argument.type.incompatible",
"nullness:argument",
"nullness:return.type.incompatible",
"nullness:return"
})
public static Handler createHandler( public static Handler createHandler(
Looper looper, @Nullable Handler.@UnknownInitialization Callback callback) { Looper looper, @Nullable Handler.@UnknownInitialization Callback callback) {
return new Handler(looper, callback); return new Handler(looper, callback);
@ -1212,7 +1237,11 @@ public final class Util {
*/ */
// incompatible types in argument. // incompatible types in argument.
// dereference of possibly-null reference matcher.group(9) // dereference of possibly-null reference matcher.group(9)
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:dereference.of.nullable"}) @SuppressWarnings({
"nullness:argument.type.incompatible",
"nullness:argument",
"nullness:dereference.of.nullable"
})
public static long parseXsDateTime(String value) throws ParserException { public static long parseXsDateTime(String value) throws ParserException {
Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value); Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
if (!matcher.matches()) { if (!matcher.matches()) {