diff --git a/android/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java b/android/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java index c8989d34d884..e87c42be38bc 100644 --- a/android/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java +++ b/android/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java @@ -75,7 +75,7 @@ protected abstract > Set copyOf( public void testCreation_noArgs() { Set set = of(); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCreation_oneElement() { @@ -122,7 +122,7 @@ public void testCopyOf_emptyArray() { String[] array = new String[0]; Set set = copyOf(array); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCopyOf_arrayOfOneElement() { @@ -153,7 +153,7 @@ public void testCopyOf_collection_empty() { Collection c = MinimalCollection.of(); Set set = copyOf(c); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCopyOf_collection_oneElement() { @@ -203,7 +203,7 @@ public void testCopyOf_iterator_empty() { Iterator iterator = Iterators.emptyIterator(); Set set = copyOf(iterator); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCopyOf_iterator_oneElement() { diff --git a/android/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java b/android/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java index 3a46bb4c3034..67a47e67d355 100644 --- a/android/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java +++ b/android/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java @@ -249,11 +249,12 @@ public void testTransformEntrySetContains() { Set> entries = map.entrySet(); assertTrue(entries.contains(Maps.immutableEntry("a", true))); - assertTrue(entries.contains(Maps.immutableEntry("b", (Boolean) null))); - assertTrue(entries.contains(Maps.immutableEntry((String) null, (Boolean) null))); + assertTrue(entries.contains(Maps.immutableEntry("b", null))); + assertTrue( + entries.contains(Maps.<@Nullable String, @Nullable Boolean>immutableEntry(null, null))); - assertFalse(entries.contains(Maps.immutableEntry("c", (Boolean) null))); - assertFalse(entries.contains(Maps.immutableEntry((String) null, true))); + assertFalse(entries.contains(Maps.immutableEntry("c", null))); + assertFalse(entries.contains(Maps.<@Nullable String, Boolean>immutableEntry(null, true))); } @Override diff --git a/android/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java b/android/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java index daa929df6c2c..b021a0de47f0 100644 --- a/android/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java +++ b/android/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java @@ -52,7 +52,7 @@ public ForwardingSortedMapImplementsMapTest() { @Override protected SortedMap makeEmptyMap() { return new SimpleForwardingSortedMap<>( - new TreeMap(Ordering.natural().nullsFirst())); + new TreeMap(Ordering.natural().nullsFirst())); } @Override diff --git a/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java b/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java index d2b1d488878d..c50f1f5c46d1 100644 --- a/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java +++ b/android/guava-tests/test/com/google/common/collect/GeneralRangeTest.java @@ -35,7 +35,8 @@ @GwtCompatible(emulated = true) @ElementTypesAreNonnullByDefault public class GeneralRangeTest extends TestCase { - private static final Ordering<@Nullable Integer> ORDERING = Ordering.natural().nullsFirst(); + private static final Ordering<@Nullable Integer> ORDERING = + Ordering.natural().nullsFirst(); private static final List<@Nullable Integer> IN_ORDER_VALUES = Arrays.asList(null, 1, 2, 3, 4, 5); @@ -150,7 +151,7 @@ public void testIntersectAgainstBiggerRange() { assertEquals( GeneralRange.range(ORDERING, 2, CLOSED, 4, OPEN), - range.intersect(GeneralRange.range(ORDERING, null, OPEN, 5, CLOSED))); + range.intersect(GeneralRange.<@Nullable Integer>range(ORDERING, null, OPEN, 5, CLOSED))); assertEquals( GeneralRange.range(ORDERING, 2, OPEN, 4, OPEN), diff --git a/android/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java b/android/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java index 59c8e3361214..a5f501ea5ad4 100644 --- a/android/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java +++ b/android/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java @@ -383,10 +383,10 @@ public void testCopyOfNullKey() { } public void testCopyOfNullValue() { - ArrayListMultimap input = ArrayListMultimap.create(); - input.putAll("foo", Arrays.asList(1, null, 3)); + ArrayListMultimap input = ArrayListMultimap.create(); + input.putAll("foo", Arrays.<@Nullable Integer>asList(1, null, 3)); try { - ImmutableListMultimap.copyOf(input); + ImmutableListMultimap.copyOf((ArrayListMultimap) input); fail(); } catch (NullPointerException expected) { } diff --git a/android/guava-tests/test/com/google/common/collect/ImmutableListTest.java b/android/guava-tests/test/com/google/common/collect/ImmutableListTest.java index 7fe9305ac6b9..46ac06279f63 100644 --- a/android/guava-tests/test/com/google/common/collect/ImmutableListTest.java +++ b/android/guava-tests/test/com/google/common/collect/ImmutableListTest.java @@ -635,9 +635,10 @@ public void testBuilderAddAllHandlesNullsCorrectly() { } builder = ImmutableList.builder(); - Iterator iteratorWithNulls = asList("a", null, "b").iterator(); + Iterator<@Nullable String> iteratorWithNulls = + Arrays.<@Nullable String>asList("a", null, "b").iterator(); try { - builder.addAll(iteratorWithNulls); + builder.addAll((Iterator) iteratorWithNulls); fail("expected NullPointerException"); } catch (NullPointerException expected) { } diff --git a/android/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java b/android/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java index 1bf1f4f841f5..815c7529eb3b 100644 --- a/android/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java +++ b/android/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java @@ -37,6 +37,7 @@ import com.google.common.testing.NullPointerTester; import com.google.common.testing.SerializableTester; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -264,9 +265,10 @@ public void testCopyOf_multiset_general() { } public void testCopyOf_multisetContainingNull() { - Multiset c = HashMultiset.create(asList("a", null, "b")); + Multiset<@Nullable String> c = + HashMultiset.create(Arrays.<@Nullable String>asList("a", null, "b")); try { - ImmutableMultiset.copyOf(c); + ImmutableMultiset.copyOf((Multiset) c); fail(); } catch (NullPointerException expected) { } @@ -291,9 +293,10 @@ public void testCopyOf_iterator_general() { } public void testCopyOf_iteratorContainingNull() { - Iterator iterator = asList("a", null, "b").iterator(); + Iterator<@Nullable String> iterator = + Arrays.<@Nullable String>asList("a", null, "b").iterator(); try { - ImmutableMultiset.copyOf(iterator); + ImmutableMultiset.copyOf((Iterator) iterator); fail(); } catch (NullPointerException expected) { } @@ -430,9 +433,10 @@ public void testBuilderAddAllHandlesNullsCorrectly() { } builder = ImmutableMultiset.builder(); - Multiset multisetWithNull = LinkedHashMultiset.create(asList("a", null, "b")); + Multiset<@Nullable String> multisetWithNull = + LinkedHashMultiset.create(Arrays.<@Nullable String>asList("a", null, "b")); try { - builder.addAll(multisetWithNull); + builder.addAll((Multiset) multisetWithNull); fail("expected NullPointerException"); } catch (NullPointerException expected) { } diff --git a/android/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java b/android/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java index 33c6c0f0c570..a8663f619419 100644 --- a/android/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java +++ b/android/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java @@ -396,10 +396,10 @@ public void testCopyOfNullKey() { } public void testCopyOfNullValue() { - HashMultimap input = HashMultimap.create(); - input.putAll("foo", Arrays.asList(1, null, 3)); + HashMultimap input = HashMultimap.create(); + input.putAll("foo", Arrays.<@Nullable Integer>asList(1, null, 3)); try { - ImmutableSetMultimap.copyOf(input); + ImmutableSetMultimap.copyOf((Multimap) input); fail(); } catch (NullPointerException expected) { } diff --git a/android/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java b/android/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java index 1bdc6092f4f7..2180f947dfb0 100644 --- a/android/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java +++ b/android/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java @@ -511,7 +511,7 @@ public void testCopyOf() { } public void testCopyOfExplicitComparator() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); Map original = new LinkedHashMap<>(); original.put("one", 1); original.put("two", 2); @@ -524,7 +524,7 @@ public void testCopyOfExplicitComparator() { } public void testCopyOfImmutableSortedSetDifferentComparator() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); Map original = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3); ImmutableSortedMap copy = ImmutableSortedMap.copyOf(original, comparator); assertMapEquals(copy, "two", 2, "three", 3, "one", 1); @@ -545,7 +545,7 @@ public void testCopyOfSortedNatural() { } public void testCopyOfSortedExplicit() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); SortedMap original = Maps.newTreeMap(comparator); original.put("one", 1); original.put("two", 2); @@ -613,11 +613,11 @@ public void testBuilderReverseOrder() { .put("five", 5) .build(); assertMapEquals(map, "two", 2, "three", 3, "one", 1, "four", 4, "five", 5); - assertEquals(Ordering.natural().reverse(), map.comparator()); + assertEquals(Ordering.natural().reverse(), map.comparator()); } public void testBuilderComparator() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); ImmutableSortedMap map = new ImmutableSortedMap.Builder(comparator) .put("one", 1) diff --git a/android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java b/android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java index 644d474b8d31..4f518b6eb8b3 100644 --- a/android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java +++ b/android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java @@ -293,8 +293,8 @@ public void testSingle_headSet() { SortedSet set = of("e"); assertTrue(set.headSet("g") instanceof ImmutableSortedSet); assertThat(set.headSet("g")).contains("e"); - assertSame(of(), set.headSet("c")); - assertSame(of(), set.headSet("e")); + assertSame(this.of(), set.headSet("c")); + assertSame(this.of(), set.headSet("e")); } public void testSingle_tailSet() { @@ -302,7 +302,7 @@ public void testSingle_tailSet() { assertTrue(set.tailSet("c") instanceof ImmutableSortedSet); assertThat(set.tailSet("c")).contains("e"); assertThat(set.tailSet("e")).contains("e"); - assertSame(of(), set.tailSet("g")); + assertSame(this.of(), set.tailSet("g")); } public void testSingle_subSet() { @@ -310,9 +310,9 @@ public void testSingle_subSet() { assertTrue(set.subSet("c", "g") instanceof ImmutableSortedSet); assertThat(set.subSet("c", "g")).contains("e"); assertThat(set.subSet("e", "g")).contains("e"); - assertSame(of(), set.subSet("f", "g")); - assertSame(of(), set.subSet("c", "e")); - assertSame(of(), set.subSet("c", "d")); + assertSame(this.of(), set.subSet("f", "g")); + assertSame(this.of(), set.subSet("c", "e")); + assertSame(this.of(), set.subSet("c", "d")); } public void testSingle_first() { @@ -398,8 +398,8 @@ public void testOf_headSet() { assertTrue(set.headSet("e") instanceof ImmutableSortedSet); assertThat(set.headSet("e")).containsExactly("b", "c", "d").inOrder(); assertThat(set.headSet("g")).containsExactly("b", "c", "d", "e", "f").inOrder(); - assertSame(of(), set.headSet("a")); - assertSame(of(), set.headSet("b")); + assertSame(this.of(), set.headSet("a")); + assertSame(this.of(), set.headSet("b")); } public void testOf_tailSet() { @@ -407,7 +407,7 @@ public void testOf_tailSet() { assertTrue(set.tailSet("e") instanceof ImmutableSortedSet); assertThat(set.tailSet("e")).containsExactly("e", "f").inOrder(); assertThat(set.tailSet("a")).containsExactly("b", "c", "d", "e", "f").inOrder(); - assertSame(of(), set.tailSet("g")); + assertSame(this.of(), set.tailSet("g")); } public void testOf_subSet() { @@ -415,9 +415,9 @@ public void testOf_subSet() { assertTrue(set.subSet("c", "e") instanceof ImmutableSortedSet); assertThat(set.subSet("c", "e")).containsExactly("c", "d").inOrder(); assertThat(set.subSet("a", "g")).containsExactly("b", "c", "d", "e", "f").inOrder(); - assertSame(of(), set.subSet("a", "b")); - assertSame(of(), set.subSet("g", "h")); - assertSame(of(), set.subSet("c", "c")); + assertSame(this.of(), set.subSet("a", "b")); + assertSame(this.of(), set.subSet("g", "h")); + assertSame(this.of(), set.subSet("c", "c")); try { set.subSet("e", "c"); fail(); @@ -1138,7 +1138,7 @@ private static ImmutableList sortedNumberNames(int i, int j) { ImmutableList.of("one", "two", "three", "four", "five", "six", "seven"); private static final ImmutableList SORTED_NUMBER_NAMES = - Ordering.natural().immutableSortedCopy(NUMBER_NAMES); + Ordering.natural().immutableSortedCopy(NUMBER_NAMES); private static class SelfComparableExample implements Comparable { @Override diff --git a/android/guava-tests/test/com/google/common/collect/IterablesTest.java b/android/guava-tests/test/com/google/common/collect/IterablesTest.java index 5a049862ba2f..9d3ab7a35494 100644 --- a/android/guava-tests/test/com/google/common/collect/IterablesTest.java +++ b/android/guava-tests/test/com/google/common/collect/IterablesTest.java @@ -179,7 +179,7 @@ public void testGetOnlyElement_withDefault_empty() { public void testGetOnlyElement_withDefault_empty_null() { Iterable iterable = Collections.emptyList(); - assertNull(Iterables.getOnlyElement(iterable, null)); + assertNull(Iterables.<@Nullable String>getOnlyElement(iterable, null)); } public void testGetOnlyElement_withDefault_multiple() { @@ -479,7 +479,7 @@ public void testPaddedPartition_basic() { List list = asList(1, 2, 3, 4, 5); Iterable> partitions = Iterables.paddedPartition(list, 2); assertEquals(3, Iterables.size(partitions)); - assertEquals(asList(5, null), Iterables.getLast(partitions)); + assertEquals(Arrays.<@Nullable Integer>asList(5, null), Iterables.getLast(partitions)); } public void testPaddedPartitionRandomAccessInput() { @@ -537,7 +537,7 @@ public void testElementsEqual() throws Exception { assertFalse(Iterables.elementsEqual(a, b)); // null versus non-null. - a = asList(4, 8, 15, null, 23, 42); + a = Arrays.<@Nullable Integer>asList(4, 8, 15, null, 23, 42); b = asList(4, 8, 15, 16, 23, 42); assertFalse(Iterables.elementsEqual(a, b)); assertFalse(Iterables.elementsEqual(b, a)); @@ -824,7 +824,7 @@ public void testGetFirst_withDefault_empty() { public void testGetFirst_withDefault_empty_null() { Iterable iterable = Collections.emptyList(); - assertNull(Iterables.getFirst(iterable, null)); + assertNull(Iterables.<@Nullable String>getFirst(iterable, null)); } public void testGetFirst_withDefault_multiple() { @@ -863,7 +863,7 @@ public void testGetLast_withDefault_empty() { public void testGetLast_withDefault_empty_null() { Iterable iterable = Collections.emptyList(); - assertNull(Iterables.getLast(iterable, null)); + assertNull(Iterables.<@Nullable String>getLast(iterable, null)); } public void testGetLast_withDefault_multiple() { @@ -1350,7 +1350,7 @@ public void testMergeSorted_pyramid() { list.add(j); allIntegers.add(j); } - iterables.add(Ordering.natural().sortedCopy(list)); + iterables.add(Ordering.natural().sortedCopy(list)); } verifyMergeSorted(iterables, allIntegers); @@ -1367,7 +1367,7 @@ public void testMergeSorted_skipping_pyramid() { list.add(j * i); allIntegers.add(j * i); } - iterables.add(Ordering.natural().sortedCopy(list)); + iterables.add(Ordering.natural().sortedCopy(list)); } verifyMergeSorted(iterables, allIntegers); @@ -1385,7 +1385,7 @@ public void testIterables_nullCheck() throws Exception { private static void verifyMergeSorted( Iterable> iterables, Iterable unsortedExpected) { - Iterable expected = Ordering.natural().sortedCopy(unsortedExpected); + Iterable expected = Ordering.natural().sortedCopy(unsortedExpected); Iterable mergedIterator = Iterables.mergeSorted(iterables, Ordering.natural()); diff --git a/android/guava-tests/test/com/google/common/collect/IteratorsTest.java b/android/guava-tests/test/com/google/common/collect/IteratorsTest.java index 6d4b4307f237..aba34944c1fa 100644 --- a/android/guava-tests/test/com/google/common/collect/IteratorsTest.java +++ b/android/guava-tests/test/com/google/common/collect/IteratorsTest.java @@ -162,7 +162,7 @@ public void testSize_partiallyConsumed() { } public void test_contains_nonnull_yes() { - Iterator set = asList("a", null, "b").iterator(); + Iterator<@Nullable String> set = Arrays.<@Nullable String>asList("a", null, "b").iterator(); assertTrue(Iterators.contains(set, "b")); } @@ -172,7 +172,7 @@ public void test_contains_nonnull_no() { } public void test_contains_null_yes() { - Iterator set = asList("a", null, "b").iterator(); + Iterator<@Nullable String> set = Arrays.<@Nullable String>asList("a", null, "b").iterator(); assertTrue(Iterators.contains(set, null)); } @@ -241,7 +241,7 @@ public void testGetOnlyElement_withDefault_empty() { public void testGetOnlyElement_withDefault_empty_null() { Iterator iterator = Iterators.emptyIterator(); - assertNull(Iterators.getOnlyElement(iterator, null)); + assertNull(Iterators.<@Nullable String>getOnlyElement(iterator, null)); } public void testGetOnlyElement_withDefault_two() { @@ -821,7 +821,10 @@ public void testConcatPartiallyAdvancedFirst() { /** Illustrates the somewhat bizarre behavior when a null is passed in. */ public void testConcatContainingNull() { - Iterator> input = asList(iterateOver(1, 2), null, iterateOver(3)).iterator(); + Iterator> input = + (Iterator>) + Arrays.<@Nullable Iterator>asList(iterateOver(1, 2), null, iterateOver(3)) + .iterator(); Iterator result = Iterators.concat(input); assertEquals(1, (int) result.next()); assertEquals(2, (int) result.next()); @@ -939,8 +942,8 @@ public void testElementsEqual() { assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator())); // The same, but with nulls. - a = asList(4, 8, null, 16, 23, 42); - b = asList(4, 8, null, 16, 23, 42); + a = Arrays.<@Nullable Integer>asList(4, 8, null, 16, 23, 42); + b = Arrays.<@Nullable Integer>asList(4, 8, null, 16, 23, 42); assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator())); // Different Iterable types (still equal elements, though). @@ -954,7 +957,7 @@ public void testElementsEqual() { assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator())); // null versus non-null. - a = asList(4, 8, 15, null, 23, 42); + a = Arrays.<@Nullable Integer>asList(4, 8, 15, null, 23, 42); b = asList(4, 8, 15, 16, 23, 42); assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator())); assertFalse(Iterators.elementsEqual(b.iterator(), a.iterator())); @@ -1072,17 +1075,17 @@ public void testPaddedPartition_singleton2() { Iterator> partitions = Iterators.paddedPartition(source, 2); assertTrue(partitions.hasNext()); assertTrue(partitions.hasNext()); - assertEquals(asList(1, null), partitions.next()); + assertEquals(Arrays.<@Nullable Integer>asList(1, null), partitions.next()); assertFalse(partitions.hasNext()); } @GwtIncompatible // fairly slow (~50s) public void testPaddedPartition_general() { + ImmutableList> expectedElements = + ImmutableList.of( + asList(1, 2, 3), asList(4, 5, 6), Arrays.<@Nullable Integer>asList(7, null, null)); new IteratorTester>( - 5, - IteratorFeature.UNMODIFIABLE, - ImmutableList.of(asList(1, 2, 3), asList(4, 5, 6), asList(7, null, null)), - IteratorTester.KnownOrder.KNOWN_ORDER) { + 5, IteratorFeature.UNMODIFIABLE, expectedElements, IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator> newTargetIterator() { Iterator source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); @@ -1287,7 +1290,8 @@ public void testToString() { } public void testToStringWithNull() { - Iterator iterator = Lists.newArrayList("hello", null, "world").iterator(); + Iterator<@Nullable String> iterator = + Lists.<@Nullable String>newArrayList("hello", null, "world").iterator(); assertEquals("[hello, null, world]", Iterators.toString(iterator)); } @@ -1355,7 +1359,7 @@ public void testGetNext_withDefault_empty() { public void testGetNext_withDefault_empty_null() { Iterator iterator = Iterators.emptyIterator(); - assertNull(Iterators.getNext(iterator, null)); + assertNull(Iterators.<@Nullable String>getNext(iterator, null)); } public void testGetNext_withDefault_two() { @@ -1391,7 +1395,7 @@ public void testGetLast_withDefault_empty() { public void testGetLast_withDefault_empty_null() { Iterator iterator = Iterators.emptyIterator(); - assertNull(Iterators.getLast(iterator, null)); + assertNull(Iterators.<@Nullable String>getLast(iterator, null)); } public void testGetLast_withDefault_two() { diff --git a/android/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java b/android/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java index 049c1ea7df85..3583c5675848 100644 --- a/android/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java +++ b/android/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java @@ -358,11 +358,12 @@ public void testTransformEntrySetContains() { Set> entries = map.entrySet(); assertTrue(entries.contains(Maps.immutableEntry("a", true))); - assertTrue(entries.contains(Maps.immutableEntry("b", (Boolean) null))); - assertTrue(entries.contains(Maps.immutableEntry((String) null, (Boolean) null))); + assertTrue(entries.contains(Maps.immutableEntry("b", null))); + assertTrue( + entries.contains(Maps.<@Nullable String, @Nullable Boolean>immutableEntry(null, null))); - assertFalse(entries.contains(Maps.immutableEntry("c", (Boolean) null))); - assertFalse(entries.contains(Maps.immutableEntry((String) null, true))); + assertFalse(entries.contains(Maps.immutableEntry("c", null))); + assertFalse(entries.contains(Maps.<@Nullable String, Boolean>immutableEntry(null, true))); } @Override diff --git a/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java b/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java index 83a835609a3a..ca19020ab9fd 100644 --- a/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java +++ b/android/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java @@ -59,7 +59,7 @@ @GwtCompatible(emulated = true) @ElementTypesAreNonnullByDefault public class MinMaxPriorityQueueTest extends TestCase { - private static final Ordering SOME_COMPARATOR = Ordering.natural().reverse(); + private static final Ordering SOME_COMPARATOR = Ordering.natural().reverse(); @J2ktIncompatible @GwtIncompatible // suite diff --git a/android/guava-tests/test/com/google/common/collect/MultimapsTest.java b/android/guava-tests/test/com/google/common/collect/MultimapsTest.java index 3cb1b6d75873..37ad3fece911 100644 --- a/android/guava-tests/test/com/google/common/collect/MultimapsTest.java +++ b/android/guava-tests/test/com/google/common/collect/MultimapsTest.java @@ -110,7 +110,8 @@ public void testUnmodifiableMultimapShortCircuit() { @GwtIncompatible // slow (~10s) public void testUnmodifiableArrayListMultimap() { - checkUnmodifiableMultimap(ArrayListMultimap.create(), true); + checkUnmodifiableMultimap( + ArrayListMultimap.<@Nullable String, @Nullable Integer>create(), true); } @J2ktIncompatible @@ -141,7 +142,7 @@ public void testUnmodifiableLinkedListMultimapRandomAccess() { @GwtIncompatible // slow (~10s) public void testUnmodifiableHashMultimap() { - checkUnmodifiableMultimap(HashMultimap.create(), false); + checkUnmodifiableMultimap(HashMultimap.<@Nullable String, @Nullable Integer>create(), false); } @J2ktIncompatible @@ -168,7 +169,9 @@ public void testSerializingUnmodifiableTreeMultimap() { @GwtIncompatible // slow (~10s) public void testUnmodifiableSynchronizedArrayListMultimap() { checkUnmodifiableMultimap( - Multimaps.synchronizedListMultimap(ArrayListMultimap.create()), true); + Multimaps.synchronizedListMultimap( + ArrayListMultimap.<@Nullable String, @Nullable Integer>create()), + true); } @J2ktIncompatible @@ -186,7 +189,9 @@ public void testSerializingUnmodifiableSynchronizedArrayListMultimap() { @GwtIncompatible // slow (~10s) public void testUnmodifiableSynchronizedHashMultimap() { checkUnmodifiableMultimap( - Multimaps.synchronizedSetMultimap(HashMultimap.create()), false); + Multimaps.synchronizedSetMultimap( + HashMultimap.<@Nullable String, @Nullable Integer>create()), + false); } @J2ktIncompatible diff --git a/android/guava-tests/test/com/google/common/collect/ObjectArraysTest.java b/android/guava-tests/test/com/google/common/collect/ObjectArraysTest.java index 7e6646d354a3..c3ad40278fb2 100644 --- a/android/guava-tests/test/com/google/common/collect/ObjectArraysTest.java +++ b/android/guava-tests/test/com/google/common/collect/ObjectArraysTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.List; import junit.framework.TestCase; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Unit test for {@code ObjectArrays}. @@ -124,7 +125,7 @@ public void testConcatWithMoreGeneralType() { public void testToArrayImpl1() { doTestToArrayImpl1(Lists.newArrayList()); doTestToArrayImpl1(Lists.newArrayList(1)); - doTestToArrayImpl1(Lists.newArrayList(1, null, 3)); + doTestToArrayImpl1(Lists.<@Nullable Integer>newArrayList(1, null, 3)); } private void doTestToArrayImpl1(List list) { @@ -142,9 +143,9 @@ public void testToArrayImpl2() { doTestToArrayImpl2(Lists.newArrayList(1), new Integer[1], true); doTestToArrayImpl2(Lists.newArrayList(1), new Integer[] {2, 3}, true); - doTestToArrayImpl2(Lists.newArrayList(1, null, 3), new Integer[0], false); - doTestToArrayImpl2(Lists.newArrayList(1, null, 3), new Integer[2], false); - doTestToArrayImpl2(Lists.newArrayList(1, null, 3), new Integer[3], true); + doTestToArrayImpl2(Lists.<@Nullable Integer>newArrayList(1, null, 3), new Integer[0], false); + doTestToArrayImpl2(Lists.<@Nullable Integer>newArrayList(1, null, 3), new Integer[2], false); + doTestToArrayImpl2(Lists.<@Nullable Integer>newArrayList(1, null, 3), new Integer[3], true); } private void doTestToArrayImpl2(List list, Integer[] array1, boolean expectModify) { diff --git a/android/guava-tests/test/com/google/common/collect/OrderingTest.java b/android/guava-tests/test/com/google/common/collect/OrderingTest.java index 311552735a1e..3a50b54e648f 100644 --- a/android/guava-tests/test/com/google/common/collect/OrderingTest.java +++ b/android/guava-tests/test/com/google/common/collect/OrderingTest.java @@ -97,9 +97,9 @@ public void testComplicatedOrderingExample() { // [[null, null], [null], [1, null, 2], [1, 1], [1, 2], [1], [2], [], null] assertThat(sorted) .containsExactly( - Lists.newArrayList(nullInt, nullInt), - Lists.newArrayList(nullInt), - Lists.newArrayList(1, null, 2), + Lists.<@Nullable Integer>newArrayList(nullInt, nullInt), + Lists.<@Nullable Integer>newArrayList(nullInt), + Lists.<@Nullable Integer>newArrayList(1, null, 2), Lists.newArrayList(1, 1), Lists.newArrayList(1, 2), Lists.newArrayList(1), @@ -291,7 +291,7 @@ public Character apply(String string) { } private static Ordering byCharAt(int index) { - return Ordering.natural().onResultOf(CharAtFunction.values()[index]); + return Ordering.natural().onResultOf(CharAtFunction.values()[index]); } public void testCompound_static() { @@ -385,18 +385,18 @@ public Integer apply(String string) { } } - private static final Ordering DECREASING_INTEGER = Ordering.natural().reverse(); + private static final Ordering DECREASING_INTEGER = Ordering.natural().reverse(); public void testOnResultOf_natural() { Comparator comparator = - Ordering.natural().onResultOf(StringLengthFunction.StringLength); + Ordering.natural().onResultOf(StringLengthFunction.StringLength); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("or", "not") < 0); assertTrue(comparator.compare("that", "to") > 0); new EqualsTester() .addEqualityGroup( - comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) + comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) .addEqualityGroup(DECREASING_INTEGER) .testEquals(); reserializeAndAssert(comparator); @@ -440,8 +440,8 @@ public void testLexicographical() { } public void testNullsFirst() { - Ordering ordering = Ordering.natural().nullsFirst(); - Helpers.testComparator(ordering, null, Integer.MIN_VALUE, 0, 1); + Ordering<@Nullable Integer> ordering = Ordering.natural().nullsFirst(); + Helpers.<@Nullable Integer>testComparator(ordering, null, Integer.MIN_VALUE, 0, 1); new EqualsTester() .addEqualityGroup(ordering, Ordering.natural().nullsFirst()) @@ -451,8 +451,8 @@ public void testNullsFirst() { } public void testNullsLast() { - Ordering ordering = Ordering.natural().nullsLast(); - Helpers.testComparator(ordering, 0, 1, Integer.MAX_VALUE, null); + Ordering<@Nullable Integer> ordering = Ordering.natural().nullsLast(); + Helpers.<@Nullable Integer>testComparator(ordering, 0, 1, Integer.MAX_VALUE, null); new EqualsTester() .addEqualityGroup(ordering, Ordering.natural().nullsLast()) @@ -467,9 +467,10 @@ public void testBinarySearch() { } public void testSortedCopy() { - List unsortedInts = Collections.unmodifiableList(Arrays.asList(5, 0, 3, null, 0, 9)); - List sortedInts = numberOrdering.nullsLast().sortedCopy(unsortedInts); - assertEquals(Arrays.asList(0, 0, 3, 5, 9, null), sortedInts); + List<@Nullable Integer> unsortedInts = + Collections.unmodifiableList(Arrays.<@Nullable Integer>asList(5, 0, 3, null, 0, 9)); + List<@Nullable Integer> sortedInts = numberOrdering.nullsLast().sortedCopy(unsortedInts); + assertEquals(Arrays.<@Nullable Integer>asList(0, 0, 3, 5, 9, null), sortedInts); assertEquals( Collections.emptyList(), numberOrdering.sortedCopy(Collections.emptyList())); @@ -484,9 +485,9 @@ public void testImmutableSortedCopy() { Collections.emptyList(), numberOrdering.immutableSortedCopy(Collections.emptyList())); - List listWithNull = Arrays.asList(5, 3, null, 9); + List<@Nullable Integer> listWithNull = Arrays.asList(5, 3, null, 9); try { - Ordering.natural().nullsFirst().immutableSortedCopy(listWithNull); + Ordering.natural().nullsFirst().immutableSortedCopy((List) listWithNull); fail(); } catch (NullPointerException expected) { } @@ -599,16 +600,17 @@ public void testLeastOfIterator_simple_1() { } public void testLeastOfIterable_simple_nMinusOne_withNullElement() { - List list = Arrays.asList(3, null, 5, -1); - List result = Ordering.natural().nullsLast().leastOf(list, list.size() - 1); + List<@Nullable Integer> list = Arrays.asList(3, null, 5, -1); + List<@Nullable Integer> result = + Ordering.natural().nullsLast().leastOf(list, list.size() - 1); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.of(-1, 3, 5), result); } public void testLeastOfIterator_simple_nMinusOne_withNullElement() { - Iterator itr = Iterators.forArray(3, null, 5, -1); - List result = Ordering.natural().nullsLast().leastOf(itr, 3); + Iterator<@Nullable Integer> itr = Iterators.forArray(3, null, 5, -1); + List<@Nullable Integer> result = Ordering.natural().nullsLast().leastOf(itr, 3); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.of(-1, 3, 5), result); @@ -647,19 +649,21 @@ public void testLeastOfIterator_simple_n() { } public void testLeastOfIterable_simple_n_withNullElement() { - List list = Arrays.asList(3, 4, 5, null, -1); - List result = Ordering.natural().nullsLast().leastOf(list, list.size()); + List<@Nullable Integer> list = Arrays.asList(3, 4, 5, null, -1); + List<@Nullable Integer> result = + Ordering.natural().nullsLast().leastOf(list, list.size()); assertTrue(result instanceof RandomAccess); assertListImmutable(result); - assertEquals(Arrays.asList(-1, 3, 4, 5, null), result); + assertEquals(Arrays.<@Nullable Integer>asList(-1, 3, 4, 5, null), result); } public void testLeastOfIterator_simple_n_withNullElement() { - List list = Arrays.asList(3, 4, 5, null, -1); - List result = Ordering.natural().nullsLast().leastOf(list.iterator(), list.size()); + List<@Nullable Integer> list = Arrays.asList(3, 4, 5, null, -1); + List<@Nullable Integer> result = + Ordering.natural().nullsLast().leastOf(list.iterator(), list.size()); assertTrue(result instanceof RandomAccess); assertListImmutable(result); - assertEquals(Arrays.asList(-1, 3, 4, 5, null), result); + assertEquals(Arrays.<@Nullable Integer>asList(-1, 3, 4, 5, null), result); } public void testLeastOfIterable_simple_nPlusOne() { @@ -730,14 +734,15 @@ private static void runLeastOfComparison(int iterations, int elements, int seeds public void testLeastOfIterableLargeK() { List list = Arrays.asList(4, 2, 3, 5, 1); - assertEquals(Arrays.asList(1, 2, 3, 4, 5), Ordering.natural().leastOf(list, Integer.MAX_VALUE)); + assertEquals( + Arrays.asList(1, 2, 3, 4, 5), Ordering.natural().leastOf(list, Integer.MAX_VALUE)); } public void testLeastOfIteratorLargeK() { List list = Arrays.asList(4, 2, 3, 5, 1); assertEquals( Arrays.asList(1, 2, 3, 4, 5), - Ordering.natural().leastOf(list.iterator(), Integer.MAX_VALUE)); + Ordering.natural().leastOf(list.iterator(), Integer.MAX_VALUE)); } public void testGreatestOfIterable_simple() { @@ -1094,7 +1099,7 @@ public T apply(Integer from) { composites.add(new Composite(t, 2)); } Ordering> ordering = - Ordering.natural() + Ordering.>natural() .compound(scenario.ordering.onResultOf(Composite.getValueFunction())); return new Scenario>( ordering, composites, (Composite[]) new Composite[0]); diff --git a/android/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java b/android/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java index d070936c3bac..22686633c6ae 100644 --- a/android/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java +++ b/android/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java @@ -106,7 +106,7 @@ public void testPeekingIteratorBehavesLikeIteratorOnThreeElementIterable() { @GwtIncompatible // works but takes 5 minutes to run public void testPeekingIteratorAcceptsNullElements() { - actsLikeIteratorHelper(Lists.newArrayList(null, "A", null)); + actsLikeIteratorHelper(Lists.<@Nullable String>newArrayList(null, "A", null)); } public void testPeekOnEmptyList() { diff --git a/android/guava-tests/test/com/google/common/collect/SetsTest.java b/android/guava-tests/test/com/google/common/collect/SetsTest.java index 6809d6ef509a..4306b7343717 100644 --- a/android/guava-tests/test/com/google/common/collect/SetsTest.java +++ b/android/guava-tests/test/com/google/common/collect/SetsTest.java @@ -861,7 +861,7 @@ public void testPowerSetContents() { assertTrue(powerSet.contains(subset)); } assertFalse(powerSet.contains(ImmutableSet.of(1, 2, 4))); - assertFalse(powerSet.contains(singleton(null))); + assertFalse(powerSet.contains(Collections.<@Nullable Integer>singleton(null))); assertFalse(powerSet.contains(null)); assertFalse(powerSet.contains((Object) "notASet")); } diff --git a/android/guava-tests/test/com/google/common/collect/TablesTest.java b/android/guava-tests/test/com/google/common/collect/TablesTest.java index 23915f2723d0..fd1096fc4475 100644 --- a/android/guava-tests/test/com/google/common/collect/TablesTest.java +++ b/android/guava-tests/test/com/google/common/collect/TablesTest.java @@ -56,18 +56,27 @@ public void testEntryEquals() { .addEqualityGroup(Tables.immutableCell("bar", 1, 'a')) .addEqualityGroup(Tables.immutableCell("foo", 2, 'a')) .addEqualityGroup(Tables.immutableCell("foo", 1, 'b')) - .addEqualityGroup(Tables.immutableCell(null, null, null)) + .addEqualityGroup( + Tables.<@Nullable Object, @Nullable Object, @Nullable Object>immutableCell( + null, null, null)) .testEquals(); } public void testEntryEqualsNull() { - Cell entry = Tables.immutableCell(null, null, null); + Cell<@Nullable String, @Nullable Integer, @Nullable Character> entry = + Tables.immutableCell(null, null, null); new EqualsTester() - .addEqualityGroup(entry, Tables.immutableCell(null, null, null)) - .addEqualityGroup(Tables.immutableCell("bar", null, null)) - .addEqualityGroup(Tables.immutableCell(null, 2, null)) - .addEqualityGroup(Tables.immutableCell(null, null, 'b')) + .addEqualityGroup( + entry, + Tables.<@Nullable Object, @Nullable Object, @Nullable Object>immutableCell( + null, null, null)) + .addEqualityGroup( + Tables.immutableCell("bar", null, null)) + .addEqualityGroup( + Tables.<@Nullable Object, Integer, @Nullable Object>immutableCell(null, 2, null)) + .addEqualityGroup( + Tables.<@Nullable Object, @Nullable Object, Character>immutableCell(null, null, 'b')) .addEqualityGroup(Tables.immutableCell("foo", 1, 'a')) .testEquals(); } diff --git a/android/guava-tests/test/com/google/common/collect/TopKSelectorTest.java b/android/guava-tests/test/com/google/common/collect/TopKSelectorTest.java index 2cebdc338b08..05ecb2040fe4 100644 --- a/android/guava-tests/test/com/google/common/collect/TopKSelectorTest.java +++ b/android/guava-tests/test/com/google/common/collect/TopKSelectorTest.java @@ -37,12 +37,12 @@ public class TopKSelectorTest extends TestCase { public void testNegativeK() { try { - TopKSelector.least(-1); + TopKSelector.least(-1); fail(); } catch (IllegalArgumentException expected) { } try { - TopKSelector.greatest(-1); + TopKSelector.greatest(-1); fail(); } catch (IllegalArgumentException expected) { } diff --git a/android/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java b/android/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java index 7f4d8ff822ab..c1a9f0066b9f 100644 --- a/android/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java +++ b/android/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java @@ -286,7 +286,7 @@ public void testColumnKeySet_isSortedWithRealComparator() { table = create( String.CASE_INSENSITIVE_ORDER, - Ordering.natural().reverse(), + Ordering.natural().reverse(), "a", 2, 'X', diff --git a/android/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java b/android/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java index 601709b105e6..e887c0fadfa4 100644 --- a/android/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java +++ b/android/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java @@ -150,10 +150,10 @@ public void testOrderedEntries() { TreeMultimap<@Nullable String, @Nullable Integer> multimap = createPopulate(); assertThat(multimap.entries()) .containsExactly( - Maps.immutableEntry((String) null, 7), - Maps.immutableEntry((String) null, 3), - Maps.immutableEntry((String) null, 1), - Maps.immutableEntry("tree", (Integer) null), + Maps.<@Nullable String, Integer>immutableEntry(null, 7), + Maps.<@Nullable String, Integer>immutableEntry(null, 3), + Maps.<@Nullable String, Integer>immutableEntry(null, 1), + Maps.immutableEntry("tree", null), Maps.immutableEntry("tree", 0), Maps.immutableEntry("google", 6), Maps.immutableEntry("google", 2)) @@ -193,7 +193,7 @@ public void testSortedKeySet() { assertEquals(null, keySet.first()); assertEquals("google", keySet.last()); assertEquals(StringLength.COMPARATOR, keySet.comparator()); - assertEquals(Sets.newHashSet(null, "tree"), keySet.headSet("yahoo")); + assertEquals(Sets.<@Nullable String>newHashSet(null, "tree"), keySet.headSet("yahoo")); assertEquals(Sets.newHashSet("google"), keySet.tailSet("yahoo")); assertEquals(Sets.newHashSet("tree"), keySet.subSet("ask", "yahoo")); } diff --git a/android/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java b/android/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java index 012a14c5aab6..f475e87f996c 100644 --- a/android/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java +++ b/android/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java @@ -354,7 +354,7 @@ public void testMultimapConstructor() { private static final Comparator KEY_COMPARATOR = Ordering.natural(); private static final Comparator VALUE_COMPARATOR = - Ordering.natural().reverse().nullsFirst(); + Ordering.natural().reverse().nullsFirst(); /** * Test that creating one TreeMultimap from another does not copy the comparators from the source diff --git a/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java b/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java index 0077b75d168a..6f9651a9df51 100644 --- a/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java +++ b/android/guava-tests/test/com/google/common/collect/TreeMultisetTest.java @@ -287,8 +287,8 @@ public int compare(String o1, String o2) { } public void testNullAcceptingComparator() throws Exception { - Comparator comparator = Ordering.natural().nullsFirst(); - TreeMultiset ms = TreeMultiset.create(comparator); + Comparator<@Nullable String> comparator = Ordering.natural().nullsFirst(); + TreeMultiset<@Nullable String> ms = TreeMultiset.create(comparator); ms.add("b"); ms.add(null); diff --git a/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java b/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java index c8989d34d884..e87c42be38bc 100644 --- a/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java +++ b/guava-tests/test/com/google/common/collect/AbstractImmutableSetTest.java @@ -75,7 +75,7 @@ protected abstract > Set copyOf( public void testCreation_noArgs() { Set set = of(); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCreation_oneElement() { @@ -122,7 +122,7 @@ public void testCopyOf_emptyArray() { String[] array = new String[0]; Set set = copyOf(array); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCopyOf_arrayOfOneElement() { @@ -153,7 +153,7 @@ public void testCopyOf_collection_empty() { Collection c = MinimalCollection.of(); Set set = copyOf(c); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCopyOf_collection_oneElement() { @@ -203,7 +203,7 @@ public void testCopyOf_iterator_empty() { Iterator iterator = Iterators.emptyIterator(); Set set = copyOf(iterator); assertEquals(Collections.emptySet(), set); - assertSame(of(), set); + assertSame(this.of(), set); } public void testCopyOf_iterator_oneElement() { diff --git a/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java b/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java index 3a46bb4c3034..67a47e67d355 100644 --- a/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java +++ b/guava-tests/test/com/google/common/collect/AbstractMapsTransformValuesTest.java @@ -249,11 +249,12 @@ public void testTransformEntrySetContains() { Set> entries = map.entrySet(); assertTrue(entries.contains(Maps.immutableEntry("a", true))); - assertTrue(entries.contains(Maps.immutableEntry("b", (Boolean) null))); - assertTrue(entries.contains(Maps.immutableEntry((String) null, (Boolean) null))); + assertTrue(entries.contains(Maps.immutableEntry("b", null))); + assertTrue( + entries.contains(Maps.<@Nullable String, @Nullable Boolean>immutableEntry(null, null))); - assertFalse(entries.contains(Maps.immutableEntry("c", (Boolean) null))); - assertFalse(entries.contains(Maps.immutableEntry((String) null, true))); + assertFalse(entries.contains(Maps.immutableEntry("c", null))); + assertFalse(entries.contains(Maps.<@Nullable String, Boolean>immutableEntry(null, true))); } @Override diff --git a/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java b/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java index daa929df6c2c..b021a0de47f0 100644 --- a/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java +++ b/guava-tests/test/com/google/common/collect/ForwardingSortedMapImplementsMapTest.java @@ -52,7 +52,7 @@ public ForwardingSortedMapImplementsMapTest() { @Override protected SortedMap makeEmptyMap() { return new SimpleForwardingSortedMap<>( - new TreeMap(Ordering.natural().nullsFirst())); + new TreeMap(Ordering.natural().nullsFirst())); } @Override diff --git a/guava-tests/test/com/google/common/collect/GeneralRangeTest.java b/guava-tests/test/com/google/common/collect/GeneralRangeTest.java index d2b1d488878d..c50f1f5c46d1 100644 --- a/guava-tests/test/com/google/common/collect/GeneralRangeTest.java +++ b/guava-tests/test/com/google/common/collect/GeneralRangeTest.java @@ -35,7 +35,8 @@ @GwtCompatible(emulated = true) @ElementTypesAreNonnullByDefault public class GeneralRangeTest extends TestCase { - private static final Ordering<@Nullable Integer> ORDERING = Ordering.natural().nullsFirst(); + private static final Ordering<@Nullable Integer> ORDERING = + Ordering.natural().nullsFirst(); private static final List<@Nullable Integer> IN_ORDER_VALUES = Arrays.asList(null, 1, 2, 3, 4, 5); @@ -150,7 +151,7 @@ public void testIntersectAgainstBiggerRange() { assertEquals( GeneralRange.range(ORDERING, 2, CLOSED, 4, OPEN), - range.intersect(GeneralRange.range(ORDERING, null, OPEN, 5, CLOSED))); + range.intersect(GeneralRange.<@Nullable Integer>range(ORDERING, null, OPEN, 5, CLOSED))); assertEquals( GeneralRange.range(ORDERING, 2, OPEN, 4, OPEN), diff --git a/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java b/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java index acd02621bb5d..1c4520ea2aa5 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableListMultimapTest.java @@ -389,10 +389,10 @@ public void testCopyOfNullKey() { } public void testCopyOfNullValue() { - ArrayListMultimap input = ArrayListMultimap.create(); - input.putAll("foo", Arrays.asList(1, null, 3)); + ArrayListMultimap input = ArrayListMultimap.create(); + input.putAll("foo", Arrays.<@Nullable Integer>asList(1, null, 3)); try { - ImmutableListMultimap.copyOf(input); + ImmutableListMultimap.copyOf((ArrayListMultimap) input); fail(); } catch (NullPointerException expected) { } diff --git a/guava-tests/test/com/google/common/collect/ImmutableListTest.java b/guava-tests/test/com/google/common/collect/ImmutableListTest.java index d804778b5fb6..c0bb5fab9ede 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableListTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableListTest.java @@ -633,9 +633,10 @@ public void testBuilderAddAllHandlesNullsCorrectly() { } builder = ImmutableList.builder(); - Iterator iteratorWithNulls = asList("a", null, "b").iterator(); + Iterator<@Nullable String> iteratorWithNulls = + Arrays.<@Nullable String>asList("a", null, "b").iterator(); try { - builder.addAll(iteratorWithNulls); + builder.addAll((Iterator) iteratorWithNulls); fail("expected NullPointerException"); } catch (NullPointerException expected) { } diff --git a/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java b/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java index 3e556c35c9fc..2ef1c8a46b7c 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableMultisetTest.java @@ -38,6 +38,7 @@ import com.google.common.testing.NullPointerTester; import com.google.common.testing.SerializableTester; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; @@ -282,9 +283,10 @@ public void testCopyOf_multiset_general() { } public void testCopyOf_multisetContainingNull() { - Multiset c = HashMultiset.create(asList("a", null, "b")); + Multiset<@Nullable String> c = + HashMultiset.create(Arrays.<@Nullable String>asList("a", null, "b")); try { - ImmutableMultiset.copyOf(c); + ImmutableMultiset.copyOf((Multiset) c); fail(); } catch (NullPointerException expected) { } @@ -309,9 +311,10 @@ public void testCopyOf_iterator_general() { } public void testCopyOf_iteratorContainingNull() { - Iterator iterator = asList("a", null, "b").iterator(); + Iterator<@Nullable String> iterator = + Arrays.<@Nullable String>asList("a", null, "b").iterator(); try { - ImmutableMultiset.copyOf(iterator); + ImmutableMultiset.copyOf((Iterator) iterator); fail(); } catch (NullPointerException expected) { } @@ -536,9 +539,10 @@ public void testBuilderAddAllHandlesNullsCorrectly() { } builder = ImmutableMultiset.builder(); - Multiset multisetWithNull = LinkedHashMultiset.create(asList("a", null, "b")); + Multiset<@Nullable String> multisetWithNull = + LinkedHashMultiset.create(Arrays.<@Nullable String>asList("a", null, "b")); try { - builder.addAll(multisetWithNull); + builder.addAll((Multiset) multisetWithNull); fail("expected NullPointerException"); } catch (NullPointerException expected) { } diff --git a/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java b/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java index 6115cdddd584..776215293ba0 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableSetMultimapTest.java @@ -402,10 +402,10 @@ public void testCopyOfNullKey() { } public void testCopyOfNullValue() { - HashMultimap input = HashMultimap.create(); - input.putAll("foo", Arrays.asList(1, null, 3)); + HashMultimap input = HashMultimap.create(); + input.putAll("foo", Arrays.<@Nullable Integer>asList(1, null, 3)); try { - ImmutableSetMultimap.copyOf(input); + ImmutableSetMultimap.copyOf((Multimap) input); fail(); } catch (NullPointerException expected) { } diff --git a/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java b/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java index badaf835ccdf..5c923fbf6545 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableSortedMapTest.java @@ -517,7 +517,7 @@ public void testCopyOf() { } public void testCopyOfExplicitComparator() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); Map original = new LinkedHashMap<>(); original.put("one", 1); original.put("two", 2); @@ -530,7 +530,7 @@ public void testCopyOfExplicitComparator() { } public void testCopyOfImmutableSortedSetDifferentComparator() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); Map original = ImmutableSortedMap.of("one", 1, "two", 2, "three", 3); ImmutableSortedMap copy = ImmutableSortedMap.copyOf(original, comparator); assertMapEquals(copy, "two", 2, "three", 3, "one", 1); @@ -551,7 +551,7 @@ public void testCopyOfSortedNatural() { } public void testCopyOfSortedExplicit() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); SortedMap original = Maps.newTreeMap(comparator); original.put("one", 1); original.put("two", 2); @@ -619,11 +619,11 @@ public void testBuilderReverseOrder() { .put("five", 5) .build(); assertMapEquals(map, "two", 2, "three", 3, "one", 1, "four", 4, "five", 5); - assertEquals(Ordering.natural().reverse(), map.comparator()); + assertEquals(Ordering.natural().reverse(), map.comparator()); } public void testBuilderComparator() { - Comparator comparator = Ordering.natural().reverse(); + Comparator comparator = Ordering.natural().reverse(); ImmutableSortedMap map = new ImmutableSortedMap.Builder(comparator) .put("one", 1) diff --git a/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java b/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java index 32c1b81dcb00..4bb9736e3a7e 100644 --- a/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java +++ b/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java @@ -298,8 +298,8 @@ public void testSingle_headSet() { SortedSet set = of("e"); assertTrue(set.headSet("g") instanceof ImmutableSortedSet); assertThat(set.headSet("g")).contains("e"); - assertSame(of(), set.headSet("c")); - assertSame(of(), set.headSet("e")); + assertSame(this.of(), set.headSet("c")); + assertSame(this.of(), set.headSet("e")); } public void testSingle_tailSet() { @@ -307,7 +307,7 @@ public void testSingle_tailSet() { assertTrue(set.tailSet("c") instanceof ImmutableSortedSet); assertThat(set.tailSet("c")).contains("e"); assertThat(set.tailSet("e")).contains("e"); - assertSame(of(), set.tailSet("g")); + assertSame(this.of(), set.tailSet("g")); } public void testSingle_subSet() { @@ -315,9 +315,9 @@ public void testSingle_subSet() { assertTrue(set.subSet("c", "g") instanceof ImmutableSortedSet); assertThat(set.subSet("c", "g")).contains("e"); assertThat(set.subSet("e", "g")).contains("e"); - assertSame(of(), set.subSet("f", "g")); - assertSame(of(), set.subSet("c", "e")); - assertSame(of(), set.subSet("c", "d")); + assertSame(this.of(), set.subSet("f", "g")); + assertSame(this.of(), set.subSet("c", "e")); + assertSame(this.of(), set.subSet("c", "d")); } public void testSingle_first() { @@ -403,8 +403,8 @@ public void testOf_headSet() { assertTrue(set.headSet("e") instanceof ImmutableSortedSet); assertThat(set.headSet("e")).containsExactly("b", "c", "d").inOrder(); assertThat(set.headSet("g")).containsExactly("b", "c", "d", "e", "f").inOrder(); - assertSame(of(), set.headSet("a")); - assertSame(of(), set.headSet("b")); + assertSame(this.of(), set.headSet("a")); + assertSame(this.of(), set.headSet("b")); } public void testOf_tailSet() { @@ -412,7 +412,7 @@ public void testOf_tailSet() { assertTrue(set.tailSet("e") instanceof ImmutableSortedSet); assertThat(set.tailSet("e")).containsExactly("e", "f").inOrder(); assertThat(set.tailSet("a")).containsExactly("b", "c", "d", "e", "f").inOrder(); - assertSame(of(), set.tailSet("g")); + assertSame(this.of(), set.tailSet("g")); } public void testOf_subSet() { @@ -420,9 +420,9 @@ public void testOf_subSet() { assertTrue(set.subSet("c", "e") instanceof ImmutableSortedSet); assertThat(set.subSet("c", "e")).containsExactly("c", "d").inOrder(); assertThat(set.subSet("a", "g")).containsExactly("b", "c", "d", "e", "f").inOrder(); - assertSame(of(), set.subSet("a", "b")); - assertSame(of(), set.subSet("g", "h")); - assertSame(of(), set.subSet("c", "c")); + assertSame(this.of(), set.subSet("a", "b")); + assertSame(this.of(), set.subSet("g", "h")); + assertSame(this.of(), set.subSet("c", "c")); try { set.subSet("e", "c"); fail(); @@ -1191,7 +1191,7 @@ private static ImmutableList sortedNumberNames(int i, int j) { ImmutableList.of("one", "two", "three", "four", "five", "six", "seven"); private static final ImmutableList SORTED_NUMBER_NAMES = - Ordering.natural().immutableSortedCopy(NUMBER_NAMES); + Ordering.natural().immutableSortedCopy(NUMBER_NAMES); private static class SelfComparableExample implements Comparable { @Override diff --git a/guava-tests/test/com/google/common/collect/IterablesTest.java b/guava-tests/test/com/google/common/collect/IterablesTest.java index 2e7d89712808..68158d86c132 100644 --- a/guava-tests/test/com/google/common/collect/IterablesTest.java +++ b/guava-tests/test/com/google/common/collect/IterablesTest.java @@ -179,7 +179,7 @@ public void testGetOnlyElement_withDefault_empty() { public void testGetOnlyElement_withDefault_empty_null() { Iterable iterable = Collections.emptyList(); - assertNull(Iterables.getOnlyElement(iterable, null)); + assertNull(Iterables.<@Nullable String>getOnlyElement(iterable, null)); } public void testGetOnlyElement_withDefault_multiple() { @@ -508,7 +508,7 @@ public void testPaddedPartition_basic() { List list = asList(1, 2, 3, 4, 5); Iterable> partitions = Iterables.paddedPartition(list, 2); assertEquals(3, Iterables.size(partitions)); - assertEquals(asList(5, null), Iterables.getLast(partitions)); + assertEquals(Arrays.<@Nullable Integer>asList(5, null), Iterables.getLast(partitions)); } public void testPaddedPartitionRandomAccessInput() { @@ -566,7 +566,7 @@ public void testElementsEqual() throws Exception { assertFalse(Iterables.elementsEqual(a, b)); // null versus non-null. - a = asList(4, 8, 15, null, 23, 42); + a = Arrays.<@Nullable Integer>asList(4, 8, 15, null, 23, 42); b = asList(4, 8, 15, 16, 23, 42); assertFalse(Iterables.elementsEqual(a, b)); assertFalse(Iterables.elementsEqual(b, a)); @@ -853,7 +853,7 @@ public void testGetFirst_withDefault_empty() { public void testGetFirst_withDefault_empty_null() { Iterable iterable = Collections.emptyList(); - assertNull(Iterables.getFirst(iterable, null)); + assertNull(Iterables.<@Nullable String>getFirst(iterable, null)); } public void testGetFirst_withDefault_multiple() { @@ -892,7 +892,7 @@ public void testGetLast_withDefault_empty() { public void testGetLast_withDefault_empty_null() { Iterable iterable = Collections.emptyList(); - assertNull(Iterables.getLast(iterable, null)); + assertNull(Iterables.<@Nullable String>getLast(iterable, null)); } public void testGetLast_withDefault_multiple() { @@ -1387,7 +1387,7 @@ public void testMergeSorted_pyramid() { list.add(j); allIntegers.add(j); } - iterables.add(Ordering.natural().sortedCopy(list)); + iterables.add(Ordering.natural().sortedCopy(list)); } verifyMergeSorted(iterables, allIntegers); @@ -1404,7 +1404,7 @@ public void testMergeSorted_skipping_pyramid() { list.add(j * i); allIntegers.add(j * i); } - iterables.add(Ordering.natural().sortedCopy(list)); + iterables.add(Ordering.natural().sortedCopy(list)); } verifyMergeSorted(iterables, allIntegers); @@ -1422,7 +1422,7 @@ public void testIterables_nullCheck() throws Exception { private static void verifyMergeSorted( Iterable> iterables, Iterable unsortedExpected) { - Iterable expected = Ordering.natural().sortedCopy(unsortedExpected); + Iterable expected = Ordering.natural().sortedCopy(unsortedExpected); Iterable mergedIterator = Iterables.mergeSorted(iterables, Ordering.natural()); diff --git a/guava-tests/test/com/google/common/collect/IteratorsTest.java b/guava-tests/test/com/google/common/collect/IteratorsTest.java index 6d4b4307f237..7e173ab6a0bd 100644 --- a/guava-tests/test/com/google/common/collect/IteratorsTest.java +++ b/guava-tests/test/com/google/common/collect/IteratorsTest.java @@ -162,7 +162,7 @@ public void testSize_partiallyConsumed() { } public void test_contains_nonnull_yes() { - Iterator set = asList("a", null, "b").iterator(); + Iterator<@Nullable String> set = Arrays.<@Nullable String>asList("a", null, "b").iterator(); assertTrue(Iterators.contains(set, "b")); } @@ -172,7 +172,7 @@ public void test_contains_nonnull_no() { } public void test_contains_null_yes() { - Iterator set = asList("a", null, "b").iterator(); + Iterator<@Nullable String> set = Arrays.<@Nullable String>asList("a", null, "b").iterator(); assertTrue(Iterators.contains(set, null)); } @@ -241,7 +241,7 @@ public void testGetOnlyElement_withDefault_empty() { public void testGetOnlyElement_withDefault_empty_null() { Iterator iterator = Iterators.emptyIterator(); - assertNull(Iterators.getOnlyElement(iterator, null)); + assertNull(Iterators.<@Nullable String>getOnlyElement(iterator, null)); } public void testGetOnlyElement_withDefault_two() { @@ -513,7 +513,7 @@ public Integer apply(String from) { } public void testNullFriendlyTransform() { - Iterator input = asList(1, 2, null, 3).iterator(); + Iterator<@Nullable Integer> input = Arrays.<@Nullable Integer>asList(1, 2, null, 3).iterator(); Iterator result = Iterators.transform( input, @@ -821,7 +821,10 @@ public void testConcatPartiallyAdvancedFirst() { /** Illustrates the somewhat bizarre behavior when a null is passed in. */ public void testConcatContainingNull() { - Iterator> input = asList(iterateOver(1, 2), null, iterateOver(3)).iterator(); + Iterator> input = + (Iterator>) + Arrays.<@Nullable Iterator>asList(iterateOver(1, 2), null, iterateOver(3)) + .iterator(); Iterator result = Iterators.concat(input); assertEquals(1, (int) result.next()); assertEquals(2, (int) result.next()); @@ -939,8 +942,8 @@ public void testElementsEqual() { assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator())); // The same, but with nulls. - a = asList(4, 8, null, 16, 23, 42); - b = asList(4, 8, null, 16, 23, 42); + a = Arrays.<@Nullable Integer>asList(4, 8, null, 16, 23, 42); + b = Arrays.<@Nullable Integer>asList(4, 8, null, 16, 23, 42); assertTrue(Iterators.elementsEqual(a.iterator(), b.iterator())); // Different Iterable types (still equal elements, though). @@ -954,7 +957,7 @@ public void testElementsEqual() { assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator())); // null versus non-null. - a = asList(4, 8, 15, null, 23, 42); + a = Arrays.<@Nullable Integer>asList(4, 8, 15, null, 23, 42); b = asList(4, 8, 15, 16, 23, 42); assertFalse(Iterators.elementsEqual(a.iterator(), b.iterator())); assertFalse(Iterators.elementsEqual(b.iterator(), a.iterator())); @@ -1072,17 +1075,17 @@ public void testPaddedPartition_singleton2() { Iterator> partitions = Iterators.paddedPartition(source, 2); assertTrue(partitions.hasNext()); assertTrue(partitions.hasNext()); - assertEquals(asList(1, null), partitions.next()); + assertEquals(Arrays.<@Nullable Integer>asList(1, null), partitions.next()); assertFalse(partitions.hasNext()); } @GwtIncompatible // fairly slow (~50s) public void testPaddedPartition_general() { + ImmutableList> expectedElements = + ImmutableList.of( + asList(1, 2, 3), asList(4, 5, 6), Arrays.<@Nullable Integer>asList(7, null, null)); new IteratorTester>( - 5, - IteratorFeature.UNMODIFIABLE, - ImmutableList.of(asList(1, 2, 3), asList(4, 5, 6), asList(7, null, null)), - IteratorTester.KnownOrder.KNOWN_ORDER) { + 5, IteratorFeature.UNMODIFIABLE, expectedElements, IteratorTester.KnownOrder.KNOWN_ORDER) { @Override protected Iterator> newTargetIterator() { Iterator source = Iterators.forArray(1, 2, 3, 4, 5, 6, 7); @@ -1287,7 +1290,8 @@ public void testToString() { } public void testToStringWithNull() { - Iterator iterator = Lists.newArrayList("hello", null, "world").iterator(); + Iterator<@Nullable String> iterator = + Lists.<@Nullable String>newArrayList("hello", null, "world").iterator(); assertEquals("[hello, null, world]", Iterators.toString(iterator)); } @@ -1355,7 +1359,7 @@ public void testGetNext_withDefault_empty() { public void testGetNext_withDefault_empty_null() { Iterator iterator = Iterators.emptyIterator(); - assertNull(Iterators.getNext(iterator, null)); + assertNull(Iterators.<@Nullable String>getNext(iterator, null)); } public void testGetNext_withDefault_two() { @@ -1391,7 +1395,7 @@ public void testGetLast_withDefault_empty() { public void testGetLast_withDefault_empty_null() { Iterator iterator = Iterators.emptyIterator(); - assertNull(Iterators.getLast(iterator, null)); + assertNull(Iterators.<@Nullable String>getLast(iterator, null)); } public void testGetLast_withDefault_two() { diff --git a/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java b/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java index 049c1ea7df85..3583c5675848 100644 --- a/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java +++ b/guava-tests/test/com/google/common/collect/MapsTransformValuesUnmodifiableIteratorTest.java @@ -358,11 +358,12 @@ public void testTransformEntrySetContains() { Set> entries = map.entrySet(); assertTrue(entries.contains(Maps.immutableEntry("a", true))); - assertTrue(entries.contains(Maps.immutableEntry("b", (Boolean) null))); - assertTrue(entries.contains(Maps.immutableEntry((String) null, (Boolean) null))); + assertTrue(entries.contains(Maps.immutableEntry("b", null))); + assertTrue( + entries.contains(Maps.<@Nullable String, @Nullable Boolean>immutableEntry(null, null))); - assertFalse(entries.contains(Maps.immutableEntry("c", (Boolean) null))); - assertFalse(entries.contains(Maps.immutableEntry((String) null, true))); + assertFalse(entries.contains(Maps.immutableEntry("c", null))); + assertFalse(entries.contains(Maps.<@Nullable String, Boolean>immutableEntry(null, true))); } @Override diff --git a/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java b/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java index 83a835609a3a..ca19020ab9fd 100644 --- a/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java +++ b/guava-tests/test/com/google/common/collect/MinMaxPriorityQueueTest.java @@ -59,7 +59,7 @@ @GwtCompatible(emulated = true) @ElementTypesAreNonnullByDefault public class MinMaxPriorityQueueTest extends TestCase { - private static final Ordering SOME_COMPARATOR = Ordering.natural().reverse(); + private static final Ordering SOME_COMPARATOR = Ordering.natural().reverse(); @J2ktIncompatible @GwtIncompatible // suite diff --git a/guava-tests/test/com/google/common/collect/MoreCollectorsTest.java b/guava-tests/test/com/google/common/collect/MoreCollectorsTest.java index f6b327000c92..9244c0c11fb8 100644 --- a/guava-tests/test/com/google/common/collect/MoreCollectorsTest.java +++ b/guava-tests/test/com/google/common/collect/MoreCollectorsTest.java @@ -88,7 +88,8 @@ public void testOnlyElementSingleton() { } public void testOnlyElementNull() { - assertThat(Stream.of((Object) null).collect(MoreCollectors.onlyElement())).isNull(); + assertThat(Stream.<@Nullable Object>of((Object) null).collect(MoreCollectors.onlyElement())) + .isNull(); } public void testOnlyElementMultiple() { diff --git a/guava-tests/test/com/google/common/collect/MultimapsTest.java b/guava-tests/test/com/google/common/collect/MultimapsTest.java index 2555cb5ea63b..dce5cae26730 100644 --- a/guava-tests/test/com/google/common/collect/MultimapsTest.java +++ b/guava-tests/test/com/google/common/collect/MultimapsTest.java @@ -179,7 +179,8 @@ public void testUnmodifiableMultimapShortCircuit() { @GwtIncompatible // slow (~10s) public void testUnmodifiableArrayListMultimap() { - checkUnmodifiableMultimap(ArrayListMultimap.create(), true); + checkUnmodifiableMultimap( + ArrayListMultimap.<@Nullable String, @Nullable Integer>create(), true); } @J2ktIncompatible @@ -210,7 +211,7 @@ public void testUnmodifiableLinkedListMultimapRandomAccess() { @GwtIncompatible // slow (~10s) public void testUnmodifiableHashMultimap() { - checkUnmodifiableMultimap(HashMultimap.create(), false); + checkUnmodifiableMultimap(HashMultimap.<@Nullable String, @Nullable Integer>create(), false); } @J2ktIncompatible @@ -237,7 +238,9 @@ public void testSerializingUnmodifiableTreeMultimap() { @GwtIncompatible // slow (~10s) public void testUnmodifiableSynchronizedArrayListMultimap() { checkUnmodifiableMultimap( - Multimaps.synchronizedListMultimap(ArrayListMultimap.create()), true); + Multimaps.synchronizedListMultimap( + ArrayListMultimap.<@Nullable String, @Nullable Integer>create()), + true); } @J2ktIncompatible @@ -255,7 +258,9 @@ public void testSerializingUnmodifiableSynchronizedArrayListMultimap() { @GwtIncompatible // slow (~10s) public void testUnmodifiableSynchronizedHashMultimap() { checkUnmodifiableMultimap( - Multimaps.synchronizedSetMultimap(HashMultimap.create()), false); + Multimaps.synchronizedSetMultimap( + HashMultimap.<@Nullable String, @Nullable Integer>create()), + false); } @J2ktIncompatible diff --git a/guava-tests/test/com/google/common/collect/ObjectArraysTest.java b/guava-tests/test/com/google/common/collect/ObjectArraysTest.java index 7e6646d354a3..c3ad40278fb2 100644 --- a/guava-tests/test/com/google/common/collect/ObjectArraysTest.java +++ b/guava-tests/test/com/google/common/collect/ObjectArraysTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.List; import junit.framework.TestCase; +import org.checkerframework.checker.nullness.qual.Nullable; /** * Unit test for {@code ObjectArrays}. @@ -124,7 +125,7 @@ public void testConcatWithMoreGeneralType() { public void testToArrayImpl1() { doTestToArrayImpl1(Lists.newArrayList()); doTestToArrayImpl1(Lists.newArrayList(1)); - doTestToArrayImpl1(Lists.newArrayList(1, null, 3)); + doTestToArrayImpl1(Lists.<@Nullable Integer>newArrayList(1, null, 3)); } private void doTestToArrayImpl1(List list) { @@ -142,9 +143,9 @@ public void testToArrayImpl2() { doTestToArrayImpl2(Lists.newArrayList(1), new Integer[1], true); doTestToArrayImpl2(Lists.newArrayList(1), new Integer[] {2, 3}, true); - doTestToArrayImpl2(Lists.newArrayList(1, null, 3), new Integer[0], false); - doTestToArrayImpl2(Lists.newArrayList(1, null, 3), new Integer[2], false); - doTestToArrayImpl2(Lists.newArrayList(1, null, 3), new Integer[3], true); + doTestToArrayImpl2(Lists.<@Nullable Integer>newArrayList(1, null, 3), new Integer[0], false); + doTestToArrayImpl2(Lists.<@Nullable Integer>newArrayList(1, null, 3), new Integer[2], false); + doTestToArrayImpl2(Lists.<@Nullable Integer>newArrayList(1, null, 3), new Integer[3], true); } private void doTestToArrayImpl2(List list, Integer[] array1, boolean expectModify) { diff --git a/guava-tests/test/com/google/common/collect/OrderingTest.java b/guava-tests/test/com/google/common/collect/OrderingTest.java index 311552735a1e..3a50b54e648f 100644 --- a/guava-tests/test/com/google/common/collect/OrderingTest.java +++ b/guava-tests/test/com/google/common/collect/OrderingTest.java @@ -97,9 +97,9 @@ public void testComplicatedOrderingExample() { // [[null, null], [null], [1, null, 2], [1, 1], [1, 2], [1], [2], [], null] assertThat(sorted) .containsExactly( - Lists.newArrayList(nullInt, nullInt), - Lists.newArrayList(nullInt), - Lists.newArrayList(1, null, 2), + Lists.<@Nullable Integer>newArrayList(nullInt, nullInt), + Lists.<@Nullable Integer>newArrayList(nullInt), + Lists.<@Nullable Integer>newArrayList(1, null, 2), Lists.newArrayList(1, 1), Lists.newArrayList(1, 2), Lists.newArrayList(1), @@ -291,7 +291,7 @@ public Character apply(String string) { } private static Ordering byCharAt(int index) { - return Ordering.natural().onResultOf(CharAtFunction.values()[index]); + return Ordering.natural().onResultOf(CharAtFunction.values()[index]); } public void testCompound_static() { @@ -385,18 +385,18 @@ public Integer apply(String string) { } } - private static final Ordering DECREASING_INTEGER = Ordering.natural().reverse(); + private static final Ordering DECREASING_INTEGER = Ordering.natural().reverse(); public void testOnResultOf_natural() { Comparator comparator = - Ordering.natural().onResultOf(StringLengthFunction.StringLength); + Ordering.natural().onResultOf(StringLengthFunction.StringLength); assertTrue(comparator.compare("to", "be") == 0); assertTrue(comparator.compare("or", "not") < 0); assertTrue(comparator.compare("that", "to") > 0); new EqualsTester() .addEqualityGroup( - comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) + comparator, Ordering.natural().onResultOf(StringLengthFunction.StringLength)) .addEqualityGroup(DECREASING_INTEGER) .testEquals(); reserializeAndAssert(comparator); @@ -440,8 +440,8 @@ public void testLexicographical() { } public void testNullsFirst() { - Ordering ordering = Ordering.natural().nullsFirst(); - Helpers.testComparator(ordering, null, Integer.MIN_VALUE, 0, 1); + Ordering<@Nullable Integer> ordering = Ordering.natural().nullsFirst(); + Helpers.<@Nullable Integer>testComparator(ordering, null, Integer.MIN_VALUE, 0, 1); new EqualsTester() .addEqualityGroup(ordering, Ordering.natural().nullsFirst()) @@ -451,8 +451,8 @@ public void testNullsFirst() { } public void testNullsLast() { - Ordering ordering = Ordering.natural().nullsLast(); - Helpers.testComparator(ordering, 0, 1, Integer.MAX_VALUE, null); + Ordering<@Nullable Integer> ordering = Ordering.natural().nullsLast(); + Helpers.<@Nullable Integer>testComparator(ordering, 0, 1, Integer.MAX_VALUE, null); new EqualsTester() .addEqualityGroup(ordering, Ordering.natural().nullsLast()) @@ -467,9 +467,10 @@ public void testBinarySearch() { } public void testSortedCopy() { - List unsortedInts = Collections.unmodifiableList(Arrays.asList(5, 0, 3, null, 0, 9)); - List sortedInts = numberOrdering.nullsLast().sortedCopy(unsortedInts); - assertEquals(Arrays.asList(0, 0, 3, 5, 9, null), sortedInts); + List<@Nullable Integer> unsortedInts = + Collections.unmodifiableList(Arrays.<@Nullable Integer>asList(5, 0, 3, null, 0, 9)); + List<@Nullable Integer> sortedInts = numberOrdering.nullsLast().sortedCopy(unsortedInts); + assertEquals(Arrays.<@Nullable Integer>asList(0, 0, 3, 5, 9, null), sortedInts); assertEquals( Collections.emptyList(), numberOrdering.sortedCopy(Collections.emptyList())); @@ -484,9 +485,9 @@ public void testImmutableSortedCopy() { Collections.emptyList(), numberOrdering.immutableSortedCopy(Collections.emptyList())); - List listWithNull = Arrays.asList(5, 3, null, 9); + List<@Nullable Integer> listWithNull = Arrays.asList(5, 3, null, 9); try { - Ordering.natural().nullsFirst().immutableSortedCopy(listWithNull); + Ordering.natural().nullsFirst().immutableSortedCopy((List) listWithNull); fail(); } catch (NullPointerException expected) { } @@ -599,16 +600,17 @@ public void testLeastOfIterator_simple_1() { } public void testLeastOfIterable_simple_nMinusOne_withNullElement() { - List list = Arrays.asList(3, null, 5, -1); - List result = Ordering.natural().nullsLast().leastOf(list, list.size() - 1); + List<@Nullable Integer> list = Arrays.asList(3, null, 5, -1); + List<@Nullable Integer> result = + Ordering.natural().nullsLast().leastOf(list, list.size() - 1); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.of(-1, 3, 5), result); } public void testLeastOfIterator_simple_nMinusOne_withNullElement() { - Iterator itr = Iterators.forArray(3, null, 5, -1); - List result = Ordering.natural().nullsLast().leastOf(itr, 3); + Iterator<@Nullable Integer> itr = Iterators.forArray(3, null, 5, -1); + List<@Nullable Integer> result = Ordering.natural().nullsLast().leastOf(itr, 3); assertTrue(result instanceof RandomAccess); assertListImmutable(result); assertEquals(ImmutableList.of(-1, 3, 5), result); @@ -647,19 +649,21 @@ public void testLeastOfIterator_simple_n() { } public void testLeastOfIterable_simple_n_withNullElement() { - List list = Arrays.asList(3, 4, 5, null, -1); - List result = Ordering.natural().nullsLast().leastOf(list, list.size()); + List<@Nullable Integer> list = Arrays.asList(3, 4, 5, null, -1); + List<@Nullable Integer> result = + Ordering.natural().nullsLast().leastOf(list, list.size()); assertTrue(result instanceof RandomAccess); assertListImmutable(result); - assertEquals(Arrays.asList(-1, 3, 4, 5, null), result); + assertEquals(Arrays.<@Nullable Integer>asList(-1, 3, 4, 5, null), result); } public void testLeastOfIterator_simple_n_withNullElement() { - List list = Arrays.asList(3, 4, 5, null, -1); - List result = Ordering.natural().nullsLast().leastOf(list.iterator(), list.size()); + List<@Nullable Integer> list = Arrays.asList(3, 4, 5, null, -1); + List<@Nullable Integer> result = + Ordering.natural().nullsLast().leastOf(list.iterator(), list.size()); assertTrue(result instanceof RandomAccess); assertListImmutable(result); - assertEquals(Arrays.asList(-1, 3, 4, 5, null), result); + assertEquals(Arrays.<@Nullable Integer>asList(-1, 3, 4, 5, null), result); } public void testLeastOfIterable_simple_nPlusOne() { @@ -730,14 +734,15 @@ private static void runLeastOfComparison(int iterations, int elements, int seeds public void testLeastOfIterableLargeK() { List list = Arrays.asList(4, 2, 3, 5, 1); - assertEquals(Arrays.asList(1, 2, 3, 4, 5), Ordering.natural().leastOf(list, Integer.MAX_VALUE)); + assertEquals( + Arrays.asList(1, 2, 3, 4, 5), Ordering.natural().leastOf(list, Integer.MAX_VALUE)); } public void testLeastOfIteratorLargeK() { List list = Arrays.asList(4, 2, 3, 5, 1); assertEquals( Arrays.asList(1, 2, 3, 4, 5), - Ordering.natural().leastOf(list.iterator(), Integer.MAX_VALUE)); + Ordering.natural().leastOf(list.iterator(), Integer.MAX_VALUE)); } public void testGreatestOfIterable_simple() { @@ -1094,7 +1099,7 @@ public T apply(Integer from) { composites.add(new Composite(t, 2)); } Ordering> ordering = - Ordering.natural() + Ordering.>natural() .compound(scenario.ordering.onResultOf(Composite.getValueFunction())); return new Scenario>( ordering, composites, (Composite[]) new Composite[0]); diff --git a/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java b/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java index d070936c3bac..22686633c6ae 100644 --- a/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java +++ b/guava-tests/test/com/google/common/collect/PeekingIteratorTest.java @@ -106,7 +106,7 @@ public void testPeekingIteratorBehavesLikeIteratorOnThreeElementIterable() { @GwtIncompatible // works but takes 5 minutes to run public void testPeekingIteratorAcceptsNullElements() { - actsLikeIteratorHelper(Lists.newArrayList(null, "A", null)); + actsLikeIteratorHelper(Lists.<@Nullable String>newArrayList(null, "A", null)); } public void testPeekOnEmptyList() { diff --git a/guava-tests/test/com/google/common/collect/SetsTest.java b/guava-tests/test/com/google/common/collect/SetsTest.java index 3e6f01d2b67c..278127a40374 100644 --- a/guava-tests/test/com/google/common/collect/SetsTest.java +++ b/guava-tests/test/com/google/common/collect/SetsTest.java @@ -894,7 +894,7 @@ public void testPowerSetContents() { assertTrue(powerSet.contains(subset)); } assertFalse(powerSet.contains(ImmutableSet.of(1, 2, 4))); - assertFalse(powerSet.contains(singleton(null))); + assertFalse(powerSet.contains(Collections.<@Nullable Integer>singleton(null))); assertFalse(powerSet.contains(null)); assertFalse(powerSet.contains((Object) "notASet")); } diff --git a/guava-tests/test/com/google/common/collect/StreamsTest.java b/guava-tests/test/com/google/common/collect/StreamsTest.java index fc64f84d893a..ca607e1a38db 100644 --- a/guava-tests/test/com/google/common/collect/StreamsTest.java +++ b/guava-tests/test/com/google/common/collect/StreamsTest.java @@ -40,6 +40,7 @@ import java.util.stream.LongStream; import java.util.stream.Stream; import junit.framework.TestCase; +import org.checkerframework.checker.nullness.qual.Nullable; /** Unit test for {@link Streams}. */ @GwtCompatible(emulated = true) @@ -307,7 +308,9 @@ public void testMapWithIndex_linkedHashSetSource() { public void testMapWithIndex_unsizedSource() { testMapWithIndex( - elems -> Stream.of((Object) null).flatMap(unused -> ImmutableList.copyOf(elems).stream())); + elems -> + Stream.<@Nullable Object>of((Object) null) + .flatMap(unused -> ImmutableList.copyOf(elems).stream())); } public void testMapWithIndex_closeIsPropagated_sizedSource() { @@ -316,7 +319,7 @@ public void testMapWithIndex_closeIsPropagated_sizedSource() { public void testMapWithIndex_closeIsPropagated_unsizedSource() { testMapWithIndex_closeIsPropagated( - Stream.of((Object) null).flatMap(unused -> Stream.of("a", "b", "c"))); + Stream.<@Nullable Object>of((Object) null).flatMap(unused -> Stream.of("a", "b", "c"))); } private void testMapWithIndex_closeIsPropagated(Stream source) { diff --git a/guava-tests/test/com/google/common/collect/TablesTest.java b/guava-tests/test/com/google/common/collect/TablesTest.java index b1b1fb2d6357..1eeb3afd6f0f 100644 --- a/guava-tests/test/com/google/common/collect/TablesTest.java +++ b/guava-tests/test/com/google/common/collect/TablesTest.java @@ -55,18 +55,27 @@ public void testEntryEquals() { .addEqualityGroup(Tables.immutableCell("bar", 1, 'a')) .addEqualityGroup(Tables.immutableCell("foo", 2, 'a')) .addEqualityGroup(Tables.immutableCell("foo", 1, 'b')) - .addEqualityGroup(Tables.immutableCell(null, null, null)) + .addEqualityGroup( + Tables.<@Nullable Object, @Nullable Object, @Nullable Object>immutableCell( + null, null, null)) .testEquals(); } public void testEntryEqualsNull() { - Cell entry = Tables.immutableCell(null, null, null); + Cell<@Nullable String, @Nullable Integer, @Nullable Character> entry = + Tables.immutableCell(null, null, null); new EqualsTester() - .addEqualityGroup(entry, Tables.immutableCell(null, null, null)) - .addEqualityGroup(Tables.immutableCell("bar", null, null)) - .addEqualityGroup(Tables.immutableCell(null, 2, null)) - .addEqualityGroup(Tables.immutableCell(null, null, 'b')) + .addEqualityGroup( + entry, + Tables.<@Nullable Object, @Nullable Object, @Nullable Object>immutableCell( + null, null, null)) + .addEqualityGroup( + Tables.immutableCell("bar", null, null)) + .addEqualityGroup( + Tables.<@Nullable Object, Integer, @Nullable Object>immutableCell(null, 2, null)) + .addEqualityGroup( + Tables.<@Nullable Object, @Nullable Object, Character>immutableCell(null, null, 'b')) .addEqualityGroup(Tables.immutableCell("foo", 1, 'a')) .testEquals(); } diff --git a/guava-tests/test/com/google/common/collect/TopKSelectorTest.java b/guava-tests/test/com/google/common/collect/TopKSelectorTest.java index 2cebdc338b08..05ecb2040fe4 100644 --- a/guava-tests/test/com/google/common/collect/TopKSelectorTest.java +++ b/guava-tests/test/com/google/common/collect/TopKSelectorTest.java @@ -37,12 +37,12 @@ public class TopKSelectorTest extends TestCase { public void testNegativeK() { try { - TopKSelector.least(-1); + TopKSelector.least(-1); fail(); } catch (IllegalArgumentException expected) { } try { - TopKSelector.greatest(-1); + TopKSelector.greatest(-1); fail(); } catch (IllegalArgumentException expected) { } diff --git a/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java b/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java index 7f4d8ff822ab..c1a9f0066b9f 100644 --- a/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java +++ b/guava-tests/test/com/google/common/collect/TreeBasedTableTest.java @@ -286,7 +286,7 @@ public void testColumnKeySet_isSortedWithRealComparator() { table = create( String.CASE_INSENSITIVE_ORDER, - Ordering.natural().reverse(), + Ordering.natural().reverse(), "a", 2, 'X', diff --git a/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java b/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java index 601709b105e6..e887c0fadfa4 100644 --- a/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java +++ b/guava-tests/test/com/google/common/collect/TreeMultimapExplicitTest.java @@ -150,10 +150,10 @@ public void testOrderedEntries() { TreeMultimap<@Nullable String, @Nullable Integer> multimap = createPopulate(); assertThat(multimap.entries()) .containsExactly( - Maps.immutableEntry((String) null, 7), - Maps.immutableEntry((String) null, 3), - Maps.immutableEntry((String) null, 1), - Maps.immutableEntry("tree", (Integer) null), + Maps.<@Nullable String, Integer>immutableEntry(null, 7), + Maps.<@Nullable String, Integer>immutableEntry(null, 3), + Maps.<@Nullable String, Integer>immutableEntry(null, 1), + Maps.immutableEntry("tree", null), Maps.immutableEntry("tree", 0), Maps.immutableEntry("google", 6), Maps.immutableEntry("google", 2)) @@ -193,7 +193,7 @@ public void testSortedKeySet() { assertEquals(null, keySet.first()); assertEquals("google", keySet.last()); assertEquals(StringLength.COMPARATOR, keySet.comparator()); - assertEquals(Sets.newHashSet(null, "tree"), keySet.headSet("yahoo")); + assertEquals(Sets.<@Nullable String>newHashSet(null, "tree"), keySet.headSet("yahoo")); assertEquals(Sets.newHashSet("google"), keySet.tailSet("yahoo")); assertEquals(Sets.newHashSet("tree"), keySet.subSet("ask", "yahoo")); } diff --git a/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java b/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java index 012a14c5aab6..f475e87f996c 100644 --- a/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java +++ b/guava-tests/test/com/google/common/collect/TreeMultimapNaturalTest.java @@ -354,7 +354,7 @@ public void testMultimapConstructor() { private static final Comparator KEY_COMPARATOR = Ordering.natural(); private static final Comparator VALUE_COMPARATOR = - Ordering.natural().reverse().nullsFirst(); + Ordering.natural().reverse().nullsFirst(); /** * Test that creating one TreeMultimap from another does not copy the comparators from the source diff --git a/guava-tests/test/com/google/common/collect/TreeMultisetTest.java b/guava-tests/test/com/google/common/collect/TreeMultisetTest.java index 0077b75d168a..6f9651a9df51 100644 --- a/guava-tests/test/com/google/common/collect/TreeMultisetTest.java +++ b/guava-tests/test/com/google/common/collect/TreeMultisetTest.java @@ -287,8 +287,8 @@ public int compare(String o1, String o2) { } public void testNullAcceptingComparator() throws Exception { - Comparator comparator = Ordering.natural().nullsFirst(); - TreeMultiset ms = TreeMultiset.create(comparator); + Comparator<@Nullable String> comparator = Ordering.natural().nullsFirst(); + TreeMultiset<@Nullable String> ms = TreeMultiset.create(comparator); ms.add("b"); ms.add(null);