Skip to content

Commit

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

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` (compare cl/550872250) and some `FauxveridesTest` tests (compare cl/576629272) under Android.

This CL is further progress toward #6567

RELNOTES=n/a
PiperOrigin-RevId: 576830997
  • Loading branch information
cpovirk authored and Google Java Core Libraries committed Oct 27, 2023
1 parent 1723ddf commit cb9804c
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @author Chris Povirk
*/
public class FauxveridesTest extends TestCase {
@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableBiMap() {
doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
}
Expand All @@ -57,6 +58,7 @@ public void testImmutableSetMultimap() {
doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMap() {
doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ public void testAsMultimapCaches() {
}

@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMap.class);
Expand Down
2 changes: 2 additions & 0 deletions android/guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1133,4 +1133,6 @@ Object writeReplace() {
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Use SerializedForm");
}

private static final long serialVersionUID = 0xdecaf;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1148,9 +1148,8 @@ private void readObject(ObjectInputStream stream) throws InvalidObjectException
private static final long serialVersionUID = 0;

/**
* Not supported. Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety,
* instead. This method exists only to hide {@link ImmutableMap#builder} from consumers of {@code
* ImmutableSortedMap}.
* Not supported. Use {@link #naturalOrder}, which offers better type-safety, instead. This method
* exists only to hide {@link ImmutableMap#builder} from consumers of {@code ImmutableSortedMap}.
*
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
* @author Chris Povirk
*/
public class FauxveridesTest extends TestCase {
@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableBiMap() {
doHasAllFauxveridesTest(ImmutableBiMap.class, ImmutableMap.class);
}
Expand All @@ -57,6 +58,7 @@ public void testImmutableSetMultimap() {
doHasAllFauxveridesTest(ImmutableSetMultimap.class, ImmutableMultimap.class);
}

@AndroidIncompatible // similar to ImmutableTableTest.testNullPointerInstance
public void testImmutableSortedMap() {
doHasAllFauxveridesTest(ImmutableSortedMap.class, ImmutableMap.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ public void testAsMultimapCaches() {
}

@GwtIncompatible // NullPointerTester
@AndroidIncompatible // see ImmutableTableTest.testNullPointerInstance
public void testNullPointers() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(ImmutableMap.class);
Expand Down
2 changes: 2 additions & 0 deletions guava/src/com/google/common/collect/ImmutableMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1284,4 +1284,6 @@ Object writeReplace() {
private void readObject(ObjectInputStream stream) throws InvalidObjectException {
throw new InvalidObjectException("Use SerializedForm");
}

private static final long serialVersionUID = 0xcafebabe;
}

0 comments on commit cb9804c

Please sign in to comment.