Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate formattingDiffsUsing methods as supporting nullable element/value types. #1314

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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