diff --git a/android/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java b/android/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java index 514251d29ffb..ea975de0537c 100644 --- a/android/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java +++ b/android/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java @@ -678,7 +678,10 @@ public void testEntrySetRetainAll() { } Set> entrySet = map.entrySet(); - Set> entriesToRetain = singleton(entrySet.iterator().next()); + Entry originalEntry = entrySet.iterator().next(); + // Copy the Entry, as discussed in testEntrySetRemoveAll. + Set> entriesToRetain = + singleton(mapEntry(originalEntry.getKey(), originalEntry.getValue())); if (supportsRemove) { boolean shouldRemove = (entrySet.size() > entriesToRetain.size()); boolean didRemove = entrySet.retainAll(entriesToRetain); diff --git a/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java b/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java index 514251d29ffb..ea975de0537c 100644 --- a/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java +++ b/guava-testlib/src/com/google/common/collect/testing/MapInterfaceTest.java @@ -678,7 +678,10 @@ public void testEntrySetRetainAll() { } Set> entrySet = map.entrySet(); - Set> entriesToRetain = singleton(entrySet.iterator().next()); + Entry originalEntry = entrySet.iterator().next(); + // Copy the Entry, as discussed in testEntrySetRemoveAll. + Set> entriesToRetain = + singleton(mapEntry(originalEntry.getKey(), originalEntry.getValue())); if (supportsRemove) { boolean shouldRemove = (entrySet.size() > entriesToRetain.size()); boolean didRemove = entrySet.retainAll(entriesToRetain);