Skip to content

Commit

Permalink
Migrate from jsr305 @nullable to Checker Framework @NullableDecl.
Browse files Browse the repository at this point in the history
RELNOTES=Use Checker Framework `@NullableDecl` instead of jsr305 `@Nullable`. Tools that read these annotations may need to be updated to recognize the new annotation.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=191950093
  • Loading branch information
cushon authored and ronshapiro committed Apr 11, 2018
1 parent 46c8d3d commit 10ee459
Show file tree
Hide file tree
Showing 87 changed files with 589 additions and 565 deletions.
14 changes: 7 additions & 7 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
<artifactId>truth</artifactId>
<name>Truth Core</name>
<properties>
<guava.version>23.4-android</guava.version>
<guava-gwt.version>23.4-jre</guava-gwt.version>
<guava.version>23.6-android</guava.version>
<guava-gwt.version>23.6-jre</guava-gwt.version>
<gwt.version>2.8.2</gwt.version>
<junit.version>4.12</junit.version>
<diffutils.version>1.3.0</diffutils.version>
<jsr305.version>3.0.2</jsr305.version>
<checker-framework.version>2.0.0</checker-framework.version>
<auto-value.version>1.5.3</auto-value.version>
<compile-testing.version>0.15</compile-testing.version>
<error-prone.annotations.version>2.1.3</error-prone.annotations.version>
<error-prone.annotations.version>2.2.0</error-prone.annotations.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -27,9 +27,9 @@
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${jsr305.version}</version>
<groupId>org.checkerframework</groupId>
<artifactId>checker-compat-qual</artifactId>
<version>${checker-framework.version}</version>
<optional>true</optional>
</dependency>
<dependency>
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.factWithoutValue;

