aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcpovirk <cpovirk@google.com>2021-06-28 19:10:37 -0700
committerGoogle Java Core Libraries <java-core-libraries-team+copybara@google.com>2021-06-28 19:13:00 -0700
commit904d567679509526bbc4461c8412ac99db51b248 (patch)
treec9f05a47b14a64e218714a05fc867fee9c2dce60
parent6ad72dd8e97688745267edfa7d0da7a432f57170 (diff)
downloadguava-904d567679509526bbc4461c8412ac99db51b248.tar.gz
Annotate some "sorted" types for nullness.
RELNOTES=n/a PiperOrigin-RevId: 381992970
-rw-r--r--android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java2
-rw-r--r--android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java11
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableSortedMap.java10
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java9
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableSortedSet.java25
-rw-r--r--android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java11
-rw-r--r--android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java16
-rw-r--r--android/guava/src/com/google/common/collect/SortedIterable.java4
-rw-r--r--guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java2
-rw-r--r--guava/src/com/google/common/collect/DescendingImmutableSortedSet.java11
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedAsList.java9
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedMap.java29
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java28
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedSet.java23
-rw-r--r--guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java12
-rw-r--r--guava/src/com/google/common/collect/RegularImmutableSortedSet.java14
-rw-r--r--guava/src/com/google/common/collect/SortedIterable.java4
17 files changed, 160 insertions, 60 deletions
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 2ebff40fe..ea0e3a8d1 100644
--- a/android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java
+++ b/android/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java
@@ -915,7 +915,7 @@ public class ImmutableSortedSetTest extends AbstractImmutableSetTest {
assertTrue(Iterables.elementsEqual(LegacyComparable.VALUES_BACKWARD, set));
}
- @SuppressWarnings({"deprecation", "static-access"})
+ @SuppressWarnings({"deprecation", "static-access", "DoNotCall"})
public void testBuilderMethod() {
try {
ImmutableSortedSet.builder();
diff --git a/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
index 64e3e89ac..88c7d6b5c 100644
--- a/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
+++ b/android/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
@@ -17,7 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
-import org.checkerframework.checker.nullness.compatqual.NullableDecl;
+import javax.annotation.CheckForNull;
/**
* Skeletal implementation of {@link ImmutableSortedSet#descendingSet()}.
@@ -25,6 +25,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
* @author Louis Wasserman
*/
@GwtIncompatible
+@ElementTypesAreNonnullByDefault
final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
private final ImmutableSortedSet<E> forward;
@@ -34,7 +35,7 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- public boolean contains(@NullableDecl Object object) {
+ public boolean contains(@CheckForNull Object object) {
return forward.contains(object);
}
@@ -83,27 +84,31 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
+ @CheckForNull
public E lower(E element) {
return forward.higher(element);
}
@Override
+ @CheckForNull
public E floor(E element) {
return forward.ceiling(element);
}
@Override
+ @CheckForNull
public E ceiling(E element) {
return forward.floor(element);
}
@Override
+ @CheckForNull
public E higher(E element) {
return forward.lower(element);
}
@Override
- int indexOf(@NullableDecl Object target) {
+ int indexOf(@CheckForNull Object target) {
int index = forward.indexOf(target);
if (index == -1) {
return index;
diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedMap.java b/android/guava/src/com/google/common/collect/ImmutableSortedMap.java
index b0bae12be..1f5001b8b 100644
--- a/android/guava/src/com/google/common/collect/ImmutableSortedMap.java
+++ b/android/guava/src/com/google/common/collect/ImmutableSortedMap.java
@@ -33,7 +33,6 @@ import java.util.NavigableMap;
import java.util.SortedMap;
import java.util.TreeMap;
import javax.annotation.CheckForNull;
-import org.checkerframework.checker.nullness.compatqual.NullableDecl;
/**
* A {@link NavigableMap} whose contents will never change, with many other important properties
@@ -53,6 +52,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
* @since 2.0 (implements {@code NavigableMap} since 12.0)
*/
@GwtCompatible(serializable = true, emulated = true)
+@ElementTypesAreNonnullByDefault
public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxverideShim<K, V>
implements NavigableMap<K, V> {
@@ -558,7 +558,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
private final transient RegularImmutableSortedSet<K> keySet;
private final transient ImmutableList<V> valueList;
- private transient ImmutableSortedMap<K, V> descendingMap;
+ @CheckForNull private transient ImmutableSortedMap<K, V> descendingMap;
ImmutableSortedMap(RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList) {
this(keySet, valueList, null);
@@ -567,7 +567,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
ImmutableSortedMap(
RegularImmutableSortedSet<K> keySet,
ImmutableList<V> valueList,
- ImmutableSortedMap<K, V> descendingMap) {
+ @CheckForNull ImmutableSortedMap<K, V> descendingMap) {
this.keySet = keySet;
this.valueList = valueList;
this.descendingMap = descendingMap;
@@ -580,7 +580,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
@Override
@CheckForNull
- public V get(@NullableDecl Object key) {
+ public V get(@CheckForNull Object key) {
int index = keySet.indexOf(key);
return (index == -1) ? null : valueList.get(index);
}
@@ -860,6 +860,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final Entry<K, V> pollFirstEntry() {
throw new UnsupportedOperationException();
}
@@ -874,6 +875,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final Entry<K, V> pollLastEntry() {
throw new UnsupportedOperationException();
}
diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java b/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java
index 1e875a3b0..6fed81740 100644
--- a/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java
+++ b/android/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java
@@ -17,6 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.errorprone.annotations.DoNotCall;
/**
* "Overrides" the {@link ImmutableMap} static methods that lack {@link ImmutableSortedMap}
@@ -26,6 +27,7 @@ import com.google.common.annotations.GwtIncompatible;
* @author Chris Povirk
*/
@GwtIncompatible
+@ElementTypesAreNonnullByDefault
abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> {
/**
* Not supported. Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety,
@@ -35,6 +37,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety.
*/
+ @DoNotCall("Use naturalOrder")
@Deprecated
public static <K, V> ImmutableSortedMap.Builder<K, V> builder() {
throw new UnsupportedOperationException();
@@ -46,6 +49,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @throws UnsupportedOperationException always
* @deprecated Not supported for ImmutableSortedMap.
*/
+ @DoNotCall("Use naturalOrder (which does not accept an expected size)")
@Deprecated
public static <K, V> ImmutableSortedMap.Builder<K, V> builderWithExpectedSize(int expectedSize) {
throw new UnsupportedOperationException();
@@ -60,6 +64,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @deprecated <b>Pass a key of type {@code Comparable} to use {@link
* ImmutableSortedMap#of(Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass a key of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1) {
throw new UnsupportedOperationException();
@@ -74,6 +79,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @deprecated <b>Pass keys of type {@code Comparable} to use {@link
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) {
throw new UnsupportedOperationException();
@@ -88,6 +94,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @deprecated <b>Pass keys of type {@code Comparable} to use {@link
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
throw new UnsupportedOperationException();
@@ -103,6 +110,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object,
* Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
throw new UnsupportedOperationException();
@@ -118,6 +126,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object,
* Comparable, Object, Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedSet.java b/android/guava/src/com/google/common/collect/ImmutableSortedSet.java
index e10b4d7a7..fabf599f1 100644
--- a/android/guava/src/com/google/common/collect/ImmutableSortedSet.java
+++ b/android/guava/src/com/google/common/collect/ImmutableSortedSet.java
@@ -35,7 +35,8 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.NavigableSet;
import java.util.SortedSet;
-import org.checkerframework.checker.nullness.compatqual.NullableDecl;
+import javax.annotation.CheckForNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* A {@link NavigableSet} whose contents will never change, with many other important properties
@@ -57,6 +58,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
// TODO(benyu): benchmark and optimize all creation paths, which are a mess now
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
+@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E>
implements NavigableSet<E>, SortedIterable<E> {
static <E> RegularImmutableSortedSet<E> emptySet(Comparator<? super E> comparator) {
@@ -507,16 +509,16 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
}
}
- int unsafeCompare(Object a, Object b) {
+ int unsafeCompare(Object a, @CheckForNull Object b) {
return unsafeCompare(comparator, a, b);
}
- static int unsafeCompare(Comparator<?> comparator, Object a, Object b) {
+ static int unsafeCompare(Comparator<?> comparator, Object a, @CheckForNull Object b) {
// Pretend the comparator can compare anything. If it turns out it can't
- // compare a and b, we should get a CCE on the subsequent line. Only methods
- // that are spec'd to throw CCE should call this.
- @SuppressWarnings("unchecked")
- Comparator<Object> unsafeComparator = (Comparator<Object>) comparator;
+ // compare a and b, we should get a CCE or NPE on the subsequent line. Only methods
+ // that are spec'd to throw CCE and NPE should call this.
+ @SuppressWarnings({"unchecked", "nullness"})
+ Comparator<@Nullable Object> unsafeComparator = (Comparator<@Nullable Object>) comparator;
return unsafeComparator.compare(a, b);
}
@@ -623,18 +625,21 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
/** @since 12.0 */
@GwtIncompatible // NavigableSet
@Override
+ @CheckForNull
public E lower(E e) {
return Iterators.getNext(headSet(e, false).descendingIterator(), null);
}
/** @since 12.0 */
@Override
+ @CheckForNull
public E floor(E e) {
return Iterators.getNext(headSet(e, true).descendingIterator(), null);
}
/** @since 12.0 */
@Override
+ @CheckForNull
public E ceiling(E e) {
return Iterables.getFirst(tailSet(e, true), null);
}
@@ -642,6 +647,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
/** @since 12.0 */
@GwtIncompatible // NavigableSet
@Override
+ @CheckForNull
public E higher(E e) {
return Iterables.getFirst(tailSet(e, false), null);
}
@@ -668,6 +674,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
@GwtIncompatible // NavigableSet
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final E pollFirst() {
throw new UnsupportedOperationException();
}
@@ -684,12 +691,14 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
@GwtIncompatible // NavigableSet
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final E pollLast() {
throw new UnsupportedOperationException();
}
@GwtIncompatible // NavigableSet
@LazyInit
+ @CheckForNull
transient ImmutableSortedSet<E> descendingSet;
/** @since 12.0 */
@@ -717,7 +726,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
public abstract UnmodifiableIterator<E> descendingIterator();
/** Returns the position of an element within the set, or -1 if not present. */
- abstract int indexOf(@NullableDecl Object target);
+ abstract int indexOf(@CheckForNull Object target);
/*
* This class is used to serialize all ImmutableSortedSet instances,
diff --git a/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java b/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java
index 9d2af2c18..ca19d79db 100644
--- a/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java
+++ b/android/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java
@@ -17,6 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.errorprone.annotations.DoNotCall;
/**
* "Overrides" the {@link ImmutableSet} static methods that lack {@link ImmutableSortedSet}
@@ -36,6 +37,7 @@ import com.google.common.annotations.GwtIncompatible;
* @author Chris Povirk
*/
@GwtIncompatible
+@ElementTypesAreNonnullByDefault
abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
/**
* Not supported. Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety,
@@ -45,6 +47,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety.
*/
+ @DoNotCall("Use naturalOrder")
@Deprecated
public static <E> ImmutableSortedSet.Builder<E> builder() {
throw new UnsupportedOperationException();
@@ -57,6 +60,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @throws UnsupportedOperationException always
* @deprecated Not supported by ImmutableSortedSet.
*/
+ @DoNotCall("Use naturalOrder (which does not accept an expected size)")
@Deprecated
public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) {
throw new UnsupportedOperationException();
@@ -71,6 +75,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable)}.</b>
*/
+ @DoNotCall("Pass a parameter of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E element) {
throw new UnsupportedOperationException();
@@ -85,6 +90,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable, Comparable)}.</b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2) {
throw new UnsupportedOperationException();
@@ -99,6 +105,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) {
throw new UnsupportedOperationException();
@@ -113,6 +120,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. </b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4) {
throw new UnsupportedOperationException();
@@ -127,6 +135,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of( Comparable, Comparable, Comparable, Comparable, Comparable)}. </b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5) {
throw new UnsupportedOperationException();
@@ -142,6 +151,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, Comparable,
* Comparable, Comparable...)}. </b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) {
throw new UnsupportedOperationException();
@@ -156,6 +166,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#copyOf(Comparable[])}.</b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> copyOf(E[] elements) {
throw new UnsupportedOperationException();
diff --git a/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
index d70d8fb74..dd987988b 100644
--- a/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
+++ b/android/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
@@ -27,7 +27,8 @@ import java.util.Comparator;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Set;
-import org.checkerframework.checker.nullness.compatqual.NullableDecl;
+import javax.annotation.CheckForNull;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* An immutable sorted set with one or more elements. TODO(jlevy): Consider separate class for a
@@ -38,6 +39,7 @@ import org.checkerframework.checker.nullness.compatqual.NullableDecl;
*/
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings({"serial", "rawtypes"})
+@ElementTypesAreNonnullByDefault
final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET =
new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural());
@@ -50,6 +52,8 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
+ @CheckForNull
+ @Nullable
Object[] internalArray() {
return elements.internalArray();
}
@@ -81,7 +85,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- public boolean contains(@NullableDecl Object o) {
+ public boolean contains(@CheckForNull Object o) {
try {
return o != null && unsafeBinarySearch(o) >= 0;
} catch (ClassCastException e) {
@@ -156,7 +160,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- public boolean equals(@NullableDecl Object object) {
+ public boolean equals(@CheckForNull Object object) {
if (object == this) {
return true;
}
@@ -209,24 +213,28 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
+ @CheckForNull
public E lower(E element) {
int index = headIndex(element, false) - 1;
return (index == -1) ? null : elements.get(index);
}
@Override
+ @CheckForNull
public E floor(E element) {
int index = headIndex(element, true) - 1;
return (index == -1) ? null : elements.get(index);
}
@Override
+ @CheckForNull
public E ceiling(E element) {
int index = tailIndex(element, true);
return (index == size()) ? null : elements.get(index);
}
@Override
+ @CheckForNull
public E higher(E element) {
int index = tailIndex(element, false);
return (index == size()) ? null : elements.get(index);
@@ -286,7 +294,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- int indexOf(@NullableDecl Object target) {
+ int indexOf(@CheckForNull Object target) {
if (target == null) {
return -1;
}
diff --git a/android/guava/src/com/google/common/collect/SortedIterable.java b/android/guava/src/com/google/common/collect/SortedIterable.java
index d46e8afcd..64ec08ef3 100644
--- a/android/guava/src/com/google/common/collect/SortedIterable.java
+++ b/android/guava/src/com/google/common/collect/SortedIterable.java
@@ -17,6 +17,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import java.util.Comparator;
import java.util.Iterator;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* An {@code Iterable} whose elements are sorted relative to a {@code Comparator}, typically
@@ -25,7 +26,8 @@ import java.util.Iterator;
* @author Louis Wasserman
*/
@GwtCompatible
-interface SortedIterable<T> extends Iterable<T> {
+@ElementTypesAreNonnullByDefault
+interface SortedIterable<T extends @Nullable Object> extends Iterable<T> {
/**
* Returns the {@code Comparator} by which the elements of this iterable are ordered, or {@code
* Ordering.natural()} if the elements are ordered by their natural ordering.
diff --git a/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java b/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java
index 1f45227cd..b4cd891b2 100644
--- a/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java
+++ b/guava-tests/test/com/google/common/collect/ImmutableSortedSetTest.java
@@ -965,7 +965,7 @@ public class ImmutableSortedSetTest extends AbstractImmutableSetTest {
assertTrue(Iterables.elementsEqual(LegacyComparable.VALUES_BACKWARD, set));
}
- @SuppressWarnings({"deprecation", "static-access"})
+ @SuppressWarnings({"deprecation", "static-access", "DoNotCall"})
public void testBuilderMethod() {
try {
ImmutableSortedSet.builder();
diff --git a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
index 635437837..88c7d6b5c 100644
--- a/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
+++ b/guava/src/com/google/common/collect/DescendingImmutableSortedSet.java
@@ -17,7 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import javax.annotation.CheckForNull;
/**
* Skeletal implementation of {@link ImmutableSortedSet#descendingSet()}.
@@ -25,6 +25,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* @author Louis Wasserman
*/
@GwtIncompatible
+@ElementTypesAreNonnullByDefault
final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
private final ImmutableSortedSet<E> forward;
@@ -34,7 +35,7 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- public boolean contains(@Nullable Object object) {
+ public boolean contains(@CheckForNull Object object) {
return forward.contains(object);
}
@@ -83,27 +84,31 @@ final class DescendingImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
+ @CheckForNull
public E lower(E element) {
return forward.higher(element);
}
@Override
+ @CheckForNull
public E floor(E element) {
return forward.ceiling(element);
}
@Override
+ @CheckForNull
public E ceiling(E element) {
return forward.floor(element);
}
@Override
+ @CheckForNull
public E higher(E element) {
return forward.lower(element);
}
@Override
- int indexOf(@Nullable Object target) {
+ int indexOf(@CheckForNull Object target) {
int index = forward.indexOf(target);
if (index == -1) {
return index;
diff --git a/guava/src/com/google/common/collect/ImmutableSortedAsList.java b/guava/src/com/google/common/collect/ImmutableSortedAsList.java
index 91f700ece..30f19a02e 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedAsList.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedAsList.java
@@ -18,7 +18,7 @@ import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.util.Comparator;
import java.util.Spliterator;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import javax.annotation.CheckForNull;
/**
* List returned by {@code ImmutableSortedSet.asList()} when the set isn't empty.
@@ -28,6 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
@GwtCompatible(emulated = true)
@SuppressWarnings("serial")
+@ElementTypesAreNonnullByDefault
final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E>
implements SortedIterable<E> {
ImmutableSortedAsList(ImmutableSortedSet<E> backingSet, ImmutableList<E> backingList) {
@@ -49,7 +50,7 @@ final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E>
@GwtIncompatible // ImmutableSortedSet.indexOf
// TODO(cpovirk): consider manual binary search under GWT to preserve O(log N) lookup
@Override
- public int indexOf(@Nullable Object target) {
+ public int indexOf(@CheckForNull Object target) {
int index = delegateCollection().indexOf(target);
// TODO(kevinb): reconsider if it's really worth making feeble attempts at
@@ -62,12 +63,12 @@ final class ImmutableSortedAsList<E> extends RegularImmutableAsList<E>
@GwtIncompatible // ImmutableSortedSet.indexOf
@Override
- public int lastIndexOf(@Nullable Object target) {
+ public int lastIndexOf(@CheckForNull Object target) {
return indexOf(target);
}
@Override
- public boolean contains(Object target) {
+ public boolean contains(@CheckForNull Object target) {
// Necessary for ISS's with comparators inconsistent with equals.
return indexOf(target) >= 0;
}
diff --git a/guava/src/com/google/common/collect/ImmutableSortedMap.java b/guava/src/com/google/common/collect/ImmutableSortedMap.java
index 74b4e2879..3c5c07265 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedMap.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedMap.java
@@ -60,6 +60,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
* @since 2.0 (implements {@code NavigableMap} since 12.0)
*/
@GwtCompatible(serializable = true, emulated = true)
+@ElementTypesAreNonnullByDefault
public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxverideShim<K, V>
implements NavigableMap<K, V> {
/**
@@ -74,10 +75,11 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
*
* @since 21.0
*/
- public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
- Comparator<? super K> comparator,
- Function<? super T, ? extends K> keyFunction,
- Function<? super T, ? extends V> valueFunction) {
+ public static <T extends @Nullable Object, K, V>
+ Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
+ Comparator<? super K> comparator,
+ Function<? super T, ? extends K> keyFunction,
+ Function<? super T, ? extends V> valueFunction) {
return CollectCollectors.toImmutableSortedMap(comparator, keyFunction, valueFunction);
}
@@ -92,11 +94,12 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
*
* @since 21.0
*/
- public static <T, K, V> Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
- Comparator<? super K> comparator,
- Function<? super T, ? extends K> keyFunction,
- Function<? super T, ? extends V> valueFunction,
- BinaryOperator<V> mergeFunction) {
+ public static <T extends @Nullable Object, K, V>
+ Collector<T, ?, ImmutableSortedMap<K, V>> toImmutableSortedMap(
+ Comparator<? super K> comparator,
+ Function<? super T, ? extends K> keyFunction,
+ Function<? super T, ? extends V> valueFunction,
+ BinaryOperator<V> mergeFunction) {
return CollectCollectors.toImmutableSortedMap(
comparator, keyFunction, valueFunction, mergeFunction);
}
@@ -558,7 +561,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
private final transient RegularImmutableSortedSet<K> keySet;
private final transient ImmutableList<V> valueList;
- private transient ImmutableSortedMap<K, V> descendingMap;
+ @CheckForNull private transient ImmutableSortedMap<K, V> descendingMap;
ImmutableSortedMap(RegularImmutableSortedSet<K> keySet, ImmutableList<V> valueList) {
this(keySet, valueList, null);
@@ -567,7 +570,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
ImmutableSortedMap(
RegularImmutableSortedSet<K> keySet,
ImmutableList<V> valueList,
- ImmutableSortedMap<K, V> descendingMap) {
+ @CheckForNull ImmutableSortedMap<K, V> descendingMap) {
this.keySet = keySet;
this.valueList = valueList;
this.descendingMap = descendingMap;
@@ -589,7 +592,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
@Override
@CheckForNull
- public V get(@Nullable Object key) {
+ public V get(@CheckForNull Object key) {
int index = keySet.indexOf(key);
return (index == -1) ? null : valueList.get(index);
}
@@ -880,6 +883,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final Entry<K, V> pollFirstEntry() {
throw new UnsupportedOperationException();
}
@@ -894,6 +898,7 @@ public final class ImmutableSortedMap<K, V> extends ImmutableSortedMapFauxveride
@Deprecated
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final Entry<K, V> pollLastEntry() {
throw new UnsupportedOperationException();
}
diff --git a/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java
index 87b83519e..9ccf02c65 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedMapFauxverideShim.java
@@ -17,9 +17,11 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.errorprone.annotations.DoNotCall;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.stream.Collector;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* "Overrides" the {@link ImmutableMap} static methods that lack {@link ImmutableSortedMap}
@@ -29,6 +31,7 @@ import java.util.stream.Collector;
* @author Chris Povirk
*/
@GwtIncompatible
+@ElementTypesAreNonnullByDefault
abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V> {
/**
* Not supported. Use {@link ImmutableSortedMap#toImmutableSortedMap}, which offers better
@@ -38,10 +41,12 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}.
*/
+ @DoNotCall("Use toImmutableSortedMap")
@Deprecated
- public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
- Function<? super T, ? extends K> keyFunction,
- Function<? super T, ? extends V> valueFunction) {
+ public static <T extends @Nullable Object, K, V>
+ Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
+ Function<? super T, ? extends K> keyFunction,
+ Function<? super T, ? extends V> valueFunction) {
throw new UnsupportedOperationException();
}
@@ -53,11 +58,13 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedMap#toImmutableSortedMap}.
*/
+ @DoNotCall("Use toImmutableSortedMap")
@Deprecated
- public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
- Function<? super T, ? extends K> keyFunction,
- Function<? super T, ? extends V> valueFunction,
- BinaryOperator<V> mergeFunction) {
+ public static <T extends @Nullable Object, K, V>
+ Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
+ Function<? super T, ? extends K> keyFunction,
+ Function<? super T, ? extends V> valueFunction,
+ BinaryOperator<V> mergeFunction) {
throw new UnsupportedOperationException();
}
@@ -69,6 +76,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedMap#naturalOrder}, which offers better type-safety.
*/
+ @DoNotCall("Use naturalOrder")
@Deprecated
public static <K, V> ImmutableSortedMap.Builder<K, V> builder() {
throw new UnsupportedOperationException();
@@ -80,6 +88,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @throws UnsupportedOperationException always
* @deprecated Not supported for ImmutableSortedMap.
*/
+ @DoNotCall("Use naturalOrder (which does not accept an expected size)")
@Deprecated
public static <K, V> ImmutableSortedMap.Builder<K, V> builderWithExpectedSize(int expectedSize) {
throw new UnsupportedOperationException();
@@ -94,6 +103,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @deprecated <b>Pass a key of type {@code Comparable} to use {@link
* ImmutableSortedMap#of(Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass a key of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1) {
throw new UnsupportedOperationException();
@@ -108,6 +118,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @deprecated <b>Pass keys of type {@code Comparable} to use {@link
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2) {
throw new UnsupportedOperationException();
@@ -122,6 +133,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* @deprecated <b>Pass keys of type {@code Comparable} to use {@link
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3) {
throw new UnsupportedOperationException();
@@ -137,6 +149,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object,
* Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) {
throw new UnsupportedOperationException();
@@ -152,6 +165,7 @@ abstract class ImmutableSortedMapFauxverideShim<K, V> extends ImmutableMap<K, V>
* ImmutableSortedMap#of(Comparable, Object, Comparable, Object, Comparable, Object,
* Comparable, Object, Comparable, Object)}.</b>
*/
+ @DoNotCall("Pass keys of type Comparable")
@Deprecated
public static <K, V> ImmutableSortedMap<K, V> of(
K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4, K k5, V v5) {
diff --git a/guava/src/com/google/common/collect/ImmutableSortedSet.java b/guava/src/com/google/common/collect/ImmutableSortedSet.java
index 7e74eecd4..8a7aec16c 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedSet.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedSet.java
@@ -39,6 +39,7 @@ import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.Consumer;
import java.util.stream.Collector;
+import javax.annotation.CheckForNull;
import org.checkerframework.checker.nullness.qual.Nullable;
/**
@@ -61,6 +62,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
// TODO(benyu): benchmark and optimize all creation paths, which are a mess now
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings("serial") // we're overriding default serialization
+@ElementTypesAreNonnullByDefault
public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxverideShim<E>
implements NavigableSet<E>, SortedIterable<E> {
static final int SPLITERATOR_CHARACTERISTICS =
@@ -575,16 +577,16 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
}
}
- int unsafeCompare(Object a, Object b) {
+ int unsafeCompare(Object a, @CheckForNull Object b) {
return unsafeCompare(comparator, a, b);
}
- static int unsafeCompare(Comparator<?> comparator, Object a, Object b) {
+ static int unsafeCompare(Comparator<?> comparator, Object a, @CheckForNull Object b) {
// Pretend the comparator can compare anything. If it turns out it can't
- // compare a and b, we should get a CCE on the subsequent line. Only methods
- // that are spec'd to throw CCE should call this.
- @SuppressWarnings("unchecked")
- Comparator<Object> unsafeComparator = (Comparator<Object>) comparator;
+ // compare a and b, we should get a CCE or NPE on the subsequent line. Only methods
+ // that are spec'd to throw CCE and NPE should call this.
+ @SuppressWarnings({"unchecked", "nullness"})
+ Comparator<@Nullable Object> unsafeComparator = (Comparator<@Nullable Object>) comparator;
return unsafeComparator.compare(a, b);
}
@@ -691,18 +693,21 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
/** @since 12.0 */
@GwtIncompatible // NavigableSet
@Override
+ @CheckForNull
public E lower(E e) {
return Iterators.getNext(headSet(e, false).descendingIterator(), null);
}
/** @since 12.0 */
@Override
+ @CheckForNull
public E floor(E e) {
return Iterators.getNext(headSet(e, true).descendingIterator(), null);
}
/** @since 12.0 */
@Override
+ @CheckForNull
public E ceiling(E e) {
return Iterables.getFirst(tailSet(e, true), null);
}
@@ -710,6 +715,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
/** @since 12.0 */
@GwtIncompatible // NavigableSet
@Override
+ @CheckForNull
public E higher(E e) {
return Iterables.getFirst(tailSet(e, false), null);
}
@@ -736,6 +742,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
@GwtIncompatible // NavigableSet
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final E pollFirst() {
throw new UnsupportedOperationException();
}
@@ -752,12 +759,14 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
@GwtIncompatible // NavigableSet
@Override
@DoNotCall("Always throws UnsupportedOperationException")
+ @CheckForNull
public final E pollLast() {
throw new UnsupportedOperationException();
}
@GwtIncompatible // NavigableSet
@LazyInit
+ @CheckForNull
transient ImmutableSortedSet<E> descendingSet;
/** @since 12.0 */
@@ -808,7 +817,7 @@ public abstract class ImmutableSortedSet<E> extends ImmutableSortedSetFauxveride
public abstract UnmodifiableIterator<E> descendingIterator();
/** Returns the position of an element within the set, or -1 if not present. */
- abstract int indexOf(@Nullable Object target);
+ abstract int indexOf(@CheckForNull Object target);
/*
* This class is used to serialize all ImmutableSortedSet instances,
diff --git a/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java b/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java
index 9a49fcbe2..d563506ee 100644
--- a/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java
+++ b/guava/src/com/google/common/collect/ImmutableSortedSetFauxverideShim.java
@@ -17,6 +17,7 @@
package com.google.common.collect;
import com.google.common.annotations.GwtIncompatible;
+import com.google.errorprone.annotations.DoNotCall;
import java.util.stream.Collector;
/**
@@ -37,6 +38,7 @@ import java.util.stream.Collector;
* @author Chris Povirk
*/
@GwtIncompatible
+@ElementTypesAreNonnullByDefault
abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
/**
* Not supported. Use {@link ImmutableSortedSet#toImmutableSortedSet} instead. This method exists
@@ -46,6 +48,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated Use {@link ImmutableSortedSet#toImmutableSortedSet}.
* @since 21.0
*/
+ @DoNotCall("Use toImmutableSortedSet")
@Deprecated
public static <E> Collector<E, ?, ImmutableSet<E>> toImmutableSet() {
throw new UnsupportedOperationException();
@@ -59,6 +62,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @throws UnsupportedOperationException always
* @deprecated Use {@link ImmutableSortedSet#naturalOrder}, which offers better type-safety.
*/
+ @DoNotCall("Use naturalOrder")
@Deprecated
public static <E> ImmutableSortedSet.Builder<E> builder() {
throw new UnsupportedOperationException();
@@ -71,6 +75,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @throws UnsupportedOperationException always
* @deprecated Not supported by ImmutableSortedSet.
*/
+ @DoNotCall("Use naturalOrder (which does not accept an expected size)")
@Deprecated
public static <E> ImmutableSortedSet.Builder<E> builderWithExpectedSize(int expectedSize) {
throw new UnsupportedOperationException();
@@ -85,6 +90,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass a parameter of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable)}.</b>
*/
+ @DoNotCall("Pass a parameter of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E element) {
throw new UnsupportedOperationException();
@@ -99,6 +105,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable, Comparable)}.</b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2) {
throw new UnsupportedOperationException();
@@ -113,6 +120,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable, Comparable, Comparable)}.</b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3) {
throw new UnsupportedOperationException();
@@ -127,6 +135,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable)}. </b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4) {
throw new UnsupportedOperationException();
@@ -141,6 +150,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass the parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#of( Comparable, Comparable, Comparable, Comparable, Comparable)}. </b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5) {
throw new UnsupportedOperationException();
@@ -156,6 +166,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* ImmutableSortedSet#of(Comparable, Comparable, Comparable, Comparable, Comparable,
* Comparable, Comparable...)}. </b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> of(E e1, E e2, E e3, E e4, E e5, E e6, E... remaining) {
throw new UnsupportedOperationException();
@@ -170,6 +181,7 @@ abstract class ImmutableSortedSetFauxverideShim<E> extends ImmutableSet<E> {
* @deprecated <b>Pass parameters of type {@code Comparable} to use {@link
* ImmutableSortedSet#copyOf(Comparable[])}.</b>
*/
+ @DoNotCall("Pass parameters of type Comparable")
@Deprecated
public static <E> ImmutableSortedSet<E> copyOf(E[] elements) {
throw new UnsupportedOperationException();
diff --git a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
index c659adad7..fcb683f56 100644
--- a/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
+++ b/guava/src/com/google/common/collect/RegularImmutableSortedSet.java
@@ -28,7 +28,7 @@ import java.util.NoSuchElementException;
import java.util.Set;
import java.util.Spliterator;
import java.util.function.Consumer;
-import org.checkerframework.checker.nullness.qual.Nullable;
+import javax.annotation.CheckForNull;
/**
* An immutable sorted set with one or more elements. TODO(jlevy): Consider separate class for a
@@ -39,6 +39,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*/
@GwtCompatible(serializable = true, emulated = true)
@SuppressWarnings({"serial", "rawtypes"})
+@ElementTypesAreNonnullByDefault
final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
static final RegularImmutableSortedSet<Comparable> NATURAL_EMPTY_SET =
new RegularImmutableSortedSet<>(ImmutableList.<Comparable>of(), Ordering.natural());
@@ -51,6 +52,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
+ @CheckForNull
Object[] internalArray() {
return elements.internalArray();
}
@@ -92,7 +94,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- public boolean contains(@Nullable Object o) {
+ public boolean contains(@CheckForNull Object o) {
try {
return o != null && unsafeBinarySearch(o) >= 0;
} catch (ClassCastException e) {
@@ -167,7 +169,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- public boolean equals(@Nullable Object object) {
+ public boolean equals(@CheckForNull Object object) {
if (object == this) {
return true;
}
@@ -220,24 +222,28 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
+ @CheckForNull
public E lower(E element) {
int index = headIndex(element, false) - 1;
return (index == -1) ? null : elements.get(index);
}
@Override
+ @CheckForNull
public E floor(E element) {
int index = headIndex(element, true) - 1;
return (index == -1) ? null : elements.get(index);
}
@Override
+ @CheckForNull
public E ceiling(E element) {
int index = tailIndex(element, true);
return (index == size()) ? null : elements.get(index);
}
@Override
+ @CheckForNull
public E higher(E element) {
int index = tailIndex(element, false);
return (index == size()) ? null : elements.get(index);
@@ -297,7 +303,7 @@ final class RegularImmutableSortedSet<E> extends ImmutableSortedSet<E> {
}
@Override
- int indexOf(@Nullable Object target) {
+ int indexOf(@CheckForNull Object target) {
if (target == null) {
return -1;
}
diff --git a/guava/src/com/google/common/collect/SortedIterable.java b/guava/src/com/google/common/collect/SortedIterable.java
index d46e8afcd..64ec08ef3 100644
--- a/guava/src/com/google/common/collect/SortedIterable.java
+++ b/guava/src/com/google/common/collect/SortedIterable.java
@@ -17,6 +17,7 @@ package com.google.common.collect;
import com.google.common.annotations.GwtCompatible;
import java.util.Comparator;
import java.util.Iterator;
+import org.checkerframework.checker.nullness.qual.Nullable;
/**
* An {@code Iterable} whose elements are sorted relative to a {@code Comparator}, typically
@@ -25,7 +26,8 @@ import java.util.Iterator;
* @author Louis Wasserman
*/
@GwtCompatible
-interface SortedIterable<T> extends Iterable<T> {
+@ElementTypesAreNonnullByDefault
+interface SortedIterable<T extends @Nullable Object> extends Iterable<T> {
/**
* Returns the {@code Comparator} by which the elements of this iterable are ordered, or {@code
* Ordering.natural()} if the elements are ordered by their natural ordering.