Skip to content

Commit 5efd53f

Browse files
martinkretzschmarGoogle Java Core Libraries
authored andcommitted
Change assertThat(array) to allow arrays of non-nullable elements
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
1 parent bbd8d12 commit 5efd53f

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

core/src/main/java/com/google/common/truth/ObjectArraySubject.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
* @author Christian Gruber
2727
*/
2828
public final class ObjectArraySubject<T extends @Nullable Object> extends AbstractArraySubject {
29-
private final @Nullable T @Nullable [] actual;
29+
private final T @Nullable [] actual;
3030

31-
ObjectArraySubject(
32-
FailureMetadata metadata, @Nullable T @Nullable [] o, @Nullable String typeDescription) {
31+
ObjectArraySubject(FailureMetadata metadata, T @Nullable [] o, @Nullable String typeDescription) {
3332
super(metadata, o, typeDescription);
3433
this.actual = o;
3534
}

core/src/main/java/com/google/common/truth/StandardSubjectBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public final IterableSubject that(@Nullable Iterable<?> actual) {
121121
}
122122

123123
@SuppressWarnings("AvoidObjectArrays")
124-
public final <T> ObjectArraySubject<T> that(@Nullable T @Nullable [] actual) {
124+
public final <T extends @Nullable Object> ObjectArraySubject<T> that(T @Nullable [] actual) {
125125
return new ObjectArraySubject<>(metadata(), actual, "array");
126126
}
127127

core/src/main/java/com/google/common/truth/Truth.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ public static IterableSubject assertThat(@Nullable Iterable<?> actual) {
201201
}
202202

203203
@SuppressWarnings("AvoidObjectArrays")
204-
public static <T> ObjectArraySubject<T> assertThat(@Nullable T @Nullable [] actual) {
204+
public static <T extends @Nullable Object> ObjectArraySubject<T> assertThat(
205+
T @Nullable [] actual) {
205206
return assert_().that(actual);
206207
}
207208

0 commit comments

Comments
 (0)