FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Use JSpecify annotations in the public release. · google/truth@ee680cb · GitHub

/ truth Public

Commit ee680cb

Browse files
authored andcommitted
Use JSpecify annotations in the public release.
We've been using these internally for over a year. With JSpecify 1.0 not far off and wider adoption to gradually follow, now seems like the time to expand our public usage of the annotations. We've already been using them in a few projects, but Truth may become the mostly widely used project that users actually link against to use them. At the same time, it's a library that's used only in testing code, so the stakes remain relatively low. Most users will see no effect from this change, since most users don't use nullness checking and since we already used some nullness annotations in our public release. The main effect users are likely to see is if they pass nullable values for parameters that are now recognized as non-nullable. Under Kotlin, the effect should normally be a warning, not an error, at least until [Kotlin 2.1 or so](https://youtrack.jetbrains.com/issue/KT-55586/Handle-nullability-from-jspecify-annotations-properly#focus=Comments-27-8368666.0-0). Please still [report any problems](https://github.com/google/truth/issues/new). (progress toward JSpecify adoption in our projects in general, including google/guava#2960) RELNOTES=Added more nullness information to our APIs (in the form of [JSpecify](https://jspecify.dev/) annotations). This could lead to additional warnings (or even errors) for users of Kotlin and other nullness checkers. Please [report any problems](https://github.com/google/truth/issues/new). PiperOrigin-RevId: 647012817
1 parent d39e722 commit ee680cb

92 files changed

Lines changed: 198 additions & 88 deletions

File tree

Some content is hidden

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

‎core/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
<artifactId>guava</artifactId>
1616
</dependency>
1717
<dependency>
18-
<groupId>org.checkerframework</groupId>
19-
<artifactId>checker-qual</artifactId>
18+
<groupId>org.jspecify</groupId>
19+
<artifactId>jspecify</artifactId>
2020
</dependency>
2121
<dependency>
2222
<groupId>junit</groupId>

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

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

2222
import java.lang.reflect.Array;
23-
import org.checkerframework.checker.nullness.qual.Nullable;
23+
import org.jspecify.annotations.NullMarked;
24+
import org.jspecify.annotations.Nullable;
2425

