From e71b57b9f81f8b0f221a34bfd31e96ff4ba22668 Mon Sep 17 00:00:00 2001 From: Olek Wojnar Date: Thu, 10 Sep 2020 18:48:17 -0700 Subject: [PATCH] Replace obsolete @NullableDecl Also, remove dependency on checker-compat-qual since it is no longer needed. From downstream fix in Debian. Fixes #704 Fixes #497 RELNOTES=Changed Checker Framework annotations from checker-qual to qual. PiperOrigin-RevId: 331062272 --- core/pom.xml | 13 +--- .../common/truth/AbstractArraySubject.java | 4 +- .../common/truth/ActualValueInference.java | 9 ++- .../common/truth/AssertionErrorWithFacts.java | 9 ++- .../common/truth/BigDecimalSubject.java | 6 +- .../google/common/truth/BooleanSubject.java | 4 +- .../com/google/common/truth/ClassSubject.java | 4 +- .../common/truth/ComparableSubject.java | 4 +- .../truth/ComparisonFailureWithFacts.java | 10 +-- .../google/common/truth/Correspondence.java | 32 ++++---- .../common/truth/CustomSubjectBuilder.java | 2 +- .../google/common/truth/DoubleSubject.java | 10 +-- .../java/com/google/common/truth/Expect.java | 6 +- .../google/common/truth/ExpectFailure.java | 4 +- .../java/com/google/common/truth/Fact.java | 8 +- .../google/common/truth/FailureMetadata.java | 21 +++--- .../com/google/common/truth/FloatSubject.java | 10 +-- .../common/truth/GuavaOptionalSubject.java | 6 +- .../google/common/truth/IntegerSubject.java | 4 +- .../google/common/truth/IterableSubject.java | 67 ++++++++--------- .../com/google/common/truth/LazyMessage.java | 3 +- .../com/google/common/truth/LongSubject.java | 4 +- .../com/google/common/truth/MapSubject.java | 46 ++++++------ .../google/common/truth/MultimapSubject.java | 39 +++++----- .../google/common/truth/MultisetSubject.java | 6 +- .../common/truth/ObjectArraySubject.java | 4 +- .../com/google/common/truth/Platform.java | 9 +-- .../truth/PrimitiveBooleanArraySubject.java | 4 +- .../truth/PrimitiveByteArraySubject.java | 4 +- .../truth/PrimitiveCharArraySubject.java | 4 +- .../truth/PrimitiveDoubleArraySubject.java | 4 +- .../truth/PrimitiveFloatArraySubject.java | 4 +- .../truth/PrimitiveIntArraySubject.java | 4 +- .../truth/PrimitiveLongArraySubject.java | 4 +- .../truth/PrimitiveShortArraySubject.java | 4 +- .../common/truth/SimpleSubjectBuilder.java | 4 +- .../common/truth/StandardSubjectBuilder.java | 58 +++++++-------- .../google/common/truth/StringSubject.java | 4 +- .../java/com/google/common/truth/Subject.java | 42 +++++------ .../com/google/common/truth/TableSubject.java | 18 ++--- .../google/common/truth/ThrowableSubject.java | 8 +- .../java/com/google/common/truth/Truth.java | 62 ++++++++-------- .../common/truth/TruthFailureSubject.java | 8 +- .../com/google/common/truth/Platform.java | 5 +- .../common/truth/CorrespondenceTest.java | 15 ++-- .../common/truth/DoubleSubjectTest.java | 16 ++-- .../google/common/truth/FloatSubjectTest.java | 16 ++-- .../com/google/common/truth/MathUtilTest.java | 2 +- .../com/google/common/truth/SubjectTest.java | 8 +- .../common/truth/TestCorrespondences.java | 37 ++++------ .../truth/extension/EmployeeSubject.java | 6 +- extensions/java8/pom.xml | 2 +- .../google/common/truth/IntStreamSubject.java | 8 +- .../common/truth/LongStreamSubject.java | 8 +- .../common/truth/OptionalDoubleSubject.java | 6 +- .../common/truth/OptionalIntSubject.java | 6 +- .../common/truth/OptionalLongSubject.java | 6 +- .../google/common/truth/OptionalSubject.java | 6 +- .../google/common/truth/StreamSubject.java | 20 ++--- .../java/com/google/common/truth/Truth8.java | 18 ++--- extensions/liteproto/pom.xml | 2 +- .../extensions/proto/LiteProtoSubject.java | 19 +++-- .../extensions/proto/LiteProtoTruth.java | 4 +- .../proto/LiteProtoSubjectTest.java | 6 +- extensions/proto/pom.xml | 2 +- .../proto/FluentEqualityConfig.java | 8 +- .../proto/IterableOfProtosSubject.java | 42 +++++------ .../IterableOfProtosUsingCorrespondence.java | 16 ++-- .../MapWithProtoValuesFluentAssertion.java | 8 +- .../proto/MapWithProtoValuesSubject.java | 15 ++-- ...ultimapWithProtoValuesFluentAssertion.java | 8 +- .../proto/MultimapWithProtoValuesSubject.java | 16 ++-- .../proto/ProtoFluentAssertion.java | 6 +- .../truth/extensions/proto/ProtoSubject.java | 20 ++--- .../extensions/proto/ProtoSubjectBuilder.java | 13 ++-- .../truth/extensions/proto/ProtoTruth.java | 12 +-- .../proto/ProtoTruthMessageDifferencer.java | 73 +++++++++---------- .../proto/ProtoSubjectTestBase.java | 6 +- pom.xml | 5 -- 79 files changed, 495 insertions(+), 551 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index 870c415f4..022cfcc3f 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -14,20 +14,9 @@ com.google.guava guava - - org.checkerframework - checker-compat-qual - - org.checkerframework checker-qual - test junit @@ -111,7 +100,7 @@ - + maven-jar-plugin diff --git a/core/src/main/java/com/google/common/truth/AbstractArraySubject.java b/core/src/main/java/com/google/common/truth/AbstractArraySubject.java index 340abc1b2..a0cd2fdcb 100644 --- a/core/src/main/java/com/google/common/truth/AbstractArraySubject.java +++ b/core/src/main/java/com/google/common/truth/AbstractArraySubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import java.lang.reflect.Array; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A common supertype for Array subjects, abstracting some common display and error infrastructure. @@ -30,7 +30,7 @@ abstract class AbstractArraySubject extends Subject { private final Object actual; AbstractArraySubject( - FailureMetadata metadata, @NullableDecl Object actual, @NullableDecl String typeDescription) { + FailureMetadata metadata, @Nullable Object actual, @Nullable String typeDescription) { super(metadata, actual, typeDescription); this.actual = actual; } diff --git a/core/src/main/java/com/google/common/truth/ActualValueInference.java b/core/src/main/java/com/google/common/truth/ActualValueInference.java index 2eac8c2bd..5959bb606 100644 --- a/core/src/main/java/com/google/common/truth/ActualValueInference.java +++ b/core/src/main/java/com/google/common/truth/ActualValueInference.java @@ -1355,7 +1355,7 @@ static InferredType create(String descriptor) { abstract String descriptor(); @Override - public String toString() { + public final String toString() { return descriptor(); } @@ -1508,8 +1508,11 @@ private static void closeQuietly(InputStream stream) { } /* - * For @AutoValue, which doesn't support @NullableDecl. (We're avoiding both JSR305 and the - * Checker Framework type annotations.) + * TODO(cpovirk): Switch to using Checker Framework @Nullable. The problem I see if I try to + * switch now is that the AutoValue-generated code is `@Nullable ActualValueInference.StackEntry` + * rather than `ActualValueInference.@Nullable StackEntry`. AutoValue normally gets this right + * (b/29530042), so I think the failure here is because we use `-source 7`. That might still be + * fine, except that j2objc compilation appears to then use `-source 8`. */ @interface Nullable {} diff --git a/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java b/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java index 92b0dae5e..4429639f7 100644 --- a/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java +++ b/core/src/main/java/com/google/common/truth/AssertionErrorWithFacts.java @@ -19,25 +19,26 @@ import static com.google.common.truth.Fact.makeMessage; import com.google.common.collect.ImmutableList; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An {@link AssertionError} composed of structured {@link Fact} instances and other string * messages. */ +@SuppressWarnings("OverrideThrowableToString") // We intentionally hide the class name. final class AssertionErrorWithFacts extends AssertionError implements ErrorWithFacts { static AssertionErrorWithFacts create( - ImmutableList messages, ImmutableList facts, @NullableDecl Throwable cause) { + ImmutableList messages, ImmutableList facts, @Nullable Throwable cause) { return new AssertionErrorWithFacts(messages, facts, cause); } final ImmutableList facts; /** Separate cause field, in case initCause() fails. */ - @NullableDecl private final Throwable cause; + private final @Nullable Throwable cause; private AssertionErrorWithFacts( - ImmutableList messages, ImmutableList facts, @NullableDecl Throwable cause) { + ImmutableList messages, ImmutableList facts, @Nullable Throwable cause) { super(makeMessage(messages, facts)); this.facts = checkNotNull(facts); diff --git a/core/src/main/java/com/google/common/truth/BigDecimalSubject.java b/core/src/main/java/com/google/common/truth/BigDecimalSubject.java index 30f042134..64cf82369 100644 --- a/core/src/main/java/com/google/common/truth/BigDecimalSubject.java +++ b/core/src/main/java/com/google/common/truth/BigDecimalSubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import java.math.BigDecimal; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link BigDecimal} typed subjects. @@ -29,7 +29,7 @@ public final class BigDecimalSubject extends ComparableSubject { private final BigDecimal actual; - BigDecimalSubject(FailureMetadata metadata, @NullableDecl BigDecimal actual) { + BigDecimalSubject(FailureMetadata metadata, @Nullable BigDecimal actual) { super(metadata, actual); this.actual = actual; } @@ -75,7 +75,7 @@ public void isEqualToIgnoringScale(long expected) { * use {@link #isEqualToIgnoringScale(BigDecimal)} instead. */ @Override // To express more specific javadoc - public void isEqualTo(@NullableDecl Object expected) { + public void isEqualTo(@Nullable Object expected) { super.isEqualTo(expected); } diff --git a/core/src/main/java/com/google/common/truth/BooleanSubject.java b/core/src/main/java/com/google/common/truth/BooleanSubject.java index 2ac258daf..528cbc626 100644 --- a/core/src/main/java/com/google/common/truth/BooleanSubject.java +++ b/core/src/main/java/com/google/common/truth/BooleanSubject.java @@ -17,7 +17,7 @@ import static com.google.common.truth.Fact.simpleFact; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for boolean subjects. @@ -27,7 +27,7 @@ public final class BooleanSubject extends Subject { private final Boolean actual; - BooleanSubject(FailureMetadata metadata, @NullableDecl Boolean actual) { + BooleanSubject(FailureMetadata metadata, @Nullable Boolean actual) { super(metadata, actual); this.actual = actual; } diff --git a/core/src/main/java/com/google/common/truth/ClassSubject.java b/core/src/main/java/com/google/common/truth/ClassSubject.java index b72ac7cf6..a2ca5c487 100644 --- a/core/src/main/java/com/google/common/truth/ClassSubject.java +++ b/core/src/main/java/com/google/common/truth/ClassSubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.annotations.GwtIncompatible; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Class} subjects. @@ -27,7 +27,7 @@ public final class ClassSubject extends Subject { private final Class actual; - ClassSubject(FailureMetadata metadata, @NullableDecl Class o) { + ClassSubject(FailureMetadata metadata, @Nullable Class o) { super(metadata, o); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/ComparableSubject.java b/core/src/main/java/com/google/common/truth/ComparableSubject.java index 5ac6f972b..ed769734f 100644 --- a/core/src/main/java/com/google/common/truth/ComparableSubject.java +++ b/core/src/main/java/com/google/common/truth/ComparableSubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.collect.Range; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Comparable} typed subjects. @@ -31,7 +31,7 @@ public abstract class ComparableSubject extends Subject { */ private final T actual; - protected ComparableSubject(FailureMetadata metadata, @NullableDecl T actual) { + protected ComparableSubject(FailureMetadata metadata, @Nullable T actual) { super(metadata, actual); this.actual = actual; } diff --git a/core/src/main/java/com/google/common/truth/ComparisonFailureWithFacts.java b/core/src/main/java/com/google/common/truth/ComparisonFailureWithFacts.java index cf51d95d3..08f5d9d1d 100644 --- a/core/src/main/java/com/google/common/truth/ComparisonFailureWithFacts.java +++ b/core/src/main/java/com/google/common/truth/ComparisonFailureWithFacts.java @@ -29,7 +29,7 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; import com.google.common.truth.Platform.PlatformComparisonFailure; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An {@link AssertionError} (usually a JUnit {@code ComparisonFailure}, but not under GWT) composed @@ -44,7 +44,7 @@ static ComparisonFailureWithFacts create( ImmutableList tailFacts, String expected, String actual, - @NullableDecl Throwable cause) { + @Nullable Throwable cause) { ImmutableList facts = makeFacts(headFacts, tailFacts, expected, actual); return new ComparisonFailureWithFacts(messages, facts, expected, actual, cause); } @@ -56,7 +56,7 @@ private ComparisonFailureWithFacts( ImmutableList facts, String expected, String actual, - @NullableDecl Throwable cause) { + @Nullable Throwable cause) { super(makeMessage(messages, facts), checkNotNull(expected), checkNotNull(actual), cause); this.facts = checkNotNull(facts); } @@ -105,8 +105,8 @@ static ImmutableList formatExpectedAndActual(String expected, String actua return ImmutableList.of(fact("expected", expected), fact("but was", actual)); } - @NullableDecl - private static ImmutableList removeCommonPrefixAndSuffix(String expected, String actual) { + private static @Nullable ImmutableList removeCommonPrefixAndSuffix( + String expected, String actual) { int originalExpectedLength = expected.length(); // TODO(cpovirk): Use something like BreakIterator where available. diff --git a/core/src/main/java/com/google/common/truth/Correspondence.java b/core/src/main/java/com/google/common/truth/Correspondence.java index ed7235424..79ea6d286 100644 --- a/core/src/main/java/com/google/common/truth/Correspondence.java +++ b/core/src/main/java/com/google/common/truth/Correspondence.java @@ -31,7 +31,7 @@ import com.google.common.collect.ImmutableList; import java.util.Arrays; import java.util.List; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Determines whether an instance of type {@code A} corresponds in some way to an instance of type @@ -132,7 +132,7 @@ public interface BinaryPredicate { * Returns whether or not the actual and expected values satisfy the condition defined by this * predicate. */ - boolean apply(@NullableDecl A actual, @NullableDecl E expected); + boolean apply(@Nullable A actual, @Nullable E expected); } private static final class FromBinaryPredicate extends Correspondence { @@ -145,7 +145,7 @@ private FromBinaryPredicate(BinaryPredicate correspondencePredicate, Strin } @Override - public boolean compare(@NullableDecl A actual, @NullableDecl E expected) { + public boolean compare(@Nullable A actual, @Nullable E expected) { return predicate.apply(actual, expected); } @@ -259,7 +259,7 @@ private Transforming( } @Override - public boolean compare(@NullableDecl A actual, @NullableDecl E expected) { + public boolean compare(@Nullable A actual, @Nullable E expected) { return Objects.equal(actualTransform.apply(actual), expectedTransform.apply(expected)); } @@ -401,8 +401,8 @@ public interface DiffFormatter { * Returns a {@link String} describing the difference between the {@code actual} and {@code * expected} values, if possible, or {@code null} if not. */ - @NullableDecl - String formatDiff(@NullableDecl A actual, @NullableDecl E expected); + @Nullable + String formatDiff(@Nullable A actual, @Nullable E expected); } private static class FormattingDiffs extends Correspondence { @@ -416,13 +416,12 @@ private static class FormattingDiffs extends Correspondence { } @Override - public boolean compare(@NullableDecl A actual, @NullableDecl E expected) { + public boolean compare(@Nullable A actual, @Nullable E expected) { return delegate.compare(actual, expected); } @Override - @NullableDecl - public String formatDiff(@NullableDecl A actual, @NullableDecl E expected) { + public @Nullable String formatDiff(@Nullable A actual, @Nullable E expected) { return formatter.formatDiff(actual, expected); } @@ -518,7 +517,7 @@ boolean isEquality() { * returned false. (Note that, in the latter case at least, it is likely that the test author's * intention was not for the test to pass with these values.) */ - public abstract boolean compare(@NullableDecl A actual, @NullableDecl E expected); + public abstract boolean compare(@Nullable A actual, @Nullable E expected); private static class StoredException { @@ -719,8 +718,7 @@ private static void truncateStackTrace(Exception exception, Class callingClas * returns false. This method can help with implementing the exception-handling policy described * above, but note that assertions using it must fail later if an exception was stored. */ - final boolean safeCompare( - @NullableDecl A actual, @NullableDecl E expected, ExceptionStore exceptions) { + final boolean safeCompare(@Nullable A actual, @Nullable E expected, ExceptionStore exceptions) { try { return compare(actual, expected); } catch (RuntimeException e) { @@ -746,8 +744,7 @@ final boolean safeCompare( * exception and continue to describe the original failure as if this method had returned null, * mentioning the failure from this method as additional information. */ - @NullableDecl - public String formatDiff(@NullableDecl A actual, @NullableDecl E expected) { + public @Nullable String formatDiff(@Nullable A actual, @Nullable E expected) { return null; } @@ -756,9 +753,8 @@ public String formatDiff(@NullableDecl A actual, @NullableDecl E expected) { * the result. If it does throw, adds the exception to the given {@link ExceptionStore} and * returns null. */ - @NullableDecl - final String safeFormatDiff( - @NullableDecl A actual, @NullableDecl E expected, ExceptionStore exceptions) { + final @Nullable String safeFormatDiff( + @Nullable A actual, @Nullable E expected, ExceptionStore exceptions) { try { return formatDiff(actual, expected); } catch (RuntimeException e) { @@ -827,7 +823,7 @@ final ImmutableList describeForMapValues() { */ @Deprecated @Override - public final boolean equals(@NullableDecl Object o) { + public final boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "Correspondence.equals(object) is not supported. If you meant to compare objects, use" + " .compare(actual, expected) instead."); diff --git a/core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java b/core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java index fe4817f85..fee0aa01d 100644 --- a/core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/CustomSubjectBuilder.java @@ -68,5 +68,5 @@ protected final FailureMetadata metadata() { return metadata; } - // TODO(user,cgruber): Better enforce that subclasses implement a that() method. + // TODO(user): Better enforce that subclasses implement a that() method. } diff --git a/core/src/main/java/com/google/common/truth/DoubleSubject.java b/core/src/main/java/com/google/common/truth/DoubleSubject.java index 53854c9a5..a198bff81 100644 --- a/core/src/main/java/com/google/common/truth/DoubleSubject.java +++ b/core/src/main/java/com/google/common/truth/DoubleSubject.java @@ -26,7 +26,7 @@ import static java.lang.Double.NaN; import static java.lang.Double.doubleToLongBits; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Double} subjects. @@ -38,7 +38,7 @@ public final class DoubleSubject extends ComparableSubject { private final Double actual; - DoubleSubject(FailureMetadata metadata, @NullableDecl Double actual) { + DoubleSubject(FailureMetadata metadata, @Nullable Double actual) { super(metadata, actual); this.actual = actual; } @@ -66,7 +66,7 @@ private TolerantDoubleComparison() {} */ @Deprecated @Override - public boolean equals(@NullableDecl Object o) { + public boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "If you meant to compare doubles, use .of(double) instead."); } @@ -178,7 +178,7 @@ public void of(double expected) { * #isZero}. */ @Override - public final void isEqualTo(@NullableDecl Object other) { + public final void isEqualTo(@Nullable Object other) { super.isEqualTo(other); } @@ -192,7 +192,7 @@ public final void isEqualTo(@NullableDecl Object other) { * #isNonZero}. */ @Override - public final void isNotEqualTo(@NullableDecl Object other) { + public final void isNotEqualTo(@Nullable Object other) { super.isNotEqualTo(other); } diff --git a/core/src/main/java/com/google/common/truth/Expect.java b/core/src/main/java/com/google/common/truth/Expect.java index aa31a9240..454c2688a 100644 --- a/core/src/main/java/com/google/common/truth/Expect.java +++ b/core/src/main/java/com/google/common/truth/Expect.java @@ -30,7 +30,7 @@ import com.google.errorprone.annotations.concurrent.GuardedBy; import java.util.ArrayList; import java.util.List; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.internal.AssumptionViolatedException; import org.junit.rules.ErrorCollector; import org.junit.rules.TestRule; @@ -101,7 +101,7 @@ synchronized void enterRuleContext() { inRuleContext = DURING; } - synchronized void leaveRuleContext(@NullableDecl Throwable caught) throws Throwable { + synchronized void leaveRuleContext(@Nullable Throwable caught) throws Throwable { try { if (caught == null) { doLeaveRuleContext(); @@ -172,7 +172,7 @@ private String printSubsequentFailure( } @GuardedBy("this") - private void doCheckInRuleContext(@NullableDecl AssertionError failure) { + private void doCheckInRuleContext(@Nullable AssertionError failure) { switch (inRuleContext) { case BEFORE: throw new IllegalStateException( diff --git a/core/src/main/java/com/google/common/truth/ExpectFailure.java b/core/src/main/java/com/google/common/truth/ExpectFailure.java index 4b8200a63..970f52616 100644 --- a/core/src/main/java/com/google/common/truth/ExpectFailure.java +++ b/core/src/main/java/com/google/common/truth/ExpectFailure.java @@ -23,7 +23,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.truth.Truth.SimpleAssertionError; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.runner.Description; import org.junit.runners.model.Statement; @@ -76,7 +76,7 @@ public void fail(AssertionError failure) { private boolean inRuleContext = false; private boolean failureExpected = false; - @NullableDecl private AssertionError failure = null; + private @Nullable AssertionError failure = null; /** * Creates a new instance for use as a {@code @Rule}. See the class documentation for details, and diff --git a/core/src/main/java/com/google/common/truth/Fact.java b/core/src/main/java/com/google/common/truth/Fact.java index 48943f3f0..02e2bea4b 100644 --- a/core/src/main/java/com/google/common/truth/Fact.java +++ b/core/src/main/java/com/google/common/truth/Fact.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList; import java.io.Serializable; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A string key-value pair in a failure message, such as "expected: abc" or "but was: xyz." @@ -39,7 +39,7 @@ public final class Fact implements Serializable { * Creates a fact with the given key and value, which will be printed in a format like "key: * value." The value is converted to a string by calling {@code String.valueOf} on it. */ - public static Fact fact(String key, @NullableDecl Object value) { + public static Fact fact(String key, @Nullable Object value) { return new Fact(key, String.valueOf(value)); } @@ -63,9 +63,9 @@ public static Fact simpleFact(String key) { } final String key; - @NullableDecl final String value; + final @Nullable String value; - private Fact(String key, @NullableDecl String value) { + private Fact(String key, @Nullable String value) { this.key = checkNotNull(key); this.value = value; } diff --git a/core/src/main/java/com/google/common/truth/FailureMetadata.java b/core/src/main/java/com/google/common/truth/FailureMetadata.java index 59bf07d79..7fb6a156d 100644 --- a/core/src/main/java/com/google/common/truth/FailureMetadata.java +++ b/core/src/main/java/com/google/common/truth/FailureMetadata.java @@ -27,7 +27,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An opaque, immutable object containing state from the previous calls in the fluent assertion @@ -67,7 +67,7 @@ static Step subjectCreation(Subject subject) { static Step checkCall( OldAndNewValuesAreSimilar valuesAreSimilar, - @NullableDecl Function descriptionUpdate) { + @Nullable Function descriptionUpdate) { return new Step(null, descriptionUpdate, valuesAreSimilar); } @@ -78,17 +78,17 @@ static Step checkCall( * time we receive it. We *might* be able to make it safe to call if it looks only at actual(), * but it might try to look at facts initialized by a subclass, which aren't ready yet. */ - @NullableDecl final Subject subject; + final @Nullable Subject subject; - @NullableDecl final Function descriptionUpdate; + final @Nullable Function descriptionUpdate; // Present only when descriptionUpdate is. - @NullableDecl final OldAndNewValuesAreSimilar valuesAreSimilar; + final @Nullable OldAndNewValuesAreSimilar valuesAreSimilar; private Step( - @NullableDecl Subject subject, - @NullableDecl Function descriptionUpdate, - @NullableDecl OldAndNewValuesAreSimilar valuesAreSimilar) { + @Nullable Subject subject, + @Nullable Function descriptionUpdate, + @Nullable OldAndNewValuesAreSimilar valuesAreSimilar) { this.subject = subject; this.descriptionUpdate = descriptionUpdate; this.valuesAreSimilar = valuesAreSimilar; @@ -159,7 +159,7 @@ enum OldAndNewValuesAreSimilar { * to set a message is {@code check(...).withMessage(...).that(...)} (for calls from within a * {@code Subject}) or {@link Truth#assertWithMessage} (for most other calls). */ - FailureMetadata withMessage(String format, Object[] args) { + FailureMetadata withMessage(String format, /*@Nullable*/ Object[] args) { ImmutableList messages = append(this.messages, new LazyMessage(format, args)); return derive(messages, steps); } @@ -314,8 +314,7 @@ private ImmutableList rootUnlessThrowable() { * Returns the first {@link Throwable} in the chain of actual values. Typically, we'll have a root * cause only if the assertion chain contains a {@link ThrowableSubject}. */ - @NullableDecl - private Throwable rootCause() { + private @Nullable Throwable rootCause() { for (Step step : steps) { if (!step.isCheckCall() && step.subject.actual() instanceof Throwable) { return (Throwable) step.subject.actual(); diff --git a/core/src/main/java/com/google/common/truth/FloatSubject.java b/core/src/main/java/com/google/common/truth/FloatSubject.java index 4f9fd66eb..765b3844b 100644 --- a/core/src/main/java/com/google/common/truth/FloatSubject.java +++ b/core/src/main/java/com/google/common/truth/FloatSubject.java @@ -26,7 +26,7 @@ import static java.lang.Float.NaN; import static java.lang.Float.floatToIntBits; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Float} subjects. @@ -39,7 +39,7 @@ public final class FloatSubject extends ComparableSubject { private final Float actual; private final DoubleSubject asDouble; - FloatSubject(FailureMetadata metadata, @NullableDecl Float actual) { + FloatSubject(FailureMetadata metadata, @Nullable Float actual) { super(metadata, actual); this.actual = actual; /* @@ -74,7 +74,7 @@ private TolerantFloatComparison() {} */ @Deprecated @Override - public boolean equals(@NullableDecl Object o) { + public boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "If you meant to compare floats, use .of(float) instead."); } @@ -186,7 +186,7 @@ public void of(float expected) { * #isZero}. */ @Override - public final void isEqualTo(@NullableDecl Object other) { + public final void isEqualTo(@Nullable Object other) { super.isEqualTo(other); } @@ -200,7 +200,7 @@ public final void isEqualTo(@NullableDecl Object other) { * #isNonZero}. */ @Override - public final void isNotEqualTo(@NullableDecl Object other) { + public final void isNotEqualTo(@Nullable Object other) { super.isNotEqualTo(other); } diff --git a/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java b/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java index 4745bd06b..bbaf8053e 100644 --- a/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java +++ b/core/src/main/java/com/google/common/truth/GuavaOptionalSubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import com.google.common.base.Optional; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for Guava {@link Optional} subjects. @@ -33,9 +33,7 @@ public final class GuavaOptionalSubject extends Subject { private final Optional actual; GuavaOptionalSubject( - FailureMetadata metadata, - @NullableDecl Optional actual, - @NullableDecl String typeDescription) { + FailureMetadata metadata, @Nullable Optional actual, @Nullable String typeDescription) { super(metadata, actual, typeDescription); this.actual = actual; } diff --git a/core/src/main/java/com/google/common/truth/IntegerSubject.java b/core/src/main/java/com/google/common/truth/IntegerSubject.java index 8bba895c4..2f892379b 100644 --- a/core/src/main/java/com/google/common/truth/IntegerSubject.java +++ b/core/src/main/java/com/google/common/truth/IntegerSubject.java @@ -15,7 +15,7 @@ */ package com.google.common.truth; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Integer} subjects. @@ -29,7 +29,7 @@ public class IntegerSubject extends ComparableSubject { * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected IntegerSubject(FailureMetadata metadata, @NullableDecl Integer integer) { + protected IntegerSubject(FailureMetadata metadata, @Nullable Integer integer) { super(metadata, integer); } diff --git a/core/src/main/java/com/google/common/truth/IterableSubject.java b/core/src/main/java/com/google/common/truth/IterableSubject.java index 3daacb3bb..bfb5dad26 100644 --- a/core/src/main/java/com/google/common/truth/IterableSubject.java +++ b/core/src/main/java/com/google/common/truth/IterableSubject.java @@ -66,7 +66,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Iterable} subjects. @@ -95,7 +95,7 @@ public class IterableSubject extends Subject { * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected IterableSubject(FailureMetadata metadata, @NullableDecl Iterable iterable) { + protected IterableSubject(FailureMetadata metadata, @Nullable Iterable iterable) { super(metadata, iterable); this.actual = iterable; } @@ -115,7 +115,7 @@ protected String actualCustomStringRepresentation() { } @Override - public void isEqualTo(@NullableDecl Object expected) { + public void isEqualTo(@Nullable Object expected) { @SuppressWarnings("UndefinedEquals") // method contract requires testing iterables for equality boolean equal = Objects.equal(actual, expected); if (equal) { @@ -160,7 +160,7 @@ public final void hasSize(int expectedSize) { } /** Checks (with a side-effect failure) that the subject contains the supplied item. */ - public final void contains(@NullableDecl Object element) { + public final void contains(@Nullable Object element) { if (!Iterables.contains(actual, element)) { List elementList = newArrayList(element); if (hasMatchingToStringPair(actual, elementList)) { @@ -180,7 +180,7 @@ public final void contains(@NullableDecl Object element) { } /** Checks (with a side-effect failure) that the subject does not contain the supplied item. */ - public final void doesNotContain(@NullableDecl Object element) { + public final void doesNotContain(@Nullable Object element) { if (Iterables.contains(actual, element)) { failWithActual("expected not to contain", element); } @@ -204,7 +204,7 @@ public final void containsNoDuplicates() { /** Checks that the subject contains at least one of the provided objects or fails. */ public final void containsAnyOf( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object /*@Nullable*/... rest) { containsAnyIn(accumulate(first, second, rest)); } @@ -253,9 +253,9 @@ public final void containsAnyIn(Object[] expected) { */ @CanIgnoreReturnValue public final Ordered containsAtLeast( - @NullableDecl Object firstExpected, - @NullableDecl Object secondExpected, - @NullableDecl Object... restOfExpected) { + @Nullable Object firstExpected, + @Nullable Object secondExpected, + @Nullable Object /*@Nullable*/... restOfExpected) { return containsAtLeastElementsIn(accumulate(firstExpected, secondExpected, restOfExpected)); } @@ -379,7 +379,7 @@ private static void moveElements(List input, Collection output, int m * elements, not an element itself. This helps human readers and avoids a compiler warning. */ @CanIgnoreReturnValue - public final Ordered containsExactly(@NullableDecl Object... varargs) { + public final Ordered containsExactly(@Nullable Object /*@Nullable*/... varargs) { List expected = (varargs == null) ? newArrayList((Object) null) : asList(varargs); return containsExactlyElementsIn( expected, varargs != null && varargs.length == 1 && varargs[0] instanceof Iterable); @@ -692,9 +692,9 @@ enum ElementFactGrouping { * irrelevant to this test, which fails if any of the actual elements equal any of the excluded.) */ public final void containsNoneOf( - @NullableDecl Object firstExcluded, - @NullableDecl Object secondExcluded, - @NullableDecl Object... restOfExcluded) { + @Nullable Object firstExcluded, + @Nullable Object secondExcluded, + @Nullable Object /*@Nullable*/... restOfExcluded) { containsNoneIn(accumulate(firstExcluded, secondExcluded, restOfExcluded)); } @@ -845,7 +845,7 @@ private void pairwiseCheck(String expectedFact, PairwiseChecker checker) { @Override @Deprecated public void isNoneOf( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object /*@Nullable*/... rest) { super.isNoneOf(first, second, rest); } @@ -1056,7 +1056,7 @@ public UsingCorrespondence displayingDiffsPairedBy( * Checks that the subject contains at least one element that corresponds to the given expected * element. */ - public void contains(@NullableDecl E expected) { + public void contains(@Nullable E expected) { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); for (A actual : getCastActual()) { if (correspondence.safeCompare(actual, expected, exceptions)) { @@ -1106,7 +1106,7 @@ public void contains(@NullableDecl E expected) { } /** Checks that none of the actual elements correspond to the given element. */ - public void doesNotContain(@NullableDecl E excluded) { + public void doesNotContain(@Nullable E excluded) { Correspondence.ExceptionStore exceptions = Correspondence.ExceptionStore.forIterable(); List matchingElements = new ArrayList<>(); for (A actual : getCastActual()) { @@ -1153,7 +1153,7 @@ public void doesNotContain(@NullableDecl E excluded) { */ @SafeVarargs @CanIgnoreReturnValue - public final Ordered containsExactly(@NullableDecl E... expected) { + public final Ordered containsExactly(@Nullable E /*@Nullable*/... expected) { return containsExactlyElementsIn( (expected == null) ? newArrayList((E) null) : asList(expected)); } @@ -1330,7 +1330,7 @@ private ImmutableList describeMissingOrExtra( List extra, Correspondence.ExceptionStore exceptions) { if (pairer.isPresent()) { - @NullableDecl Pairing pairing = pairer.get().pair(missing, extra, exceptions); + @Nullable Pairing pairing = pairer.get().pair(missing, extra, exceptions); if (pairing != null) { return describeMissingOrExtraWithPairing(pairing, exceptions); } else { @@ -1387,7 +1387,7 @@ private ImmutableList formatExtras( boolean hasDiffs = false; for (int i = 0; i < extras.size(); i++) { A extra = extras.get(i); - @NullableDecl String diff = correspondence.safeFormatDiff(extra, missing, exceptions); + @Nullable String diff = correspondence.safeFormatDiff(extra, missing, exceptions); diffs.add(diff); if (diff != null) { hasDiffs = true; @@ -1504,7 +1504,7 @@ private boolean failIfOneToOneMappingHasMissingOrExtra( @SafeVarargs @CanIgnoreReturnValue public final Ordered containsAtLeast( - @NullableDecl E first, @NullableDecl E second, @NullableDecl E... rest) { + @Nullable E first, @Nullable E second, @Nullable E /*@Nullable*/... rest) { return containsAtLeastElementsIn(accumulate(first, second, rest)); } @@ -1667,7 +1667,7 @@ private ImmutableList describeMissing( List extra, Correspondence.ExceptionStore exceptions) { if (pairer.isPresent()) { - @NullableDecl Pairing pairing = pairer.get().pair(missing, extra, exceptions); + @Nullable Pairing pairing = pairer.get().pair(missing, extra, exceptions); if (pairing != null) { return describeMissingWithPairing(pairing, exceptions); } else { @@ -1753,7 +1753,7 @@ private boolean failIfOneToOneMappingHasMissing( */ @SafeVarargs public final void containsAnyOf( - @NullableDecl E first, @NullableDecl E second, @NullableDecl E... rest) { + @Nullable E first, @Nullable E second, @Nullable E /*@Nullable*/... rest) { containsAnyIn(accumulate(first, second, rest)); } @@ -1784,7 +1784,6 @@ public void containsAnyIn(Iterable expected) { } // Found no match. Fail, reporting elements that have a correct key if there are any. if (pairer.isPresent()) { - @NullableDecl Pairing pairing = pairer.get().pair(iterableToList(expected), iterableToList(actual), exceptions); if (pairing != null) { @@ -1860,9 +1859,9 @@ private ImmutableList describeAnyMatchesByKey( */ @SafeVarargs public final void containsNoneOf( - @NullableDecl E firstExcluded, - @NullableDecl E secondExcluded, - @NullableDecl E... restOfExcluded) { + @Nullable E firstExcluded, + @Nullable E secondExcluded, + @Nullable E /*@Nullable*/... restOfExcluded) { containsNoneIn(accumulate(firstExcluded, secondExcluded, restOfExcluded)); } @@ -1951,7 +1950,7 @@ private final class Pairer { * Returns a {@link Pairing} of the given expected and actual values, or {@code null} if the * expected values are not uniquely keyed. */ - @NullableDecl + @Nullable Pairing pair( List expectedValues, List actualValues, @@ -1969,7 +1968,7 @@ Pairing pair( // We will remove the unpaired keys later. Return null if we find a duplicate key. for (int i = 0; i < expectedValues.size(); i++) { E expected = expectedValues.get(i); - @NullableDecl Object key = expectedKeys.get(i); + @Nullable Object key = expectedKeys.get(i); if (key != null) { if (pairing.pairedKeysToExpectedValues.containsKey(key)) { return null; @@ -1981,7 +1980,7 @@ Pairing pair( // Populate pairedKeysToActualValues and unpairedActualValues. for (A actual : actualValues) { - @NullableDecl Object key = actualKey(actual, exceptions); + @Nullable Object key = actualKey(actual, exceptions); if (pairing.pairedKeysToExpectedValues.containsKey(key)) { pairing.pairedKeysToActualValues.put(key, actual); } else { @@ -1992,7 +1991,7 @@ Pairing pair( // Populate unpairedExpectedValues and remove unpaired keys from pairedKeysToExpectedValues. for (int i = 0; i < expectedValues.size(); i++) { E expected = expectedValues.get(i); - @NullableDecl Object key = expectedKeys.get(i); + @Nullable Object key = expectedKeys.get(i); if (!pairing.pairedKeysToActualValues.containsKey(key)) { pairing.unpairedExpectedValues.add(expected); pairing.pairedKeysToExpectedValues.remove(key); @@ -2006,7 +2005,7 @@ List pairOne( E expectedValue, Iterable actualValues, Correspondence.ExceptionStore exceptions) { - @NullableDecl Object key = expectedKey(expectedValue, exceptions); + @Nullable Object key = expectedKey(expectedValue, exceptions); List matches = new ArrayList<>(); if (key != null) { for (A actual : actualValues) { @@ -2018,8 +2017,7 @@ List pairOne( return matches; } - @NullableDecl - private Object actualKey(A actual, Correspondence.ExceptionStore exceptions) { + private @Nullable Object actualKey(A actual, Correspondence.ExceptionStore exceptions) { try { return actualKeyFunction.apply(actual); } catch (RuntimeException e) { @@ -2029,8 +2027,7 @@ private Object actualKey(A actual, Correspondence.ExceptionStore exceptions) { } } - @NullableDecl - private Object expectedKey(E expected, Correspondence.ExceptionStore exceptions) { + private @Nullable Object expectedKey(E expected, Correspondence.ExceptionStore exceptions) { try { return expectedKeyFunction.apply(expected); } catch (RuntimeException e) { diff --git a/core/src/main/java/com/google/common/truth/LazyMessage.java b/core/src/main/java/com/google/common/truth/LazyMessage.java index e244eaf3a..aa5b3c54c 100644 --- a/core/src/main/java/com/google/common/truth/LazyMessage.java +++ b/core/src/main/java/com/google/common/truth/LazyMessage.java @@ -20,7 +20,6 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.collect.ImmutableList; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; final class LazyMessage { private static final String PLACEHOLDER_ERR = @@ -29,7 +28,7 @@ final class LazyMessage { private final String format; private final Object[] args; - LazyMessage(String format, @NullableDecl Object... args) { + LazyMessage(String format, /*@Nullable*/ Object... args) { this.format = format; this.args = args; int placeholders = countPlaceholders(format); diff --git a/core/src/main/java/com/google/common/truth/LongSubject.java b/core/src/main/java/com/google/common/truth/LongSubject.java index 33458dcf1..27f99f546 100644 --- a/core/src/main/java/com/google/common/truth/LongSubject.java +++ b/core/src/main/java/com/google/common/truth/LongSubject.java @@ -15,7 +15,7 @@ */ package com.google.common.truth; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@code long} subjects. @@ -29,7 +29,7 @@ public class LongSubject extends ComparableSubject { * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected LongSubject(FailureMetadata metadata, @NullableDecl Long actual) { + protected LongSubject(FailureMetadata metadata, @Nullable Long actual) { super(metadata, actual); } diff --git a/core/src/main/java/com/google/common/truth/MapSubject.java b/core/src/main/java/com/google/common/truth/MapSubject.java index 6d174b372..6315a8e8a 100644 --- a/core/src/main/java/com/google/common/truth/MapSubject.java +++ b/core/src/main/java/com/google/common/truth/MapSubject.java @@ -42,7 +42,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Map} subjects. @@ -57,13 +57,13 @@ public class MapSubject extends Subject { * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected MapSubject(FailureMetadata metadata, @NullableDecl Map map) { + protected MapSubject(FailureMetadata metadata, @Nullable Map map) { super(metadata, map); this.actual = map; } @Override - public final void isEqualTo(@NullableDecl Object other) { + public final void isEqualTo(@Nullable Object other) { if (Objects.equal(actual, other)) { return; } @@ -99,17 +99,17 @@ public final void hasSize(int expectedSize) { } /** Fails if the map does not contain the given key. */ - public final void containsKey(@NullableDecl Object key) { + public final void containsKey(@Nullable Object key) { check("keySet()").that(actual.keySet()).contains(key); } /** Fails if the map contains the given key. */ - public final void doesNotContainKey(@NullableDecl Object key) { + public final void doesNotContainKey(@Nullable Object key) { check("keySet()").that(actual.keySet()).doesNotContain(key); } /** Fails if the map does not contain the given entry. */ - public final void containsEntry(@NullableDecl Object key, @NullableDecl Object value) { + public final void containsEntry(@Nullable Object key, @Nullable Object value) { Map.Entry entry = immutableEntry(key, value); if (!actual.entrySet().contains(entry)) { List keyList = singletonList(key); @@ -166,7 +166,7 @@ public final void containsEntry(@NullableDecl Object key, @NullableDecl Object v } /** Fails if the map contains the given entry. */ - public final void doesNotContainEntry(@NullableDecl Object key, @NullableDecl Object value) { + public final void doesNotContainEntry(@Nullable Object key, @Nullable Object value) { checkNoNeedToDisplayBothValues("entrySet()") .that(actual.entrySet()) .doesNotContain(immutableEntry(key, value)); @@ -188,18 +188,18 @@ public final Ordered containsExactly() { */ @CanIgnoreReturnValue public final Ordered containsExactly( - @NullableDecl Object k0, @NullableDecl Object v0, Object... rest) { + @Nullable Object k0, @Nullable Object v0, /*@Nullable*/ Object... rest) { return containsExactlyEntriesIn(accumulateMap("containsExactly", k0, v0, rest)); } @CanIgnoreReturnValue public final Ordered containsAtLeast( - @NullableDecl Object k0, @NullableDecl Object v0, Object... rest) { + @Nullable Object k0, @Nullable Object v0, /*@Nullable*/ Object... rest) { return containsAtLeastEntriesIn(accumulateMap("containsAtLeast", k0, v0, rest)); } private static Map accumulateMap( - String functionName, @NullableDecl Object k0, @NullableDecl Object v0, Object... rest) { + String functionName, @Nullable Object k0, @Nullable Object v0, /*@Nullable*/ Object... rest) { checkArgument( rest.length % 2 == 0, "There must be an equal number of key/value pairs " @@ -285,14 +285,14 @@ private boolean containsEntriesInAnyOrder(Map expectedMap, boolean allowUn } private interface ValueTester { - boolean test(@NullableDecl A actualValue, @NullableDecl E expectedValue); + boolean test(@Nullable A actualValue, @Nullable E expectedValue); } @SuppressWarnings("UnnecessaryAnonymousClass") // for Java 7 compatibility private static final ValueTester EQUALITY = new ValueTester() { @Override - public boolean test(@NullableDecl Object actualValue, @NullableDecl Object expectedValue) { + public boolean test(@Nullable Object actualValue, @Nullable Object expectedValue) { return Objects.equal(actualValue, expectedValue); } }; @@ -352,7 +352,7 @@ boolean isEmpty() { return missing.isEmpty() && unexpected.isEmpty() && wrongValues.isEmpty(); } - ImmutableList describe(@NullableDecl Differ differ) { + ImmutableList describe(@Nullable Differ differ) { boolean includeKeyTypes = includeKeyTypes(); ImmutableList.Builder facts = ImmutableList.builder(); if (!wrongValues.isEmpty()) { @@ -394,12 +394,12 @@ private static class ValueDifference { private final A actual; private final E expected; - ValueDifference(@NullableDecl A actual, @NullableDecl E expected) { + ValueDifference(@Nullable A actual, @Nullable E expected) { this.actual = actual; this.expected = expected; } - ImmutableList describe(@NullableDecl Differ differ) { + ImmutableList describe(@Nullable Differ differ) { boolean includeTypes = differ == null && String.valueOf(actual).equals(String.valueOf(expected)); ImmutableList.Builder facts = @@ -427,12 +427,12 @@ private class MapInOrder implements Ordered { private final Map expectedMap; private final boolean allowUnexpected; - @NullableDecl private final Correspondence correspondence; + private final @Nullable Correspondence correspondence; MapInOrder( Map expectedMap, boolean allowUnexpected, - @NullableDecl Correspondence correspondence) { + @Nullable Correspondence correspondence) { this.expectedMap = expectedMap; this.allowUnexpected = allowUnexpected; this.correspondence = correspondence; @@ -564,7 +564,7 @@ private UsingCorrespondence(Correspondence correspondence) * Fails if the map does not contain an entry with the given key and a value that corresponds to * the given value. */ - public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl E expectedValue) { + public void containsEntry(@Nullable Object expectedKey, @Nullable E expectedValue) { if (actual.containsKey(expectedKey)) { // Found matching key. A actualValue = getCastSubject().get(expectedKey); @@ -575,7 +575,6 @@ public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl E expe return; } // Found matching key with non-matching value. - @NullableDecl String diff = correspondence.safeFormatDiff(actualValue, expectedValue, exceptions); if (diff != null) { failWithoutActual( @@ -639,8 +638,7 @@ public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl E expe * Fails if the map contains an entry with the given key and a value that corresponds to the * given value. */ - public void doesNotContainEntry( - @NullableDecl Object excludedKey, @NullableDecl E excludedValue) { + public void doesNotContainEntry(@Nullable Object excludedKey, @Nullable E excludedValue) { if (actual.containsKey(excludedKey)) { // Found matching key. Fail if the value matches, too. A actualValue = getCastSubject().get(excludedKey); @@ -684,7 +682,8 @@ public void doesNotContainEntry( // TODO(b/25744307): Can we add an error-prone check that rest.length % 2 == 0? // For bonus points, checking that the even-numbered values are of type E would be sweet. @CanIgnoreReturnValue - public Ordered containsExactly(@NullableDecl Object k0, @NullableDecl E v0, Object... rest) { + public Ordered containsExactly( + @Nullable Object k0, @Nullable E v0, /*@Nullable*/ Object... rest) { @SuppressWarnings("unchecked") // throwing ClassCastException is the correct behaviour Map expectedMap = (Map) accumulateMap("containsExactly", k0, v0, rest); return containsExactlyEntriesIn(expectedMap); @@ -703,7 +702,8 @@ public Ordered containsExactly(@NullableDecl Object k0, @NullableDecl E v0, Obje // TODO(b/25744307): Can we add an error-prone check that rest.length % 2 == 0? // For bonus points, checking that the even-numbered values are of type E would be sweet. @CanIgnoreReturnValue - public Ordered containsAtLeast(@NullableDecl Object k0, @NullableDecl E v0, Object... rest) { + public Ordered containsAtLeast( + @Nullable Object k0, @Nullable E v0, /*@Nullable*/ Object... rest) { @SuppressWarnings("unchecked") // throwing ClassCastException is the correct behaviour Map expectedMap = (Map) accumulateMap("containsAtLeast", k0, v0, rest); return containsAtLeastEntriesIn(expectedMap); diff --git a/core/src/main/java/com/google/common/truth/MultimapSubject.java b/core/src/main/java/com/google/common/truth/MultimapSubject.java index 2670105a5..332da4ae0 100644 --- a/core/src/main/java/com/google/common/truth/MultimapSubject.java +++ b/core/src/main/java/com/google/common/truth/MultimapSubject.java @@ -45,7 +45,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Multimap} subjects. @@ -69,14 +69,14 @@ public void inOrder() {} * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected MultimapSubject(FailureMetadata metadata, @NullableDecl Multimap multimap) { + protected MultimapSubject(FailureMetadata metadata, @Nullable Multimap multimap) { this(metadata, multimap, null); } MultimapSubject( FailureMetadata metadata, - @NullableDecl Multimap multimap, - @NullableDecl String typeDescription) { + @Nullable Multimap multimap, + @Nullable String typeDescription) { super(metadata, multimap, typeDescription); this.actual = multimap; } @@ -102,17 +102,17 @@ public final void hasSize(int expectedSize) { } /** Fails if the multimap does not contain the given key. */ - public final void containsKey(@NullableDecl Object key) { + public final void containsKey(@Nullable Object key) { check("keySet()").that(actual.keySet()).contains(key); } /** Fails if the multimap contains the given key. */ - public final void doesNotContainKey(@NullableDecl Object key) { + public final void doesNotContainKey(@Nullable Object key) { check("keySet()").that(actual.keySet()).doesNotContain(key); } /** Fails if the multimap does not contain the given entry. */ - public final void containsEntry(@NullableDecl Object key, @NullableDecl Object value) { + public final void containsEntry(@Nullable Object key, @Nullable Object value) { // TODO(kak): Can we share any of this logic w/ MapSubject.containsEntry()? if (!actual.containsEntry(key, value)) { Map.Entry entry = immutableEntry(key, value); @@ -154,7 +154,7 @@ public final void containsEntry(@NullableDecl Object key, @NullableDecl Object v } /** Fails if the multimap contains the given entry. */ - public final void doesNotContainEntry(@NullableDecl Object key, @NullableDecl Object value) { + public final void doesNotContainEntry(@Nullable Object key, @Nullable Object value) { checkNoNeedToDisplayBothValues("entries()") .that(actual.entries()) .doesNotContain(immutableEntry(key, value)); @@ -176,12 +176,12 @@ public final void doesNotContainEntry(@NullableDecl Object key, @NullableDecl Ob * would force callers to perform any configuration _before_ the valuesForKey call, while * currently they must perform it _after_. */ - public IterableSubject valuesForKey(@NullableDecl Object key) { + public IterableSubject valuesForKey(@Nullable Object key) { return check("valuesForKey(%s)", key).that(((Multimap) actual).get(key)); } @Override - public final void isEqualTo(@NullableDecl Object other) { + public final void isEqualTo(@Nullable Object other) { @SuppressWarnings("UndefinedEquals") // the contract of this method is to follow Multimap.equals boolean isEqual = Objects.equal(actual, other); if (isEqual) { @@ -305,7 +305,7 @@ public final Ordered containsExactly() { */ @CanIgnoreReturnValue public final Ordered containsExactly( - @NullableDecl Object k0, @NullableDecl Object v0, Object... rest) { + @Nullable Object k0, @Nullable Object v0, /*@Nullable*/ Object... rest) { return containsExactlyEntriesIn(accumulateMultimap(k0, v0, rest)); } @@ -317,12 +317,12 @@ public final Ordered containsExactly( */ @CanIgnoreReturnValue public final Ordered containsAtLeast( - @NullableDecl Object k0, @NullableDecl Object v0, Object... rest) { + @Nullable Object k0, @Nullable Object v0, /*@Nullable*/ Object... rest) { return containsAtLeastEntriesIn(accumulateMultimap(k0, v0, rest)); } private static Multimap accumulateMultimap( - @NullableDecl Object k0, @NullableDecl Object v0, Object... rest) { + @Nullable Object k0, @Nullable Object v0, /*@Nullable*/ Object... rest) { checkArgument( rest.length % 2 == 0, "There must be an equal number of key/value pairs " @@ -441,7 +441,7 @@ private static boolean advanceToFind(Iterator iterator, Object value) { return false; } - private static Collection get(Multimap multimap, @NullableDecl Object key) { + private static Collection get(Multimap multimap, @Nullable Object key) { if (multimap.containsKey(key)) { return multimap.asMap().get(key); } else { @@ -554,7 +554,7 @@ private UsingCorrespondence(Correspondence correspondence) * Fails if the multimap does not contain an entry with the given key and a value that * corresponds to the given value. */ - public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl E expectedValue) { + public void containsEntry(@Nullable Object expectedKey, @Nullable E expectedValue) { if (actual.containsKey(expectedKey)) { // Found matching key. Collection actualValues = getCastActual().asMap().get(expectedKey); @@ -647,8 +647,7 @@ public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl E expe * Fails if the multimap contains an entry with the given key and a value that corresponds to * the given value. */ - public void doesNotContainEntry( - @NullableDecl Object excludedKey, @NullableDecl E excludedValue) { + public void doesNotContainEntry(@Nullable Object excludedKey, @Nullable E excludedValue) { if (actual.containsKey(excludedKey)) { Collection actualValues = getCastActual().asMap().get(excludedKey); List matchingValues = new ArrayList<>(); @@ -771,7 +770,8 @@ private Ordered internalContainsAtLeastEntriesIn( * key/value pairs at compile time. Please make sure you provide varargs in key/value pairs! */ @CanIgnoreReturnValue - public Ordered containsExactly(@NullableDecl Object k0, @NullableDecl E v0, Object... rest) { + public Ordered containsExactly( + @Nullable Object k0, @Nullable E v0, /*@Nullable*/ Object... rest) { @SuppressWarnings("unchecked") Multimap expectedMultimap = (Multimap) accumulateMultimap(k0, v0, rest); return containsExactlyEntriesIn(expectedMultimap); @@ -790,7 +790,8 @@ public Ordered containsExactly() { * key/value pairs at compile time. Please make sure you provide varargs in key/value pairs! */ @CanIgnoreReturnValue - public Ordered containsAtLeast(@NullableDecl Object k0, @NullableDecl E v0, Object... rest) { + public Ordered containsAtLeast( + @Nullable Object k0, @Nullable E v0, /*@Nullable*/ Object... rest) { @SuppressWarnings("unchecked") Multimap expectedMultimap = (Multimap) accumulateMultimap(k0, v0, rest); return containsAtLeastEntriesIn(expectedMultimap); diff --git a/core/src/main/java/com/google/common/truth/MultisetSubject.java b/core/src/main/java/com/google/common/truth/MultisetSubject.java index 984da1fa2..40037fe38 100644 --- a/core/src/main/java/com/google/common/truth/MultisetSubject.java +++ b/core/src/main/java/com/google/common/truth/MultisetSubject.java @@ -18,7 +18,7 @@ import static com.google.common.base.Preconditions.checkArgument; import com.google.common.collect.Multiset; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Multiset} subjects. @@ -29,13 +29,13 @@ public final class MultisetSubject extends IterableSubject { private final Multiset actual; - MultisetSubject(FailureMetadata metadata, @NullableDecl Multiset multiset) { + MultisetSubject(FailureMetadata metadata, @Nullable Multiset multiset) { super(metadata, multiset); this.actual = multiset; } /** Fails if the element does not have the given count. */ - public final void hasCount(@NullableDecl Object element, int expectedCount) { + public final void hasCount(@Nullable Object element, int expectedCount) { checkArgument(expectedCount >= 0, "expectedCount(%s) must be >= 0", expectedCount); int actualCount = ((Multiset) actual).count(element); check("count(%s)", element).that(actualCount).isEqualTo(expectedCount); diff --git a/core/src/main/java/com/google/common/truth/ObjectArraySubject.java b/core/src/main/java/com/google/common/truth/ObjectArraySubject.java index d8a6bc691..cd6b42b5a 100644 --- a/core/src/main/java/com/google/common/truth/ObjectArraySubject.java +++ b/core/src/main/java/com/google/common/truth/ObjectArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import java.util.Arrays; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code Object[]} and more generically {@code T[]}. @@ -27,7 +27,7 @@ public final class ObjectArraySubject extends AbstractArraySubject { private final T[] actual; ObjectArraySubject( - FailureMetadata metadata, @NullableDecl T[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, @Nullable T /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/Platform.java b/core/src/main/java/com/google/common/truth/Platform.java index bf216c9e9..b47cb87b2 100644 --- a/core/src/main/java/com/google/common/truth/Platform.java +++ b/core/src/main/java/com/google/common/truth/Platform.java @@ -26,7 +26,7 @@ import java.lang.reflect.Method; import java.util.List; import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.ComparisonFailure; import org.junit.rules.TestRule; @@ -122,8 +122,7 @@ static String inferDescription() { } } - @NullableDecl - static ImmutableList makeDiff(String expected, String actual) { + static @Nullable ImmutableList makeDiff(String expected, String actual) { ImmutableList expectedLines = splitLines(expected); ImmutableList actualLines = splitLines(actual); List unifiedDiff = @@ -149,10 +148,10 @@ abstract static class PlatformComparisonFailure extends ComparisonFailure { private final String message; /** Separate cause field, in case initCause() fails. */ - @NullableDecl private final Throwable cause; + private final @Nullable Throwable cause; PlatformComparisonFailure( - String message, String expected, String actual, @NullableDecl Throwable cause) { + String message, String expected, String actual, @Nullable Throwable cause) { super(message, expected, actual); this.message = message; this.cause = cause; diff --git a/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java index c8121c3e6..47605bc64 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveBooleanArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.primitives.Booleans; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code boolean[]}. @@ -27,7 +27,7 @@ public final class PrimitiveBooleanArraySubject extends AbstractArraySubject { private final boolean[] actual; PrimitiveBooleanArraySubject( - FailureMetadata metadata, @NullableDecl boolean[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, boolean /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java index 1f4176608..59a3c7dda 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveByteArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.primitives.Bytes; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code byte[]}. @@ -27,7 +27,7 @@ public final class PrimitiveByteArraySubject extends AbstractArraySubject { private final byte[] actual; PrimitiveByteArraySubject( - FailureMetadata metadata, @NullableDecl byte[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, byte /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java index 48c9925a0..6e94b2cf1 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveCharArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.primitives.Chars; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code char[]}. @@ -27,7 +27,7 @@ public final class PrimitiveCharArraySubject extends AbstractArraySubject { private final char[] actual; PrimitiveCharArraySubject( - FailureMetadata metadata, @NullableDecl char[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, char /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java index 018a89b05..dc2651051 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveDoubleArraySubject.java @@ -23,7 +23,7 @@ import com.google.common.primitives.Doubles; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Arrays; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code double[]}. @@ -34,7 +34,7 @@ public final class PrimitiveDoubleArraySubject extends AbstractArraySubject { private final double[] actual; PrimitiveDoubleArraySubject( - FailureMetadata metadata, @NullableDecl double[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, double /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java index 90e30fb1b..ae106d5f3 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveFloatArraySubject.java @@ -23,7 +23,7 @@ import com.google.common.primitives.Floats; import com.google.errorprone.annotations.CanIgnoreReturnValue; import java.util.Arrays; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code float[]}. @@ -34,7 +34,7 @@ public final class PrimitiveFloatArraySubject extends AbstractArraySubject { private final float[] actual; PrimitiveFloatArraySubject( - FailureMetadata metadata, @NullableDecl float[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, float /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java index 5c886398d..f2c4abb5b 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveIntArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.primitives.Ints; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code int[]}. @@ -27,7 +27,7 @@ public final class PrimitiveIntArraySubject extends AbstractArraySubject { private final int[] actual; PrimitiveIntArraySubject( - FailureMetadata metadata, @NullableDecl int[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, int /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java index cb2599129..1d5aec0c0 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveLongArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.primitives.Longs; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code long[]}. @@ -27,7 +27,7 @@ public final class PrimitiveLongArraySubject extends AbstractArraySubject { private final long[] actual; PrimitiveLongArraySubject( - FailureMetadata metadata, @NullableDecl long[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, long /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java b/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java index 2db7ea069..cd17c874e 100644 --- a/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java +++ b/core/src/main/java/com/google/common/truth/PrimitiveShortArraySubject.java @@ -16,7 +16,7 @@ package com.google.common.truth; import com.google.common.primitives.Shorts; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Subject for {@code short[]}. @@ -27,7 +27,7 @@ public final class PrimitiveShortArraySubject extends AbstractArraySubject { private final short[] actual; PrimitiveShortArraySubject( - FailureMetadata metadata, @NullableDecl short[] o, @NullableDecl String typeDescription) { + FailureMetadata metadata, short /*@Nullable*/[] o, @Nullable String typeDescription) { super(metadata, o, typeDescription); this.actual = o; } diff --git a/core/src/main/java/com/google/common/truth/SimpleSubjectBuilder.java b/core/src/main/java/com/google/common/truth/SimpleSubjectBuilder.java index dce9bbee4..4451ee464 100644 --- a/core/src/main/java/com/google/common/truth/SimpleSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/SimpleSubjectBuilder.java @@ -17,7 +17,7 @@ import static com.google.common.base.Preconditions.checkNotNull; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * In a fluent assertion chain, exposes the most common {@code that} method, which accepts a value @@ -41,7 +41,7 @@ public final class SimpleSubjectBuilder { this.subjectFactory = checkNotNull(subjectFactory); } - public SubjectT that(@NullableDecl ActualT actual) { + public SubjectT that(@Nullable ActualT actual) { return subjectFactory.createSubject(metadata, actual); } } diff --git a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java index 720fd3b85..512de7e85 100644 --- a/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java +++ b/core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java @@ -25,7 +25,7 @@ import com.google.common.collect.Table; import java.math.BigDecimal; import java.util.Map; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * In a fluent assertion chain, an object with which you can do any of the following: @@ -63,108 +63,108 @@ public static StandardSubjectBuilder forCustomFailureStrategy(FailureStrategy fa @SuppressWarnings({"unchecked", "rawtypes"}) public final > ComparableSubject that( - @NullableDecl ComparableT actual) { + @Nullable ComparableT actual) { return new ComparableSubject(metadata(), actual) {}; } - public final BigDecimalSubject that(@NullableDecl BigDecimal actual) { + public final BigDecimalSubject that(@Nullable BigDecimal actual) { return new BigDecimalSubject(metadata(), actual); } - public final Subject that(@NullableDecl Object actual) { + public final Subject that(@Nullable Object actual) { return new Subject(metadata(), actual); } @GwtIncompatible("ClassSubject.java") - public final ClassSubject that(@NullableDecl Class actual) { + public final ClassSubject that(@Nullable Class actual) { return new ClassSubject(metadata(), actual); } - public final ThrowableSubject that(@NullableDecl Throwable actual) { + public final ThrowableSubject that(@Nullable Throwable actual) { return new ThrowableSubject(metadata(), actual, "throwable"); } - public final LongSubject that(@NullableDecl Long actual) { + public final LongSubject that(@Nullable Long actual) { return new LongSubject(metadata(), actual); } - public final DoubleSubject that(@NullableDecl Double actual) { + public final DoubleSubject that(@Nullable Double actual) { return new DoubleSubject(metadata(), actual); } - public final FloatSubject that(@NullableDecl Float actual) { + public final FloatSubject that(@Nullable Float actual) { return new FloatSubject(metadata(), actual); } - public final IntegerSubject that(@NullableDecl Integer actual) { + public final IntegerSubject that(@Nullable Integer actual) { return new IntegerSubject(metadata(), actual); } - public final BooleanSubject that(@NullableDecl Boolean actual) { + public final BooleanSubject that(@Nullable Boolean actual) { return new BooleanSubject(metadata(), actual); } - public final StringSubject that(@NullableDecl String actual) { + public final StringSubject that(@Nullable String actual) { return new StringSubject(metadata(), actual); } - public final IterableSubject that(@NullableDecl Iterable actual) { + public final IterableSubject that(@Nullable Iterable actual) { return new IterableSubject(metadata(), actual); } - public final ObjectArraySubject that(@NullableDecl T[] actual) { + public final ObjectArraySubject that(@Nullable T /*@Nullable*/[] actual) { return new ObjectArraySubject<>(metadata(), actual, "array"); } - public final PrimitiveBooleanArraySubject that(@NullableDecl boolean[] actual) { + public final PrimitiveBooleanArraySubject that(boolean /*@Nullable*/[] actual) { return new PrimitiveBooleanArraySubject(metadata(), actual, "array"); } - public final PrimitiveShortArraySubject that(@NullableDecl short[] actual) { + public final PrimitiveShortArraySubject that(short /*@Nullable*/[] actual) { return new PrimitiveShortArraySubject(metadata(), actual, "array"); } - public final PrimitiveIntArraySubject that(@NullableDecl int[] actual) { + public final PrimitiveIntArraySubject that(int /*@Nullable*/[] actual) { return new PrimitiveIntArraySubject(metadata(), actual, "array"); } - public final PrimitiveLongArraySubject that(@NullableDecl long[] actual) { + public final PrimitiveLongArraySubject that(long /*@Nullable*/[] actual) { return new PrimitiveLongArraySubject(metadata(), actual, "array"); } - public final PrimitiveCharArraySubject that(@NullableDecl char[] actual) { + public final PrimitiveCharArraySubject that(char /*@Nullable*/[] actual) { return new PrimitiveCharArraySubject(metadata(), actual, "array"); } - public final PrimitiveByteArraySubject that(@NullableDecl byte[] actual) { + public final PrimitiveByteArraySubject that(byte /*@Nullable*/[] actual) { return new PrimitiveByteArraySubject(metadata(), actual, "array"); } - public final PrimitiveFloatArraySubject that(@NullableDecl float[] actual) { + public final PrimitiveFloatArraySubject that(float /*@Nullable*/[] actual) { return new PrimitiveFloatArraySubject(metadata(), actual, "array"); } - public final PrimitiveDoubleArraySubject that(@NullableDecl double[] actual) { + public final PrimitiveDoubleArraySubject that(double /*@Nullable*/[] actual) { return new PrimitiveDoubleArraySubject(metadata(), actual, "array"); } - public final GuavaOptionalSubject that(@NullableDecl Optional actual) { + public final GuavaOptionalSubject that(@Nullable Optional actual) { return new GuavaOptionalSubject(metadata(), actual, "optional"); } - public final MapSubject that(@NullableDecl Map actual) { + public final MapSubject that(@Nullable Map actual) { return new MapSubject(metadata(), actual); } - public final MultimapSubject that(@NullableDecl Multimap actual) { + public final MultimapSubject that(@Nullable Multimap actual) { return new MultimapSubject(metadata(), actual, "multimap"); } - public final MultisetSubject that(@NullableDecl Multiset actual) { + public final MultisetSubject that(@Nullable Multiset actual) { return new MultisetSubject(metadata(), actual); } - public final TableSubject that(@NullableDecl Table actual) { + public final TableSubject that(@Nullable Table actual) { return new TableSubject(metadata(), actual); } @@ -173,7 +173,7 @@ public final TableSubject that(@NullableDecl Table actual) { * this method is called multiple times, the messages will appear in the order that they were * specified. */ - public final StandardSubjectBuilder withMessage(@NullableDecl String messageToPrepend) { + public final StandardSubjectBuilder withMessage(@Nullable String messageToPrepend) { return withMessage("%s", messageToPrepend); } @@ -189,7 +189,7 @@ public final StandardSubjectBuilder withMessage(@NullableDecl String messageToPr * @throws IllegalArgumentException if the number of placeholders in the format string does not * equal the number of given arguments */ - public final StandardSubjectBuilder withMessage(String format, Object... args) { + public final StandardSubjectBuilder withMessage(String format, /*@Nullable*/ Object... args) { return new StandardSubjectBuilder(metadata().withMessage(format, args)); } diff --git a/core/src/main/java/com/google/common/truth/StringSubject.java b/core/src/main/java/com/google/common/truth/StringSubject.java index c0f9addfd..6e58b0d50 100644 --- a/core/src/main/java/com/google/common/truth/StringSubject.java +++ b/core/src/main/java/com/google/common/truth/StringSubject.java @@ -23,7 +23,7 @@ import com.google.common.annotations.GwtIncompatible; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for string subjects. @@ -38,7 +38,7 @@ public class StringSubject extends ComparableSubject { * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected StringSubject(FailureMetadata metadata, @NullableDecl String string) { + protected StringSubject(FailureMetadata metadata, @Nullable String string) { super(metadata, string); this.actual = string; } diff --git a/core/src/main/java/com/google/common/truth/Subject.java b/core/src/main/java/com/google/common/truth/Subject.java index 17af53c8f..5780f11af 100644 --- a/core/src/main/java/com/google/common/truth/Subject.java +++ b/core/src/main/java/com/google/common/truth/Subject.java @@ -48,7 +48,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * An object that lets you perform checks on the value under test. For example, {@code Subject} @@ -95,13 +95,13 @@ public void fail(AssertionError failure) {} private final FailureMetadata metadata; private final Object actual; private String customName = null; - @NullableDecl private final String typeDescriptionOverride; + private final @Nullable String typeDescriptionOverride; /** * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected Subject(FailureMetadata metadata, @NullableDecl Object actual) { + protected Subject(FailureMetadata metadata, @Nullable Object actual) { this(metadata, actual, /*typeDescriptionOverride=*/ null); } @@ -117,9 +117,7 @@ protected Subject(FailureMetadata metadata, @NullableDecl Object actual) { * obfuscated names. */ Subject( - FailureMetadata metadata, - @NullableDecl Object actual, - @NullableDecl String typeDescriptionOverride) { + FailureMetadata metadata, @Nullable Object actual, @Nullable String typeDescriptionOverride) { this.metadata = metadata.updateForSubject(this); this.actual = actual; this.typeDescriptionOverride = typeDescriptionOverride; @@ -166,11 +164,11 @@ public void isNotNull() { * method, they would get a ComparisonFailure and other message niceties, and they'd have less to * test. */ - public void isEqualTo(@NullableDecl Object expected) { + public void isEqualTo(@Nullable Object expected) { standardIsEqualTo(expected); } - private void standardIsEqualTo(@NullableDecl Object expected) { + private void standardIsEqualTo(@Nullable Object expected) { ComparisonResult difference = compareForEquality(expected); if (!difference.valuesAreEqual()) { failEqualityCheck(EqualityCheck.EQUAL, expected, difference); @@ -181,11 +179,11 @@ private void standardIsEqualTo(@NullableDecl Object expected) { * Fails if the subject is equal to the given object. The meaning of equality is the same as for * the {@link #isEqualTo} method. */ - public void isNotEqualTo(@NullableDecl Object unexpected) { + public void isNotEqualTo(@Nullable Object unexpected) { standardIsNotEqualTo(unexpected); } - private void standardIsNotEqualTo(@NullableDecl Object unexpected) { + private void standardIsNotEqualTo(@Nullable Object unexpected) { ComparisonResult difference = compareForEquality(unexpected); if (difference.valuesAreEqual()) { String unexpectedAsString = formatActualOrExpected(unexpected); @@ -207,7 +205,7 @@ private void standardIsNotEqualTo(@NullableDecl Object unexpected) { * *

