Skip to content

Commit

Permalink
Annotate formattingDiffsUsing methods as supporting nullable elemen…
Browse files Browse the repository at this point in the history
…t/value types.

RELNOTES=n/a
PiperOrigin-RevId: 388534517
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Jun 27, 2024
1 parent ee680cb commit 0220b74
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,13 +325,13 @@ public String toString() {
* diff-formatting functionality to it. See e.g. {@link IterableSubject#formattingDiffsUsing}.
*/
@SuppressWarnings("unchecked") // safe covariant cast
static <T> Correspondence<T, T> equality() {
static <T extends @Nullable Object> Correspondence<T, T> equality() {
return (Equality<T>) Equality.INSTANCE;
}

private static final class Equality<T> extends Correspondence<T, T> {
private static final class Equality<T extends @Nullable Object> extends Correspondence<T, T> {

private static final Equality<Object> INSTANCE = new Equality<>();
private static final Equality<@Nullable Object> INSTANCE = new Equality<>();

@Override
public boolean compare(T actual, T expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ UsingCorrespondence<A, E> comparingElementsUsing(
*
* @since 1.1
*/
public <T> UsingCorrespondence<T, T> formattingDiffsUsing(
public <T extends @Nullable Object> UsingCorrespondence<T, T> formattingDiffsUsing(
DiffFormatter<? super T, ? super T> formatter) {
return comparingElementsUsing(Correspondence.<T>equality().formattingDiffsUsing(formatter));
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/google/common/truth/MapSubject.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ UsingCorrespondence<A, E> comparingValuesUsing(
*
* @since 1.1
*/
public final <V> UsingCorrespondence<V, V> formattingDiffsUsing(
public final <V extends @Nullable Object> UsingCorrespondence<V, V> formattingDiffsUsing(
DiffFormatter<? super V, ? super V> formatter) {
return comparingValuesUsing(Correspondence.<V>equality().formattingDiffsUsing(formatter));
}
Expand Down

0 comments on commit 0220b74

Please sign in to comment.