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.
* @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"})
@Pure
public static <T> T checkStateNotNull(@Nullable T reference) {
@ -128,7 +133,12 @@ public final class Assertions {
* @return The non-null reference that was validated.
* @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"})
@Pure
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.
* @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"})
@Pure
public static <T> T checkNotNull(@Nullable T reference) {
@ -166,7 +181,12 @@ public final class Assertions {
* @return The non-null reference that was validated.
* @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"})
@Pure
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.
* @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"})
@Pure
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.
* @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"})
@Pure
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".
@SuppressWarnings("nullness:argument.type.incompatible")
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:argument"})
@Nullable
private static IBinder getBinderByReflection(Bundle bundle, @Nullable String key) {
@Nullable Method getIBinder = getIBinderMethod;
@ -85,7 +85,7 @@ public final class BundleUtil {
}
// Method.invoke may take null "key" and "binder".
@SuppressWarnings("nullness:argument.type.incompatible")
@SuppressWarnings({"nullness:argument.type.incompatible", "nullness:argument"})
private static void putBinderByReflection(
Bundle bundle, @Nullable String key, @Nullable IBinder binder) {
@Nullable Method putIBinder = putIBinderMethod;

View File

@ -102,7 +102,7 @@ public final class ListenerSet<T> {
flushingEvents = new ArrayDeque<>();
queuedEvents = new ArrayDeque<>();
// 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);
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 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) {
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.
*/
@SuppressWarnings({"contracts.postcondition.not.satisfied", "return.type.incompatible"})
@SuppressWarnings({
"contracts.postcondition.not.satisfied",
"nullness:contracts.postcondition",
"return.type.incompatible",
"nullness:return"
})
@EnsuresNonNull("#1")
public static <T> T castNonNull(@Nullable T value) {
return value;
}
/** 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")
public static <T> T[] castNonNullTypeArray(@NullableType T[] 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.
* @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) {
Assertions.checkArgument(length <= 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.
* @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) {
Assertions.checkArgument(0 <= from);
Assertions.checkArgument(to <= input.length);
@ -397,7 +417,7 @@ public final class Util {
* @param second The second array.
* @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) {
T[] concatenation = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(
@ -491,7 +511,12 @@ public final class Util {
* callback is required.
* @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(
Looper looper, @Nullable Handler.@UnknownInitialization Callback callback) {
return new Handler(looper, callback);
@ -1212,7 +1237,11 @@ public final class Util {
*/
// incompatible types in argument.
// 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 {
Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
if (!matcher.matches()) {