import java.lang.reflect.Array;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* A common supertype for Array subjects, abstracting some common display and error infrastructure.
Expand All @@ -28,7 +28,7 @@
*/
abstract class AbstractArraySubject<S extends AbstractArraySubject<S, T>, T> extends Subject<S, T> {
AbstractArraySubject(
FailureMetadata metadata, @Nullable T actual, @Nullable String typeDescription) {
FailureMetadata metadata, @NullableDecl T actual, @NullableDecl String typeDescription) {
super(metadata, actual, typeDescription);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,25 @@
import static com.google.common.truth.Fact.makeMessage;

import com.google.common.collect.ImmutableList;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* An {@link AssertionError} composed of structured {@link Fact} instances and other string
* messages.
*/
final class AssertionErrorWithFacts extends AssertionError implements ErrorWithFacts {
static AssertionErrorWithFacts create(
ImmutableList<String> messages, ImmutableList<Fact> facts, @Nullable Throwable cause) {
ImmutableList<String> messages, ImmutableList<Fact> facts, @NullableDecl Throwable cause) {
return new AssertionErrorWithFacts(messages, facts, cause);
}

final ImmutableList<Fact> facts;

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

import com.google.common.collect.Maps;
import com.google.common.util.concurrent.AtomicLongMap;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Propositions for {@link AtomicLongMap} subjects.
*
* @author Kurt Alfred Kluever
*/
public final class AtomicLongMapSubject extends Subject<AtomicLongMapSubject, AtomicLongMap<?>> {
AtomicLongMapSubject(FailureMetadata metadata, @Nullable AtomicLongMap<?> map) {
AtomicLongMapSubject(FailureMetadata metadata, @NullableDecl AtomicLongMap<?> map) {
super(metadata, map);
}

Expand All @@ -40,7 +40,7 @@ public final class AtomicLongMapSubject extends Subject<AtomicLongMapSubject, At
*/
@Deprecated
@Override
public void isEqualTo(@Nullable Object other) {
public void isEqualTo(@NullableDecl Object other) {
super.isEqualTo(other);
}

Expand All @@ -51,7 +51,7 @@ public void isEqualTo(@Nullable Object other) {
*/
@Deprecated
@Override
public void isNotEqualTo(@Nullable Object other) {
public void isNotEqualTo(@NullableDecl Object other) {
super.isNotEqualTo(other);
}

Expand Down Expand Up @@ -106,7 +106,7 @@ public void containsEntry(Object key, long value) {
}

/** Fails if the {@link AtomicLongMap} contains the given entry. */
public void doesNotContainEntry(@Nullable Object key, long value) {
public void doesNotContainEntry(@NullableDecl Object key, long value) {
if (key != null) {
long actualValue = ((AtomicLongMap<Object>) actual()).get(key);
if (actualValue == value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
import static com.google.common.truth.Fact.factWithoutValue;

import java.math.BigDecimal;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Propositions for {@link BigDecimal} typed subjects.
*
* @author Kurt Alfred Kluever
*/
public final class BigDecimalSubject extends ComparableSubject<BigDecimalSubject, BigDecimal> {
BigDecimalSubject(FailureMetadata metadata, @Nullable BigDecimal actual) {
BigDecimalSubject(FailureMetadata metadata, @NullableDecl BigDecimal actual) {
super(metadata, actual);
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public void isEqualToIgnoringScale(long expected) {
* use {@link #isEqualToIgnoringScale(BigDecimal)} instead.
*/
@Override // To express more specific javadoc
public void isEqualTo(@Nullable Object expected) {
public void isEqualTo(@NullableDecl Object expected) {
super.isEqualTo(expected);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import static com.google.common.truth.Fact.factWithoutValue;

import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Propositions for boolean subjects.
*
* @author Christian Gruber (cgruber@israfil.net)
*/
public final class BooleanSubject extends Subject<BooleanSubject, Boolean> {
BooleanSubject(FailureMetadata metadata, @Nullable Boolean actual) {
BooleanSubject(FailureMetadata metadata, @NullableDecl Boolean actual) {
super(metadata, 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 javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Propositions for {@link Class} subjects.
Expand All @@ -25,7 +25,7 @@
*/
@GwtIncompatible("reflection")
public final class ClassSubject extends Subject<ClassSubject, Class<?>> {
ClassSubject(FailureMetadata metadata, @Nullable Class<?> o) {
ClassSubject(FailureMetadata metadata, @NullableDecl Class<?> o) {
super(metadata, 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 javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Propositions for {@link Comparable} typed subjects.
Expand All @@ -29,7 +29,7 @@ public abstract class ComparableSubject<S extends ComparableSubject<S, T>, T ext
* Constructor for use by subclasses. If you want to create an instance of this class itself, call
* {@link Subject#check}{@code .that(actual)}.
*/
protected ComparableSubject(FailureMetadata metadata, @Nullable T actual) {
protected ComparableSubject(FailureMetadata metadata, @NullableDecl T actual) {
super(metadata, actual);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Platform.PlatformComparisonFailure;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* An {@link AssertionError} (usually a JUnit {@code ComparisonFailure}, but not under GWT) composed
Expand All @@ -45,7 +45,7 @@ static ComparisonFailureWithFacts create(
ImmutableList<Fact> tailFacts,
String expected,
String actual,
@Nullable Throwable cause) {
@NullableDecl Throwable cause) {
ImmutableList<Fact> facts = makeFacts(headFacts, tailFacts, expected, actual);
return new ComparisonFailureWithFacts(messages, facts, expected, actual, cause);
}
Expand All @@ -57,7 +57,7 @@ private ComparisonFailureWithFacts(
ImmutableList<Fact> facts,
String expected,
String actual,
@Nullable Throwable cause) {
@NullableDecl Throwable cause) {
super(
makeMessage(messages, facts),
checkNotNull(expected),
Expand Down Expand Up @@ -112,7 +112,7 @@ static ImmutableList<Fact> formatExpectedAndActual(String expected, String actua
return ImmutableList.of(fact("expected", expected), fact("but was", actual));
}

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

Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/com/google/common/truth/Correspondence.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.truth.DoubleSubject.checkTolerance;

import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Determines whether an instance of type {@code A} corresponds in some way to an instance of type
Expand Down Expand Up @@ -94,7 +94,7 @@ public String toString() {
* Returns whether or not the {@code actual} value is said to correspond to the {@code expected}
* value for the purposes of this test.
*/
public abstract boolean compare(@Nullable A actual, @Nullable E expected);
public abstract boolean compare(@NullableDecl A actual, @NullableDecl E expected);

/**
* Returns a {@link String} describing the difference between the {@code actual} and {@code
Expand All @@ -106,8 +106,8 @@ public String toString() {
* <p>Assertions should only invoke this with parameters for which {@link #compare} returns {@code
* false}.
*/
@Nullable
public String formatDiff(@Nullable A actual, @Nullable E expected) {
@NullableDecl
public String formatDiff(@NullableDecl A actual, @NullableDecl E expected) {
return null;
}

Expand Down Expand Up @@ -136,7 +136,7 @@ public String formatDiff(@Nullable A actual, @Nullable E expected) {
*/
@Deprecated
@Override
public final boolean equals(@Nullable Object o) {
public final boolean equals(@NullableDecl 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 @@ -15,15 +15,15 @@
*/
package com.google.common.truth;

import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

// TODO(cpovirk): Make this package-private, and later remove it?
public final class DefaultSubject extends Subject<DefaultSubject, Object> {
/**
* Constructor for use by subclasses. If you want to create an instance of this class itself, call
* {@link Subject#check}{@code .that(actual)}.
*/
DefaultSubject(FailureMetadata metadata, @Nullable Object o) {
DefaultSubject(FailureMetadata metadata, @NullableDecl Object o) {
super(metadata, o);
}
}
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 javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;

/**
* Propositions for {@link Double} subjects.
Expand All @@ -36,7 +36,7 @@
public final class DoubleSubject extends ComparableSubject<DoubleSubject, Double> {
private static final long NEG_ZERO_BITS = doubleToLongBits(-0.0);

DoubleSubject(FailureMetadata metadata, @Nullable Double actual) {
DoubleSubject(FailureMetadata metadata, @NullableDecl Double actual) {
super(metadata, actual);
}

Expand All @@ -63,7 +63,7 @@ private TolerantDoubleComparison() {}
*/
@Deprecated
@Override
public boolean equals(@Nullable Object o) {
public boolean equals(@NullableDecl Object o) {
throw new UnsupportedOperationException(
"If you meant to compare doubles, use .of(double) instead.");
}
Expand Down Expand Up @@ -174,7 +174,7 @@ public void of(double expected) {
* vice versa. For an assertion that passes for either {@code 0.0} or {@code -0.0}, use {@link
* #isZero}.
*/
public final void isEqualTo(@Nullable Double other) {
public final void isEqualTo(@NullableDecl Double other) {
super.isEqualTo(other);
}

Expand All @@ -187,7 +187,7 @@ public final void isEqualTo(@Nullable Double other) {
* versa. For an assertion that fails for either {@code 0.0} or {@code -0.0}, use {@link
* #isNonZero}.
*/
public final void isNotEqualTo(@Nullable Double other) {
public final void isNotEqualTo(@NullableDecl Double other) {
super.isNotEqualTo(other);
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/google/common/truth/Expect.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import com.google.errorprone.annotations.concurrent.GuardedBy;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.junit.internal.AssumptionViolatedException;
import org.junit.rules.ErrorCollector;
import org.junit.rules.TestRule;
Expand Down Expand Up @@ -91,7 +91,7 @@ synchronized void enterRuleContext() {
inRuleContext = DURING;
}

synchronized void leaveRuleContext(@Nullable Throwable caught) throws Throwable {
synchronized void leaveRuleContext(@NullableDecl Throwable caught) throws Throwable {
try {
if (caught == null) {
doLeaveRuleContext();
Expand Down Expand Up @@ -167,7 +167,7 @@ private String printSubsequentFailure(
}

@GuardedBy("this")
private void doCheckInRuleContext(@Nullable AssertionError failure) {
private void doCheckInRuleContext(@NullableDecl AssertionError failure) {
switch (inRuleContext) {
case BEFORE:
throw new IllegalStateException(
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/google/common/truth/ExpectFailure.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import com.google.common.annotations.GwtIncompatible;
import com.google.common.truth.Truth.SimpleAssertionError;
import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

Expand Down Expand Up @@ -74,7 +74,7 @@ public void fail(AssertionError failure) {

private boolean inRuleContext = false;
private boolean failureExpected = false;
private @Nullable AssertionError failure = null;
private @NullableDecl AssertionError failure = null;

/**
* Creates a new instance for use as a {@code @Rule}. See the class documentation for details, and
Expand Down
Loading

0 comments on commit 10ee459

Please sign in to comment.