2526
/**
2627
* A common supertype for Array subjects, abstracting some common display and error infrastructure.
2728
*
2829
* @author Christian Gruber (cgruber@israfil.net)
2930
*/
31+
@NullMarked
3032
abstract class AbstractArraySubject extends Subject {
3133
private final @Nullable Object actual;
3234

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
import java.io.InputStream;
3434
import java.util.ArrayList;
3535
import java.util.Map.Entry;
36-
import org.checkerframework.checker.nullness.qual.Nullable;
36+
import org.jspecify.annotations.NullMarked;
37+
import org.jspecify.annotations.Nullable;
3738
import org.objectweb.asm.ClassReader;
3839
import org.objectweb.asm.ClassVisitor;
3940
import org.objectweb.asm.Handle;
@@ -69,6 +70,7 @@
6970
*/
7071
@GwtIncompatible
7172
@J2ktIncompatible
73+
@NullMarked
7274
final class ActualValueInference {
7375
/** <b>Call {@link Platform#inferDescription} rather than calling this directly.</b> */
7476
static @Nullable String describeActualValue(String className, String methodName, int lineNumber) {

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

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

2121
import com.google.common.collect.ImmutableList;
22-
import org.checkerframework.checker.nullness.qual.Nullable;
22+
import org.jspecify.annotations.NullMarked;
23+
import org.jspecify.annotations.Nullable;
2324

2425
/**
2526
* An {@link AssertionError} composed of structured {@link Fact} instances and other string
2627
* messages.
2728
*/
2829
@SuppressWarnings("OverrideThrowableToString") // We intentionally hide the class name.
30+
@NullMarked
2931
final class AssertionErrorWithFacts extends AssertionError implements ErrorWithFacts {
3032
private final ImmutableList<Fact> facts;
3133

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

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

2222
import java.math.BigDecimal;
23-
import org.checkerframework.checker.nullness.qual.Nullable;
23+
import org.jspecify.annotations.NullMarked;
24+
import org.jspecify.annotations.Nullable;
2425

2526
/**
2627
* Propositions for {@link BigDecimal} typed subjects.
2728
*
2829
* @author Kurt Alfred Kluever
2930
*/
31+
@NullMarked
3032
public final class BigDecimalSubject extends ComparableSubject<BigDecimal> {
3133
private final @Nullable BigDecimal actual;
3234

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717

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

20-
import org.checkerframework.checker.nullness.qual.Nullable;
20+
import org.jspecify.annotations.NullMarked;
21+
import org.jspecify.annotations.Nullable;
2122

2223
/**
2324
* Propositions for boolean subjects.
2425
*
2526
* @author Christian Gruber (cgruber@israfil.net)
2627
*/
28+
@NullMarked
2729
public final class BooleanSubject extends Subject {
2830
private final @Nullable Boolean actual;
2931

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

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

2020
import com.google.common.annotations.GwtIncompatible;
21-
import org.checkerframework.checker.nullness.qual.Nullable;
21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
2223

2324
/**
2425
* Propositions for {@link Class} subjects.
2526
*
2627
* @author Kurt Alfred Kluever
2728
*/
29+
@NullMarked
2830
@GwtIncompatible("reflection")
2931
@J2ktIncompatible
3032
public final class ClassSubject extends Subject {

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,16 @@
1818
import static com.google.common.base.Preconditions.checkNotNull;
1919

2020
import com.google.common.collect.Range;
21-
import org.checkerframework.checker.nullness.qual.Nullable;
21+
import org.jspecify.annotations.NullMarked;
22+
import org.jspecify.annotations.Nullable;
2223

2324
/**
2425
* Propositions for {@link Comparable} typed subjects.
2526
*
2627
* @author Kurt Alfred Kluever
2728
* @param <T> the type of the object being tested by this {@code ComparableSubject}
2829
*/
30+
@NullMarked
2931
// TODO(b/136040841): Consider further tightening this to the proper `extends Comparable<? super T>`
3032
public abstract class ComparableSubject<T extends Comparable<?>> extends Subject {
3133
/**

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121

2222
import com.google.common.collect.ImmutableList;
2323
import com.google.common.truth.Platform.PlatformComparisonFailure;
24-
import org.checkerframework.checker.nullness.qual.Nullable;
24+
import org.jspecify.annotations.NullMarked;
25+
import org.jspecify.annotations.Nullable;
2526

2627
/**
2728
* An {@link AssertionError} (usually a JUnit {@code ComparisonFailure}, but not under GWT) composed
2829
* of structured {@link Fact} instances and other string messages.
2930
*/
31+
@NullMarked
3032
final class ComparisonFailureWithFacts extends PlatformComparisonFailure implements ErrorWithFacts {
3133
private final ImmutableList<Fact> facts;
3234

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727
import com.google.common.annotations.VisibleForTesting;
2828
import com.google.common.collect.ImmutableList;
29-
import org.checkerframework.checker.nullness.qual.Nullable;
29+
import org.jspecify.annotations.NullMarked;
30+
import org.jspecify.annotations.Nullable;
3031

3132
/**
3233
* Contains part of the code responsible for creating a JUnit {@code ComparisonFailure} (if
@@ -42,6 +43,7 @@
4243
* different implementation under GWT/j2cl, where {@code ComparisonFailure} is also unavailable but
4344
* we can't just recover from that at runtime.
4445
*/
46+
@NullMarked
4547
final class ComparisonFailures {
4648
static ImmutableList<Fact> makeComparisonFailureFacts(
4749
ImmutableList<Fact> headFacts,

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL