Skip to content

Commit

Permalink
Change assertThat(array) to allow arrays of non-nullable elements
Browse files Browse the repository at this point in the history
Though array types are covariant in Java, in Kotlin they are not and this
change makes it easier to translate Java callers to Kotlin with J2KT.

RELNOTES=n/a
PiperOrigin-RevId: 608590844
  • Loading branch information
martinkretzschmar authored and Google Java Core Libraries committed Feb 20, 2024
1 parent bbd8d12 commit 5efd53f
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 @@ -26,10 +26,9 @@
* @author Christian Gruber
*/
public final class ObjectArraySubject<T extends @Nullable Object> extends AbstractArraySubject {
private final @Nullable T @Nullable [] actual;
private final T @Nullable [] actual;

ObjectArraySubject(
FailureMetadata metadata, @Nullable T @Nullable [] o, @Nullable String typeDescription) {
ObjectArraySubject(FailureMetadata metadata, T @Nullable [] o, @Nullable String typeDescription) {
super(metadata, o, typeDescription);
this.actual = o;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public final IterableSubject that(@Nullable Iterable<?> actual) {
}

@SuppressWarnings("AvoidObjectArrays")
public final <T> ObjectArraySubject<T> that(@Nullable T @Nullable [] actual) {
public final <T extends @Nullable Object> ObjectArraySubject<T> that(T @Nullable [] actual) {
return new ObjectArraySubject<>(metadata(), actual, "array");
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/google/common/truth/Truth.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public static IterableSubject assertThat(@Nullable Iterable<?> actual) {
}

@SuppressWarnings("AvoidObjectArrays")
public static <T> ObjectArraySubject<T> assertThat(@Nullable T @Nullable [] actual) {
public static <T extends @Nullable Object> ObjectArraySubject<T> assertThat(
T @Nullable [] actual) {
return assert_().that(actual);
}

Expand Down

0 comments on commit 5efd53f

Please sign in to comment.