Skip to content

Commit

Permalink
OrderingTest: nullness type-bound fix
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
martinkretzschmar authored and Google Java Core Libraries committed Feb 27, 2024
1 parent 91d2a34 commit 0ea03da
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Random;
import java.util.RandomAccess;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand Down Expand Up @@ -916,7 +917,7 @@ private static <T> void testExhaustively(

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

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

if (!strictlyOrderedList.contains(null)) {
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(shuffledList));
List<@NonNull T> nonNullShuffledList = (List<@NonNull T>) shuffledList;
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(nonNullShuffledList));
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions guava-tests/test/com/google/common/collect/OrderingTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.Random;
import java.util.RandomAccess;
import junit.framework.TestCase;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

/**
Expand Down Expand Up @@ -916,7 +917,7 @@ private static <T> void testExhaustively(

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

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

if (!strictlyOrderedList.contains(null)) {
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(shuffledList));
List<@NonNull T> nonNullShuffledList = (List<@NonNull T>) shuffledList;
assertEquals(strictlyOrderedList, ordering.immutableSortedCopy(nonNullShuffledList));
}
}
}
Expand Down

0 comments on commit 0ea03da

Please sign in to comment.