#1148 added support for @MonotonicNonNull for non-static fields. It would be great to have this work for static fields as well. Right now a static field with the annotation is treated as if it were annotated with @Nullable.
Example in chrome where this would be useful: ServiceLoaderUtil.sOverridesForTesting
import org.chromium.build.annotations.NullMarked;
import org.chromium.build.annotations.MonotonicNonNull;
import java.util.Map;
@NullMarked
public final class Foo {
private static @MonotonicNonNull Map<Class<?>, Object> sOverridesForTesting;
public static void doLater(Runnable r) {
}
public static void test() {
if (sOverridesForTesting == null) {
sOverridesForTesting = Map.of();
}
doLater(() -> sOverridesForTesting.clear());
}
}
Foo.java:16: warning: [NullAway] dereferenced expression sOverridesForTesting is @Nullable
doLater(() -> sOverridesForTesting.clear());
^
(see http://t.uber.com/nullaway )
#1148 added support for
@MonotonicNonNullfor non-static fields. It would be great to have this work for static fields as well. Right now a static field with the annotation is treated as if it were annotated with@Nullable.Example in chrome where this would be useful: ServiceLoaderUtil.sOverridesForTesting