Skip to content

Commit e107aea

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Annotate the rest of the main package (basically just the Java 8 subjects) for nullness.
And move the `@NullMarked` annotation from individual classes up to the package. Motivation: - The annotating is about potentially making things nicer for callers (or any future J2KT use?). - Moving `@NullMarked` to the package is about saving Truth users from [a warning when running Error Prone with `--release 8`](#1320): When `@NullMarked` appears on a _class_, Error Prone processes the entire `NullMarked` class in order to check whether `NullMarked` is `@Inherited`. This leads to `warning: unknown enum constant ElementType.MODULE` because `NullMarked` has `@Target(MODULE, ...)` but `MODULE` isn't available until Java 9. We'll also be fixing this on the Error Prone side, but we might as well work around it on the Truth side, too—and annotate the rest of Truth while we're at it. (In principle, I should now add `@NullUnmarked` to all of Truth's test classes, since they haven't been annotated. But doing so would have little to no effect in practice unless maybe IntelliJ recognizes `@NullUnmarked` (probably not now?) or we improve our nullness offerings in Error Prone. I'm planning to not bother, but let me know if I'm being overly lazy.) Note that this CL applies `@Nullable` to some assertion methods' parameters even though those assertions would always fail if the callers passed `null`. This follows a principle that we'd applied (albeit incompletely) in cl/516515683, which showed that such changes avoided producing build errors in existing, working code. The principle is the same as that discussed for `EqualsTester` in cl/578260904. Fixes #1320 RELNOTES=Annotated the rest of the main package for nullness, and moved the `@NullMarked` annotation from individual classes up to the package to avoid [a warning under `--release 8`](#1320). PiperOrigin-RevId: 651891918
1 parent 8ac91a6 commit e107aea

Some content is hidden

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

62 files changed

+58
-133
lines changed

core/src/main/java/com/google/common/truth/AbstractArraySubject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
import static com.google.common.truth.Fact.simpleFact;
2121

2222
import java.lang.reflect.Array;
23-
import org.jspecify.annotations.NullMarked;
2423
import org.jspecify.annotations.Nullable;
2524

2625
/**
2726
* A common supertype for Array subjects, abstracting some common display and error infrastructure.
2827
*
2928
* @author Christian Gruber ([email protected])
3029
*/
31-
@NullMarked
3230
abstract class AbstractArraySubject extends Subject {
3331
private final @Nullable Object actual;
3432

core/src/main/java/com/google/common/truth/ActualValueInference.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import java.io.InputStream;
3434
import java.util.ArrayList;
3535
import java.util.Map.Entry;
36-
import org.jspecify.annotations.NullMarked;
3736
import org.jspecify.annotations.Nullable;
3837
import org.objectweb.asm.ClassReader;
3938
import org.objectweb.asm.ClassVisitor;
@@ -70,7 +69,6 @@
7069
*/
7170
@GwtIncompatible
7271
@J2ktIncompatible
73-
@NullMarked
7472
final class ActualValueInference {
7573
/** <b>Call {@link Platform#inferDescription} rather than calling this directly.</b> */
7674
static @Nullable String describeActualValue(String className, String methodName, int lineNumber) {

core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@
1919
import static com.google.common.truth.Fact.makeMessage;
2020

2121
import com.google.common.collect.ImmutableList;
22-
import org.jspecify.annotations.NullMarked;
2322
import org.jspecify.annotations.Nullable;
2423

2524
/**
2625
* An {@link AssertionError} composed of structured {@link Fact} instances and other string
2726
* messages.
2827
*/
2928
@SuppressWarnings("OverrideThrowableToString") // We intentionally hide the class name.
30-
@NullMarked
3129
final class AssertionErrorWithFacts extends AssertionError implements ErrorWithFacts {
3230
private final ImmutableList<Fact> facts;
3331

core/src/main/java/com/google/common/truth/BigDecimalSubject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
import static com.google.common.truth.Fact.simpleFact;
2121

2222
import java.math.BigDecimal;
23-
import org.jspecify.annotations.NullMarked;
2423
import org.jspecify.annotations.Nullable;
2524

2625
/**
2726
* Propositions for {@link BigDecimal} typed subjects.
2827
*
2928
* @author Kurt Alfred Kluever
3029
*/
31-
@NullMarked
3230
public final class BigDecimalSubject extends ComparableSubject<BigDecimal> {
3331
private final @Nullable BigDecimal actual;
3432

core/src/main/java/com/google/common/truth/BooleanSubject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
import static com.google.common.truth.Fact.simpleFact;
1919

20-
import org.jspecify.annotations.NullMarked;
2120
import org.jspecify.annotations.Nullable;
2221

2322
/**
2423
* Propositions for boolean subjects.
2524
*
2625
* @author Christian Gruber ([email protected])
2726
*/
28-
@NullMarked
2927
public final class BooleanSubject extends Subject {
3028
private final @Nullable Boolean actual;
3129

core/src/main/java/com/google/common/truth/ClassSubject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818
import static com.google.common.base.Preconditions.checkNotNull;
1919

2020
import com.google.common.annotations.GwtIncompatible;
21-
import org.jspecify.annotations.NullMarked;
2221
import org.jspecify.annotations.Nullable;
2322

2423
/**
2524
* Propositions for {@link Class} subjects.
2625
*
2726
* @author Kurt Alfred Kluever
2827
*/
29-
@NullMarked
3028
@GwtIncompatible("reflection")
3129
@J2ktIncompatible
3230
public final class ClassSubject extends Subject {

core/src/main/java/com/google/common/truth/ComparableSubject.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static com.google.common.base.Preconditions.checkNotNull;
1919

2020
import com.google.common.collect.Range;
21-
import org.jspecify.annotations.NullMarked;
2221
import org.jspecify.annotations.Nullable;
2322

2423
/**
@@ -27,7 +26,6 @@
2726
* @author Kurt Alfred Kluever
2827
* @param <T> the type of the object being tested by this {@code ComparableSubject}
2928
*/
30-
@NullMarked
3129
// TODO(b/136040841): Consider further tightening this to the proper `extends Comparable<? super T>`
3230
public abstract class ComparableSubject<T extends Comparable<?>> extends Subject {
3331
/**

core/src/main/java/com/google/common/truth/ComparisonFailureWithFacts.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@
2121

2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.truth.Platform.PlatformComparisonFailure;
24-
import org.jspecify.annotations.NullMarked;
2524
import org.jspecify.annotations.Nullable;
2625

2726
/**
2827
* An {@link AssertionError} (usually a JUnit {@code ComparisonFailure}, but not under GWT) composed
2928
* of structured {@link Fact} instances and other string messages.
3029
*/
31-
@NullMarked
3230
final class ComparisonFailureWithFacts extends PlatformComparisonFailure implements ErrorWithFacts {
3331
private final ImmutableList<Fact> facts;
3432

core/src/main/java/com/google/common/truth/ComparisonFailures.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import com.google.common.annotations.VisibleForTesting;
2828
import com.google.common.collect.ImmutableList;
29-
import org.jspecify.annotations.NullMarked;
3029
import org.jspecify.annotations.Nullable;
3130

3231
/**
@@ -43,7 +42,6 @@
4342
* different implementation under GWT/j2cl, where {@code ComparisonFailure} is also unavailable but
4443
* we can't just recover from that at runtime.
4544
*/
46-
@NullMarked
4745
final class ComparisonFailures {
4846
static ImmutableList<Fact> makeComparisonFailureFacts(
4947
ImmutableList<Fact> headFacts,

core/src/main/java/com/google/common/truth/Correspondence.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import com.google.common.collect.ImmutableList;
3232
import java.util.Arrays;
3333
import java.util.List;
34-
import org.jspecify.annotations.NullMarked;
3534
import org.jspecify.annotations.Nullable;
3635

3736
/**
@@ -66,7 +65,6 @@
6665
*
6766
* @author Pete Gillin
6867
*/
69-
@NullMarked
7068
public abstract class Correspondence<A extends @Nullable Object, E extends @Nullable Object> {
7169

7270
/**

0 commit comments

Comments
 (0)