Skip to content

Commit

Permalink
Use @NullMarked instead of our custom `@ElementTypesAreNonnullByDef…
Browse files Browse the repository at this point in the history
…ault` annotations.

This is the first 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: 707134516
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Dec 18, 2024
1 parent e25ee0c commit 9dd412f
Show file tree
Hide file tree
Showing 1,798 changed files with 779 additions and 3,381 deletions.
4 changes: 4 additions & 0 deletions android/guava-testlib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
unit testing - particularly to assist the tests for Guava itself.
</description>
<dependencies>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
@Ignore("test runners must not instantiate and run this directly, only via suites we build")
// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
@ElementTypesAreNonnullByDefault
public abstract class AbstractCollectionTester<E extends @Nullable Object>
extends AbstractContainerTester<Collection<E>, E> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
@Ignore("test runners must not instantiate and run this directly, only via suites we build")
// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
@ElementTypesAreNonnullByDefault
public abstract class AbstractContainerTester<C, E extends @Nullable Object>
extends AbstractTester<OneSizeTestContainerGenerator<C, E>> {
protected SampleElements<E> samples;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
* @author Chris Povirk
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
abstract class AbstractIteratorTester<E extends @Nullable Object, I extends Iterator<E>> {
private Stimulus<E, ? super I>[] stimuli;
private final Iterator<E> elementsToInsert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
@Ignore("test runners must not instantiate and run this directly, only via suites we build")
// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
@ElementTypesAreNonnullByDefault
public abstract class AbstractMapTester<K extends @Nullable Object, V extends @Nullable Object>
extends AbstractContainerTester<Map<K, V>, Entry<K, V>> {
protected Map<K, V> getMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @author George van den Driessche
*/
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public class AbstractTester<G> extends TestCase {
private G subjectGenerator;
private String suiteName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class DerivedCollectionGenerators {
public static class MapEntrySetGenerator<K extends @Nullable Object, V extends @Nullable Object>
implements TestSetGenerator<Entry<K, V>>, DerivedGenerator {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.checkerframework.checker.nullness.qual.Nullable;

@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
public class Helpers {
// Clone of Objects.equal
static boolean equal(@Nullable Object a, @Nullable Object b) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@
* <p>Each package's copy of this annotation needs to be listed in our {@code pom.xml}.
*/
@Target({METHOD, CONSTRUCTOR, TYPE})
@ElementTypesAreNonnullByDefault
@interface IgnoreJRERequirement {}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
* @author Chris Povirk
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class IteratorTester<E extends @Nullable Object>
extends AbstractIteratorTester<E, Iterator<E>> {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
* @author Chris Povirk
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class ListIteratorTester<E extends @Nullable Object>
extends AbstractIteratorTester<E, ListIterator<E>> {
protected ListIteratorTester(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
// check the order if so.
// TODO: Refactor to share code with SetTestBuilder etc.
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class MapInterfaceTest<K extends @Nullable Object, V extends @Nullable Object>
extends TestCase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public class MinimalCollection<E extends @Nullable Object> extends AbstractCollection<E> {
// TODO: expose allow nulls parameter?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
* @author Regina O'Dell
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public class MinimalSet<E extends @Nullable Object> extends MinimalCollection<E> implements Set<E> {

@SuppressWarnings("unchecked") // empty Object[] as E[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public final class OneSizeGenerator<T, E extends @Nullable Object>
implements OneSizeTestContainerGenerator<T, E> {
private final TestContainerGenerator<T, E> generator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface OneSizeTestContainerGenerator<T, E extends @Nullable Object>
extends TestSubjectGenerator<T>, TestContainerGenerator<T, E> {
TestContainerGenerator<T, E> getInnerGenerator();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@

/** Replacements for JUnit's {@code assertThrows} that work under GWT/J2CL. */
@GwtCompatible(emulated = true)
@ElementTypesAreNonnullByDefault
final class ReflectionFreeAssertThrows {
interface ThrowingRunnable {
void run() throws Throwable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public class SampleElements<E extends @Nullable Object> implements Iterable<E> {
// TODO: rename e3, e4 => missing1, missing2
private final E e0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
* @since 33.4.0 (but since 21.0 in the JRE flavor)
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
@SuppressWarnings("Java7ApiChecker")
@IgnoreJRERequirement // Users will use this only if they're already using Spliterator.
public final class SpliteratorTester<E extends @Nullable Object> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Louis Wasserman
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestCharacterListGenerator implements TestListGenerator<Character> {
@Override
public SampleElements<Character> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestCollectionGenerator<E extends @Nullable Object>
extends TestContainerGenerator<Collection<E>, E> {}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestCollidingSetGenerator implements TestSetGenerator<Object> {
@Override
public SampleElements<Object> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestContainerGenerator<T, E extends @Nullable Object> {
/** Returns the sample elements that this generate populates its container with. */
SampleElements<E> samples();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestEnumMapGenerator implements TestMapGenerator<AnEnum, String> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestEnumSetGenerator implements TestSetGenerator<AnEnum> {
@Override
public SampleElements<AnEnum> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Gregory Kick
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestIntegerSetGenerator implements TestSetGenerator<Integer> {
@Override
public SampleElements<Integer> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @author Jared Levy
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestIntegerSortedSetGenerator extends TestIntegerSetGenerator {
@Override
protected abstract SortedSet<Integer> create(Integer[] elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestListGenerator<E extends @Nullable Object> extends TestCollectionGenerator<E> {
@Override
List<E> create(Object... elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @author Jesse Wilson
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestMapEntrySetGenerator<
K extends @Nullable Object, V extends @Nullable Object>
implements TestSetGenerator<Map.Entry<K, V>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestMapGenerator<K extends @Nullable Object, V extends @Nullable Object>
extends TestContainerGenerator<Map<K, V>, Map.Entry<K, V>> {
K[] createKeyArray(int length);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author Jared Levy
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestQueueGenerator<E extends @Nullable Object> extends TestCollectionGenerator<E> {
@Override
Queue<E> create(Object... elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestSetGenerator<E extends @Nullable Object> extends TestCollectionGenerator<E> {
@Override
Set<E> create(Object... elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Louis Wasserman
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestSortedMapGenerator<K extends @Nullable Object, V extends @Nullable Object>
extends TestMapGenerator<K, V> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author Louis Wasserman
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestSortedSetGenerator<E extends @Nullable Object> extends TestSetGenerator<E> {
@Override
SortedSet<E> create(Object... elements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Jared Levy
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringCollectionGenerator implements TestCollectionGenerator<String> {
@Override
public SampleElements<String> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringListGenerator implements TestListGenerator<String> {
@Override
public SampleElements<String> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringMapGenerator implements TestMapGenerator<String, String> {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Jared Levy
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringQueueGenerator implements TestQueueGenerator<String> {
@Override
public SampleElements<String> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Kevin Bourrillion
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringSetGenerator implements TestSetGenerator<String> {
@Override
public SampleElements<String> samples() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @author Chris Povirk
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringSortedMapGenerator extends TestStringMapGenerator
implements TestSortedMapGenerator<String, String> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* @author Jared Levy
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestStringSortedSetGenerator extends TestStringSetGenerator
implements TestSortedSetGenerator<String> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author George van den Driessche
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public interface TestSubjectGenerator<T extends @Nullable Object> {
T createTestSubject();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
* @author Regina O'Dell
*/
@GwtCompatible
@ElementTypesAreNonnullByDefault
public abstract class TestUnhashableCollectionGenerator<T extends Collection<UnhashableObject>>
implements TestCollectionGenerator<UnhashableObject> {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
@Ignore("test runners must not instantiate and run this directly, only via suites we build")
// @Ignore affects the Android test runner, which respects JUnit 4 annotations on JUnit 3 tests.
@SuppressWarnings("JUnit4ClassUsedInJUnit3")
@ElementTypesAreNonnullByDefault
public abstract class AbstractBiMapTester<K extends @Nullable Object, V extends @Nullable Object>
extends AbstractMapTester<K, V> {

Expand Down
Loading

0 comments on commit 9dd412f

Please sign in to comment.