Skip to content

Commit 8ebb375

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedDec 21, 2024·
Use @NullMarked instead of our custom @ElementTypesAreNonnullByDefault annotations.
This is the next step toward [using JSpecify in Guava](jspecify/jspecify#239 (comment)). At the end of that path, we'll be able to [remove our dependency on JSR-305](#2960) (and on the Checker Framework's annotations), and we'll have one less blocker to [providing a `module-info`](#2970). `@NullMarked` allows tools like kotlinc to produce errors for code like `ImmutableList<String?>`. (Before releasing this change, I'll conduct some further testing to more fully characterize the effects, both under Kotlin 2.1 and prior.) As we make further changes, it will allow kotlinc to detect even more nullness problems. We will make these changes in a series of incremental releases so that users can pick them up gradually, as we did inside Google. In simple cases, users may wish to pick up all the changes at once instead by upgrading straight from Guava 33.4.0 (or an earlier version) to Guava 33.4.4 (or whatever the version to make the final changes ends up being). RELNOTES=Replaced our custom `@ElementTypesAreNonnullByDefault` annotations with the JSpecify `@NullMarked` annotation. PiperOrigin-RevId: 708598410
1 parent ce43463 commit 8ebb375

File tree

595 files changed

+1144
-1855
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

595 files changed

+1144
-1855
lines changed
 

Diff for: ‎android/guava-testlib/src/com/google/common/collect/testing/AbstractCollectionTester.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.google.common.annotations.GwtCompatible;
2020
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2121
import java.util.Collection;
22+
import org.jspecify.annotations.NullMarked;
2223
import org.checkerframework.checker.nullness.qual.Nullable;
2324
import org.junit.Ignore;
2425

@@ -32,7 +33,7 @@
3233
@Ignore("test runners must not instantiate and run this directly, only via suites we build")
3334
// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
3435
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
35-
@ElementTypesAreNonnullByDefault
36+
@NullMarked
3637
public abstract class AbstractCollectionTester<E extends @Nullable Object>
3738
extends AbstractContainerTester<Collection<E>, E> {
3839

Diff for: ‎android/guava-testlib/src/com/google/common/collect/testing/AbstractContainerTester.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.ArrayList;
2828
import java.util.Collection;
2929
import java.util.List;
30+
import org.jspecify.annotations.NullMarked;
3031
import org.checkerframework.checker.nullness.qual.Nullable;
3132
import org.junit.Ignore;
3233

@@ -42,7 +43,7 @@
4243
@Ignore("test runners must not instantiate and run this directly, only via suites we build")
4344
// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
4445
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
45-
@ElementTypesAreNonnullByDefault
46+
@NullMarked
4647
public abstract class AbstractContainerTester<C, E extends @Nullable Object>
4748
extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
4849
protected SampleElements<E> samples;

0 commit comments

Comments
 (0)
Please sign in to comment.