Skip to content

Commit

Permalink
Prepare to make ImmutableSet.toImmutableSet available in guava-andr…
Browse files Browse the repository at this point in the history
…oid (but don't do so yet).

This includes adding `ImmutableCollection.spliterator()` as a further attempt to shake out any problems that might arise when we make "real" API changes. The method is callable under API Level 24 or higher, under which it overrides the method inherited from `Collection`. (But when last I checked (over 2 years ago!), library desugaring rewrote it to _not_ be an override: b/187166349.) In any case, we don't expect users to call it directly.

(Compare cl/543468006.)

This CL also includes updates to avoid problems with reflection when Java 8+ APIs are not present. That means adding a `serialVersionUID` (so that Java/Android reflection doesn't try to compute one with reflection) and skipping `NullPointerTester` under Android (though we still run `NullPointerTester` against the Android flavor under a JVM). (I might have added `serialVersionUID` more places than necessary; I'm not sure.)

(Compare cl/550872250.)

This CL is further progress toward #6567

(To make this work with some of our Android library-desugaring infrastructure, I had to first implement the new `SequencedCollection` methods in `ImmutableSortedSet`. That happened in cl/575207552.)

RELNOTES=n/a
PiperOrigin-RevId: 573288649
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 25, 2023
1 parent adde55e commit 330bb9c
Show file tree
Hide file tree
Showing 20 changed files with 532 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ public void testImmutableSortedMap() {
doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedSet() {
doHasAllFauxveridesTest(ImmutableSortedSet.class, ImmutableSet.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMultiset() {
doHasAllFauxveridesTest(ImmutableSortedMultiset.class, ImmutableMultiset.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ public void testToImmutableList_java7_combine() {
// Basic tests

@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableList.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ public void testBuilderSetCountIllegal() {
}

@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMultiset.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ public void testBuilderSetCountIllegal() {
assertThrows(IllegalArgumentException.class, () -> builder.setCount("a", -2));
}

@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(ImmutableSortedMultiset.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ protected <E extends Comparable<? super E>> SortedSet<E> copyOf(Iterator<? exten
}

@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
new NullPointerTester().testAllPublicStaticMethods(ImmutableSortedSet.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1396,6 +1396,7 @@ public void testMergeSorted_skipping_pyramid() {
}

@GwtIncompatible // reflection
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testIterables_nullCheck() throws Exception {
new ClassSanityTester()
.forAllPublicStaticMethods(Iterables.class)
Expand Down
Loading

0 comments on commit 330bb9c

Please sign in to comment.