Skip to content

Commit 0ea03da

Browse files
martinkretzschmarGoogle Java Core Libraries
authored and
Google Java Core Libraries
committed
OrderingTest: nullness type-bound fix
`immutableSortedCopy` is only applicable to itereables that don’t contain null, which is guaranteed with a runtime check in this case. Plus a rawtype tweak for J2KT. RELNOTES=n/a PiperOrigin-RevId: 610816720
1 parent 91d2a34 commit 0ea03da

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

android/guava-tests/test/com/google/common/collect/OrderingTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Random;
4343
import java.util.RandomAccess;
4444
import junit.framework.TestCase;
45+
import org.checkerframework.checker.nullness.qual.NonNull;
4546
import org.checkerframework.checker.nullness.qual.Nullable;
4647

4748
/**
@@ -916,7 +917,7 @@ private static <T> void testExhaustively(
916917

917918
// shoot me, but I didn't want to deal with wildcards through the whole test
918919
@SuppressWarnings("unchecked")
919-
Scenario<T> starter = new Scenario<>((Ordering) ordering, list, emptyArray);
920+
Scenario<T> starter = new Scenario<>((Ordering<T>) ordering, list, emptyArray);
920921
verifyScenario(starter, 0);
921922
}
922923

@@ -1000,7 +1001,8 @@ void testSortedCopy() {
10001001
assertEquals(strictlyOrderedList, ordering.sortedCopy(shuffledList));
10011002

10021003
if (!strictlyOrderedList.contains(null)) {
1003-
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(shuffledList));
1004+
List<@NonNull T> nonNullShuffledList = (List<@NonNull T>) shuffledList;
1005+
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(nonNullShuffledList));
10041006
}
10051007
}
10061008
}

guava-tests/test/com/google/common/collect/OrderingTest.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Random;
4343
import java.util.RandomAccess;
4444
import junit.framework.TestCase;
45+
import org.checkerframework.checker.nullness.qual.NonNull;
4546
import org.checkerframework.checker.nullness.qual.Nullable;
4647

4748
/**
@@ -916,7 +917,7 @@ private static <T> void testExhaustively(
916917

917918
// shoot me, but I didn't want to deal with wildcards through the whole test
918919
@SuppressWarnings("unchecked")
919-
Scenario<T> starter = new Scenario<>((Ordering) ordering, list, emptyArray);
920+
Scenario<T> starter = new Scenario<>((Ordering<T>) ordering, list, emptyArray);
920921
verifyScenario(starter, 0);
921922
}
922923

@@ -1000,7 +1001,8 @@ void testSortedCopy() {
10001001
assertEquals(strictlyOrderedList, ordering.sortedCopy(shuffledList));
10011002

10021003
if (!strictlyOrderedList.contains(null)) {
1003-
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(shuffledList));
1004+
List<@NonNull T> nonNullShuffledList = (List<@NonNull T>) shuffledList;
1005+
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(nonNullShuffledList));
10041006
}
10051007
}
10061008
}

0 commit comments

Comments
 (0)