The equality check follows the rules described on {@link #isEqualTo}. */ - private ComparisonResult compareForEquality(@NullableDecl Object expected) { + private ComparisonResult compareForEquality(@Nullable Object expected) { if (actual == null && expected == null) { return ComparisonResult.equal(); } else if (actual == null || expected == null) { @@ -245,7 +243,7 @@ private ComparisonResult compareForEquality(@NullableDecl Object expected) { } } - private static boolean isIntegralBoxedPrimitive(@NullableDecl Object o) { + private static boolean isIntegralBoxedPrimitive(@Nullable Object o) { return o instanceof Byte || o instanceof Short || o instanceof Character @@ -264,7 +262,7 @@ private static long integralValue(Object o) { } /** Fails if the subject is not the same instance as the given object. */ - public final void isSameInstanceAs(@NullableDecl Object expected) { + public final void isSameInstanceAs(@Nullable Object expected) { if (actual != expected) { failEqualityCheck( SAME_INSTANCE, @@ -280,7 +278,7 @@ public final void isSameInstanceAs(@NullableDecl Object expected) { } /** Fails if the subject is the same instance as the given object. */ - public final void isNotSameInstanceAs(@NullableDecl Object unexpected) { + public final void isNotSameInstanceAs(@Nullable Object unexpected) { if (actual == unexpected) { /* * We use actualCustomStringRepresentation() because it might be overridden to be better than @@ -347,7 +345,7 @@ public void isIn(Iterable iterable) { /** Fails unless the subject is equal to any of the given elements. */ public void isAnyOf( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object /*@Nullable*/... rest) { isIn(accumulate(first, second, rest)); } @@ -360,7 +358,7 @@ public void isNotIn(Iterable iterable) { /** Fails if the subject is equal to any of the given elements. */ public void isNoneOf( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object /*@Nullable*/... rest) { isNotIn(accumulate(first, second, rest)); } @@ -398,7 +396,7 @@ final String actualCustomStringRepresentationForPackageMembersToCall() { return actualCustomStringRepresentation(); } - private String formatActualOrExpected(@NullableDecl Object o) { + private String formatActualOrExpected(@Nullable Object o) { if (o instanceof byte[]) { return base16((byte[]) o); } else if (o != null && o.getClass().isArray()) { @@ -431,7 +429,7 @@ private static Iterable stringableIterable(Object[] array) { private static final Function STRINGIFY = new Function() { @Override - public Object apply(@NullableDecl Object input) { + public Object apply(@Nullable Object input) { if (input != null && input.getClass().isArray()) { Iterable iterable; if (input.getClass() == boolean[].class) { @@ -491,7 +489,7 @@ static ComparisonResult differentNoDescription() { private static final ComparisonResult DIFFERENT_NO_DESCRIPTION = new ComparisonResult(ImmutableList.of()); - @NullableDecl private final ImmutableList facts; + private final @Nullable ImmutableList facts; private ComparisonResult(ImmutableList facts) { this.facts = facts; @@ -716,7 +714,7 @@ protected final StandardSubjectBuilder ignoreCheck() { *

Example usage: The check {@code contains(String)} calls {@code failWithActual("expected to * contain", string)}. */ - protected final void failWithActual(String key, @NullableDecl Object value) { + protected final void failWithActual(String key, @Nullable Object value) { failWithActual(fact(key, value)); } @@ -1095,7 +1093,7 @@ final void failWithoutActual(String check) { */ @Deprecated @Override - public final boolean equals(@NullableDecl Object o) { + public final boolean equals(@Nullable Object o) { throw new UnsupportedOperationException( "If you meant to test object equality, use .isEqualTo(other) instead."); } @@ -1144,7 +1142,7 @@ final String typeDescription() { } private static String typeDescriptionOrGuess( - Class clazz, @NullableDecl String typeDescriptionOverride) { + Class clazz, @Nullable String typeDescriptionOverride) { if (typeDescriptionOverride != null) { return typeDescriptionOverride; } diff --git a/core/src/main/java/com/google/common/truth/TableSubject.java b/core/src/main/java/com/google/common/truth/TableSubject.java index d59e10b8d..87fcd69f0 100644 --- a/core/src/main/java/com/google/common/truth/TableSubject.java +++ b/core/src/main/java/com/google/common/truth/TableSubject.java @@ -22,7 +22,7 @@ import com.google.common.collect.Table; import com.google.common.collect.Table.Cell; import com.google.common.collect.Tables; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Table} subjects. @@ -32,7 +32,7 @@ public final class TableSubject extends Subject { private final Table actual; - TableSubject(FailureMetadata metadata, @NullableDecl Table table) { + TableSubject(FailureMetadata metadata, @Nullable Table table) { super(metadata, table); this.actual = table; } @@ -58,14 +58,14 @@ public final void hasSize(int expectedSize) { } /** Fails if the table does not contain a mapping for the given row key and column key. */ - public void contains(@NullableDecl Object rowKey, @NullableDecl Object columnKey) { + public void contains(@Nullable Object rowKey, @Nullable Object columnKey) { if (!actual.contains(rowKey, columnKey)) { fail("contains mapping for row/column", rowKey, columnKey); } } /** Fails if the table contains a mapping for the given row key and column key. */ - public void doesNotContain(@NullableDecl Object rowKey, @NullableDecl Object columnKey) { + public void doesNotContain(@Nullable Object rowKey, @Nullable Object columnKey) { if (actual.contains(rowKey, columnKey)) { fail("does not contain mapping for row/column", rowKey, columnKey); } @@ -73,7 +73,7 @@ public void doesNotContain(@NullableDecl Object rowKey, @NullableDecl Object col /** Fails if the table does not contain the given cell. */ public void containsCell( - @NullableDecl Object rowKey, @NullableDecl Object colKey, @NullableDecl Object value) { + @Nullable Object rowKey, @Nullable Object colKey, @Nullable Object value) { containsCell(Tables.immutableCell(rowKey, colKey, value)); } @@ -85,7 +85,7 @@ public void containsCell(Cell cell) { /** Fails if the table contains the given cell. */ public void doesNotContainCell( - @NullableDecl Object rowKey, @NullableDecl Object colKey, @NullableDecl Object value) { + @Nullable Object rowKey, @Nullable Object colKey, @Nullable Object value) { doesNotContainCell(Tables.immutableCell(rowKey, colKey, value)); } @@ -96,17 +96,17 @@ public void doesNotContainCell(Cell cell) { } /** Fails if the table does not contain the given row key. */ - public void containsRow(@NullableDecl Object rowKey) { + public void containsRow(@Nullable Object rowKey) { check("rowKeySet()").that(actual.rowKeySet()).contains(rowKey); } /** Fails if the table does not contain the given column key. */ - public void containsColumn(@NullableDecl Object columnKey) { + public void containsColumn(@Nullable Object columnKey) { check("columnKeySet()").that(actual.columnKeySet()).contains(columnKey); } /** Fails if the table does not contain the given value. */ - public void containsValue(@NullableDecl Object value) { + public void containsValue(@Nullable Object value) { check("values()").that(actual.values()).contains(value); } } diff --git a/core/src/main/java/com/google/common/truth/ThrowableSubject.java b/core/src/main/java/com/google/common/truth/ThrowableSubject.java index bf6d539c2..8e0761da4 100644 --- a/core/src/main/java/com/google/common/truth/ThrowableSubject.java +++ b/core/src/main/java/com/google/common/truth/ThrowableSubject.java @@ -15,7 +15,7 @@ */ package com.google.common.truth; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Throwable} subjects. @@ -29,14 +29,12 @@ public class ThrowableSubject extends Subject { * Constructor for use by subclasses. If you want to create an instance of this class itself, call * {@link Subject#check(String, Object...) check(...)}{@code .that(actual)}. */ - protected ThrowableSubject(FailureMetadata metadata, @NullableDecl Throwable throwable) { + protected ThrowableSubject(FailureMetadata metadata, @Nullable Throwable throwable) { this(metadata, throwable, null); } ThrowableSubject( - FailureMetadata metadata, - @NullableDecl Throwable throwable, - @NullableDecl String typeDescription) { + FailureMetadata metadata, @Nullable Throwable throwable, @Nullable String typeDescription) { super(metadata, throwable, typeDescription); this.actual = throwable; } diff --git a/core/src/main/java/com/google/common/truth/Truth.java b/core/src/main/java/com/google/common/truth/Truth.java index 77bc2ce8f..0ff732f0e 100644 --- a/core/src/main/java/com/google/common/truth/Truth.java +++ b/core/src/main/java/com/google/common/truth/Truth.java @@ -24,7 +24,7 @@ import com.google.common.collect.Table; import java.math.BigDecimal; import java.util.Map; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * The primary entry point for Truth, a library for fluent test @@ -144,108 +144,108 @@ CustomSubjectBuilderT assertAbout( return assert_().about(factory); } - public static > ComparableSubject assertThat(@NullableDecl T actual) { + public static > ComparableSubject assertThat(@Nullable T actual) { return assert_().that(actual); } - public static BigDecimalSubject assertThat(@NullableDecl BigDecimal actual) { + public static BigDecimalSubject assertThat(@Nullable BigDecimal actual) { return assert_().that(actual); } - public static Subject assertThat(@NullableDecl Object actual) { + public static Subject assertThat(@Nullable Object actual) { return assert_().that(actual); } @GwtIncompatible("ClassSubject.java") - public static ClassSubject assertThat(@NullableDecl Class actual) { + public static ClassSubject assertThat(@Nullable Class actual) { return assert_().that(actual); } - public static ThrowableSubject assertThat(@NullableDecl Throwable actual) { + public static ThrowableSubject assertThat(@Nullable Throwable actual) { return assert_().that(actual); } - public static LongSubject assertThat(@NullableDecl Long actual) { + public static LongSubject assertThat(@Nullable Long actual) { return assert_().that(actual); } - public static DoubleSubject assertThat(@NullableDecl Double actual) { + public static DoubleSubject assertThat(@Nullable Double actual) { return assert_().that(actual); } - public static FloatSubject assertThat(@NullableDecl Float actual) { + public static FloatSubject assertThat(@Nullable Float actual) { return assert_().that(actual); } - public static IntegerSubject assertThat(@NullableDecl Integer actual) { + public static IntegerSubject assertThat(@Nullable Integer actual) { return assert_().that(actual); } - public static BooleanSubject assertThat(@NullableDecl Boolean actual) { + public static BooleanSubject assertThat(@Nullable Boolean actual) { return assert_().that(actual); } - public static StringSubject assertThat(@NullableDecl String actual) { + public static StringSubject assertThat(@Nullable String actual) { return assert_().that(actual); } - public static IterableSubject assertThat(@NullableDecl Iterable actual) { + public static IterableSubject assertThat(@Nullable Iterable actual) { return assert_().that(actual); } - public static ObjectArraySubject assertThat(@NullableDecl T[] actual) { + public static ObjectArraySubject assertThat(@Nullable T /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveBooleanArraySubject assertThat(@NullableDecl boolean[] actual) { + public static PrimitiveBooleanArraySubject assertThat(boolean /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveShortArraySubject assertThat(@NullableDecl short[] actual) { + public static PrimitiveShortArraySubject assertThat(short /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveIntArraySubject assertThat(@NullableDecl int[] actual) { + public static PrimitiveIntArraySubject assertThat(int /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveLongArraySubject assertThat(@NullableDecl long[] actual) { + public static PrimitiveLongArraySubject assertThat(long /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveByteArraySubject assertThat(@NullableDecl byte[] actual) { + public static PrimitiveByteArraySubject assertThat(byte /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveCharArraySubject assertThat(@NullableDecl char[] actual) { + public static PrimitiveCharArraySubject assertThat(char /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveFloatArraySubject assertThat(@NullableDecl float[] actual) { + public static PrimitiveFloatArraySubject assertThat(float /*@Nullable*/[] actual) { return assert_().that(actual); } - public static PrimitiveDoubleArraySubject assertThat(@NullableDecl double[] actual) { + public static PrimitiveDoubleArraySubject assertThat(double /*@Nullable*/[] actual) { return assert_().that(actual); } - public static GuavaOptionalSubject assertThat(@NullableDecl Optional actual) { + public static GuavaOptionalSubject assertThat(@Nullable Optional actual) { return assert_().that(actual); } - public static MapSubject assertThat(@NullableDecl Map actual) { + public static MapSubject assertThat(@Nullable Map actual) { return assert_().that(actual); } - public static MultimapSubject assertThat(@NullableDecl Multimap actual) { + public static MultimapSubject assertThat(@Nullable Multimap actual) { return assert_().that(actual); } - public static MultisetSubject assertThat(@NullableDecl Multiset actual) { + public static MultisetSubject assertThat(@Nullable Multiset actual) { return assert_().that(actual); } - public static TableSubject assertThat(@NullableDecl Table actual) { + public static TableSubject assertThat(@Nullable Table actual) { return assert_().that(actual); } @@ -256,9 +256,9 @@ public static TableSubject assertThat(@NullableDecl Table actual) { // TODO(cpovirk): Consider eliminating this, adding its functionality to AssertionErrorWithFacts? static final class SimpleAssertionError extends AssertionError { /** Separate cause field, in case initCause() fails. */ - @NullableDecl private final Throwable cause; + private final @Nullable Throwable cause; - private SimpleAssertionError(String message, @NullableDecl Throwable cause) { + private SimpleAssertionError(String message, @Nullable Throwable cause) { super(checkNotNull(message)); this.cause = cause; @@ -272,11 +272,11 @@ private SimpleAssertionError(String message, @NullableDecl Throwable cause) { } } - static SimpleAssertionError create(String message, @NullableDecl Throwable cause) { + static SimpleAssertionError create(String message, @Nullable Throwable cause) { return new SimpleAssertionError(message, cause); } - static SimpleAssertionError createWithNoStack(String message, @NullableDecl Throwable cause) { + static SimpleAssertionError createWithNoStack(String message, @Nullable Throwable cause) { SimpleAssertionError error = create(message, cause); error.setStackTrace(new StackTraceElement[0]); return error; diff --git a/core/src/main/java/com/google/common/truth/TruthFailureSubject.java b/core/src/main/java/com/google/common/truth/TruthFailureSubject.java index 54970badd..8724f9913 100644 --- a/core/src/main/java/com/google/common/truth/TruthFailureSubject.java +++ b/core/src/main/java/com/google/common/truth/TruthFailureSubject.java @@ -23,7 +23,7 @@ import static com.google.common.truth.Fact.simpleFact; import com.google.common.collect.ImmutableList; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Subject for {@link AssertionError} objects thrown by Truth. {@code TruthFailureSubject} contains @@ -63,9 +63,7 @@ public TruthFailureSubject createSubject(FailureMetadata metadata, AssertionErro private final AssertionError actual; TruthFailureSubject( - FailureMetadata metadata, - @NullableDecl AssertionError actual, - @NullableDecl String typeDescription) { + FailureMetadata metadata, @Nullable AssertionError actual, @Nullable String typeDescription) { super(metadata, actual, typeDescription); this.actual = actual; } @@ -123,7 +121,7 @@ public StringSubject factValue(String key, int index) { return doFactValue(key, index); } - private StringSubject doFactValue(String key, @NullableDecl Integer index) { + private StringSubject doFactValue(String key, @Nullable Integer index) { checkNotNull(key); if (!(actual instanceof ErrorWithFacts)) { failWithActual(simpleFact("expected a failure thrown by Truth's new failure API")); diff --git a/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java b/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java index 45a290e28..a64c502ab 100644 --- a/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java +++ b/core/src/main/java/com/google/common/truth/super/com/google/common/truth/Platform.java @@ -22,7 +22,7 @@ import com.google.common.collect.ImmutableList; import jsinterop.annotations.JsProperty; import jsinterop.annotations.JsType; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Extracted routines that need to be swapped in for GWT, to allow for minimal deltas between the @@ -86,8 +86,7 @@ static String inferDescription() { return null; } - @NullableDecl - static ImmutableList makeDiff(String expected, String actual) { + static @Nullable ImmutableList makeDiff(String expected, String actual) { /* * IIUC, GWT messages lose their newlines by the time users see them. Given that, users are * likely better served by showing the expected and actual values with mangled newlines than by diff --git a/core/src/test/java/com/google/common/truth/CorrespondenceTest.java b/core/src/test/java/com/google/common/truth/CorrespondenceTest.java index 27f3e5a6a..ac29057e2 100644 --- a/core/src/test/java/com/google/common/truth/CorrespondenceTest.java +++ b/core/src/test/java/com/google/common/truth/CorrespondenceTest.java @@ -24,7 +24,7 @@ import com.google.common.base.Function; import com.google.common.collect.ImmutableList; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -44,7 +44,7 @@ public final class CorrespondenceTest extends BaseSubjectTestCase { // (a, e) -> false, new Correspondence.BinaryPredicate() { @Override - public boolean apply(@NullableDecl Object actual, @NullableDecl Object expected) { + public boolean apply(@Nullable Object actual, @Nullable Object expected) { return false; } }, @@ -154,7 +154,6 @@ public void testFrom_viaIterableSubjectContainsExactly_null() { Correspondence.transforming( new Function() { @Override - @NullableDecl public Integer apply(String str) { return str.length(); } @@ -173,8 +172,7 @@ public Integer apply(String str) { Correspondence.transforming( new Function() { @Override - @NullableDecl - public Integer apply(String str) { + public @Nullable Integer apply(String str) { int index = str.indexOf('-'); return (index >= 0) ? index : null; } @@ -286,16 +284,14 @@ public void testTransforming_actual_viaIterableSubjectContainsExactly_nullTransf Correspondence.transforming( new Function() { @Override - @NullableDecl - public Integer apply(String str) { + public @Nullable Integer apply(String str) { int index = str.indexOf('-'); return (index >= 0) ? index : null; } }, new Function() { @Override - @NullableDecl - public Integer apply(String str) { + public @Nullable Integer apply(String str) { int index = str.indexOf(':'); return (index >= 0) ? index : null; } @@ -577,7 +573,6 @@ public void testEquality_viaIterableSubjectContains_failure() { Correspondence.transforming( new Function() { @Override - @NullableDecl public Integer apply(String str) { return str.length(); } diff --git a/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java b/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java index 74fe3140b..f96b474e1 100644 --- a/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java +++ b/core/src/test/java/com/google/common/truth/DoubleSubjectTest.java @@ -23,7 +23,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.truth.ExpectFailure.SimpleSubjectBuilderCallback; import com.google.errorprone.annotations.CanIgnoreReturnValue; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -394,7 +394,7 @@ public void isNotEqualTo() { assertThat(1.0).isNotEqualTo(2); } - private static void assertThatIsNotEqualToFails(@NullableDecl final Double value) { + private static void assertThatIsNotEqualToFails(final @Nullable Double value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -416,7 +416,7 @@ public void isZero() { assertThatIsZeroFails(null); } - private static void assertThatIsZeroFails(@NullableDecl final Double value) { + private static void assertThatIsZeroFails(final @Nullable Double value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -439,7 +439,7 @@ public void isNonZero() { assertThatIsNonZeroFails(null, "expected a double other than zero"); } - private static void assertThatIsNonZeroFails(@NullableDecl final Double value, String factKey) { + private static void assertThatIsNonZeroFails(final @Nullable Double value, String factKey) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -460,7 +460,7 @@ public void isPositiveInfinity() { assertThatIsPositiveInfinityFails(null); } - private static void assertThatIsPositiveInfinityFails(@NullableDecl final Double value) { + private static void assertThatIsPositiveInfinityFails(final @Nullable Double value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -480,7 +480,7 @@ public void isNegativeInfinity() { assertThatIsNegativeInfinityFails(null); } - private static void assertThatIsNegativeInfinityFails(@NullableDecl final Double value) { + private static void assertThatIsNegativeInfinityFails(final @Nullable Double value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -500,7 +500,7 @@ public void isNaN() { assertThatIsNaNFails(null); } - private static void assertThatIsNaNFails(@NullableDecl final Double value) { + private static void assertThatIsNaNFails(final @Nullable Double value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -522,7 +522,7 @@ public void isFinite() { assertThatIsFiniteFails(null); } - private static void assertThatIsFiniteFails(@NullableDecl final Double value) { + private static void assertThatIsFiniteFails(final @Nullable Double value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override diff --git a/core/src/test/java/com/google/common/truth/FloatSubjectTest.java b/core/src/test/java/com/google/common/truth/FloatSubjectTest.java index 46dee7fef..c404a731b 100644 --- a/core/src/test/java/com/google/common/truth/FloatSubjectTest.java +++ b/core/src/test/java/com/google/common/truth/FloatSubjectTest.java @@ -23,7 +23,7 @@ import com.google.common.annotations.GwtIncompatible; import com.google.common.truth.ExpectFailure.SimpleSubjectBuilderCallback; import com.google.errorprone.annotations.CanIgnoreReturnValue; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -394,7 +394,7 @@ public void isNotEqualTo() { assertThat(1.0f).isNotEqualTo(2); } - private static void assertThatIsNotEqualToFails(@NullableDecl final Float value) { + private static void assertThatIsNotEqualToFails(final @Nullable Float value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -416,7 +416,7 @@ public void isZero() { assertThatIsZeroFails(null); } - private static void assertThatIsZeroFails(@NullableDecl final Float value) { + private static void assertThatIsZeroFails(final @Nullable Float value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -439,7 +439,7 @@ public void isNonZero() { assertThatIsNonZeroFails(null, "expected a float other than zero"); } - private static void assertThatIsNonZeroFails(@NullableDecl final Float value, String factKey) { + private static void assertThatIsNonZeroFails(final @Nullable Float value, String factKey) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -460,7 +460,7 @@ public void isPositiveInfinity() { assertThatIsPositiveInfinityFails(null); } - private static void assertThatIsPositiveInfinityFails(@NullableDecl final Float value) { + private static void assertThatIsPositiveInfinityFails(final @Nullable Float value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -480,7 +480,7 @@ public void isNegativeInfinity() { assertThatIsNegativeInfinityFails(null); } - private static void assertThatIsNegativeInfinityFails(@NullableDecl final Float value) { + private static void assertThatIsNegativeInfinityFails(final @Nullable Float value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -500,7 +500,7 @@ public void isNaN() { assertThatIsNaNFails(null); } - private static void assertThatIsNaNFails(@NullableDecl final Float value) { + private static void assertThatIsNaNFails(final @Nullable Float value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override @@ -522,7 +522,7 @@ public void isFinite() { assertThatIsFiniteFails(null); } - private static void assertThatIsFiniteFails(@NullableDecl final Float value) { + private static void assertThatIsFiniteFails(final @Nullable Float value) { ExpectFailure.SimpleSubjectBuilderCallback callback = new ExpectFailure.SimpleSubjectBuilderCallback() { @Override diff --git a/core/src/test/java/com/google/common/truth/MathUtilTest.java b/core/src/test/java/com/google/common/truth/MathUtilTest.java index 1200fafe7..292bacd88 100644 --- a/core/src/test/java/com/google/common/truth/MathUtilTest.java +++ b/core/src/test/java/com/google/common/truth/MathUtilTest.java @@ -107,6 +107,6 @@ public void equalsDifferentTypes() { assertThat(equalWithinTolerance(1.3f, 1.3d, 0.00000000000001f)).isFalse(); } - // TODO(cgruber): More complicated ways to break float/double casting to make sure. + // TODO(user): More complicated ways to break float/double casting to make sure. } diff --git a/core/src/test/java/com/google/common/truth/SubjectTest.java b/core/src/test/java/com/google/common/truth/SubjectTest.java index 5731d71c4..d85449859 100644 --- a/core/src/test/java/com/google/common/truth/SubjectTest.java +++ b/core/src/test/java/com/google/common/truth/SubjectTest.java @@ -41,7 +41,7 @@ import java.math.BigDecimal; import java.util.Arrays; import java.util.Iterator; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @@ -780,19 +780,19 @@ public boolean equals(Object obj) { } private static final class ForbidsEqualityChecksSubject extends Subject { - ForbidsEqualityChecksSubject(FailureMetadata metadata, @NullableDecl Object actual) { + ForbidsEqualityChecksSubject(FailureMetadata metadata, @Nullable Object actual) { super(metadata, actual); } // Not sure how to feel about this, but people do it: @Override - public void isEqualTo(@NullableDecl Object expected) { + public void isEqualTo(@Nullable Object expected) { throw new UnsupportedOperationException(); } @Override - public void isNotEqualTo(@NullableDecl Object unexpected) { + public void isNotEqualTo(@Nullable Object unexpected) { throw new UnsupportedOperationException(); } } diff --git a/core/src/test/java/com/google/common/truth/TestCorrespondences.java b/core/src/test/java/com/google/common/truth/TestCorrespondences.java index 9f2dfe054..d9cca3e1b 100644 --- a/core/src/test/java/com/google/common/truth/TestCorrespondences.java +++ b/core/src/test/java/com/google/common/truth/TestCorrespondences.java @@ -23,7 +23,7 @@ import com.google.common.base.Splitter; import com.google.common.primitives.Ints; import java.util.List; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** {@link Correspondence} implementations for testing purposes. */ final class TestCorrespondences { @@ -38,14 +38,14 @@ final class TestCorrespondences { // TestCorrespondences::stringParsesToInteger, new Correspondence.BinaryPredicate() { @Override - public boolean apply(@NullableDecl String actual, @NullableDecl Integer expected) { + public boolean apply(@Nullable String actual, @Nullable Integer expected) { return stringParsesToInteger(actual, expected); } }, "parses to"); private static boolean stringParsesToInteger( - @NullableDecl String actual, @NullableDecl Integer expected) { + @Nullable String actual, @Nullable Integer expected) { if (actual == null) { return expected == null; } @@ -174,7 +174,7 @@ boolean hasSameId(Record that) { } @Override - public boolean equals(@NullableDecl Object o) { + public boolean equals(@Nullable Object o) { if (o instanceof Record) { Record that = (Record) o; return this.id == that.id && this.score == that.score; @@ -200,14 +200,13 @@ public String toString() { * If the argument is the string form of a record, returns that record; otherwise returns {@code * null}. */ - @NullableDecl - static Record parse(String str) { + static @Nullable Record parse(String str) { List parts = Splitter.on('/').splitToList(str); if (parts.size() != 2) { return null; } - @NullableDecl Integer id = parts.get(0).equals("none") ? -1 : Ints.tryParse(parts.get(0)); - @NullableDecl Integer score = Ints.tryParse(parts.get(1)); + @Nullable Integer id = parts.get(0).equals("none") ? -1 : Ints.tryParse(parts.get(0)); + @Nullable Integer score = Ints.tryParse(parts.get(1)); if (id == null || score == null) { return null; } @@ -270,13 +269,13 @@ public String formatDiff(Record actual, Record expected) { Correspondence.from( // If we were allowed to use lambdas, this would be: // (String a, Record e) -> { - // @NullableDecl Record actualRecord = Record.parse(a); + // @Nullable Record actualRecord = Record.parse(a); // return actualRecord != null && recordsAreCloseEnough(actualRecord, e); // }, new Correspondence.BinaryPredicate() { @Override public boolean apply(String actual, Record expected) { - @NullableDecl Record actualRecord = Record.parse(actual); + @Nullable Record actualRecord = Record.parse(actual); return actualRecord != null && recordsAreCloseEnough(actualRecord, expected); } }, @@ -284,19 +283,18 @@ public boolean apply(String actual, Record expected) { .formattingDiffsUsing( // If we were allowe to use lambdas, this would be: // (a, e) -> { - // @NullableDecl Record actualRecord = Record.parse(a); + // @Nullable Record actualRecord = Record.parse(a); // return actualRecord != null ? formatRecordDiff(actualRecord, e) : null; // }); new Correspondence.DiffFormatter() { @Override public String formatDiff(String actual, Record expected) { - @NullableDecl Record actualRecord = Record.parse(actual); + @Nullable Record actualRecord = Record.parse(actual); return actualRecord != null ? formatRecordDiff(actualRecord, expected) : null; } }); - private static boolean recordsAreCloseEnough( - @NullableDecl Record actual, @NullableDecl Record expected) { + private static boolean recordsAreCloseEnough(@Nullable Record actual, @Nullable Record expected) { if (actual == null) { return expected == null; } @@ -322,8 +320,7 @@ private static String formatRecordDiff(Record actual, Record expected) { new Function() { @Override - @NullableDecl - public Integer apply(Record record) { + public @Nullable Integer apply(Record record) { return record.hasId() ? record.getId() : null; } }; @@ -336,8 +333,7 @@ public Integer apply(Record record) { new Function() { @Override - @NullableDecl - public Integer apply(Record record) { + public @Nullable Integer apply(Record record) { if (record == null) { return 0; } @@ -354,9 +350,8 @@ public Integer apply(Record record) { new Function() { @Override - @NullableDecl - public Integer apply(String str) { - @NullableDecl Record record = Record.parse(str); + public @Nullable Integer apply(String str) { + Record record = Record.parse(str); return record != null ? RECORD_ID.apply(record) : null; } }; diff --git a/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java b/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java index 6a90befeb..854afb06b 100644 --- a/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java +++ b/core/src/test/java/com/google/common/truth/extension/EmployeeSubject.java @@ -20,7 +20,7 @@ import com.google.common.truth.FailureMetadata; import com.google.common.truth.Subject; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A Truth subject for {@link Employee}. @@ -30,7 +30,7 @@ public final class EmployeeSubject extends Subject { // User-defined entry point - public static EmployeeSubject assertThat(@NullableDecl Employee employee) { + public static EmployeeSubject assertThat(@Nullable Employee employee) { return assertAbout(EMPLOYEE_SUBJECT_FACTORY).that(employee); } @@ -45,7 +45,7 @@ public static Subject.Factory employees() { private final Employee actual; - private EmployeeSubject(FailureMetadata failureMetadata, @NullableDecl Employee subject) { + private EmployeeSubject(FailureMetadata failureMetadata, @Nullable Employee subject) { super(failureMetadata, subject); this.actual = subject; } diff --git a/extensions/java8/pom.xml b/extensions/java8/pom.xml index a362b4b21..f3dfec9ff 100644 --- a/extensions/java8/pom.xml +++ b/extensions/java8/pom.xml @@ -21,7 +21,7 @@ org.checkerframework - checker-compat-qual + checker-qual diff --git a/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java index e38a4375e..cd898d074 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/IntStreamSubject.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.stream.IntStream; import java.util.stream.Stream; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link IntStream} subjects. @@ -44,7 +44,7 @@ public final class IntStreamSubject extends Subject { private final List actualList; - private IntStreamSubject(FailureMetadata failureMetadata, @NullableDecl IntStream stream) { + private IntStreamSubject(FailureMetadata failureMetadata, @Nullable IntStream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new)); @@ -227,7 +227,7 @@ private static Object[] box(int[] rest) { return IntStream.of(rest).boxed().toArray(Integer[]::new); } - // TODO(kak/cpovirk): Do we want to override + deprecate isEqualTo/isNotEqualTo? + // TODO(user): Do we want to override + deprecate isEqualTo/isNotEqualTo? - // TODO(kak/peteg): Do we want to support comparingElementsUsing() on StreamSubject? + // TODO(user): Do we want to support comparingElementsUsing() on StreamSubject? } diff --git a/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java index 1ab669a31..1e6b50290 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/LongStreamSubject.java @@ -23,7 +23,7 @@ import java.util.List; import java.util.stream.LongStream; import java.util.stream.Stream; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link LongStream} subjects. @@ -44,7 +44,7 @@ public final class LongStreamSubject extends Subject { private final List actualList; - private LongStreamSubject(FailureMetadata failureMetadata, @NullableDecl LongStream stream) { + private LongStreamSubject(FailureMetadata failureMetadata, @Nullable LongStream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.boxed().collect(toCollection(ArrayList::new)); @@ -227,7 +227,7 @@ private static Object[] box(long[] rest) { return LongStream.of(rest).boxed().toArray(Long[]::new); } - // TODO(kak/cpovirk): Do we want to override + deprecate isEqualTo/isNotEqualTo? + // TODO(user): Do we want to override + deprecate isEqualTo/isNotEqualTo? - // TODO(kak/peteg): Do we want to support comparingElementsUsing() on StreamSubject? + // TODO(user): Do we want to support comparingElementsUsing() on StreamSubject? } diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java index d2d39058a..4a9aa5f88 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalDoubleSubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import java.util.OptionalDouble; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for Java 8 {@link OptionalDouble} subjects. @@ -32,8 +32,8 @@ public final class OptionalDoubleSubject extends Subject { OptionalDoubleSubject( FailureMetadata failureMetadata, - @NullableDecl OptionalDouble subject, - @NullableDecl String typeDescription) { + @Nullable OptionalDouble subject, + @Nullable String typeDescription) { super(failureMetadata, subject, typeDescription); this.actual = subject; } diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java index 9595b6bb4..957594f72 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalIntSubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import java.util.OptionalInt; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for Java 8 {@link OptionalInt} subjects. @@ -31,8 +31,8 @@ public final class OptionalIntSubject extends Subject { OptionalIntSubject( FailureMetadata failureMetadata, - @NullableDecl OptionalInt subject, - @NullableDecl String typeDescription) { + @Nullable OptionalInt subject, + @Nullable String typeDescription) { super(failureMetadata, subject, typeDescription); this.actual = subject; } diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java index 3c6045005..9b57b9a4a 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalLongSubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import java.util.OptionalLong; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for Java 8 {@link OptionalLong} subjects. @@ -31,8 +31,8 @@ public final class OptionalLongSubject extends Subject { OptionalLongSubject( FailureMetadata failureMetadata, - @NullableDecl OptionalLong subject, - @NullableDecl String typeDescription) { + @Nullable OptionalLong subject, + @Nullable String typeDescription) { super(failureMetadata, subject, typeDescription); this.actual = subject; } diff --git a/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java b/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java index 6827a10b3..1b9fb5c96 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/OptionalSubject.java @@ -19,7 +19,7 @@ import static com.google.common.truth.Fact.simpleFact; import java.util.Optional; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for Java 8 {@link Optional} subjects. @@ -31,8 +31,8 @@ public final class OptionalSubject extends Subject { OptionalSubject( FailureMetadata failureMetadata, - @NullableDecl Optional subject, - @NullableDecl String typeDescription) { + @Nullable Optional subject, + @Nullable String typeDescription) { super(failureMetadata, subject, typeDescription); this.actual = subject; } diff --git a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java b/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java index 4b1e97828..4957686d4 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java +++ b/extensions/java8/src/main/java/com/google/common/truth/StreamSubject.java @@ -22,7 +22,7 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Stream; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Propositions for {@link Stream} subjects. @@ -43,7 +43,7 @@ public final class StreamSubject extends Subject { private final List actualList; - private StreamSubject(FailureMetadata failureMetadata, @NullableDecl Stream stream) { + private StreamSubject(FailureMetadata failureMetadata, @Nullable Stream stream) { super(failureMetadata, stream); this.actualList = (stream == null) ? null : stream.collect(toCollection(ArrayList::new)); } @@ -78,12 +78,12 @@ public void hasSize(int expectedSize) { } /** Fails if the subject does not contain the given element. */ - public void contains(@NullableDecl Object element) { + public void contains(@Nullable Object element) { check().that(actualList).contains(element); } /** Fails if the subject contains the given element. */ - public void doesNotContain(@NullableDecl Object element) { + public void doesNotContain(@Nullable Object element) { check().that(actualList).doesNotContain(element); } @@ -94,7 +94,7 @@ public void containsNoDuplicates() { /** Fails if the subject does not contain at least one of the given elements. */ public void containsAnyOf( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) { check().that(actualList).containsAnyOf(first, second, rest); } @@ -114,7 +114,7 @@ public void containsAnyIn(Iterable expected) { */ @CanIgnoreReturnValue public Ordered containsAtLeast( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) { return check().that(actualList).containsAtLeast(first, second, rest); } @@ -144,7 +144,7 @@ public Ordered containsAtLeastElementsIn(Iterable expected) { * on the object returned by this method. */ @CanIgnoreReturnValue - public Ordered containsExactly(@NullableDecl Object... varargs) { + public Ordered containsExactly(@Nullable Object @Nullable ... varargs) { return check().that(actualList).containsExactly(varargs); } @@ -167,7 +167,7 @@ public Ordered containsExactlyElementsIn(Iterable expected) { * test, which fails if any of the actual elements equal any of the excluded.) */ public void containsNoneOf( - @NullableDecl Object first, @NullableDecl Object second, @NullableDecl Object... rest) { + @Nullable Object first, @Nullable Object second, @Nullable Object @Nullable ... rest) { check().that(actualList).containsNoneOf(first, second, rest); } @@ -223,7 +223,7 @@ public void isInOrder(Comparator comparator) { check().that(actualList).isInOrder(comparator); } - // TODO(kak/cpovirk): Do we want to override + deprecate isEqualTo/isNotEqualTo? + // TODO(user): Do we want to override + deprecate isEqualTo/isNotEqualTo? - // TODO(kak/peteg): Do we want to support comparingElementsUsing() on StreamSubject? + // TODO(user): Do we want to support comparingElementsUsing() on StreamSubject? } diff --git a/extensions/java8/src/main/java/com/google/common/truth/Truth8.java b/extensions/java8/src/main/java/com/google/common/truth/Truth8.java index 325ea056e..31f0c6d94 100644 --- a/extensions/java8/src/main/java/com/google/common/truth/Truth8.java +++ b/extensions/java8/src/main/java/com/google/common/truth/Truth8.java @@ -27,7 +27,7 @@ import java.util.stream.IntStream; import java.util.stream.LongStream; import java.util.stream.Stream; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * The primary entry point for assertions about Java 8 types. @@ -44,31 +44,31 @@ * behavior/{@code Subject} type? in the Truth FAQ. */ public final class Truth8 { - public static OptionalSubject assertThat(@NullableDecl Optional target) { + public static OptionalSubject assertThat(@Nullable Optional target) { return assertAbout(OptionalSubject.optionals()).that(target); } - public static OptionalIntSubject assertThat(@NullableDecl OptionalInt target) { + public static OptionalIntSubject assertThat(@Nullable OptionalInt target) { return assertAbout(OptionalIntSubject.optionalInts()).that(target); } - public static OptionalLongSubject assertThat(@NullableDecl OptionalLong target) { + public static OptionalLongSubject assertThat(@Nullable OptionalLong target) { return assertAbout(OptionalLongSubject.optionalLongs()).that(target); } - public static OptionalDoubleSubject assertThat(@NullableDecl OptionalDouble target) { + public static OptionalDoubleSubject assertThat(@Nullable OptionalDouble target) { return assertAbout(OptionalDoubleSubject.optionalDoubles()).that(target); } - public static StreamSubject assertThat(@NullableDecl Stream target) { + public static StreamSubject assertThat(@Nullable Stream target) { return assertAbout(StreamSubject.streams()).that(target); } - public static IntStreamSubject assertThat(@NullableDecl IntStream target) { + public static IntStreamSubject assertThat(@Nullable IntStream target) { return assertAbout(IntStreamSubject.intStreams()).that(target); } - public static LongStreamSubject assertThat(@NullableDecl LongStream target) { + public static LongStreamSubject assertThat(@Nullable LongStream target) { return assertAbout(LongStreamSubject.longStreams()).that(target); } @@ -78,7 +78,7 @@ public static LongStreamSubject assertThat(@NullableDecl LongStream target) { // to support Java environments without java.nio.file such as Android and J2CL. @GwtIncompatible @J2ObjCIncompatible - public static PathSubject assertThat(@NullableDecl Path target) { + public static PathSubject assertThat(@Nullable Path target) { return assertAbout(PathSubject.paths()).that(target); } diff --git a/extensions/liteproto/pom.xml b/extensions/liteproto/pom.xml index ec8f09155..67465773c 100644 --- a/extensions/liteproto/pom.xml +++ b/extensions/liteproto/pom.xml @@ -26,7 +26,7 @@ org.checkerframework - checker-compat-qual + checker-qual com.google.auto.value diff --git a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java index 2f0bd23c7..8bee5946e 100644 --- a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java +++ b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoSubject.java @@ -27,7 +27,7 @@ import com.google.errorprone.annotations.CheckReturnValue; import com.google.protobuf.MessageLite; import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Truth subjects for the Lite version of Protocol Buffers. @@ -64,8 +64,7 @@ static Factory liteProtos() { private final FailureMetadata metadata; private final MessageLite actual; - protected LiteProtoSubject( - FailureMetadata failureMetadata, @NullableDecl MessageLite messageLite) { + protected LiteProtoSubject(FailureMetadata failureMetadata, @Nullable MessageLite messageLite) { super(failureMetadata, messageLite); this.metadata = failureMetadata; this.actual = messageLite; @@ -77,7 +76,7 @@ protected LiteProtoSubject( // from the strings alone. So, we manually strip this prefix. // In case the class names are actually relevant, Subject.isEqualTo() will add them back for us. // TODO(user): Maybe get a way to do this upstream. - static String getTrimmedToString(@NullableDecl MessageLite messageLite) { + static String getTrimmedToString(@Nullable MessageLite messageLite) { String subjectString = String.valueOf(messageLite); String trimmedSubjectString = subjectString.trim(); if (trimmedSubjectString.startsWith("# ")) { @@ -107,7 +106,7 @@ final String actualCustomStringRepresentationForProtoPackageMembersToCall() { * implementation. */ @Override - public void isEqualTo(@NullableDecl Object expected) { + public void isEqualTo(@Nullable Object expected) { // TODO(user): Do better here when MessageLite descriptors are available. if (Objects.equal(actual, expected)) { return; @@ -143,18 +142,18 @@ public void isEqualTo(@NullableDecl Object expected) { * or {@code buildPartial()} on the argument to get a MessageLite for comparison instead. */ @Deprecated - public void isEqualTo(@NullableDecl MessageLite.Builder builder) { + public void isEqualTo(MessageLite./*@Nullable*/ Builder builder) { isEqualTo((Object) builder); } private static final class LiteProtoAsStringSubject extends Subject { - LiteProtoAsStringSubject(FailureMetadata metadata, @NullableDecl String actual) { + LiteProtoAsStringSubject(FailureMetadata metadata, @Nullable String actual) { super(metadata, actual); } } @Override - public void isNotEqualTo(@NullableDecl Object expected) { + public void isNotEqualTo(@Nullable Object expected) { if (Objects.equal(actual, expected)) { if (actual == null) { super.isNotEqualTo(expected); @@ -173,7 +172,7 @@ public void isNotEqualTo(@NullableDecl Object expected) { * or {@code buildPartial()} on the argument to get a MessageLite for comparison instead. */ @Deprecated - public void isNotEqualTo(@NullableDecl MessageLite.Builder builder) { + public void isNotEqualTo(MessageLite./*@Nullable*/ Builder builder) { isNotEqualTo((Object) builder); } @@ -236,7 +235,7 @@ private static final class LiteProtoSubjectFactory @Override public LiteProtoSubject createSubject( - FailureMetadata failureMetadata, @NullableDecl MessageLite messageLite) { + FailureMetadata failureMetadata, @Nullable MessageLite messageLite) { return new LiteProtoSubject(failureMetadata, messageLite); } } diff --git a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java index c0b327eb4..94895d931 100644 --- a/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java +++ b/extensions/liteproto/src/main/java/com/google/common/truth/extensions/proto/LiteProtoTruth.java @@ -21,7 +21,7 @@ import com.google.common.truth.Subject; import com.google.errorprone.annotations.CheckReturnValue; import com.google.protobuf.MessageLite; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A set of static methods to begin a Truth assertion chain for the lite version of protocol @@ -37,7 +37,7 @@ */ @CheckReturnValue public final class LiteProtoTruth { - public static LiteProtoSubject assertThat(@NullableDecl MessageLite messageLite) { + public static LiteProtoSubject assertThat(@Nullable MessageLite messageLite) { return assertAbout(liteProtos()).that(messageLite); } diff --git a/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java b/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java index 2512a16c1..c3e0ed2dc 100644 --- a/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java +++ b/extensions/liteproto/src/test/java/com/google/common/truth/extensions/proto/LiteProtoSubjectTest.java @@ -28,7 +28,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -131,11 +131,11 @@ public LiteProtoSubjectTest(@SuppressWarnings("unused") String name, Config conf this.config = config; } - private LiteProtoSubject expectThat(@NullableDecl MessageLite m) { + private LiteProtoSubject expectThat(@Nullable MessageLite m) { return expect.about(LiteProtoTruth.liteProtos()).that(m); } - private Subject expectThat(@NullableDecl Object o) { + private Subject expectThat(@Nullable Object o) { return expect.that(o); } diff --git a/extensions/proto/pom.xml b/extensions/proto/pom.xml index 8c30eb4d3..020a5780f 100644 --- a/extensions/proto/pom.xml +++ b/extensions/proto/pom.xml @@ -30,7 +30,7 @@ org.checkerframework - checker-compat-qual + checker-qual com.google.auto.value diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FluentEqualityConfig.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FluentEqualityConfig.java index 3303e0f0d..ac22e9f35 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FluentEqualityConfig.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/FluentEqualityConfig.java @@ -35,7 +35,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Message; import com.google.protobuf.TypeRegistry; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A specification for a {@link ProtoTruthMessageDifferencer} for comparing two individual @@ -384,7 +384,7 @@ final Correspondence toCorrespondence( // ProtoTruth.assertThat(a).usingConfig(FluentEqualityConfig.this).testIsEqualTo(e), new Correspondence.BinaryPredicate() { @Override - public boolean apply(@NullableDecl M actual, @NullableDecl M expected) { + public boolean apply(@Nullable M actual, @Nullable M expected) { return ProtoTruth.assertThat(actual) .usingConfig(FluentEqualityConfig.this) .testIsEqualTo(expected); @@ -397,13 +397,13 @@ public boolean apply(@NullableDecl M actual, @NullableDecl M expected) { // If we were allowed method references, this would be this::formatDiff. new Correspondence.DiffFormatter() { @Override - public String formatDiff(@NullableDecl M actual, @NullableDecl M expected) { + public String formatDiff(@Nullable M actual, @Nullable M expected) { return FluentEqualityConfig.this.formatDiff(actual, expected); } }); } - private String formatDiff(@NullableDecl M actual, @NullableDecl M expected) { + private String formatDiff(@Nullable M actual, @Nullable M expected) { if (actual == null || expected == null) { return ""; } diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java index 5e6a2dda3..794b1f3b8 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosSubject.java @@ -31,7 +31,7 @@ import com.google.protobuf.TypeRegistry; import java.util.Arrays; import java.util.Comparator; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Truth subject for the iterables of protocol buffers. @@ -65,14 +65,14 @@ public class IterableOfProtosSubject extends IterableSubject private final FluentEqualityConfig config; protected IterableOfProtosSubject( - FailureMetadata failureMetadata, @NullableDecl Iterable messages) { + FailureMetadata failureMetadata, @Nullable Iterable messages) { this(failureMetadata, FluentEqualityConfig.defaultInstance(), messages); } IterableOfProtosSubject( FailureMetadata failureMetadata, FluentEqualityConfig config, - @NullableDecl Iterable messages) { + @Nullable Iterable messages) { super(failureMetadata, messages); this.metadata = failureMetadata; this.actual = messages; @@ -688,11 +688,11 @@ public final void isInOrder() { private static class UsingCorrespondence implements IterableOfProtosUsingCorrespondence { private final IterableOfProtosSubject subject; - @NullableDecl private final Function keyFunction; + private final @Nullable Function keyFunction; UsingCorrespondence( IterableOfProtosSubject subject, - @NullableDecl Function keyFunction) { + @Nullable Function keyFunction) { this.subject = checkNotNull(subject); this.keyFunction = keyFunction; } @@ -717,18 +717,18 @@ public IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( } @Override - public void contains(@NullableDecl M expected) { + public void contains(@Nullable M expected) { delegate(Arrays.asList(expected)).contains(expected); } @Override - public void doesNotContain(@NullableDecl M excluded) { + public void doesNotContain(@Nullable M excluded) { delegate(Arrays.asList(excluded)).doesNotContain(excluded); } @Override @CanIgnoreReturnValue - public Ordered containsExactly(@NullableDecl M... expected) { + public Ordered containsExactly(/*@Nullable*/ M... expected) { return delegate(Arrays.asList(expected)).containsExactly(expected); } @@ -746,8 +746,7 @@ public Ordered containsExactlyElementsIn(M[] expected) { @Override @CanIgnoreReturnValue - public Ordered containsAtLeast( - @NullableDecl M first, @NullableDecl M second, @NullableDecl M... rest) { + public Ordered containsAtLeast(@Nullable M first, @Nullable M second, /*@Nullable*/ M... rest) { return delegate(Lists.asList(first, second, rest)).containsAtLeast(first, second, rest); } @@ -764,8 +763,7 @@ public Ordered containsAtLeastElementsIn(M[] expected) { } @Override - public void containsAnyOf( - @NullableDecl M first, @NullableDecl M second, @NullableDecl M... rest) { + public void containsAnyOf(@Nullable M first, @Nullable M second, /*@Nullable*/ M... rest) { delegate(Lists.asList(first, second, rest)).containsAnyOf(first, second, rest); } @@ -781,9 +779,7 @@ public void containsAnyIn(M[] expected) { @Override public void containsNoneOf( - @NullableDecl M firstExcluded, - @NullableDecl M secondExcluded, - @NullableDecl M... restOfExcluded) { + @Nullable M firstExcluded, @Nullable M secondExcluded, /*@Nullable*/ M... restOfExcluded) { delegate(Lists.asList(firstExcluded, secondExcluded, restOfExcluded)) .containsNoneOf(firstExcluded, secondExcluded, restOfExcluded); } @@ -1015,17 +1011,17 @@ public IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( } @Override - public void contains(@NullableDecl M expected) { + public void contains(@Nullable M expected) { usingCorrespondence().contains(expected); } @Override - public void doesNotContain(@NullableDecl M excluded) { + public void doesNotContain(@Nullable M excluded) { usingCorrespondence().doesNotContain(excluded); } @Override - public Ordered containsExactly(@NullableDecl M... expected) { + public Ordered containsExactly(/*@Nullable*/ M... expected) { return usingCorrespondence().containsExactly(expected); } @@ -1040,8 +1036,7 @@ public Ordered containsExactlyElementsIn(M[] expected) { } @Override - public Ordered containsAtLeast( - @NullableDecl M first, @NullableDecl M second, @NullableDecl M... rest) { + public Ordered containsAtLeast(@Nullable M first, @Nullable M second, /*@Nullable*/ M... rest) { return usingCorrespondence().containsAtLeast(first, second, rest); } @@ -1056,8 +1051,7 @@ public Ordered containsAtLeastElementsIn(M[] expected) { } @Override - public void containsAnyOf( - @NullableDecl M first, @NullableDecl M second, @NullableDecl M... rest) { + public void containsAnyOf(@Nullable M first, @Nullable M second, /*@Nullable*/ M... rest) { usingCorrespondence().containsAnyOf(first, second, rest); } @@ -1073,9 +1067,7 @@ public void containsAnyIn(M[] expected) { @Override public void containsNoneOf( - @NullableDecl M firstExcluded, - @NullableDecl M secondExcluded, - @NullableDecl M... restOfExcluded) { + @Nullable M firstExcluded, @Nullable M secondExcluded, /*@Nullable*/ M... restOfExcluded) { usingCorrespondence().containsNoneOf(firstExcluded, secondExcluded, restOfExcluded); } diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosUsingCorrespondence.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosUsingCorrespondence.java index 9459dce9d..5a49369af 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosUsingCorrespondence.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/IterableOfProtosUsingCorrespondence.java @@ -19,7 +19,7 @@ import com.google.common.truth.Ordered; import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.protobuf.Message; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Comparison methods, which enforce the rules set in prior calls to {@link @@ -65,10 +65,10 @@ IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( * Checks that the subject contains at least one element that corresponds to the given expected * element. */ - void contains(@NullableDecl M expected); + void contains(@Nullable M expected); /** Checks that none of the actual elements correspond to the given element. */ - void doesNotContain(@NullableDecl M excluded); + void doesNotContain(@Nullable M excluded); /** * Checks that subject contains exactly elements that correspond to the expected elements, i.e. @@ -83,7 +83,7 @@ IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( * elements, not an element itself. */ @CanIgnoreReturnValue - Ordered containsExactly(@NullableDecl M... expected); + Ordered containsExactly(/*@Nullable*/ M... expected); /** * Checks that subject contains exactly elements that correspond to the expected elements, i.e. @@ -117,7 +117,7 @@ IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( * subject, but they are not required to be consecutive. */ @CanIgnoreReturnValue - Ordered containsAtLeast(@NullableDecl M first, @NullableDecl M second, @NullableDecl M... rest); + Ordered containsAtLeast(@Nullable M first, @Nullable M second, /*@Nullable*/ M... rest); /** * Checks that the subject contains elements that corresponds to all of the expected elements, @@ -147,7 +147,7 @@ IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( * Checks that the subject contains at least one element that corresponds to at least one of the * expected elements. */ - void containsAnyOf(@NullableDecl M first, @NullableDecl M second, @NullableDecl M... rest); + void containsAnyOf(@Nullable M first, @Nullable M second, /*@Nullable*/ M... rest); /** * Checks that the subject contains at least one element that corresponds to at least one of the @@ -167,9 +167,7 @@ IterableOfProtosUsingCorrespondence displayingDiffsPairedBy( * to any of the given elements.) */ void containsNoneOf( - @NullableDecl M firstExcluded, - @NullableDecl M secondExcluded, - @NullableDecl M... restOfExcluded); + @Nullable M firstExcluded, @Nullable M secondExcluded, /*@Nullable*/ M... restOfExcluded); /** * Checks that the subject contains no elements that correspond to any of the given elements. diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesFluentAssertion.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesFluentAssertion.java index cd1c7a67e..df796629c 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesFluentAssertion.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesFluentAssertion.java @@ -21,7 +21,7 @@ import com.google.protobuf.Message; import com.google.protobuf.TypeRegistry; import java.util.Map; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Fluent API to perform detailed, customizable comparison of maps containing protocol buffers as @@ -498,13 +498,13 @@ MapWithProtoValuesFluentAssertion ignoringFieldDescriptorsForValues( * Fails if the map does not contain an entry with the given key and a value that corresponds to * the given value. */ - void containsEntry(@NullableDecl Object expectedKey, @NullableDecl M expectedValue); + void containsEntry(@Nullable Object expectedKey, @Nullable M expectedValue); /** * Fails if the map contains an entry with the given key and a value that corresponds to the given * value. */ - void doesNotContainEntry(@NullableDecl Object excludedKey, @NullableDecl M excludedValue); + void doesNotContainEntry(@Nullable Object excludedKey, @Nullable M excludedValue); /** * Fails if the map does not contain exactly the given set of keys mapping to values that @@ -517,7 +517,7 @@ MapWithProtoValuesFluentAssertion ignoringFieldDescriptorsForValues( * key/value pairs at compile time. Please make sure you provide varargs in key/value pairs! */ @CanIgnoreReturnValue - Ordered containsExactly(@NullableDecl Object k0, @NullableDecl M v0, Object... rest); + Ordered containsExactly(@Nullable Object k0, @Nullable M v0, /*@Nullable*/ Object... rest); /** * Fails if the map does not contain exactly the keys in the given map, mapping to values that diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubject.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubject.java index 70297a66d..b338c3093 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubject.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MapWithProtoValuesSubject.java @@ -31,7 +31,7 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Truth subject for maps with protocol buffers for values. @@ -64,13 +64,12 @@ public class MapWithProtoValuesSubject extends MapSubject { private final Map actual; private final FluentEqualityConfig config; - protected MapWithProtoValuesSubject( - FailureMetadata failureMetadata, @NullableDecl Map map) { + protected MapWithProtoValuesSubject(FailureMetadata failureMetadata, @Nullable Map map) { this(failureMetadata, FluentEqualityConfig.defaultInstance(), map); } MapWithProtoValuesSubject( - FailureMetadata failureMetadata, FluentEqualityConfig config, @NullableDecl Map map) { + FailureMetadata failureMetadata, FluentEqualityConfig config, @Nullable Map map) { super(failureMetadata, map); this.metadata = failureMetadata; this.actual = map; @@ -849,15 +848,14 @@ public MapWithProtoValuesFluentAssertion usingTypeRegistryForValues( } @Override - public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl M expectedValue) { + public void containsEntry(@Nullable Object expectedKey, @Nullable M expectedValue) { subject .usingCorrespondence(Arrays.asList(expectedValue)) .containsEntry(expectedKey, expectedValue); } @Override - public void doesNotContainEntry( - @NullableDecl Object excludedKey, @NullableDecl M excludedValue) { + public void doesNotContainEntry(@Nullable Object excludedKey, @Nullable M excludedValue) { subject .usingCorrespondence(Arrays.asList(excludedValue)) .doesNotContainEntry(excludedKey, excludedValue); @@ -866,7 +864,8 @@ public void doesNotContainEntry( @Override @CanIgnoreReturnValue @SuppressWarnings("unchecked") // ClassCastException is fine - public Ordered containsExactly(@NullableDecl Object k0, @NullableDecl M v0, Object... rest) { + public Ordered containsExactly( + @Nullable Object k0, @Nullable M v0, /*@Nullable*/ Object... rest) { List expectedValues = new ArrayList<>(); expectedValues.add(v0); for (int i = 1; i < rest.length; i += 2) { diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesFluentAssertion.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesFluentAssertion.java index ac852426e..37eeb6024 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesFluentAssertion.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesFluentAssertion.java @@ -21,7 +21,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Message; import com.google.protobuf.TypeRegistry; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Fluent API to perform detailed, customizable comparison of {@link Multimap}s containing protocol @@ -499,13 +499,13 @@ MultimapWithProtoValuesFluentAssertion ignoringFieldDescriptorsForValues( * Fails if the multimap does not contain an entry with the given key and a value that corresponds * to the given value. */ - void containsEntry(@NullableDecl Object expectedKey, @NullableDecl M expectedValue); + void containsEntry(@Nullable Object expectedKey, @Nullable M expectedValue); /** * Fails if the multimap contains an entry with the given key and a value that corresponds to the * given value. */ - void doesNotContainEntry(@NullableDecl Object excludedKey, @NullableDecl M excludedValue); + void doesNotContainEntry(@Nullable Object excludedKey, @Nullable M excludedValue); /** * Fails if the map does not contain exactly the keys in the given multimap, mapping to values @@ -529,7 +529,7 @@ MultimapWithProtoValuesFluentAssertion ignoringFieldDescriptorsForValues( * key/value pairs at compile time. Please make sure you provide varargs in key/value pairs! */ @CanIgnoreReturnValue - public Ordered containsExactly(@NullableDecl Object k0, @NullableDecl M v0, Object... rest); + public Ordered containsExactly(@Nullable Object k0, @Nullable M v0, /*@Nullable*/ Object... rest); /** * @deprecated Do not call {@code equals()} on a {@code MultimapWithProtoValuesFluentAssertion}. diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubject.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubject.java index 3449f6af0..06c3f4d95 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubject.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/MultimapWithProtoValuesSubject.java @@ -34,7 +34,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Truth subject for {@link Multimap}s with protocol buffers for values. @@ -68,14 +68,14 @@ public class MultimapWithProtoValuesSubject extends MultimapS private final FluentEqualityConfig config; protected MultimapWithProtoValuesSubject( - FailureMetadata failureMetadata, @NullableDecl Multimap multimap) { + FailureMetadata failureMetadata, @Nullable Multimap multimap) { this(failureMetadata, FluentEqualityConfig.defaultInstance(), multimap); } MultimapWithProtoValuesSubject( FailureMetadata failureMetadata, FluentEqualityConfig config, - @NullableDecl Multimap multimap) { + @Nullable Multimap multimap) { super(failureMetadata, multimap); this.metadata = failureMetadata; this.actual = multimap; @@ -89,7 +89,7 @@ protected MultimapWithProtoValuesSubject( *

This method performs no checks on its own and cannot cause test failures. Subsequent * assertions must be chained onto this method call to test properties of the {@link Multimap}. */ - public IterableOfProtosSubject valuesForKey(@NullableDecl Object key) { + public IterableOfProtosSubject valuesForKey(@Nullable Object key) { return check("valuesForKey(%s)", key) .about(protos()) .that(((Multimap) actual).get(key)); @@ -880,15 +880,14 @@ public MultimapWithProtoValuesFluentAssertion usingTypeRegistryForValues( } @Override - public void containsEntry(@NullableDecl Object expectedKey, @NullableDecl M expectedValue) { + public void containsEntry(@Nullable Object expectedKey, @Nullable M expectedValue) { subject .usingCorrespondence(Arrays.asList(expectedValue)) .containsEntry(expectedKey, expectedValue); } @Override - public void doesNotContainEntry( - @NullableDecl Object excludedKey, @NullableDecl M excludedValue) { + public void doesNotContainEntry(@Nullable Object excludedKey, @Nullable M excludedValue) { subject .usingCorrespondence(Arrays.asList(excludedValue)) .doesNotContainEntry(excludedKey, excludedValue); @@ -911,7 +910,8 @@ public Ordered containsExactly() { @Override @CanIgnoreReturnValue @SuppressWarnings("unchecked") // ClassCastException is fine - public Ordered containsExactly(@NullableDecl Object k0, @NullableDecl M v0, Object... rest) { + public Ordered containsExactly( + @Nullable Object k0, @Nullable M v0, /*@Nullable*/ Object... rest) { List expectedValues = new ArrayList<>(); expectedValues.add(v0); for (int i = 1; i < rest.length; i += 2) { diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoFluentAssertion.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoFluentAssertion.java index 7bd61f8f0..fb70f1977 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoFluentAssertion.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoFluentAssertion.java @@ -18,7 +18,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import com.google.protobuf.Message; import com.google.protobuf.TypeRegistry; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Fluent API to perform detailed, customizable comparison of Protocol buffers. @@ -476,14 +476,14 @@ ProtoFluentAssertion ignoringFieldDescriptors( * earlier operations. If no settings are changed, this invokes the default {@code equals} * implementation of the subject {@link Message}. */ - void isEqualTo(@NullableDecl Message expected); + void isEqualTo(@Nullable Message expected); /** * Compares the subject of the assertion to {@code expected}, expecting a difference, using all of * the rules specified by earlier operations. If no settings are changed, this invokes the default * {@code equals} implementation of the subject {@link Message}. */ - void isNotEqualTo(@NullableDecl Message expected); + void isNotEqualTo(@Nullable Message expected); /** * @deprecated Do not call {@code equals()} on a {@code ProtoFluentAssertion}. Use {@link diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java index b3f85bf97..955d21111 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubject.java @@ -28,7 +28,7 @@ import com.google.protobuf.Message; import com.google.protobuf.TypeRegistry; import java.util.Arrays; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Truth subject for the full version of Protocol Buffers. @@ -59,12 +59,12 @@ public class ProtoSubject extends LiteProtoSubject { private final Message actual; private final FluentEqualityConfig config; - protected ProtoSubject(FailureMetadata failureMetadata, @NullableDecl Message message) { + protected ProtoSubject(FailureMetadata failureMetadata, @Nullable Message message) { this(failureMetadata, FluentEqualityConfig.defaultInstance(), message); } ProtoSubject( - FailureMetadata failureMetadata, FluentEqualityConfig config, @NullableDecl Message message) { + FailureMetadata failureMetadata, FluentEqualityConfig config, @Nullable Message message) { super(failureMetadata, message); this.metadata = failureMetadata; this.actual = message; @@ -597,7 +597,7 @@ public ProtoFluentAssertion usingTypeRegistry(TypeRegistry typeRegistry) { } private static boolean sameClassMessagesWithDifferentDescriptors( - @NullableDecl Message actual, @NullableDecl Object expected) { + @Nullable Message actual, @Nullable Object expected) { if (actual == null || !(expected instanceof Message) || actual.getClass() != expected.getClass()) { @@ -608,7 +608,7 @@ private static boolean sameClassMessagesWithDifferentDescriptors( } private static boolean notMessagesWithSameDescriptor( - @NullableDecl Message actual, @NullableDecl Object expected) { + @Nullable Message actual, @Nullable Object expected) { if (actual != null && expected instanceof Message) { return actual.getDescriptorForType() != ((Message) expected).getDescriptorForType(); } @@ -616,7 +616,7 @@ private static boolean notMessagesWithSameDescriptor( } @Override - public void isEqualTo(@NullableDecl Object expected) { + public void isEqualTo(@Nullable Object expected) { if (sameClassMessagesWithDifferentDescriptors(actual, expected)) { // This can happen with DynamicMessages, and it's very confusing if they both have the // same string. @@ -641,7 +641,7 @@ public void isEqualTo(@NullableDecl Object expected) { } @Override - public void isNotEqualTo(@NullableDecl Object expected) { + public void isNotEqualTo(@Nullable Object expected) { if (notMessagesWithSameDescriptor(actual, expected)) { super.isNotEqualTo(expected); } else { @@ -872,12 +872,12 @@ public ProtoFluentAssertion usingTypeRegistry(TypeRegistry typeRegistry) { } @Override - public void isEqualTo(@NullableDecl Message expected) { + public void isEqualTo(@Nullable Message expected) { protoSubject.isEqualTo(expected); } @Override - public void isNotEqualTo(@NullableDecl Message expected) { + public void isNotEqualTo(@Nullable Message expected) { protoSubject.isNotEqualTo(expected); } @@ -885,7 +885,7 @@ public void isNotEqualTo(@NullableDecl Message expected) { * Same as {@link #isEqualTo(Message)}, except it returns true on success and false on failure * without throwing any exceptions. */ - boolean testIsEqualTo(@NullableDecl Message expected) { + boolean testIsEqualTo(@Nullable Message expected) { if (notMessagesWithSameDescriptor(protoSubject.actual, expected)) { return Objects.equal(protoSubject.actual, expected); } else { diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java index 1c18bb2f6..0d813aa20 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoSubjectBuilder.java @@ -22,7 +22,7 @@ import com.google.protobuf.Message; import com.google.protobuf.MessageLite; import java.util.Map; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * {@link CustomSubjectBuilder} which aggregates all Proto-related {@link @@ -50,24 +50,23 @@ private ProtoSubjectBuilder(FailureMetadata failureMetadata) { super(failureMetadata); } - public LiteProtoSubject that(@NullableDecl MessageLite messageLite) { + public LiteProtoSubject that(@Nullable MessageLite messageLite) { return new LiteProtoSubject(metadata(), messageLite); } - public ProtoSubject that(@NullableDecl Message message) { + public ProtoSubject that(@Nullable Message message) { return new ProtoSubject(metadata(), message); } - public IterableOfProtosSubject that(@NullableDecl Iterable messages) { + public IterableOfProtosSubject that(@Nullable Iterable messages) { return new IterableOfProtosSubject(metadata(), messages); } - public MapWithProtoValuesSubject that(@NullableDecl Map map) { + public MapWithProtoValuesSubject that(@Nullable Map map) { return new MapWithProtoValuesSubject<>(metadata(), map); } - public MultimapWithProtoValuesSubject that( - @NullableDecl Multimap map) { + public MultimapWithProtoValuesSubject that(@Nullable Multimap map) { return new MultimapWithProtoValuesSubject<>(metadata(), map); } } diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java index 889f6e622..fbdaa9e01 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruth.java @@ -27,7 +27,7 @@ import com.google.protobuf.Message; import com.google.protobuf.MessageLite; import java.util.Map; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * A set of static methods to begin a Truth assertion chain for protocol buffers. @@ -48,12 +48,12 @@ public static CustomSubjectBuilder.Factory protos() { } /** Assert on a single {@link MessageLite} instance. */ - public static LiteProtoSubject assertThat(@NullableDecl MessageLite messageLite) { + public static LiteProtoSubject assertThat(@Nullable MessageLite messageLite) { return assertAbout(protos()).that(messageLite); } /** Assert on a single {@link Message} instance. */ - public static ProtoSubject assertThat(@NullableDecl Message message) { + public static ProtoSubject assertThat(@Nullable Message message) { return assertAbout(protos()).that(message); } @@ -69,7 +69,7 @@ public static ProtoSubject assertThat(@NullableDecl Message message) { // would result in method ambiguity errors. // See http://stackoverflow.com/a/8467804 for a more thorough explanation. public static IterableOfProtosSubject assertThat( - @NullableDecl Iterable messages) { + @Nullable Iterable messages) { return assertAbout(protos()).that(messages); } @@ -80,7 +80,7 @@ public static IterableOfProtosSubject assertThat( * comparison tests available on {@link MapSubject.UsingCorrespondence}. */ public static MapWithProtoValuesSubject assertThat( - @NullableDecl Map map) { + @Nullable Map map) { return assertAbout(protos()).that(map); } @@ -91,7 +91,7 @@ public static MapWithProtoValuesSubject assertThat( * comparison tests available on {@link MultimapSubject.UsingCorrespondence}. */ public static MultimapWithProtoValuesSubject assertThat( - @NullableDecl Multimap multimap) { + @Nullable Multimap multimap) { return assertAbout(protos()).that(multimap); } diff --git a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java index e2a5450e8..65a1573fe 100644 --- a/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java +++ b/extensions/proto/src/main/java/com/google/common/truth/extensions/proto/ProtoTruthMessageDifferencer.java @@ -55,7 +55,7 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Tool to differentiate two messages with the same {@link Descriptor}, subject to the rules set out @@ -301,7 +301,7 @@ private static Optional unpackAny(Message any, TypeRegistry typeRegistr // Helper which takes a proto map in List form, and converts it to a Map // by extracting the keys and values from the generated map-entry submessages. Returns an empty // map if null is passed in. - private static ImmutableMap toProtoMap(@NullableDecl Object container) { + private static ImmutableMap toProtoMap(@Nullable Object container) { if (container == null) { return ImmutableMap.of(); } @@ -325,7 +325,7 @@ private static Object valueAtFieldNumber(Message message, int fieldNumber) { // Takes a List or null, and returns the casted list in the first case, an empty list in // the latter case. - private static List toProtoList(@NullableDecl Object container) { + private static List toProtoList(@Nullable Object container) { if (container == null) { return Collections.emptyList(); } @@ -362,8 +362,8 @@ private List compareMapFieldsByKey( ImmutableList.Builder builder = ImmutableList.builderWithExpectedSize(actualAndExpectedKeys.size()); for (Object key : actualAndExpectedKeys) { - @NullableDecl Object actualValue = actualMap.get(key); - @NullableDecl Object expectedValue = expectedMap.get(key); + @Nullable Object actualValue = actualMap.get(key); + @Nullable Object expectedValue = expectedMap.get(key); if (ignoreExtraRepeatedFieldElements && !expectedMap.isEmpty() && expectedValue == null) { builder.add( SingularField.ignored(indexedName(mapFieldDescriptor, key, keyFieldDescriptor))); @@ -479,7 +479,6 @@ private RepeatedField compareRepeatedFieldExpectingSubsequence( Object expected = expectedList.get(expectedIndex); // Find the first actual element which matches. - @NullableDecl RepeatedField.PairResult matchingResult = findMatchingPairResult( actualIndices, @@ -544,8 +543,7 @@ private RepeatedField compareRepeatedFieldExpectingSubsequence( // Also removes the index for the matching value from actualIndicies. // // If there is no match, returns null. - @NullableDecl - private RepeatedField.PairResult findMatchingPairResult( + private RepeatedField./*@Nullable*/ PairResult findMatchingPairResult( Deque actualIndices, List actualValues, int expectedIndex, @@ -575,12 +573,12 @@ private RepeatedField.PairResult findMatchingPairResult( } private RepeatedField.PairResult compareRepeatedFieldElementPair( - @NullableDecl Object actual, - @NullableDecl Object expected, + @Nullable Object actual, + @Nullable Object expected, boolean excludeNonRecursive, FieldDescriptor fieldDescriptor, - @NullableDecl Integer actualFieldIndex, - @NullableDecl Integer expectedFieldIndex, + @Nullable Integer actualFieldIndex, + @Nullable Integer expectedFieldIndex, FluentEqualityConfig config) { SingularField comparison = compareSingularValue( @@ -633,8 +631,8 @@ private List compareRepeatedFieldByIndices( int maxSize = Math.max(actualList.size(), expectedList.size()); ImmutableList.Builder builder = ImmutableList.builderWithExpectedSize(maxSize); for (int i = 0; i < maxSize; i++) { - @NullableDecl Object actual = actualList.size() > i ? actualList.get(i) : null; - @NullableDecl Object expected = expectedList.size() > i ? expectedList.get(i) : null; + @Nullable Object actual = actualList.size() > i ? actualList.get(i) : null; + @Nullable Object expected = expectedList.size() > i ? expectedList.get(i) : null; builder.add( compareSingularValue( actual, @@ -650,9 +648,9 @@ private List compareRepeatedFieldByIndices( } private SingularField compareSingularValue( - @NullableDecl Object actual, - @NullableDecl Object expected, - @NullableDecl Object defaultValue, + @Nullable Object actual, + @Nullable Object expected, + @Nullable Object defaultValue, boolean excludeNonRecursive, FieldDescriptor fieldDescriptor, String fieldName, @@ -677,21 +675,20 @@ private SingularField compareSingularValue( // Replaces 'input' with 'defaultValue' iff input is null and we're ignoring field absence. // Otherwise, just returns the input. private T orIfIgnoringFieldAbsence( - @NullableDecl T input, @NullableDecl T defaultValue, boolean ignoreFieldAbsence) { + @Nullable T input, @Nullable T defaultValue, boolean ignoreFieldAbsence) { return (input == null && ignoreFieldAbsence) ? defaultValue : input; } // Returns 'input' if it's non-null, otherwise the default instance of 'other'. // Requires at least one parameter is non-null. - private static Message orDefaultForType( - @NullableDecl Message input, @NullableDecl Message other) { + private static Message orDefaultForType(@Nullable Message input, @Nullable Message other) { return (input != null) ? input : other.getDefaultInstanceForType(); } private SingularField compareSingularMessage( - @NullableDecl Message actual, - @NullableDecl Message expected, - @NullableDecl Message defaultValue, + @Nullable Message actual, + @Nullable Message expected, + @Nullable Message defaultValue, boolean excludeNonRecursive, FieldDescriptor fieldDescriptor, String fieldName, @@ -712,7 +709,7 @@ private SingularField compareSingularMessage( result.markAddedIf(expected == null); // Perform the detailed breakdown only if necessary. - @NullableDecl DiffResult breakdown = null; + @Nullable DiffResult breakdown = null; if (result.build() == Result.MATCHED || excludeNonRecursive) { actual = orDefaultForType(actual, expected); expected = orDefaultForType(expected, actual); @@ -746,9 +743,9 @@ private SingularField compareSingularMessage( } private SingularField compareSingularPrimitive( - @NullableDecl Object actual, - @NullableDecl Object expected, - @NullableDecl Object defaultValue, + @Nullable Object actual, + @Nullable Object expected, + @Nullable Object defaultValue, FieldDescriptor fieldDescriptor, String fieldName, FluentEqualityConfig config) { @@ -838,8 +835,8 @@ private UnknownFieldSetDiff diffUnknowns( Map actualFields = actual.asMap(); Map expectedFields = expected.asMap(); for (int fieldNumber : Sets.union(actualFields.keySet(), expectedFields.keySet())) { - @NullableDecl UnknownFieldSet.Field actualField = actualFields.get(fieldNumber); - @NullableDecl UnknownFieldSet.Field expectedField = expectedFields.get(fieldNumber); + UnknownFieldSet.Field actualField = actualFields.get(fieldNumber); + UnknownFieldSet.Field expectedField = expectedFields.get(fieldNumber); for (UnknownFieldDescriptor.Type type : UnknownFieldDescriptor.Type.all()) { List actualValues = actualField != null ? type.getValues(actualField) : Collections.emptyList(); @@ -884,8 +881,8 @@ private List compareUnknownFieldList( int maxSize = Math.max(actualValues.size(), expectedValues.size()); ImmutableList.Builder builder = ImmutableList.builderWithExpectedSize(maxSize); for (int i = 0; i < maxSize; i++) { - @NullableDecl Object actual = actualValues.size() > i ? actualValues.get(i) : null; - @NullableDecl Object expected = expectedValues.size() > i ? expectedValues.get(i) : null; + @Nullable Object actual = actualValues.size() > i ? actualValues.get(i) : null; + @Nullable Object expected = expectedValues.size() > i ? expectedValues.get(i) : null; builder.add( compareUnknownFieldValue( actual, @@ -900,8 +897,8 @@ private List compareUnknownFieldList( } private SingularField compareUnknownFieldValue( - @NullableDecl Object actual, - @NullableDecl Object expected, + @Nullable Object actual, + @Nullable Object expected, boolean excludeNonRecursive, UnknownFieldDescriptor unknownFieldDescriptor, String fieldName, @@ -921,8 +918,8 @@ private SingularField compareUnknownFieldValue( } private SingularField compareUnknownFieldSet( - @NullableDecl UnknownFieldSet actual, - @NullableDecl UnknownFieldSet expected, + @Nullable UnknownFieldSet actual, + @Nullable UnknownFieldSet expected, boolean excludeNonRecursive, UnknownFieldDescriptor unknownFieldDescriptor, String fieldName, @@ -934,7 +931,7 @@ private SingularField compareUnknownFieldSet( result.markAddedIf(expected == null); // Perform the detailed breakdown only if necessary. - @NullableDecl UnknownFieldSetDiff unknownsBreakdown = null; + @Nullable UnknownFieldSetDiff unknownsBreakdown = null; if (result.build() == Result.MATCHED || excludeNonRecursive) { actual = firstNonNull(actual, UnknownFieldSet.getDefaultInstance()); expected = firstNonNull(expected, UnknownFieldSet.getDefaultInstance()); @@ -967,8 +964,8 @@ private SingularField compareUnknownFieldSet( } private SingularField compareUnknownPrimitive( - @NullableDecl Object actual, - @NullableDecl Object expected, + @Nullable Object actual, + @Nullable Object expected, UnknownFieldDescriptor unknownFieldDescriptor, String fieldName) { Result.Builder result = Result.builder(); diff --git a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java index 5ee8bc544..2659d6397 100644 --- a/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java +++ b/extensions/proto/src/test/java/com/google/common/truth/extensions/proto/ProtoSubjectTestBase.java @@ -43,7 +43,7 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; -import org.checkerframework.checker.nullness.compatqual.NullableDecl; +import org.checkerframework.checker.nullness.qual.Nullable; import org.junit.Rule; /** Base class for testing {@link ProtoSubject} methods. */ @@ -175,7 +175,7 @@ protected final TruthFailureSubject expectThatFailure() { return expect.about(truthFailures()).that(multiExpectFailure.getFailure()); } - protected final ProtoSubject expectThat(@NullableDecl Message message) { + protected final ProtoSubject expectThat(@Nullable Message message) { return expect.about(ProtoTruth.protos()).that(message); } @@ -192,7 +192,7 @@ protected final MultimapWithProtoValuesSubject expectThat return expect.about(ProtoTruth.protos()).that(multimap); } - protected final ProtoSubject expectThatWithMessage(String msg, @NullableDecl Message message) { + protected final ProtoSubject expectThatWithMessage(String msg, @Nullable Message message) { return expect.withMessage(msg).about(ProtoTruth.protos()).that(message); } diff --git a/pom.xml b/pom.xml index b2676c441..42d0050dd 100644 --- a/pom.xml +++ b/pom.xml @@ -64,11 +64,6 @@ guava ${guava.version}-android - - org.checkerframework - checker-compat-qual - 2.5.5 - org.checkerframework checker-qual