Skip to content

Commit

Permalink
BEGIN_PUBLIC
Browse files Browse the repository at this point in the history
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
END_PUBLIC

Tested:
  global TAP
  []
RELNOTES=Changed Checker Framework annotations from checker-qual to qual.
PiperOrigin-RevId: 328733195
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Sep 11, 2020
1 parent cadedcc commit 4bef0e5
Show file tree
Hide file tree
Showing 79 changed files with 495 additions and 551 deletions.
13 changes: 1 addition & 12 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,9 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
</dependency>
<!--
Manually add a dependency that guava-gwt needs but doesn't declare as of May 2018.
But only in the test scope, since that's the only place that _we_ need it.
_Downstream users_ might need to add it manually, as we've done here, but only until we fix guava-gwt and update Truth to use the new version.
And anyway, the current setup is causing users problems, since checker-qual is built for Java 8: https://github.com/google/truth/issues/479
-->
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -111,7 +100,7 @@
</configuration>
</plugin>
<plugin>
<!-- TODO(cgruber): Replace this with Gwt annotation processing plugin. -->
<!-- TODO(user): Replace this with Gwt annotation processing plugin. -->
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,7 @@ static InferredType create(String descriptor) {
abstract String descriptor();

@Override
public String toString() {
public final String toString() {
return descriptor();
}

Expand Down Expand Up @@ -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 {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> messages, ImmutableList<Fact> facts, @NullableDecl Throwable cause) {
ImmutableList<String> messages, ImmutableList<Fact> facts, @Nullable Throwable cause) {
return new AssertionErrorWithFacts(messages, facts, cause);
}

final ImmutableList<Fact> facts;

/** Separate cause field, in case initCause() fails. */
@NullableDecl private final Throwable cause;
private final @Nullable Throwable cause;

private AssertionErrorWithFacts(
ImmutableList<String> messages, ImmutableList<Fact> facts, @NullableDecl Throwable cause) {
ImmutableList<String> messages, ImmutableList<Fact> facts, @Nullable Throwable cause) {
super(makeMessage(messages, facts));
this.facts = checkNotNull(facts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -29,7 +29,7 @@
public final class BigDecimalSubject extends ComparableSubject<BigDecimal> {
private final BigDecimal actual;

BigDecimalSubject(FailureMetadata metadata, @NullableDecl BigDecimal actual) {
BigDecimalSubject(FailureMetadata metadata, @Nullable BigDecimal actual) {
super(metadata, actual);
this.actual = actual;
}
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/google/common/truth/ClassSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -31,7 +31,7 @@ public abstract class ComparableSubject<T extends Comparable> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -44,7 +44,7 @@ static ComparisonFailureWithFacts create(
ImmutableList<Fact> tailFacts,
String expected,
String actual,
@NullableDecl Throwable cause) {
@Nullable Throwable cause) {
ImmutableList<Fact> facts = makeFacts(headFacts, tailFacts, expected, actual);
return new ComparisonFailureWithFacts(messages, facts, expected, actual, cause);
}
Expand All @@ -56,7 +56,7 @@ private ComparisonFailureWithFacts(
ImmutableList<Fact> facts,
String expected,
String actual,
@NullableDecl Throwable cause) {
@Nullable Throwable cause) {
super(makeMessage(messages, facts), checkNotNull(expected), checkNotNull(actual), cause);
this.facts = checkNotNull(facts);
}
Expand Down Expand Up @@ -105,8 +105,8 @@ static ImmutableList<Fact> formatExpectedAndActual(String expected, String actua
return ImmutableList.of(fact("expected", expected), fact("but was", actual));
}

@NullableDecl
private static ImmutableList<Fact> removeCommonPrefixAndSuffix(String expected, String actual) {
private static @Nullable ImmutableList<Fact> removeCommonPrefixAndSuffix(
String expected, String actual) {
int originalExpectedLength = expected.length();

// TODO(cpovirk): Use something like BreakIterator where available.
Expand Down
32 changes: 14 additions & 18 deletions core/src/main/java/com/google/common/truth/Correspondence.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -132,7 +132,7 @@ public interface BinaryPredicate<A, E> {
* 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<A, E> extends Correspondence<A, E> {
Expand All @@ -145,7 +145,7 @@ private FromBinaryPredicate(BinaryPredicate<A, E> 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);
}

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -401,8 +401,8 @@ public interface DiffFormatter<A, E> {
* 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<A, E> extends Correspondence<A, E> {
Expand All @@ -416,13 +416,12 @@ private static class FormattingDiffs<A, E> extends Correspondence<A, E> {
}

@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);
}

Expand Down Expand Up @@ -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 <i>not</i> 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 {

Expand Down Expand Up @@ -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 <i>must</i> 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) {
Expand All @@ -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;
}

Expand All @@ -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) {
Expand Down Expand Up @@ -827,7 +823,7 @@ final ImmutableList<Fact> 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.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
10 changes: 5 additions & 5 deletions core/src/main/java/com/google/common/truth/DoubleSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -38,7 +38,7 @@ public final class DoubleSubject extends ComparableSubject<Double> {

private final Double actual;

DoubleSubject(FailureMetadata metadata, @NullableDecl Double actual) {
DoubleSubject(FailureMetadata metadata, @Nullable Double actual) {
super(metadata, actual);
this.actual = actual;
}
Expand Down Expand Up @@ -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.");
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
Loading

0 comments on commit 4bef0e5

Please sign in to comment.