Skip to content

Commit e107aea

Browse files
cpovirkGoogle Java Core Libraries
authored and
Google Java Core Libraries
committedJul 12, 2024·
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

-2
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 (cgruber@israfil.net)
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

-2
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) {

0 commit comments

Comments
 (0)
Please sign in to comment.